Search in sources :

Example 46 with SessionId

use of org.gluu.oxauth.model.common.SessionId in project oxAuth by GluuFederation.

the class ValidationService method isValidSessionId.

public boolean isValidSessionId(String userName, String sessionId) {
    if (sessionId == null) {
        log.error("In two step authentication workflow session_id is mandatory");
        return false;
    }
    SessionId ldapSessionId = sessionIdService.getSessionId(sessionId);
    if (ldapSessionId == null) {
        log.error("Specified session_id '{}' is invalid", sessionId);
        return false;
    }
    String sessionIdUser = ldapSessionId.getSessionAttributes().get(Constants.AUTHENTICATED_USER);
    if (!StringHelper.equalsIgnoreCase(userName, sessionIdUser)) {
        log.error("Username '{}' and session_id '{}' don't match", userName, sessionId);
        return false;
    }
    return true;
}
Also used : SessionId(org.gluu.oxauth.model.common.SessionId)

Example 47 with SessionId

use of org.gluu.oxauth.model.common.SessionId in project oxAuth by GluuFederation.

the class UserSessionIdService method updateUserSessionIdOnFinishRequest.

public void updateUserSessionIdOnFinishRequest(String sessionId, String userInum, DeviceRegistrationResult deviceRegistrationResult, boolean enroll, boolean oneStep) {
    SessionId ldapSessionId = getLdapSessionId(sessionId);
    if (ldapSessionId == null) {
        return;
    }
    Map<String, String> sessionAttributes = ldapSessionId.getSessionAttributes();
    if (DeviceRegistrationResult.Status.APPROVED == deviceRegistrationResult.getStatus()) {
        sessionAttributes.put("session_custom_state", "approved");
    } else {
        sessionAttributes.put("session_custom_state", "declined");
    }
    sessionAttributes.put("oxpush2_u2f_device_id", deviceRegistrationResult.getDeviceRegistration().getId());
    sessionAttributes.put("oxpush2_u2f_device_user_inum", userInum);
    sessionAttributes.put("oxpush2_u2f_device_enroll", Boolean.toString(enroll));
    sessionAttributes.put("oxpush2_u2f_device_one_step", Boolean.toString(oneStep));
    sessionIdService.updateSessionId(ldapSessionId, true);
}
Also used : SessionId(org.gluu.oxauth.model.common.SessionId)

Example 48 with SessionId

use of org.gluu.oxauth.model.common.SessionId in project oxAuth by GluuFederation.

the class UmaSessionService method getUserDn.

public String getUserDn(HttpServletRequest httpRequest) {
    SessionId connectSession = getConnectSession(httpRequest);
    if (connectSession != null) {
        return connectSession.getUserDn();
    }
    log.trace("No logged in user.");
    return null;
}
Also used : SessionId(org.gluu.oxauth.model.common.SessionId)

Example 49 with SessionId

use of org.gluu.oxauth.model.common.SessionId in project oxAuth by GluuFederation.

the class UmaGatherer method prepareForStep.

public String prepareForStep() {
    try {
        final HttpServletRequest httpRequest = (HttpServletRequest) externalContext.getRequest();
        final HttpServletResponse httpResponse = (HttpServletResponse) externalContext.getResponse();
        final SessionId session = umaSessionService.getSession(httpRequest, httpResponse);
        if (session == null || session.getSessionAttributes().isEmpty()) {
            log.error("Invalid session.");
            return result(Constants.RESULT_EXPIRED);
        }
        CustomScriptConfiguration script = getScript(session);
        UmaGatherContext context = new UmaGatherContext(script.getConfigurationAttributes(), httpRequest, session, umaSessionService, umaPermissionService, umaPctService, pageClaims, userService, facesService, appConfiguration);
        int step = umaSessionService.getStep(session);
        if (step < 1) {
            log.error("Invalid step: {}", step);
            return result(Constants.RESULT_INVALID_STEP);
        }
        if (script == null) {
            log.error("Failed to load script, step: '{}'", step);
            return result(Constants.RESULT_FAILURE);
        }
        if (!umaSessionService.isPassedPreviousSteps(session, step)) {
            log.error("There are claims-gathering steps not marked as passed. scriptName: '{}', step: '{}'", script.getName(), step);
            return result(Constants.RESULT_FAILURE);
        }
        boolean result = external.prepareForStep(script, step, context);
        if (result) {
            context.persist();
            return result(Constants.RESULT_SUCCESS);
        } else {
            String redirectToExternalUrl = context.getRedirectToExternalUrl();
            if (StringUtils.isNotBlank(redirectToExternalUrl)) {
                log.debug("Redirect to : " + redirectToExternalUrl);
                facesService.redirectToExternalURL(redirectToExternalUrl);
                return redirectToExternalUrl;
            }
        }
    } catch (Exception e) {
        log.error("Failed to prepareForStep()", e);
    }
    return result(Constants.RESULT_FAILURE);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) UmaGatherContext(org.gluu.oxauth.uma.authorization.UmaGatherContext) SessionId(org.gluu.oxauth.model.common.SessionId) CustomScriptConfiguration(org.gluu.model.custom.script.conf.CustomScriptConfiguration)

Example 50 with SessionId

use of org.gluu.oxauth.model.common.SessionId in project oxAuth by GluuFederation.

the class UmaGatherer method gather.

public boolean gather() {
    try {
        final HttpServletRequest httpRequest = (HttpServletRequest) externalContext.getRequest();
        final HttpServletResponse httpResponse = (HttpServletResponse) externalContext.getResponse();
        final SessionId session = umaSessionService.getSession(httpRequest, httpResponse);
        CustomScriptConfiguration script = getScript(session);
        UmaGatherContext context = new UmaGatherContext(script.getConfigurationAttributes(), httpRequest, session, umaSessionService, umaPermissionService, umaPctService, pageClaims, userService, facesService, appConfiguration);
        int step = umaSessionService.getStep(session);
        if (!umaSessionService.isPassedPreviousSteps(session, step)) {
            log.error("There are claims-gathering steps not marked as passed. scriptName: '{}', step: '{}'", script.getName(), step);
            return false;
        }
        boolean gatheredResult = external.gather(script, step, context);
        log.debug("Claims-gathering result for script '{}', step: '{}', gatheredResult: '{}'", script.getName(), step, gatheredResult);
        int overridenNextStep = external.getNextStep(script, step, context);
        if (!gatheredResult && overridenNextStep == -1) {
            return false;
        }
        if (overridenNextStep != -1) {
            umaSessionService.resetToStep(session, overridenNextStep, step);
            step = overridenNextStep;
        }
        int stepsCount = external.getStepsCount(script, context);
        if (step < stepsCount || overridenNextStep != -1) {
            int nextStep;
            if (overridenNextStep != -1) {
                nextStep = overridenNextStep;
            } else {
                nextStep = step + 1;
                umaSessionService.markStep(session, step, true);
            }
            umaSessionService.setStep(nextStep, session);
            context.persist();
            String page = external.getPageForStep(script, nextStep, context);
            log.trace("Redirecting to page: '{}'", page);
            facesService.redirect(page);
            return true;
        }
        if (step == stepsCount) {
            context.persist();
            onSuccess(session, context);
            return true;
        }
    } catch (Exception e) {
        log.error("Exception during gather() method call.", e);
    }
    log.error("Failed to perform gather() method successfully.");
    return false;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) UmaGatherContext(org.gluu.oxauth.uma.authorization.UmaGatherContext) SessionId(org.gluu.oxauth.model.common.SessionId) CustomScriptConfiguration(org.gluu.model.custom.script.conf.CustomScriptConfiguration)

Aggregations

SessionId (org.gluu.oxauth.model.common.SessionId)52 CustomScriptConfiguration (org.gluu.model.custom.script.conf.CustomScriptConfiguration)9 HttpServletRequest (javax.servlet.http.HttpServletRequest)8 User (org.gluu.oxauth.model.common.User)7 Date (java.util.Date)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 URISyntaxException (java.net.URISyntaxException)4 HashMap (java.util.HashMap)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 AuthorizationGrant (org.gluu.oxauth.model.common.AuthorizationGrant)4 EntryPersistenceException (org.gluu.persist.exception.EntryPersistenceException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 BaseComponentTest (org.gluu.oxauth.BaseComponentTest)3 SimpleUser (org.gluu.oxauth.model.common.SimpleUser)3 AcrChangedException (org.gluu.oxauth.model.exception.AcrChangedException)3 InvalidSessionStateException (org.gluu.oxauth.model.exception.InvalidSessionStateException)3 Client (org.gluu.oxauth.model.registration.Client)3 ConsentGatheringContext (org.gluu.oxauth.service.external.context.ConsentGatheringContext)3 UmaGatherContext (org.gluu.oxauth.uma.authorization.UmaGatherContext)3 Parameters (org.testng.annotations.Parameters)3