@Override public Promise<ResourceResponse, ResourceException> readInstance( final Context serverContext, final String resourceId, final ReadRequest readRequest) { try { String token = ctsTokenPersistence.getToken(resourceId); if (token != null) { return newResultPromise(issuedTokenResource(token)); } else { return new NotFoundException("STS-issued token with id " + resourceId + " not found.") .asPromise(); } } catch (CTSTokenPersistenceException e) { logger.error("Exception caught reading token with id " + resourceId + ": " + e, e); return new InternalServerErrorException(e.toString(), e).asPromise(); } }
@Override public Promise<ResourceResponse, ResourceException> deleteInstance( final Context serverContext, final String resourceId, final DeleteRequest deleteRequest) { try { ctsTokenPersistence.deleteToken(resourceId); logger.debug("Deleted token with id: " + resourceId); return newResultPromise( newResourceResponse( resourceId, resourceId, json( object( field(RESULT, "token with id " + resourceId + " successfully removed."))))); } catch (CTSTokenPersistenceException e) { logger.error("Exception caught deleting token with id " + resourceId + ": " + e, e); return new InternalServerErrorException(e.toString(), e).asPromise(); } }
@Override public Promise<QueryResponse, ResourceException> queryCollection( final Context serverContext, final QueryRequest queryRequest, final QueryResourceHandler queryResultHandler) { QueryFilter<JsonPointer> queryFilter = queryRequest.getQueryFilter(); if (queryFilter == null) { return new BadRequestException(getUsageString()).asPromise(); } try { final QueryFilter<CoreTokenField> coreTokenFieldQueryFilter = convertToCoreTokenFieldQueryFilter(queryFilter); final List<STSIssuedTokenState> issuedTokens = ctsTokenPersistence.listTokens(coreTokenFieldQueryFilter); for (STSIssuedTokenState tokenState : issuedTokens) { queryResultHandler.handleResource( newResourceResponse(tokenState.getTokenId(), EMPTY_STRING, tokenState.toJson())); } return newResultPromise(newQueryResponse()); } catch (CTSTokenPersistenceException e) { logger.error("Exception caught obtaining list of sts-issued tokens: " + e, e); return e.asPromise(); } }