Search in sources :

Example 91 with NotFoundException

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

the class CheckSessionImpl method getClientSessionURI.

/**
     * {@inheritDoc}
     */
public String getClientSessionURI(HttpServletRequest request) throws UnauthorizedClientException, InvalidClientException, NotFoundException {
    SignedJwt jwt = getIDToken(request);
    if (jwt == null) {
        return "";
    }
    final ClientRegistration clientRegistration = getClientRegistration(jwt);
    if (clientRegistration != null && !isJwtValid(jwt, clientRegistration)) {
        return "";
    }
    return clientRegistration.getClientSessionURI();
}
Also used : ClientRegistration(org.forgerock.oauth2.core.ClientRegistration) SignedJwt(org.forgerock.json.jose.jws.SignedJwt)

Example 92 with NotFoundException

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

the class CheckSessionImpl method getClientRegistration.

/**
     * Gets the Client's registration based from the audience set in the JWT.
     *
     * @param jwt The JWT.
     * @return The Client's registration.
     * @throws InvalidClientException If the client's registration is not found.
     */
private ClientRegistration getClientRegistration(Jwt jwt) throws InvalidClientException, NotFoundException {
    List<String> clients = jwt.getClaimsSet().getAudience();
    final String realm = (String) jwt.getClaimsSet().getClaim(REALM);
    if (clients != null && !clients.isEmpty()) {
        String client = clients.iterator().next();
        ClientRegistration clientRegistration = clientRegistrationStore.get(client, new OAuth2Request() {

            public <T> T getRequest() {
                throw new UnsupportedOperationException();
            }

            public <T> T getParameter(String name) {
                if (REALM.equals(name)) {
                    return (T) realm;
                }
                throw new UnsupportedOperationException();
            }

            public JsonValue getBody() {
                throw new UnsupportedOperationException();
            }

            public Locale getLocale() {
                throw new UnsupportedOperationException();
            }
        });
        return clientRegistration;
    }
    return null;
}
Also used : Locale(java.util.Locale) OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) ClientRegistration(org.forgerock.oauth2.core.ClientRegistration) JsonValue(org.forgerock.json.JsonValue)

Example 93 with NotFoundException

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

the class OAuth2AuditRefreshTokenContextProvider method retrieveRefreshTokenFromChallengeResponse.

private RefreshToken retrieveRefreshTokenFromChallengeResponse(Request request) {
    RefreshToken refreshToken;
    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 {
        refreshToken = tokenStore.readRefreshToken(oAuth2Request, bearerToken);
    } catch (ServerException | InvalidGrantException | NotFoundException e) {
        return null;
    }
    return refreshToken;
}
Also used : OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) RefreshToken(org.forgerock.oauth2.core.RefreshToken) ServerException(org.forgerock.oauth2.core.exceptions.ServerException) NotFoundException(org.forgerock.oauth2.core.exceptions.NotFoundException) InvalidGrantException(org.forgerock.oauth2.core.exceptions.InvalidGrantException) ChallengeResponse(org.restlet.data.ChallengeResponse)

Example 94 with NotFoundException

use of org.forgerock.oauth2.core.exceptions.NotFoundException 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 95 with NotFoundException

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

the class RealmNormaliser method normalise.

/**
     * Normalises the realm.
     * <br/>
     * If the specified realm is {@code null} or an empty String, '/' is returned. Otherwise the specified realm is
     * checked for its validity and returned in "/" separated format . 
     *
     * @param realm The realm to normalise.
     * @return The normalised realm.
     */
public String normalise(String realm) throws NotFoundException {
    if (StringUtils.isNotEmpty(realm)) {
        try {
            SSOToken adminToken = coreWrapper.getAdminToken();
            String orgDN = coreWrapper.getOrganization(adminToken, realm);
            return coreWrapper.convertOrgNameToRealmName(orgDN);
        } catch (SSOException ssoe) {
            logger.error("RealmNormaliser::Unable to verify realm : " + realm, ssoe);
        } catch (IdRepoException idre) {
            logger.error("RealmNormaliser::Unable to verify realm : " + realm, idre);
        }
        throw new NotFoundException("Invalid realm, " + realm);
    }
    return "/";
}
Also used : SSOToken(com.iplanet.sso.SSOToken) IdRepoException(com.sun.identity.idm.IdRepoException) NotFoundException(org.forgerock.oauth2.core.exceptions.NotFoundException) SSOException(com.iplanet.sso.SSOException)

Aggregations

ServerException (org.forgerock.oauth2.core.exceptions.ServerException)44 OAuth2ProviderSettings (org.forgerock.oauth2.core.OAuth2ProviderSettings)34 OAuth2Request (org.forgerock.oauth2.core.OAuth2Request)28 NotFoundException (org.forgerock.oauth2.core.exceptions.NotFoundException)24 CoreTokenException (org.forgerock.openam.cts.exceptions.CoreTokenException)21 JsonValue (org.forgerock.json.JsonValue)20 ResourceSetDescription (org.forgerock.oauth2.resources.ResourceSetDescription)13 AccessToken (org.forgerock.oauth2.core.AccessToken)12 ClientRegistration (org.forgerock.oauth2.core.ClientRegistration)11 InvalidGrantException (org.forgerock.oauth2.core.exceptions.InvalidGrantException)11 ResourceSetStore (org.forgerock.oauth2.resources.ResourceSetStore)11 Request (org.restlet.Request)11 SSOException (com.iplanet.sso.SSOException)10 HashSet (java.util.HashSet)10 AMIdentity (com.sun.identity.idm.AMIdentity)9 HashMap (java.util.HashMap)9 IdRepoException (com.sun.identity.idm.IdRepoException)8 OAuth2Uris (org.forgerock.oauth2.core.OAuth2Uris)8 InvalidClientException (org.forgerock.oauth2.core.exceptions.InvalidClientException)8 UnauthorizedClientException (org.forgerock.oauth2.core.exceptions.UnauthorizedClientException)8