use of com.sun.identity.authentication.spi.AuthenticationException in project OpenAM by OpenRock.
the class JaspiAuthModuleWrapperTest method setUp.
@BeforeMethod
public void setUp() {
amLoginModuleBinder = mock(AMLoginModuleBinder.class);
serverAuthModule = mock(ServerAuthModule.class);
jaspiAuthModuleWrapper = new JaspiAuthModuleWrapper<ServerAuthModule>(serverAuthModule, "amAuthPersistentCookie") {
@Override
protected Map<String, Object> initialize(Subject subject, Map sharedState, Map options) {
return config;
}
@Override
protected boolean process(MessageInfo messageInfo, Subject clientSubject, Callback[] callbacks) throws LoginException {
processMethodCalled = true;
return true;
}
@Override
protected Map<String, Object> initialize(Map requestParamsMap, HttpServletRequest request, HttpServletResponse response, SSOToken ssoToken) throws AuthenticationException {
return config;
}
@Override
protected void onLoginSuccess(MessageInfo messageInfo, Map requestParamsMap, HttpServletRequest request, HttpServletResponse response, SSOToken ssoToken) throws AuthenticationException {
onLoginSuccessMethodCalled = true;
}
@Override
public Principal getPrincipal() {
return null;
}
};
jaspiAuthModuleWrapper.setAMLoginModule(amLoginModuleBinder);
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
given(amLoginModuleBinder.getHttpServletRequest()).willReturn(request);
given(amLoginModuleBinder.getHttpServletResponse()).willReturn(response);
}
use of com.sun.identity.authentication.spi.AuthenticationException in project OpenAM by OpenRock.
the class Adaptive method onLoginSuccess.
public void onLoginSuccess(Map requestParamsMap, HttpServletRequest request, HttpServletResponse response, SSOToken token) throws AuthenticationException {
Map<String, String> m = new HashMap<String, String>();
Map<String, Set> attrMap = new HashMap<String, Set>();
if (debug.messageEnabled()) {
debug.message("{} executing PostProcessClass", ADAPTIVE);
}
try {
String s = token.getProperty("ADAPTIVE");
if (s != null && !s.isEmpty()) {
stringToMap(s, m);
token.setProperty("ADAPTIVE", "");
}
if (m.containsKey("IPSAVE")) {
String value = m.get("IPSAVE");
String name = m.get("IPAttr");
Set<String> vals = new HashSet<String>();
vals.add(value);
attrMap.put(name, vals);
}
// Now we save the attribs, since we can do it in one shot
if (!attrMap.isEmpty()) {
try {
AMIdentity id = IdUtils.getIdentity(AccessController.doPrivileged(AdminTokenAction.getInstance()), token.getProperty(Constants.UNIVERSAL_IDENTIFIER));
id.setAttributes(attrMap);
id.store();
} catch (Exception e) {
debug.error("{}.getIdentity : Unable to save Attribute : {}", ADAPTIVE, attrMap, e);
}
}
// 1 year, configurable?
int autoLoginExpire = (60 * 60 * 24) * 365;
final Set<String> cookieDomains = AuthUtils.getCookieDomainsForRequest(request);
if (m.containsKey("LOGINNAME")) {
String value = m.get("LOGINVALUE");
String name = m.get("LOGINNAME");
addCookieToResponse(response, cookieDomains, name, value, autoLoginExpire);
}
if (m.containsKey("COOKIENAME")) {
String name = m.get("COOKIENAME");
String value = m.get("COOKIEVALUE");
addCookieToResponse(response, cookieDomains, name, value, autoLoginExpire);
}
if (m.containsKey("DEVICENAME")) {
String name = m.get("DEVICENAME");
String value = m.get("DEVICEVALUE");
addCookieToResponse(response, cookieDomains, name, value, autoLoginExpire);
}
} catch (Exception e) {
if (debug.messageEnabled()) {
debug.message("{}.getIdentity : Unable to Retrieve PostAuthN Params", ADAPTIVE, e);
}
}
}
use of com.sun.identity.authentication.spi.AuthenticationException in project OpenAM by OpenRock.
the class JaspiAuthModuleWrapperTest method shouldCallOnLoginSuccessWhenSecureResponseReturnsSendFailure.
@Test
public void shouldCallOnLoginSuccessWhenSecureResponseReturnsSendFailure() 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.SEND_FAILURE);
//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 JaspiAuthModuleWrapperTest method shouldCallOnLoginSuccessWhenSecureResponseReturnsSendContinue.
@Test
public void shouldCallOnLoginSuccessWhenSecureResponseReturnsSendContinue() 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.SEND_CONTINUE);
//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 JaspiAuthModuleWrapperTest method shouldCallOnLoginSuccessAndThrowAuthenticationExceptionWhenAuthExceptionCaught.
@Test
public void shouldCallOnLoginSuccessAndThrowAuthenticationExceptionWhenAuthExceptionCaught() throws AuthenticationException, AuthException {
//Given
Map requestParamsMap = new HashMap();
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
SSOToken ssoToken = mock(SSOToken.class);
doThrow(AuthException.class).when(serverAuthModule).initialize(Matchers.<MessagePolicy>anyObject(), (MessagePolicy) isNull(), Matchers.<CallbackHandler>anyObject(), eq(config));
//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));
verify(serverAuthModule, never()).secureResponse(Matchers.<MessageInfo>anyObject(), (Subject) isNull());
assertTrue(exceptionCaught);
assertEquals(exception.getErrorCode(), "authFailed");
}
Aggregations