Search in sources :

Example 1 with RegisterStatus

use of org.xdi.oxauth.model.fido.u2f.protocol.RegisterStatus in project oxAuth by GluuFederation.

the class U2fRegistrationWS method finishRegistration.

@POST
@Produces({ "application/json" })
public Response finishRegistration(@FormParam("username") String userName, @FormParam("tokenResponse") String registerResponseString) {
    String sessionState = null;
    try {
        log.debug("Finishing registration for username '{}' with response '{}'", userName, registerResponseString);
        RegisterResponse registerResponse = ServerUtil.jsonMapperWithWrapRoot().readValue(registerResponseString, RegisterResponse.class);
        String requestId = registerResponse.getRequestId();
        RegisterRequestMessageLdap registerRequestMessageLdap = u2fRegistrationService.getRegisterRequestMessageByRequestId(requestId);
        if (registerRequestMessageLdap == null) {
            throw new WebApplicationException(Response.status(Response.Status.FORBIDDEN).entity(errorResponseFactory.getJsonErrorResponse(U2fErrorResponseType.SESSION_EXPIRED)).build());
        }
        u2fRegistrationService.removeRegisterRequestMessage(registerRequestMessageLdap);
        String foundUserInum = registerRequestMessageLdap.getUserInum();
        RegisterRequestMessage registerRequestMessage = registerRequestMessageLdap.getRegisterRequestMessage();
        DeviceRegistrationResult deviceRegistrationResult = u2fRegistrationService.finishRegistration(registerRequestMessage, registerResponse, foundUserInum);
        // If sessionState is not empty update session
        sessionState = registerRequestMessageLdap.getSessionState();
        if (StringHelper.isNotEmpty(sessionState)) {
            log.debug("There is session state. Setting session state attributes");
            boolean oneStep = StringHelper.isEmpty(foundUserInum);
            userSessionStateService.updateUserSessionStateOnFinishRequest(sessionState, foundUserInum, deviceRegistrationResult, true, oneStep);
        }
        RegisterStatus registerStatus = new RegisterStatus(Constants.RESULT_SUCCESS, requestId);
        // Convert manually to avoid possible conflict between resteasy providers, e.g. jettison, jackson
        final String entity = ServerUtil.asJson(registerStatus);
        return Response.status(Response.Status.OK).entity(entity).cacheControl(ServerUtil.cacheControl(true)).build();
    } catch (Exception ex) {
        log.error("Exception happened", ex);
        try {
            // If sessionState is not empty update session
            if (StringHelper.isNotEmpty(sessionState)) {
                log.debug("There is session state. Setting session state status to 'declined'");
                userSessionStateService.updateUserSessionStateOnError(sessionState);
            }
        } catch (Exception ex2) {
            log.error("Failed to update session state status", ex2);
        }
        if (ex instanceof WebApplicationException) {
            throw (WebApplicationException) ex;
        }
        if (ex instanceof BadInputException) {
            throw new WebApplicationException(Response.status(Response.Status.FORBIDDEN).entity(errorResponseFactory.getErrorResponse(U2fErrorResponseType.INVALID_REQUEST)).build());
        }
        throw new WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorResponseFactory.getJsonErrorResponse(U2fErrorResponseType.SERVER_ERROR)).build());
    }
}
Also used : RegisterResponse(org.xdi.oxauth.model.fido.u2f.protocol.RegisterResponse) BadInputException(org.xdi.oxauth.model.fido.u2f.exception.BadInputException) WebApplicationException(javax.ws.rs.WebApplicationException) RegisterStatus(org.xdi.oxauth.model.fido.u2f.protocol.RegisterStatus) RegisterRequestMessage(org.xdi.oxauth.model.fido.u2f.protocol.RegisterRequestMessage) DeviceRegistrationResult(org.xdi.oxauth.model.fido.u2f.DeviceRegistrationResult) RegisterRequestMessageLdap(org.xdi.oxauth.model.fido.u2f.RegisterRequestMessageLdap) BadInputException(org.xdi.oxauth.model.fido.u2f.exception.BadInputException) WebApplicationException(javax.ws.rs.WebApplicationException) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Aggregations

POST (javax.ws.rs.POST)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 DeviceRegistrationResult (org.xdi.oxauth.model.fido.u2f.DeviceRegistrationResult)1 RegisterRequestMessageLdap (org.xdi.oxauth.model.fido.u2f.RegisterRequestMessageLdap)1 BadInputException (org.xdi.oxauth.model.fido.u2f.exception.BadInputException)1 RegisterRequestMessage (org.xdi.oxauth.model.fido.u2f.protocol.RegisterRequestMessage)1 RegisterResponse (org.xdi.oxauth.model.fido.u2f.protocol.RegisterResponse)1 RegisterStatus (org.xdi.oxauth.model.fido.u2f.protocol.RegisterStatus)1