Search in sources :

Example 46 with SessionProvider

use of com.sun.identity.plugin.session.SessionProvider in project OpenAM by OpenRock.

the class FSRegistrationInitiationServlet method doRegistrationInitiation.

/**
     * Called when a registration needs to be initiated with a remote provider.
     * @param request <code>HTTPServletRequest</code> object received via a 
     *  HTTP Redirect
     * @param response <code>HTTPServletResponse</code> object to send the 
     *  response back to user agent
     * @param hostedProviderDesc the provider where registration is initiated
     * @param hostedConfig the hosted provider's extended meta
     * @param hostedEntityId the hosted provider's entity id
     * @param hostedRole hosted provider's role
     * @param hostedProviderAlias hosted provider's meta alias
     */
private void doRegistrationInitiation(HttpServletRequest request, HttpServletResponse response, ProviderDescriptorType hostedProviderDesc, BaseConfigType hostedConfig, String hostedEntityId, String hostedRole, String hostedProviderAlias) {
    FSUtils.debug.message("Entered FSRegistrationInitiationServlet::doRegistrationInitiation");
    try {
        Object ssoToken = getValidToken(request);
        if (ssoToken != null) {
            String providerId = request.getParameter(IFSConstants.REGISTRATION_PROVIDER_ID);
            if (providerId == null || providerId.length() < 1) {
                FSUtils.debug.error("Provider Id not found, display error page");
                FSServiceUtils.showErrorPage(response, COMMON_ERROR_PAGE, IFSConstants.REGISTRATION_NO_PROVIDER, IFSConstants.CONTACT_ADMIN);
                return;
            }
            // session is valid, ProviderId available
            FSServiceManager instSManager = FSServiceManager.getInstance();
            if (instSManager != null) {
                FSUtils.debug.message("FSServiceManager Instance not null");
                String remoteProviderRole = IFSConstants.SP;
                FSAccountFedInfo fedinfo = null;
                if (hostedRole.equalsIgnoreCase(IFSConstants.SP)) {
                    remoteProviderRole = IFSConstants.IDP;
                    FSSessionManager sessManager = FSSessionManager.getInstance(hostedProviderAlias);
                    FSSession ssoSession = sessManager.getSession(ssoToken);
                    if (ssoSession != null) {
                        if (!ssoSession.getOneTime()) {
                            fedinfo = ssoSession.getAccountFedInfo();
                        }
                    }
                }
                SessionProvider sessionProvider = SessionManager.getProvider();
                FSNameRegistrationHandler handlerObj = instSManager.getNameRegistrationHandler(providerId, remoteProviderRole, sessionProvider.getPrincipalName(ssoToken), hostedEntityId, hostedProviderAlias);
                if (handlerObj != null) {
                    handlerObj.setHostedDescriptor(hostedProviderDesc);
                    handlerObj.setHostedDescriptorConfig(hostedConfig);
                    handlerObj.setMetaAlias(hostedProviderAlias);
                    handlerObj.setHostedProviderRole(hostedRole);
                    handlerObj.setHostedEntityId(hostedEntityId);
                    if (fedinfo != null) {
                        handlerObj.setAccountInfo(fedinfo);
                    }
                    boolean bStatus = handlerObj.handleNameRegistration(request, response, ssoToken);
                    if (FSUtils.debug.messageEnabled()) {
                        FSUtils.debug.message("handleNameRegistration status is : " + bStatus);
                    }
                    return;
                } else {
                    if (FSUtils.debug.messageEnabled()) {
                        FSUtils.debug.message("Unable to get registration " + "handler. User account Not valid");
                    }
                }
            } else {
                FSUtils.debug.message("FSServiceManager Instance null");
            }
            FSServiceUtils.returnLocallyAfterOperation(response, REGISTRATION_DONE_URL, false, IFSConstants.REGISTRATION_SUCCESS, IFSConstants.REGISTRATION_FAILURE);
            return;
        } else {
            FSServiceUtils.redirectForAuthentication(request, response, hostedProviderAlias);
            return;
        }
    } catch (IOException e) {
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("IOException in doRegistrationInitiation:", e);
        }
    } catch (SessionException ex) {
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("SessionException in doRegistrationInitiation", ex);
        }
    }
    FSServiceUtils.returnLocallyAfterOperation(response, REGISTRATION_DONE_URL, false, IFSConstants.REGISTRATION_SUCCESS, IFSConstants.REGISTRATION_FAILURE);
}
Also used : FSServiceManager(com.sun.identity.federation.services.FSServiceManager) FSAccountFedInfo(com.sun.identity.federation.accountmgmt.FSAccountFedInfo) FSSession(com.sun.identity.federation.services.FSSession) SessionException(com.sun.identity.plugin.session.SessionException) IOException(java.io.IOException) FSSessionManager(com.sun.identity.federation.services.FSSessionManager) SessionProvider(com.sun.identity.plugin.session.SessionProvider)

Example 47 with SessionProvider

use of com.sun.identity.plugin.session.SessionProvider in project OpenAM by OpenRock.

the class FSProcessLogoutServlet method getValidToken.

/**
     * Retrieves valid session from HTTP Request.
     * @param request HTTP request object
     * @return session if the session is valid; <code>null</code>
     *  otherwise.
     */
private Object getValidToken(HttpServletRequest request) {
    FSUtils.debug.message("Entered FSProcessLogoutServlet::getValidToken");
    try {
        SessionProvider sessionProvider = SessionManager.getProvider();
        Object ssoToken = sessionProvider.getSession(request);
        if ((ssoToken == null) || (!sessionProvider.isValid(ssoToken))) {
            FSUtils.debug.message("session is not valid, redirecting for authentication");
            return null;
        }
        return ssoToken;
    } catch (SessionException e) {
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("SessionException caught: " + e);
        }
        return null;
    }
}
Also used : SessionException(com.sun.identity.plugin.session.SessionException) SessionProvider(com.sun.identity.plugin.session.SessionProvider)

Example 48 with SessionProvider

use of com.sun.identity.plugin.session.SessionProvider in project OpenAM by OpenRock.

the class AssertionManagerImpl method getAssertions.

public Set getAssertions(String ssoToken) throws SAMLException {
    checkInitialization();
    try {
        SessionProvider sessionProvider = SessionManager.getProvider();
        Object token = sessionProvider.getSession(ssoToken);
        return (assertionManager.getAssertions(token));
    } catch (SessionException ssoe) {
        if (SAMLUtils.debug.messageEnabled()) {
            SAMLUtils.debug.message("AssertionManagerImpl:getAssertions: " + ssoe);
        }
        throw (new SAMLException(ssoe.getMessage()));
    }
}
Also used : SessionException(com.sun.identity.plugin.session.SessionException) SAMLException(com.sun.identity.saml.common.SAMLException) SessionProvider(com.sun.identity.plugin.session.SessionProvider)

Example 49 with SessionProvider

use of com.sun.identity.plugin.session.SessionProvider in project OpenAM by OpenRock.

the class AssertionManagerImpl method getAssertionArtifacts.

public Set getAssertionArtifacts(String ssoToken) throws SAMLException {
    checkInitialization();
    try {
        SessionProvider sessionProvider = SessionManager.getProvider();
        Object token = sessionProvider.getSession(ssoToken);
        return (assertionManager.getAssertionArtifacts(token));
    } catch (SessionException ssoe) {
        if (SAMLUtils.debug.messageEnabled()) {
            SAMLUtils.debug.message("AssertionManagerImpl:getAssertionArtifacts: " + ssoe);
        }
        throw (new SAMLException(ssoe.getMessage()));
    }
}
Also used : SessionException(com.sun.identity.plugin.session.SessionException) SAMLException(com.sun.identity.saml.common.SAMLException) SessionProvider(com.sun.identity.plugin.session.SessionProvider)

Example 50 with SessionProvider

use of com.sun.identity.plugin.session.SessionProvider in project OpenAM by OpenRock.

the class AssertionManagerImpl method createAssertion2.

public String createAssertion2(String ssoToken, List attributes) throws SAMLException {
    checkInitialization();
    Object token = null;
    try {
        SessionProvider sessionProvider = SessionManager.getProvider();
        token = sessionProvider.getSession(ssoToken);
    } catch (SessionException ssoe) {
        if (SAMLUtils.debug.messageEnabled()) {
            SAMLUtils.debug.message("AssertionManagerImpl:createAssertion(SSO + attrs) " + ssoe);
        }
        throw (new SAMLException(ssoe.getMessage()));
    }
    LinkedList ll = new LinkedList();
    for (Iterator iter = attributes.iterator(); iter.hasNext(); ) {
        ll.add(new Attribute(XMLUtils.toDOMDocument((String) iter.next(), SAMLUtils.debug).getDocumentElement()));
    }
    Assertion a = assertionManager.createAssertion(token, ll);
    return (a.toString(true, true));
}
Also used : Attribute(com.sun.identity.saml.assertion.Attribute) Assertion(com.sun.identity.saml.assertion.Assertion) SessionException(com.sun.identity.plugin.session.SessionException) SAMLException(com.sun.identity.saml.common.SAMLException) SessionProvider(com.sun.identity.plugin.session.SessionProvider)

Aggregations

SessionProvider (com.sun.identity.plugin.session.SessionProvider)66 SessionException (com.sun.identity.plugin.session.SessionException)61 SAMLException (com.sun.identity.saml.common.SAMLException)22 List (java.util.List)15 IOException (java.io.IOException)14 FSException (com.sun.identity.federation.common.FSException)13 HashMap (java.util.HashMap)12 SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)11 IDFFMetaException (com.sun.identity.federation.meta.IDFFMetaException)10 Set (java.util.Set)10 FSAccountMgmtException (com.sun.identity.federation.accountmgmt.FSAccountMgmtException)9 FSSession (com.sun.identity.federation.services.FSSession)9 FSSessionManager (com.sun.identity.federation.services.FSSessionManager)9 ArrayList (java.util.ArrayList)9 Iterator (java.util.Iterator)8 Map (java.util.Map)8 FSAccountFedInfo (com.sun.identity.federation.accountmgmt.FSAccountFedInfo)6 Assertion (com.sun.identity.saml.assertion.Assertion)6 SAML2MetaException (com.sun.identity.saml2.meta.SAML2MetaException)6 HashSet (java.util.HashSet)6