use of com.sun.identity.authentication.spi.AuthenticationException in project OpenAM by OpenRock.
the class JaspiAuthModuleWrapperTest method shouldCallOnLoginSuccessWhenSecureResponseReturnsElse.
@Test
public void shouldCallOnLoginSuccessWhenSecureResponseReturnsElse() throws AuthenticationException, AuthException {
//Given
Map requestParamsMap = new HashMap();
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
SSOToken ssoToken = mock(SSOToken.class);
given(serverAuthModule.secureResponse(Matchers.<MessageInfo>anyObject(), (Subject) isNull())).willReturn(AuthStatus.SUCCESS);
//When
boolean exceptionCaught = false;
AuthenticationException exception = null;
try {
jaspiAuthModuleWrapper.onLoginSuccess(requestParamsMap, request, response, ssoToken);
} catch (AuthenticationException e) {
exceptionCaught = true;
exception = e;
}
//Then
verify(serverAuthModule).initialize(Matchers.<MessagePolicy>anyObject(), (MessagePolicy) isNull(), Matchers.<CallbackHandler>anyObject(), eq(config));
assertTrue(onLoginSuccessMethodCalled);
verify(serverAuthModule).secureResponse(Matchers.<MessageInfo>anyObject(), (Subject) isNull());
assertTrue(exceptionCaught);
assertEquals(exception.getErrorCode(), "authFailed");
}
use of com.sun.identity.authentication.spi.AuthenticationException in project OpenAM by OpenRock.
the class SAML2 method linkAccount.
/**
* Links SAML2 accounts once all local auth steps have completed and we have a local principalId,
* sets the local principal to a new SAML2Pricipal with that ID.
*/
private void linkAccount(final String principalId, final NameID nameId) throws SAML2MetaException, AuthenticationException {
final String spEntityId = metaManager.getEntityByMetaAlias(metaAlias);
try {
NameIDInfo info = new NameIDInfo(spEntityId, entityName, nameId, SAML2Constants.SP_ROLE, false);
DEBUG.message("SAML2 :: Local User {} Linked to Federation Account - {}", principalId, nameId.getValue());
if (shouldPersistNameID(spEntityId)) {
AccountUtils.setAccountFederation(info, principalId);
}
principal = new SAML2Principal(principalId);
} catch (SAML2Exception e) {
// exception logged later
throw new AuthenticationException(BUNDLE_NAME, "localLinkError", new Object[0]);
}
}
Aggregations