Examples of SSOSessionPersistenceManager


Examples of org.wso2.carbon.identity.sso.saml.session.SSOSessionPersistenceManager

        if (request instanceof AuthnRequest) {
            AuthnRequestValidator authnRequestValidator = new AuthnRequestValidator((AuthnRequest)request);
            SAMLSSOReqValidationResponseDTO validationResp = authnRequestValidator.validate();
            validationResp.setAssertionString(authReq);
            if (validationResp.isValid()) {
                SSOSessionPersistenceManager sessionPersistenceManager = SSOSessionPersistenceManager.getPersistenceManager();
                boolean isExistingSession = sessionPersistenceManager.isExistingSession(sessionId);
                if(authnMode.equals(SAMLSSOConstants.AuthnModes.OPENID) && !isExistingSession){
                    AuthnRequestProcessor authnRequestProcessor = new AuthnRequestProcessor();
                    try {
                        return authnRequestProcessor.process(validationResp, sessionId, rpSessionId, authnMode);
                    } catch (Exception e) {
View Full Code Here

Examples of org.wso2.carbon.identity.sso.saml.session.SSOSessionPersistenceManager

                            "Provided username does not match with the requested subject");
                }
            }

            //persist the session
            SSOSessionPersistenceManager sessionPersistenceManager = SSOSessionPersistenceManager
                    .getPersistenceManager();

            //authenticate the user, if required
            if (!isAuthencated && authMode.equals(SAMLSSOConstants.AuthnModes.USERNAME_PASSWORD)) {
                if (!authenticate(authnReqDTO.getUsername(), authnReqDTO.getPassword())) {
                    log.warn("Authentication Failure, invalid username or password.");
                    SAMLSSORespDTO errorResp = buildErrorResponse(authnReqDTO.getId(), SAMLSSOConstants.StatusCodes.AUTHN_FAILURE,
                            "Authentication Failure, invalid username or password.");
                    errorResp.setLoginPageURL(authnReqDTO.getLoginPageURL());
                    return errorResp;
                }
                SAMLSSOServiceProviderDO spDO = new SAMLSSOServiceProviderDO();
                spDO.setIssuer(authnReqDTO.getIssuer());
                spDO.setAssertionConsumerUrl(authnReqDTO.getAssertionConsumerURL());
                spDO.setCertAlias(authnReqDTO.getCertAlias());
                spDO.setLogoutURL(authnReqDTO.getLogoutURL());
                sessionPersistenceManager.persistSession(sessionId, authnReqDTO.getUsername(),
                                                         spDO, authnReqDTO.getRpSessionId());
            }

            if (isAuthencated && authMode.equals(SAMLSSOConstants.AuthnModes.USERNAME_PASSWORD)) {
                SessionInfoData sessionInfo = sessionPersistenceManager.getSessionInfo(sessionId);
                authnReqDTO.setUsername(sessionInfo.getSubject());
                sessionPersistenceManager.persistSession(sessionId, authnReqDTO.getIssuer(),
                        authnReqDTO.getAssertionConsumerURL(), authnReqDTO.getRpSessionId());
            }

            if(isAuthencated && authMode.equals(SAMLSSOConstants.AuthnModes.OPENID)){
                SAMLSSOServiceProviderDO spDO = new SAMLSSOServiceProviderDO();
                spDO.setIssuer(authnReqDTO.getIssuer());
                spDO.setAssertionConsumerUrl(authnReqDTO.getAssertionConsumerURL());
                spDO.setCertAlias(authnReqDTO.getCertAlias());
                spDO.setLogoutURL(authnReqDTO.getLogoutURL());
                sessionPersistenceManager.persistSession(sessionId, authnReqDTO.getUsername(),
                                                         spDO, authnReqDTO.getRpSessionId());
            }

            //Build the response for the successful scenario
            ResponseBuilder respBuilder = new ResponseBuilder();
View Full Code Here

Examples of org.wso2.carbon.identity.sso.saml.session.SSOSessionPersistenceManager

        authReqDTO.setRpSessionId(rpSessionId);
        authReqDTO.setAssertionString(valiationDTO.getAssertionString());

        if (authMode.equals(SAMLSSOConstants.AuthnModes.USERNAME_PASSWORD)) {
            //Set the username in the SAMLSSOAuthnReqDTO
            SSOSessionPersistenceManager sessionPersistenceManager = SSOSessionPersistenceManager
                    .getPersistenceManager();
            SessionInfoData sessionInfo = sessionPersistenceManager.getSessionInfo(sessionId);
            authReqDTO.setUsername(sessionInfo.getSubject());
        }
        else{
            authReqDTO.setUsername(valiationDTO.getSubject());
        }
View Full Code Here

Examples of org.wso2.carbon.identity.sso.saml.session.SSOSessionPersistenceManager

                    return buildErrorResponse(logoutRequest.getID(), SAMLSSOConstants.StatusCodes.REQUESTOR_ERROR, message);
                }
            }

            //Get the sessions from the SessionPersistenceManager and prepare the logout responses
            SSOSessionPersistenceManager ssoSessionPersistenceManager = SSOSessionPersistenceManager.getPersistenceManager();
            SessionInfoData sessionInfoData = ssoSessionPersistenceManager.getSessionInfo(sessionId);

            if (sessionInfoData == null) {
                String message = "No Established Sessions corresponding to Session Indexes provided.";
                log.error(message);
                return buildErrorResponse(logoutRequest.getID(), SAMLSSOConstants.StatusCodes.REQUESTOR_ERROR,
                        message);
            }
            subject = sessionInfoData.getSubject();
            String issuer = logoutRequest.getIssuer().getValue();
            Map<String, SAMLSSOServiceProviderDO> sessionsList = sessionInfoData.getServiceProviderList();
            SAMLSSOServiceProviderDO logoutReqIssuer = sessionsList.get(issuer);

            // validate the signature, if it is set.
            if(logoutReqIssuer.getCertAlias() != null){
                boolean isSignatureValid = SAMLSSOUtil.validateAssertionSignature(logoutRequest, logoutReqIssuer.getCertAlias(),
                                                       MultitenantUtils.getTenantDomain(subject));
                if (!isSignatureValid) {
                    String message = "The signature contained in the Assertion is not valid.";
                    log.error(message);
                    return buildErrorResponse(logoutRequest.getID(), SAMLSSOConstants.StatusCodes.REQUESTOR_ERROR,
                            message);
                }
            }

            SingleLogoutMessageBuilder logoutMsgBuilder = new SingleLogoutMessageBuilder();
            Map<String, String> rpSessionsList = sessionInfoData.getRPSessionsList();
            SingleLogoutRequestDTO[] singleLogoutReqDTOs = new SingleLogoutRequestDTO[sessionsList.size()-1];
            LogoutRequest logoutReq = logoutMsgBuilder.buildLogoutRequest(subject, sessionId,
                    SAMLSSOConstants.SingleLogoutCodes.LOGOUT_USER);
            String logoutReqString = SAMLSSOUtil.encode(SAMLSSOUtil.marshall(logoutReq));
            int index = 0;
            for (String key : sessionsList.keySet()) {
                if (!key.equals(issuer)) {
                    SingleLogoutRequestDTO logoutReqDTO = new SingleLogoutRequestDTO();
                    logoutReqDTO.setAssertionConsumerURL(sessionsList.get(key).getLogoutURL());
                    if (sessionsList.get(key).getLogoutURL() == null ||
                        sessionsList.get(key).getLogoutURL().length() == 0) {
                        logoutReqDTO.setAssertionConsumerURL(sessionsList.get(key).getAssertionConsumerUrl());
                    }
                    logoutReqDTO.setLogoutResponse(logoutReqString);
                    logoutReqDTO.setRpSessionId(rpSessionsList.get(key));
                    singleLogoutReqDTOs[index] = logoutReqDTO;
                    index ++;
                }
                else {
                    reqValidationResponseDTO.setIssuer(sessionsList.get(key).getIssuer());
                    reqValidationResponseDTO.setAssertionConsumerURL(sessionsList.get(key).getAssertionConsumerUrl());
                    if(sessionsList.get(key).getLogoutURL() != null && sessionsList.get(key).getLogoutURL().length() > 0){
                        reqValidationResponseDTO.setAssertionConsumerURL(sessionsList.get(key).getLogoutURL());
                    }
                }
            }
            reqValidationResponseDTO.setLogoutRespDTO(singleLogoutReqDTOs);

            if (logoutRequest != null) {
                LogoutResponse logoutResponse = logoutMsgBuilder.buildLogoutResponse(logoutRequest.getID(),
                        SAMLSSOConstants.StatusCodes.SUCCESS_CODE, null);
                reqValidationResponseDTO.setLogoutResponse(SAMLSSOUtil.encode(SAMLSSOUtil.marshall(logoutResponse)));
                reqValidationResponseDTO.setValid(true);
            }

            ssoSessionPersistenceManager.removeSession(sessionId, issuer);
            return reqValidationResponseDTO;
        } catch (Exception e) {
            log.error("Error Processing the Logout Request", e);
            throw new IdentityException("Error Processing the Logout Request", e);
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.