use of org.forgerock.openam.cts.api.tokens.Token in project OpenAM by OpenRock.
the class TokenDataStoreTest method testQueryError.
@Test(expectedExceptions = ServerException.class)
public void testQueryError() throws Exception {
// Given
QueryFilter<String> query = QueryFilter.alwaysTrue();
TokenFilter tokenFilter = mock(TokenFilter.class);
when(adapter.toTokenQuery(query)).thenReturn(tokenFilter);
final Token token1 = new Token("123", TokenType.GENERIC);
final Token token2 = new Token("456", TokenType.GENERIC);
Object o1 = new Object();
Object o2 = new Object();
when(adapter.fromToken(token1)).thenReturn(o1);
when(adapter.fromToken(token2)).thenReturn(o2);
final Task task = mock(Task.class);
when(taskFactory.query(any(TokenFilter.class), any(ResultHandler.class))).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
((ResultHandler) invocation.getArguments()[1]).processError(new Exception());
return task;
}
});
// When
store.query(query);
// Then - exception;
}
use of org.forgerock.openam.cts.api.tokens.Token in project OpenAM by OpenRock.
the class TokenDataStoreTest method testQuery.
@Test
public void testQuery() throws Exception {
// Given
QueryFilter<String> query = QueryFilter.alwaysTrue();
TokenFilter tokenFilter = mock(TokenFilter.class);
when(adapter.toTokenQuery(query)).thenReturn(tokenFilter);
final Token token1 = new Token("123", TokenType.GENERIC);
final Token token2 = new Token("456", TokenType.GENERIC);
Object o1 = new Object();
Object o2 = new Object();
when(adapter.fromToken(token1)).thenReturn(o1);
when(adapter.fromToken(token2)).thenReturn(o2);
final Task task = mock(Task.class);
when(taskFactory.query(any(TokenFilter.class), any(ResultHandler.class))).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
((ResultHandler) invocation.getArguments()[1]).processResults(asSet(token1, token2));
return task;
}
});
// When
Set<Object> result = store.query(query);
// Then
verify(taskFactory).query(eq(tokenFilter), any(ResultHandler.class));
verify(taskExecutor).execute(null, task);
assertThat(result).containsOnly(o1, o2);
}
use of org.forgerock.openam.cts.api.tokens.Token in project OpenAM by OpenRock.
the class CTSSessionBlacklistTest method shouldReturnTrueForBlacklistedSessions.
@Test
public void shouldReturnTrueForBlacklistedSessions() throws Exception {
// Given
given(mockCts.read(SID)).willReturn(new Token(SID, TokenType.SESSION_BLACKLIST));
// When
final boolean result = testBlacklist.isBlacklisted(mockSession);
// Then
assertThat(result).isTrue();
}
use of org.forgerock.openam.cts.api.tokens.Token in project OpenAM by OpenRock.
the class TokenDataStoreTest method testUpdateNotExisting.
@Test(expectedExceptions = NotFoundException.class)
public void testUpdateNotExisting() throws Exception {
// Given
final Token token = new Token("123", TokenType.GENERIC);
final Task readTask = mock(Task.class);
when(adapter.toToken(anyObject())).thenReturn(token);
when(taskFactory.read(eq("123"), any(ResultHandler.class))).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
((ResultHandler) invocation.getArguments()[1]).processResults(null);
return readTask;
}
});
// When
store.update(new Object());
// Then - exception
}
use of org.forgerock.openam.cts.api.tokens.Token in project OpenAM by OpenRock.
the class CoreTokenResource method readInstance.
/**
* Read the token based on its Token ID.
*
* If successful, the Token will be returned to the caller in serialised JSON format.
*
* @param serverContext Required context.
* @param tokenId The TokenID of the Token to read.
* @param readRequest Not used.
*/
public Promise<ResourceResponse, ResourceException> readInstance(Context serverContext, String tokenId, ReadRequest readRequest) {
String principal = PrincipalRestUtils.getPrincipalNameFromServerContext(serverContext);
try {
Token token = store.read(tokenId);
if (token == null) {
error("READ by {0}: No token resource to read with ID: {1}", principal, tokenId);
return generateNotFoundException(tokenId).asPromise();
}
String json = serialisation.serialise(token);
ResourceResponse response = newResourceResponse(tokenId, String.valueOf(System.currentTimeMillis()), JsonValueBuilder.toJsonValue(json));
debug("READ by {0}: Read token resource with ID: {1}", principal, tokenId);
return newResultPromise(response);
} catch (CoreTokenException e) {
error(e, "READ by {0}: Error reading token resource with ID: {1}", principal, tokenId);
return generateException(e).asPromise();
}
}
Aggregations