Search in sources :

Example 1 with OOBAuthorizationResponse

use of org.apache.cxf.rs.security.oauth2.common.OOBAuthorizationResponse 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)

Aggregations

UriBuilder (javax.ws.rs.core.UriBuilder)1 FormAuthorizationResponse (org.apache.cxf.rs.security.oauth2.common.FormAuthorizationResponse)1 OOBAuthorizationResponse (org.apache.cxf.rs.security.oauth2.common.OOBAuthorizationResponse)1 ServerAuthorizationCodeGrant (org.apache.cxf.rs.security.oauth2.grants.code.ServerAuthorizationCodeGrant)1 OAuthServiceException (org.apache.cxf.rs.security.oauth2.provider.OAuthServiceException)1