Search in sources :

Example 16 with OAuthRedirectionState

use of org.apache.cxf.rs.security.oauth2.common.OAuthRedirectionState in project cxf by apache.

the class AuthorizationCodeGrantService method createGrant.

protected Response createGrant(OAuthRedirectionState state, Client client, List<String> requestedScope, List<String> approvedScope, UserSubject userSubject, ServerAccessToken preauthorizedToken) {
    // in this flow the code is still created, the preauthorized token
    // will be retrieved by the authorization code grant handler
    ServerAuthorizationCodeGrant grant = null;
    try {
        grant = getGrantRepresentation(state, client, requestedScope, approvedScope, userSubject, preauthorizedToken);
    } catch (OAuthServiceException ex) {
        return createErrorResponse(state.getState(), state.getRedirectUri(), OAuthConstants.ACCESS_DENIED);
    }
    String grantCode = processCodeGrant(client, grant.getCode(), grant.getSubject());
    if (state.getRedirectUri() == null) {
        OOBAuthorizationResponse bean = new OOBAuthorizationResponse();
        bean.setClientId(client.getClientId());
        bean.setClientDescription(client.getApplicationDescription());
        bean.setAuthorizationCode(grantCode);
        bean.setUserId(userSubject.getLogin());
        bean.setExpiresIn(grant.getExpiresIn());
        return deliverOOBResponse(bean);
    } else if (isFormResponse(state)) {
        FormAuthorizationResponse bean = new FormAuthorizationResponse();
        bean.setAuthorizationCode(grantCode);
        bean.setExpiresIn(grant.getExpiresIn());
        bean.setState(state.getState());
        bean.setRedirectUri(state.getRedirectUri());
        return createHtmlResponse(bean);
    } else {
        // return the code by appending it as a query parameter to the redirect URI
        UriBuilder ub = getRedirectUriBuilder(state.getState(), state.getRedirectUri());
        ub.queryParam(OAuthConstants.AUTHORIZATION_CODE_VALUE, grantCode);
        return Response.seeOther(ub.build()).build();
    }
}
Also used : OOBAuthorizationResponse(org.apache.cxf.rs.security.oauth2.common.OOBAuthorizationResponse) OAuthServiceException(org.apache.cxf.rs.security.oauth2.provider.OAuthServiceException) ServerAuthorizationCodeGrant(org.apache.cxf.rs.security.oauth2.grants.code.ServerAuthorizationCodeGrant) FormAuthorizationResponse(org.apache.cxf.rs.security.oauth2.common.FormAuthorizationResponse) UriBuilder(javax.ws.rs.core.UriBuilder)

Example 17 with OAuthRedirectionState

use of org.apache.cxf.rs.security.oauth2.common.OAuthRedirectionState in project cxf by apache.

the class AuthorizationCodeGrantService method recreateRedirectionStateFromParams.

protected OAuthRedirectionState recreateRedirectionStateFromParams(MultivaluedMap<String, String> params) {
    OAuthRedirectionState state = super.recreateRedirectionStateFromParams(params);
    setCodeChallenge(state, params);
    return state;
}
Also used : OAuthRedirectionState(org.apache.cxf.rs.security.oauth2.common.OAuthRedirectionState)

Example 18 with OAuthRedirectionState

use of org.apache.cxf.rs.security.oauth2.common.OAuthRedirectionState in project cxf by apache.

the class RedirectionBasedGrantService method recreateRedirectionStateFromParams.

protected OAuthRedirectionState recreateRedirectionStateFromParams(MultivaluedMap<String, String> params) {
    OAuthRedirectionState state = new OAuthRedirectionState();
    state.setClientId(params.getFirst(OAuthConstants.CLIENT_ID));
    state.setRedirectUri(params.getFirst(OAuthConstants.REDIRECT_URI));
    state.setAudience(params.getFirst(OAuthConstants.CLIENT_AUDIENCE));
    state.setProposedScope(params.getFirst(OAuthConstants.SCOPE));
    state.setState(params.getFirst(OAuthConstants.STATE));
    state.setNonce(params.getFirst(OAuthConstants.NONCE));
    state.setResponseType(params.getFirst(OAuthConstants.RESPONSE_TYPE));
    return state;
}
Also used : OAuthRedirectionState(org.apache.cxf.rs.security.oauth2.common.OAuthRedirectionState)

Aggregations

OAuthRedirectionState (org.apache.cxf.rs.security.oauth2.common.OAuthRedirectionState)7 ServerAuthorizationCodeGrant (org.apache.cxf.rs.security.oauth2.grants.code.ServerAuthorizationCodeGrant)5 ClientAccessToken (org.apache.cxf.rs.security.oauth2.common.ClientAccessToken)3 Map (java.util.Map)2 Properties (java.util.Properties)2 AccessTokenRegistration (org.apache.cxf.rs.security.oauth2.common.AccessTokenRegistration)2 AuthorizationCodeRegistration (org.apache.cxf.rs.security.oauth2.grants.code.AuthorizationCodeRegistration)2 OAuthServiceException (org.apache.cxf.rs.security.oauth2.provider.OAuthServiceException)2 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Principal (java.security.Principal)1 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 Collections (java.util.Collections)1 Collections.emptySet (java.util.Collections.emptySet)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ENGLISH (java.util.Locale.ENGLISH)1