Skip to content

Commit

Permalink
Issue 610: Non-configurable 'CasProfile#' username prefix in serviceR…
Browse files Browse the repository at this point in the history
…esponse / CAS to CAS
  • Loading branch information
leleuj committed Sep 1, 2014
1 parent f376973 commit 94b7073
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Expand Up @@ -58,6 +58,11 @@ public final class ClientAuthenticationHandler extends AbstractPreAndPostProcess
@NotNull
private final Clients clients;

/**
* Whether to use the typed identifier (by default) or just the identifier.
*/
private boolean useTypedId = true;

/**
* Define the clients.
*
Expand Down Expand Up @@ -95,7 +100,12 @@ protected HandlerResult doAuthentication(final Credential credential) throws Gen
logger.debug("userProfile : {}", userProfile);

if (userProfile != null) {
final String id = userProfile.getTypedId();
final String id;
if (useTypedId) {
id = userProfile.getTypedId();
} else {
id = userProfile.getId();
}
if (StringUtils.isNotBlank(id)) {
clientCredentials.setUserProfile(userProfile);
return new HandlerResult(
Expand All @@ -107,4 +117,12 @@ protected HandlerResult doAuthentication(final Credential credential) throws Gen

throw new FailedLoginException("Provider did not produce profile for " + clientCredentials);
}

public boolean isUseTypedId() {
return useTypedId;
}

public void setUseTypedId(final boolean useTypedId) {
this.useTypedId = useTypedId;
}
}
Expand Up @@ -77,6 +77,17 @@ public void testOk() throws GeneralSecurityException, PreventedException {
assertEquals(FacebookProfile.class.getSimpleName() + "#" + ID, principal.getId());
}

@Test
public void testOkWithSimpleIdentifier() throws GeneralSecurityException, PreventedException {
this.handler.setUseTypedId(false);
final FacebookProfile facebookProfile = new FacebookProfile();
facebookProfile.setId(ID);
this.fbClient.setFacebookProfile(facebookProfile);
final HandlerResult result = this.handler.authenticate(this.clientCredential);
final Principal principal = result.getPrincipal();
assertEquals(ID, principal.getId());
}

@Test(expected = FailedLoginException.class)
public void testNoProfile() throws GeneralSecurityException, PreventedException {
this.handler.authenticate(this.clientCredential);
Expand Down

0 comments on commit 94b7073

Please sign in to comment.