use of org.forgerock.openam.cts.exceptions.CoreTokenException in project OpenAM by OpenRock.
the class CTSSessionBlacklistTest method shouldConvertCtsReadExceptions.
@Test(expectedExceptions = SessionException.class)
public void shouldConvertCtsReadExceptions() throws Exception {
// Given
given(mockCts.read(SID)).willThrow(new CoreTokenException("test"));
// When
testBlacklist.isBlacklisted(mockSession);
// Then - exception
}
use of org.forgerock.openam.cts.exceptions.CoreTokenException in project OpenAM by OpenRock.
the class CTSSessionBlacklistTest method shouldConvertCtsExceptions.
@Test(expectedExceptions = SessionException.class)
public void shouldConvertCtsExceptions() throws Exception {
// Given
given(mockSession.getTimeLeft()).willReturn(3l);
willThrow(new CoreTokenException("test")).given(mockCts).create(any(Token.class));
// When
testBlacklist.blacklist(mockSession);
// Then - exception
}
use of org.forgerock.openam.cts.exceptions.CoreTokenException 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();
}
}
use of org.forgerock.openam.cts.exceptions.CoreTokenException in project OpenAM by OpenRock.
the class CoreTokenResource method deleteInstance.
/**
* Delete the instance referred to by its Resource path.
*
* @param serverContext Required context.
* @param tokenId The TokenID of the token to delete.
* @param deleteRequest Not used.
*/
public Promise<ResourceResponse, ResourceException> deleteInstance(Context serverContext, String tokenId, DeleteRequest deleteRequest) {
String principal = PrincipalRestUtils.getPrincipalNameFromServerContext(serverContext);
try {
store.deleteAsync(tokenId);
Map<String, String> result = new HashMap<String, String>();
result.put(TOKEN_ID, tokenId);
ResourceResponse resource = newResourceResponse(tokenId, String.valueOf(System.currentTimeMillis()), new JsonValue(result));
debug("DELETE by {0}: Deleted token resource with ID: {1}", principal, tokenId);
return newResultPromise(resource);
} catch (CoreTokenException e) {
error(e, "DELETE by {0}: Error deleting token resource with ID: {1}", principal, tokenId);
return generateException(e).asPromise();
}
}
use of org.forgerock.openam.cts.exceptions.CoreTokenException in project OpenAM by OpenRock.
the class CoreTokenResource method updateInstance.
/**
* Update a Token based on the Resource path.
*
* @param serverContext Required context.
* @param tokenId The tokenId to update. This must be the same TokenId as the serialised Token.
* @param updateRequest Contains the JSON serialised Token to update.
*/
public Promise<ResourceResponse, ResourceException> updateInstance(Context serverContext, String tokenId, UpdateRequest updateRequest) {
String principal = PrincipalRestUtils.getPrincipalNameFromServerContext(serverContext);
String value = updateRequest.getContent().toString();
Token newToken = serialisation.deserialise(value, Token.class);
try {
store.updateAsync(newToken);
ResourceResponse resource = newResourceResponse(newToken.getTokenId(), String.valueOf(System.currentTimeMillis()), new JsonValue("Token Updated"));
debug("UPDATE by {0}: Updated token resource with ID: {1}", principal, tokenId);
return newResultPromise(resource);
} catch (CoreTokenException e) {
error(e, "UPDATE by {0}: Error updating token resource with ID: {1}", principal, tokenId);
return generateException(e).asPromise();
}
}
Aggregations