Search in sources :

Example 26 with ChallengeResponse

use of org.restlet.data.ChallengeResponse in project qi4j-sdk by Qi4j.

the class ContextResourceClient method invokeCommand.

private HandlerCommand invokeCommand(Reference ref, Method method, Object requestObject, ResponseHandler responseHandler, ResponseHandler processingErrorHandler) {
    Request request = new Request(method, ref);
    if (requestObject == null)
        requestObject = new EmptyRepresentation();
    contextResourceFactory.writeRequest(request, requestObject);
    contextResourceFactory.updateCommandRequest(request);
    User user = request.getClientInfo().getUser();
    if (user != null)
        request.setChallengeResponse(new ChallengeResponse(ChallengeScheme.HTTP_BASIC, user.getName(), user.getSecret()));
    Response response = new Response(request);
    contextResourceFactory.getClient().handle(request, response);
    try {
        if (response.getStatus().isSuccess()) {
            contextResourceFactory.updateCache(response);
            if (responseHandler != null)
                return responseHandler.handleResponse(response, this);
        } else {
            if (response.getStatus().equals(Status.CLIENT_ERROR_UNPROCESSABLE_ENTITY) && processingErrorHandler != null) {
                return processingErrorHandler.handleResponse(response, this);
            } else {
                // TODO This needs to be expanded to allow custom handling of all the various cases
                return errorHandler.handleResponse(response, this);
            }
        }
        // No handler found
        return null;
    } finally {
        try {
            response.getEntity().exhaust();
        } catch (Throwable e) {
        // Ignore
        }
    }
}
Also used : ChallengeResponse(org.restlet.data.ChallengeResponse) Response(org.restlet.Response) User(org.restlet.security.User) EmptyRepresentation(org.restlet.representation.EmptyRepresentation) Request(org.restlet.Request) ChallengeResponse(org.restlet.data.ChallengeResponse)

Aggregations

ChallengeResponse (org.restlet.data.ChallengeResponse)26 OAuth2Request (org.forgerock.oauth2.core.OAuth2Request)17 Request (org.restlet.Request)15 Test (org.testng.annotations.Test)9 AccessToken (org.forgerock.oauth2.core.AccessToken)8 Response (org.restlet.Response)8 Status (org.restlet.data.Status)5 HttpRequest (org.restlet.engine.adapter.HttpRequest)5 InvalidGrantException (org.forgerock.oauth2.core.exceptions.InvalidGrantException)4 NotFoundException (org.forgerock.oauth2.core.exceptions.NotFoundException)4 ServerException (org.forgerock.oauth2.core.exceptions.ServerException)4 AccessTokenVerifier (org.forgerock.oauth2.core.AccessTokenVerifier)3 ApiAccessToken (cbit.vcell.modeldb.ApiAccessToken)2 SQLException (java.sql.SQLException)2 Form (org.restlet.data.Form)2 Representation (org.restlet.representation.Representation)2 ApiClient (cbit.vcell.modeldb.ApiClient)1 ParseException (java.text.ParseException)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1