use of com.iplanet.sso.SSOTokenID in project OpenAM by OpenRock.
the class PolicySSOTokenListener method ssoTokenChanged.
/**
* Callback for SSOTokenListener
* Cleans up the policy decision cache, subject evaluation cache ,
* user role cache of LDAPRoles and user <code>nsRole</code> attribute
* values cache upon user's token expiration.
* @param evt <code>SSOTokenEvent</code> with details on the change
* which happened to the <code>SSOToken</code>
*/
public void ssoTokenChanged(SSOTokenEvent evt) {
try {
SSOTokenID tokenId = evt.getToken().getTokenID();
String tokenIdStr = tokenId.toString();
if (tokenIdStr == null) {
debug.error("PolicySSOTokenListener: " + "token id string is null");
return;
}
// update the policy decision cache
synchronized (PolicyEvaluator.policyResultsCache) {
if (!(resultsCache.isEmpty())) {
Set svcInCache = resultsCache.keySet();
Iterator svcInCacheIter = svcInCache.iterator();
while (svcInCacheIter.hasNext()) {
String svcName = (String) svcInCacheIter.next();
Map svcValue = (Map) resultsCache.get(svcName);
if ((svcValue != null) && (!(svcValue.isEmpty()))) {
Set rscInCache = svcValue.keySet();
Iterator rscInCacheIter = rscInCache.iterator();
while (rscInCacheIter.hasNext()) {
String rscName = (String) rscInCacheIter.next();
Map rscValues = (Map) svcValue.get(rscName);
if ((rscValues != null) && (!(rscValues.isEmpty()))) {
if ((rscValues.remove(tokenIdStr)) != null) {
if (debug.messageEnabled()) {
debug.message("cleaned up the " + "policy results for an " + "expired token " + tokenIdStr);
}
}
}
}
}
}
}
}
//clean up userNSRoleCache
PolicyEvaluator.userNSRoleCache.remove(tokenIdStr);
if (debug.messageEnabled()) {
debug.message("PolicySSOTokenListener.ssoTokenChanged():" + "cleaned up user nsRole cache for an expired token " + tokenIdStr);
}
// clean up the subject evaluation cache
SubjectEvaluationCache.subjectEvaluationCache.remove(tokenIdStr);
if (debug.messageEnabled()) {
debug.message("PolicySSOTokenListener.ssoTokenChanged():" + "cleaned up subject evaluation cache for an expired token" + " " + tokenIdStr);
}
// clean up the user role cache from LDAPRoles
LDAPRoles.userLDAPRoleCache.remove(tokenIdStr);
if (debug.messageEnabled()) {
debug.message("PolicySSOTokenListener.ssoTokenChanged()cleaned " + "up user role cache of LDAPRoles " + "for an expired token " + tokenIdStr);
}
// clean up subject result cache inside Policy objects
if (evt.getType() == SSOTokenEvent.SSO_TOKEN_PROPERTY_CHANGED) {
if (debug.messageEnabled()) {
debug.message("PolicySSOTokenListener.ssoTokenChanged():" + " receieved sso token property change notification, " + " clearing cached subject result cache " + " for tokenIdStr XXXXXX");
}
PolicyCache.getInstance().clearSubjectResultCache(tokenIdStr);
}
PolicyEvaluator.ssoListenerRegistry.remove(tokenIdStr);
} catch (Exception e) {
debug.error("PolicySSOTokenListener.ssoTokenChanged():policy sso " + "token listener", 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