Search in sources :

Example 66 with Token

use of org.forgerock.oauth2.core.Token in project OpenAM by OpenRock.

the class OAuth2AuditAccessTokenContextProvider method retrieveAccessTokenFromRequest.

private AccessToken retrieveAccessTokenFromRequest(Request request) {
    AccessToken token;
    token = requestFactory.create(request).getToken(AccessToken.class);
    return token;
}
Also used : AccessToken(org.forgerock.oauth2.core.AccessToken)

Example 67 with Token

use of org.forgerock.oauth2.core.Token in project OpenAM by OpenRock.

the class OAuth2AuditAccessTokenContextProvider method retrieveAccessTokenFromChallengeResponse.

private AccessToken retrieveAccessTokenFromChallengeResponse(Request request) {
    AccessToken token;
    ChallengeResponse challengeResponse = request.getChallengeResponse();
    if (challengeResponse == null) {
        return null;
    }
    String bearerToken = challengeResponse.getRawValue();
    if ("undefined".equals(bearerToken)) {
        return null;
    }
    OAuth2Request oAuth2Request = requestFactory.create(request);
    try {
        token = tokenStore.readAccessToken(oAuth2Request, bearerToken);
    } catch (ServerException | InvalidGrantException | NotFoundException e) {
        return null;
    }
    return token;
}
Also used : OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) ServerException(org.forgerock.oauth2.core.exceptions.ServerException) AccessToken(org.forgerock.oauth2.core.AccessToken) NotFoundException(org.forgerock.oauth2.core.exceptions.NotFoundException) InvalidGrantException(org.forgerock.oauth2.core.exceptions.InvalidGrantException) ChallengeResponse(org.restlet.data.ChallengeResponse)

Example 68 with Token

use of org.forgerock.oauth2.core.Token in project OpenAM by OpenRock.

the class IdTokenClaimGatherer method getRequestingPartyId.

@Override
public String getRequestingPartyId(OAuth2Request oAuth2Request, AccessToken authorizationApiToken, JsonValue claimToken) {
    try {
        SignedJwt idToken = jwtReconstruction.reconstructJwt(claimToken.asString(), SignedJwt.class);
        OAuth2ProviderSettings oAuth2ProviderSettings = oauth2ProviderSettingsFactory.get(oAuth2Request);
        OAuth2Uris oAuth2Uris = oAuth2UrisFactory.get(oAuth2Request);
        byte[] clientSecret = clientRegistrationStore.get(authorizationApiToken.getClientId(), oAuth2Request).getClientSecret().getBytes(Utils.CHARSET);
        KeyPair keyPair = oAuth2ProviderSettings.getServerKeyPair();
        if (!idToken.getClaimsSet().getIssuer().equals(oAuth2Uris.getIssuer())) {
            logger.warn("Issuer of id token, {0}, does not match issuer of authorization server, {1}.", idToken.getClaimsSet().getIssuer(), oAuth2Uris.getIssuer());
            return null;
        }
        if (!verify(clientSecret, keyPair, idToken)) {
            logger.warn("Signature of id token is invalid.");
            return null;
        }
        return idToken.getClaimsSet().getSubject();
    } catch (InvalidClientException e) {
        logger.error("Failed to find client", e);
        return null;
    } catch (NotFoundException | ServerException e) {
        logger.error("Failed to find OAuth2 settings", e);
        return null;
    }
}
Also used : KeyPair(java.security.KeyPair) ServerException(org.forgerock.oauth2.core.exceptions.ServerException) OAuth2Uris(org.forgerock.oauth2.core.OAuth2Uris) InvalidClientException(org.forgerock.oauth2.core.exceptions.InvalidClientException) NotFoundException(org.forgerock.oauth2.core.exceptions.NotFoundException) SignedJwt(org.forgerock.json.jose.jws.SignedJwt) OAuth2ProviderSettings(org.forgerock.oauth2.core.OAuth2ProviderSettings)

Example 69 with Token

use of org.forgerock.oauth2.core.Token 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 70 with Token

use of org.forgerock.oauth2.core.Token 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)

Aggregations

ServerException (org.forgerock.oauth2.core.exceptions.ServerException)33 JsonValue (org.forgerock.json.JsonValue)22 AccessToken (org.forgerock.oauth2.core.AccessToken)18 OAuth2Request (org.forgerock.oauth2.core.OAuth2Request)18 NotFoundException (org.forgerock.oauth2.core.exceptions.NotFoundException)18 CoreTokenException (org.forgerock.openam.cts.exceptions.CoreTokenException)18 SSOException (com.iplanet.sso.SSOException)16 OAuth2ProviderSettings (org.forgerock.oauth2.core.OAuth2ProviderSettings)16 UnauthorizedClientException (org.forgerock.oauth2.core.exceptions.UnauthorizedClientException)16 SSOToken (com.iplanet.sso.SSOToken)13 AMIdentity (com.sun.identity.idm.AMIdentity)12 IdRepoException (com.sun.identity.idm.IdRepoException)11 Set (java.util.Set)9 InvalidClientException (org.forgerock.oauth2.core.exceptions.InvalidClientException)9 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)8 InvalidGrantException (org.forgerock.oauth2.core.exceptions.InvalidGrantException)8 Test (org.testng.annotations.Test)8 Map (java.util.Map)6 AccessTokenVerifier (org.forgerock.oauth2.core.AccessTokenVerifier)6