Search in sources :

Example 36 with CoreTokenException

use of org.forgerock.openam.cts.exceptions.CoreTokenException in project OpenAM by OpenRock.

the class DeleteOnQueryResultHandlerTest method shouldInvokeDeleteForEachHitEvenIfThereWasAnException.

@Test
public void shouldInvokeDeleteForEachHitEvenIfThereWasAnException() throws Exception {
    Collection<PartialToken> hits = getHits(5);
    handler.processResults(hits);
    willThrow(new CoreTokenException("")).willNothing().given(mockTaskDispatcher).delete(anyString(), any(ResultHandler.class));
    for (PartialToken hit : hits) {
        verify(mockTaskDispatcher).delete(eq(hit.<String>getValue(CoreTokenField.TOKEN_ID)), any(ResultHandler.class));
    }
}
Also used : PartialToken(org.forgerock.openam.sm.datalayer.api.query.PartialToken) CoreTokenException(org.forgerock.openam.cts.exceptions.CoreTokenException) ResultHandler(org.forgerock.openam.sm.datalayer.api.ResultHandler) Test(org.testng.annotations.Test)

Example 37 with CoreTokenException

use of org.forgerock.openam.cts.exceptions.CoreTokenException in project OpenAM by OpenRock.

the class CTSTokenPersistenceImpl method listTokens.

@Override
public List<STSIssuedTokenState> listTokens(QueryFilter<CoreTokenField> queryFilter) throws CTSTokenPersistenceException {
    Collection<PartialToken> partialTokens;
    try {
        partialTokens = ctsPersistentStore.attributeQuery(buildTokenFilter(queryFilter));
    } catch (CoreTokenException e) {
        throw new CTSTokenPersistenceException(ResourceException.INTERNAL_ERROR, e.getMessage(), e);
    }
    List<STSIssuedTokenState> issuedTokens = new ArrayList<>(partialTokens.size());
    for (PartialToken partialToken : partialTokens) {
        issuedTokens.add(marshalIssuedTokenState(partialToken));
    }
    return issuedTokens;
}
Also used : PartialToken(org.forgerock.openam.sm.datalayer.api.query.PartialToken) ArrayList(java.util.ArrayList) CoreTokenException(org.forgerock.openam.cts.exceptions.CoreTokenException) STSIssuedTokenState(org.forgerock.openam.sts.user.invocation.STSIssuedTokenState) CTSTokenPersistenceException(org.forgerock.openam.sts.CTSTokenPersistenceException)

Example 38 with CoreTokenException

use of org.forgerock.openam.cts.exceptions.CoreTokenException in project OpenAM by OpenRock.

the class UmaTokenStore method deleteRPT.

public void deleteRPT(String id) throws NotFoundException, ServerException {
    try {
        // check token is RPT
        readRPT(id);
        cts.delete(id);
    } catch (CoreTokenException e) {
        throw new ServerException("Could not delete token: " + id);
    }
}
Also used : ServerException(org.forgerock.oauth2.core.exceptions.ServerException) CoreTokenException(org.forgerock.openam.cts.exceptions.CoreTokenException)

Example 39 with CoreTokenException

use of org.forgerock.openam.cts.exceptions.CoreTokenException in project OpenAM by OpenRock.

the class UmaTokenStore method readToken.

public UmaToken readToken(String ticketId, JavaBeanAdapter<? extends UmaToken> adapter) throws NotFoundException {
    try {
        Token token = cts.read(ticketId);
        if (token == null) {
            throw new NotFoundException("No valid ticket exists with ticketId");
        }
        UmaToken ticket = adapter.fromToken(token);
        if (!realm.equals(ticket.getRealm())) {
            throw new NotFoundException("No valid ticket exists with ticketId in the realm, " + realm);
        }
        return ticket;
    } catch (CoreTokenException e) {
        throw new NotFoundException("No valid ticket exists with ticketId");
    }
}
Also used : NotFoundException(org.forgerock.oauth2.core.exceptions.NotFoundException) CoreTokenException(org.forgerock.openam.cts.exceptions.CoreTokenException) Token(org.forgerock.openam.cts.api.tokens.Token)

Example 40 with CoreTokenException

use of org.forgerock.openam.cts.exceptions.CoreTokenException in project OpenAM by OpenRock.

the class UmaTokenStore method createRPT.

RequestingPartyToken createRPT(PermissionTicket permissionTicket) throws ServerException, NotFoundException {
    UmaProviderSettings settings = settingsFactory.get(realm);
    Permission permission = new Permission(permissionTicket.getResourceSetId(), permissionTicket.getScopes());
    RequestingPartyToken rpt = new RequestingPartyToken(null, permissionTicket.getResourceServerClientId(), asSet(permission), System.currentTimeMillis() + (settings.getRPTLifetime() * 1000), permissionTicket.getId(), permissionTicket.getClientClientId());
    rpt.setRealm(realm);
    try {
        cts.create(rptAdapter.toToken(rpt));
    } catch (CoreTokenException e) {
        throw new ServerException(e);
    }
    return rpt;
}
Also used : ServerException(org.forgerock.oauth2.core.exceptions.ServerException) CoreTokenException(org.forgerock.openam.cts.exceptions.CoreTokenException)

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