Search in sources :

Example 1 with ChallengeScheme

use of org.restlet.data.ChallengeScheme in project OpenAM by OpenRock.

the class RestletHeaderAccessTokenVerifier method getChallengeResponse.

/**
     * Returns the authentication response sent by a client to an origin server
     * instead of org.restlet.engine.adapter.HttpRequest.
     *
     * @return The authentication response sent by a client to an origin server.
     */
public ChallengeResponse getChallengeResponse(Request request) {
    if (request instanceof HttpRequest) {
        // Extract the header value
        final Series<Header> headers = ((HttpRequest) request).getHttpCall().getRequestHeaders();
        final String authorization = headers.getValues(HeaderConstants.HEADER_AUTHORIZATION);
        if (authorization != null) {
            int space = authorization.indexOf(' ');
            if (space != -1) {
                String scheme = authorization.substring(0, space);
                if (scheme.equalsIgnoreCase("Bearer")) {
                    ChallengeResponse result = new ChallengeResponse(new ChallengeScheme("HTTP_" + scheme, scheme));
                    result.setRawValue(authorization.substring(space + 1));
                    request.setChallengeResponse(result);
                    return result;
                }
            }
        }
    }
    return request.getChallengeResponse();
}
Also used : HttpRequest(org.restlet.engine.adapter.HttpRequest) Header(org.restlet.data.Header) ChallengeScheme(org.restlet.data.ChallengeScheme) ChallengeResponse(org.restlet.data.ChallengeResponse)

Aggregations

ChallengeResponse (org.restlet.data.ChallengeResponse)1 ChallengeScheme (org.restlet.data.ChallengeScheme)1 Header (org.restlet.data.Header)1 HttpRequest (org.restlet.engine.adapter.HttpRequest)1