Search in sources :

Example 21 with CoreTokenException

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
}
Also used : CoreTokenException(org.forgerock.openam.cts.exceptions.CoreTokenException) Test(org.testng.annotations.Test)

Example 22 with CoreTokenException

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
}
Also used : CoreTokenException(org.forgerock.openam.cts.exceptions.CoreTokenException) Token(org.forgerock.openam.cts.api.tokens.Token) Test(org.testng.annotations.Test)

Example 23 with CoreTokenException

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();
    }
}
Also used : Responses.newResourceResponse(org.forgerock.json.resource.Responses.newResourceResponse) ResourceResponse(org.forgerock.json.resource.ResourceResponse) CoreTokenException(org.forgerock.openam.cts.exceptions.CoreTokenException) Token(org.forgerock.openam.cts.api.tokens.Token)

Example 24 with CoreTokenException

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();
    }
}
Also used : Responses.newResourceResponse(org.forgerock.json.resource.Responses.newResourceResponse) ResourceResponse(org.forgerock.json.resource.ResourceResponse) HashMap(java.util.HashMap) JsonValue(org.forgerock.json.JsonValue) CoreTokenException(org.forgerock.openam.cts.exceptions.CoreTokenException)

Example 25 with CoreTokenException

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();
    }
}
Also used : Responses.newResourceResponse(org.forgerock.json.resource.Responses.newResourceResponse) ResourceResponse(org.forgerock.json.resource.ResourceResponse) JsonValue(org.forgerock.json.JsonValue) CoreTokenException(org.forgerock.openam.cts.exceptions.CoreTokenException) Token(org.forgerock.openam.cts.api.tokens.Token)

Aggregations

CoreTokenException (org.forgerock.openam.cts.exceptions.CoreTokenException)59 JsonValue (org.forgerock.json.JsonValue)21 ServerException (org.forgerock.oauth2.core.exceptions.ServerException)19 Token (org.forgerock.openam.cts.api.tokens.Token)14 Test (org.testng.annotations.Test)11 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)10 ResourceException (org.forgerock.json.resource.ResourceException)9 PartialToken (org.forgerock.openam.sm.datalayer.api.query.PartialToken)9 BadRequestException (org.forgerock.json.resource.BadRequestException)8 ArrayList (java.util.ArrayList)7 ResourceResponse (org.forgerock.json.resource.ResourceResponse)7 SSOException (com.iplanet.sso.SSOException)6 SSOToken (com.iplanet.sso.SSOToken)6 IdRepoException (com.sun.identity.idm.IdRepoException)6 HashMap (java.util.HashMap)5 Responses.newResourceResponse (org.forgerock.json.resource.Responses.newResourceResponse)5 OAuth2ProviderSettings (org.forgerock.oauth2.core.OAuth2ProviderSettings)5 TokenFilter (org.forgerock.openam.cts.api.filter.TokenFilter)5 TokenFilterBuilder (org.forgerock.openam.cts.api.filter.TokenFilterBuilder)5 DeleteFailedException (org.forgerock.openam.cts.exceptions.DeleteFailedException)5