use of org.forgerock.openam.core.rest.session.SessionResource 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.openam.core.rest.session.SessionResource in project OpenAM by OpenRock.
the class SessionResourceTest method shouldUseSessionQueryManagerForAllSessionsQuery.
@Test
public void shouldUseSessionQueryManagerForAllSessionsQuery() {
// Given
String badger = "badger";
String weasel = "weasel";
SessionQueryManager mockManager = mock(SessionQueryManager.class);
QueryRequest request = mock(QueryRequest.class);
given(request.getQueryId()).willReturn(SessionResource.KEYWORD_ALL);
QueryResourceHandler handler = mock(QueryResourceHandler.class);
SessionResource resource = spy(new SessionResource(mockManager, null, null, null));
List<String> list = Arrays.asList(badger, weasel);
doReturn(list).when(resource).getAllServerIds();
// When
resource.queryCollection(null, request, handler);
// Then
List<String> result = Arrays.asList(badger, weasel);
verify(mockManager, times(1)).getAllSessions(result);
}
use of org.forgerock.openam.core.rest.session.SessionResource in project OpenAM by OpenRock.
the class SessionResourceTest method shouldQueryNamedServerInServerMode.
@Test
public void shouldQueryNamedServerInServerMode() {
// Given
String badger = "badger";
SessionQueryManager mockManager = mock(SessionQueryManager.class);
QueryResourceHandler mockHandler = mock(QueryResourceHandler.class);
QueryRequest request = mock(QueryRequest.class);
given(request.getQueryId()).willReturn(badger);
SessionResource resource = spy(new SessionResource(mockManager, null, null, null));
// When
resource.queryCollection(null, request, mockHandler);
// Then
verify(resource, times(0)).getAllServerIds();
List<String> result = Collections.singletonList(badger);
verify(mockManager, times(1)).getAllSessions(result);
}
Aggregations