use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class SessionResourceTest method setUp.
@BeforeMethod
public void setUp() throws IdRepoException, SSOException {
SessionQueryManager sessionQueryManager = mock(SessionQueryManager.class);
ssoTokenManager = mock(SSOTokenManager.class);
authUtilsWrapper = mock(AuthUtilsWrapper.class);
propertyWhitelist = mock(SessionPropertyWhitelist.class);
headerResponse = null;
urlResponse = null;
cookieResponse = null;
given(mockContext.getCallerSSOToken()).willReturn(ssoToken);
realmContext = new RealmContext(mockContext);
amIdentity = new AMIdentity(DN.valueOf("id=demo,dc=example,dc=com"), null);
configureWhitelist();
sessionResource = new SessionResource(sessionQueryManager, ssoTokenManager, authUtilsWrapper, propertyWhitelist) {
@Override
AMIdentity getIdentity(SSOToken ssoToken) throws IdRepoException, SSOException {
return amIdentity;
}
@Override
String convertDNToRealm(String dn) {
return "/";
}
@Override
protected String getTokenIdFromHeader(Context context, String cookieName) {
return headerResponse;
}
@Override
protected String getTokenIdFromUrlParam(ActionRequest request) {
return urlResponse;
}
@Override
protected String getTokenIdFromCookie(Context context, String cookieName) {
return cookieResponse;
}
};
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class SessionResourceTest method actionCollectionShouldFailToValidateSessionWhenSSOTokenIdNotSet.
@Test
public void actionCollectionShouldFailToValidateSessionWhenSSOTokenIdNotSet() {
//Given
final SSOTokenContext tokenContext = mock(SSOTokenContext.class);
final Context context = ClientContext.newInternalClientContext(tokenContext);
final ActionRequest request = mock(ActionRequest.class);
given(request.getAction()).willReturn(VALIDATE_ACTION_ID);
//When
Promise<ActionResponse, ResourceException> promise = sessionResource.actionCollection(context, request);
//Then
assertThat(promise).failedWithException().isInstanceOf(BadRequestException.class);
}
use of org.forgerock.services.context.Context 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 org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class SessionResourceTest method actionInstanceShouldBeActiveWhenSSOTokenValid.
@Test
public void actionInstanceShouldBeActiveWhenSSOTokenValid() throws SSOException {
//Given
final Context context = mock(Context.class);
final String resourceId = "SSO_TOKEN_ID";
final ActionRequest request = mock(ActionRequest.class);
final SSOToken ssoToken = mock(SSOToken.class);
given(request.getAction()).willReturn(IS_ACTIVE_ACTION_ID);
given(ssoTokenManager.retrieveValidTokenWithoutResettingIdleTime("SSO_TOKEN_ID")).willReturn(ssoToken);
given(ssoTokenManager.isValidToken(ssoToken, false)).willReturn(true);
//When
Promise<ActionResponse, ResourceException> promise = sessionResource.actionInstance(context, resourceId, request);
//Then
assertThat(promise).succeeded().withContent().booleanAt("active").isTrue();
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class SessionResourceTest method actionInstanceShouldGiveIdleTimeWhenSSOTokenValid.
@Test
public void actionInstanceShouldGiveIdleTimeWhenSSOTokenValid() throws SSOException {
final int IDLE = 50;
//Given
final Context context = mock(Context.class);
final String resourceId = "SSO_TOKEN_ID";
final ActionRequest request = mock(ActionRequest.class);
final SSOToken ssoToken = mock(SSOToken.class);
given(request.getAction()).willReturn(GET_IDLE_ACTION_ID);
given(ssoTokenManager.retrieveValidTokenWithoutResettingIdleTime("SSO_TOKEN_ID")).willReturn(ssoToken);
given(ssoTokenManager.isValidToken(ssoToken, false)).willReturn(true);
given(ssoToken.getIdleTime()).willReturn((long) IDLE);
//When
Promise<ActionResponse, ResourceException> promise = sessionResource.actionInstance(context, resourceId, request);
//Then
assertThat(promise).succeeded().withContent().integerAt("idletime").isEqualTo(IDLE);
}
Aggregations