use of com.iplanet.sso.SSOTokenID in project OpenAM by OpenRock.
the class SSOProviderImpl method refreshSession.
/**
* Refresh the Session corresponding to the single sign on token from the
* Session Server.
*
* @param token single sign on token for which session need to be refreshed.
* @param possiblyResetIdleTime if true, the idle time may be reset, if false it will never be.
* @throws SSOException if the session cannot be refreshed.
*/
@Override
public void refreshSession(SSOToken token, boolean possiblyResetIdleTime) throws SSOException {
try {
SSOTokenID tokenId = token.getTokenID();
SessionID sid = new SessionID(tokenId.toString());
Session session = sessionCache.getSession(sid);
session.refresh(possiblyResetIdleTime);
} catch (Exception e) {
debug.error("Error in refreshing the session from sessions server");
throw new SSOException(e);
}
}
use of com.iplanet.sso.SSOTokenID in project OpenAM by OpenRock.
the class SessionResourceTest method actionCollectionShouldValidateSessionAndReturnTrueWhenSSOTokenValid.
@Test
public void actionCollectionShouldValidateSessionAndReturnTrueWhenSSOTokenValid() throws SSOException {
//Given
cookieResponse = "SSO_TOKEN_ID";
final SSOTokenContext tokenContext = mock(SSOTokenContext.class);
final Context context = ClientContext.newInternalClientContext(tokenContext);
final ActionRequest request = mock(ActionRequest.class);
final SSOToken ssoToken = mock(SSOToken.class);
final SSOTokenID ssoTokenId = mock(SSOTokenID.class);
given(request.getAction()).willReturn(VALIDATE_ACTION_ID);
given(tokenContext.getCallerSSOToken()).willReturn(ssoToken);
given(ssoTokenManager.isValidToken(ssoToken)).willReturn(true);
given(ssoToken.getTokenID()).willReturn(ssoTokenId);
given(ssoTokenId.toString()).willReturn("SSO_TOKEN_ID");
given(ssoTokenManager.createSSOToken(ssoTokenId.toString())).willReturn(ssoToken);
//When
Promise<ActionResponse, ResourceException> promise = sessionResource.actionCollection(context, request);
//Then
assertThat(promise).succeeded().withContent().booleanAt("valid").isTrue();
assertThat(promise).succeeded().withContent().stringAt("uid").isEqualTo("demo");
assertThat(promise).succeeded().withContent().stringAt("realm").isEqualTo("/");
}
use of com.iplanet.sso.SSOTokenID in project OpenAM by OpenRock.
the class SessionResourceTest method actionCollectionShouldLogoutSessionAndReturnEmptyJsonObjectWhenSSOTokenValid.
@Test
public void actionCollectionShouldLogoutSessionAndReturnEmptyJsonObjectWhenSSOTokenValid() throws SSOException {
//Given
cookieResponse = "SSO_TOKEN_ID";
final AttributesContext attrContext = new AttributesContext(new SessionContext(new RootContext(), mock(Session.class)));
final AdviceContext adviceContext = new AdviceContext(attrContext, Collections.<String>emptySet());
final SecurityContext securityContext = new SecurityContext(adviceContext, null, null);
final Context context = ClientContext.newInternalClientContext(new SSOTokenContext(mock(Debug.class), null, securityContext));
final ActionRequest request = mock(ActionRequest.class);
final SSOTokenID ssoTokenId = mock(SSOTokenID.class);
given(request.getAction()).willReturn(LOGOUT_ACTION_ID);
given(authUtilsWrapper.logout(ssoTokenId.toString(), null, null)).willReturn(true);
//When
Promise<ActionResponse, ResourceException> promise = sessionResource.actionCollection(context, request);
//Then
assertThat(promise).succeeded().withContent().stringAt("result").isEqualTo("Successfully logged out");
}
use of com.iplanet.sso.SSOTokenID in project OpenAM by OpenRock.
the class PersistentCookieAuthModuleTest method shouldStoreClientIPOnLoginSuccess.
@Test
public void shouldStoreClientIPOnLoginSuccess() throws AuthenticationException, SSOException {
//Given
MessageInfo messageInfo = mock(MessageInfo.class);
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
SSOToken ssoToken = mock(SSOToken.class);
Map<String, Object> messageInfoMap = new HashMap<String, Object>();
Map<String, Object> contextMap = new HashMap<String, Object>();
Principal principal = mock(Principal.class);
SSOTokenID ssoTokenID = mock(SSOTokenID.class);
given(messageInfo.getMap()).willReturn(messageInfoMap);
messageInfoMap.put(AuthenticationFramework.ATTRIBUTE_AUTH_CONTEXT, contextMap);
given(ssoToken.getPrincipal()).willReturn(principal);
given(ssoToken.getTokenID()).willReturn(ssoTokenID);
given(request.getRemoteAddr()).willReturn("CLIENT_IP");
//When
persistentCookieAuthModule.onLoginSuccess(messageInfo, Collections.emptyMap(), request, response, ssoToken);
//Then
assertEquals(contextMap.get("openam.clientip"), "CLIENT_IP");
}
use of com.iplanet.sso.SSOTokenID in project OpenAM by OpenRock.
the class PersistentCookieAuthModuleTest method shouldCallOnLoginSuccessWhenJwtNotValidated.
@Test
public void shouldCallOnLoginSuccessWhenJwtNotValidated() throws AuthenticationException, SSOException {
//Given
persistentCookieAuthModule = new PersistentCookieAuthModule(new ServletJwtSessionModule(), amKeyProvider, coreWrapper) {
@Override
protected String getKeyAlias(String orgName) throws SSOException, SMSException {
return "KEY_ALIAS";
}
};
MessageInfo messageInfo = mock(MessageInfo.class);
Map requestParamsMap = new HashMap();
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
SSOToken ssoToken = mock(SSOToken.class);
Map<String, Object> map = new HashMap<String, Object>();
given(messageInfo.getMap()).willReturn(map);
Principal principal = mock(Principal.class);
given(principal.getName()).willReturn("PRINCIPAL_NAME");
SSOTokenID ssoTokenId = mock(SSOTokenID.class);
given(ssoTokenId.toString()).willReturn("SSO_TOKEN_ID");
given(ssoToken.getPrincipal()).willReturn(principal);
given(ssoToken.getAuthType()).willReturn("AUTH_TYPE");
given(ssoToken.getTokenID()).willReturn(ssoTokenId);
given(ssoToken.getProperty("Organization")).willReturn("ORGANISATION");
//When
persistentCookieAuthModule.onLoginSuccess(messageInfo, requestParamsMap, request, response, ssoToken);
//Then
assertEquals(map.size(), 1);
Map<String, Object> contextMap = (Map<String, Object>) map.get("org.forgerock.authentication.context");
assertEquals(contextMap.get("openam.usr"), "PRINCIPAL_NAME");
assertEquals(contextMap.get("openam.aty"), "AUTH_TYPE");
assertEquals(contextMap.get("openam.sid"), "SSO_TOKEN_ID");
assertEquals(contextMap.get("openam.rlm"), "ORGANISATION");
assertEquals(contextMap.get("openam.clientip"), null);
}
Aggregations