Search in sources :

Example 1 with OAuthErrorResponseBuilder

use of org.apache.oltu.oauth2.common.message.OAuthResponse.OAuthErrorResponseBuilder in project Kustvakt by KorAP.

the class OAuth2ResponseHandler method throwit.

public WebApplicationException throwit(OAuthProblemException e, String state) {
    OAuthResponse oAuthResponse = null;
    try {
        OAuthErrorResponseBuilder builder = OAuthResponse.errorResponse(e.getResponseStatus()).error(e);
        if (state != null && !state.isEmpty()) {
            builder.setState(state);
        }
        oAuthResponse = builder.buildJSONMessage();
    } catch (OAuthSystemException e1) {
        throwit(e1, state);
    }
    Response r = createResponse(oAuthResponse);
    return new WebApplicationException(r);
}
Also used : Response(javax.ws.rs.core.Response) OAuthResponse(org.apache.oltu.oauth2.common.message.OAuthResponse) OAuthErrorResponseBuilder(org.apache.oltu.oauth2.common.message.OAuthResponse.OAuthErrorResponseBuilder) WebApplicationException(javax.ws.rs.WebApplicationException) OAuthSystemException(org.apache.oltu.oauth2.common.exception.OAuthSystemException) OAuthResponse(org.apache.oltu.oauth2.common.message.OAuthResponse)

Example 2 with OAuthErrorResponseBuilder

use of org.apache.oltu.oauth2.common.message.OAuthResponse.OAuthErrorResponseBuilder in project Kustvakt by KorAP.

the class OAuth2ResponseHandler method createOAuthResponse.

private OAuthResponse createOAuthResponse(KustvaktException e, int statusCode, String state) throws OAuthSystemException {
    OAuthProblemException oAuthProblemException = OAuthProblemException.error(e.getEntity()).state(state).description(e.getMessage());
    OAuthErrorResponseBuilder responseBuilder = OAuthResponse.errorResponse(statusCode).error(oAuthProblemException);
    if (state != null && !state.isEmpty()) {
        responseBuilder.setState(state);
    }
    URI redirectUri = e.getRedirectUri();
    if (redirectUri != null) {
        responseBuilder.location(redirectUri.toString());
        return responseBuilder.buildQueryMessage();
    }
    return responseBuilder.buildJSONMessage();
}
Also used : OAuthProblemException(org.apache.oltu.oauth2.common.exception.OAuthProblemException) OAuthErrorResponseBuilder(org.apache.oltu.oauth2.common.message.OAuthResponse.OAuthErrorResponseBuilder) URI(java.net.URI)

Aggregations

OAuthErrorResponseBuilder (org.apache.oltu.oauth2.common.message.OAuthResponse.OAuthErrorResponseBuilder)2 URI (java.net.URI)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Response (javax.ws.rs.core.Response)1 OAuthProblemException (org.apache.oltu.oauth2.common.exception.OAuthProblemException)1 OAuthSystemException (org.apache.oltu.oauth2.common.exception.OAuthSystemException)1 OAuthResponse (org.apache.oltu.oauth2.common.message.OAuthResponse)1