Search in sources :

Example 1 with SessionProvider

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

the class FSServiceUtils method getLocale.

/**
     * Retrieves locale of a http request.
     * @param request <code>HttpServletRequest</code> object
     * @return locale of the request; or <code>null</code> if locale cannot
     *  be retrieved.
     */
public static String getLocale(HttpServletRequest request) {
    if (request == null) {
        FSUtils.debug.error("FSServiceUtil.getLocale: Request param is " + "null, returning null");
        return null;
    }
    try {
        SessionProvider sessionProvider = SessionManager.getProvider();
        Object ISSSOToken = sessionProvider.getSession(request);
        String[] returnStr = sessionProvider.getProperty(ISSSOToken, "Locale");
        if ((returnStr != null) && (returnStr.length > 0)) {
            if (FSUtils.debug.messageEnabled()) {
                FSUtils.debug.message("FSServiceUtil.getLocale returning locale from token " + returnStr[0]);
            }
            return returnStr[0];
        }
    } catch (SessionException ssoe) {
        FSUtils.debug.error("FSServiceUtil::getLocale():SessionException:", ssoe);
    } catch (UnsupportedOperationException ex) {
        FSUtils.debug.error("FSServiceUtil::getLocale():Exception:", ex);
    }
    Locale locale = request.getLocale();
    if (locale != null) {
        String returnStr = locale.toString();
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("FSServiceUtil.getLocale returning :locale from request:" + returnStr);
        }
        return returnStr;
    }
    if (FSUtils.debug.messageEnabled()) {
        FSUtils.debug.message("FSServiceUtil.getLocale Not able to get " + "locale from request either from token or header. returning " + "null ");
    }
    return null;
}
Also used : Locale(java.util.Locale) SessionException(com.sun.identity.plugin.session.SessionException) SessionProvider(com.sun.identity.plugin.session.SessionProvider)

Example 2 with SessionProvider

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

the class FSRegistrationInitiationServlet method getValidToken.

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

Example 3 with SessionProvider

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

the class DefaultIDPAccountMapper method getNameID.

@Override
public NameID getNameID(Object session, String hostEntityID, String remoteEntityID, String realm, String nameIDFormat) throws SAML2Exception {
    String userID;
    try {
        SessionProvider sessionProv = SessionManager.getProvider();
        userID = sessionProv.getPrincipalName(session);
    } catch (SessionException se) {
        throw new SAML2Exception(SAML2Utils.bundle.getString("invalidSSOToken"));
    }
    String nameIDValue = null;
    if (nameIDFormat.equals(SAML2Constants.NAMEID_TRANSIENT_FORMAT)) {
        String sessionIndex = IDPSSOUtil.getSessionIndex(session);
        if (sessionIndex != null) {
            IDPSession idpSession = IDPCache.idpSessionsByIndices.get(sessionIndex);
            if (idpSession != null) {
                List<NameIDandSPpair> list = idpSession.getNameIDandSPpairs();
                if (list != null) {
                    for (NameIDandSPpair pair : list) {
                        if (pair.getSPEntityID().equals(remoteEntityID)) {
                            nameIDValue = pair.getNameID().getValue();
                            break;
                        }
                    }
                }
            }
        }
        if (nameIDValue == null) {
            nameIDValue = getNameIDValueFromUserProfile(realm, hostEntityID, userID, nameIDFormat);
            if (nameIDValue == null) {
                nameIDValue = SAML2Utils.createNameIdentifier();
            }
        }
    } else {
        nameIDValue = getNameIDValueFromUserProfile(realm, hostEntityID, userID, nameIDFormat);
        if (nameIDValue == null) {
            if (nameIDFormat.equals(SAML2Constants.PERSISTENT)) {
                nameIDValue = SAML2Utils.createNameIdentifier();
            } else {
                throw new SAML2Exception(bundle.getString("unableToGenerateNameIDValue"));
            }
        }
    }
    NameID nameID = AssertionFactory.getInstance().createNameID();
    nameID.setValue(nameIDValue);
    nameID.setFormat(nameIDFormat);
    nameID.setNameQualifier(hostEntityID);
    nameID.setSPNameQualifier(remoteEntityID);
    nameID.setSPProvidedID(null);
    return nameID;
}
Also used : SAML2Exception(com.sun.identity.saml2.common.SAML2Exception) NameIDandSPpair(com.sun.identity.saml2.profile.NameIDandSPpair) IDPSession(com.sun.identity.saml2.profile.IDPSession) NameID(com.sun.identity.saml2.assertion.NameID) SessionException(com.sun.identity.plugin.session.SessionException) SessionProvider(com.sun.identity.plugin.session.SessionProvider)

Example 4 with SessionProvider

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

the class LibertyManager method getUser.

/** 
     * Returns the user from <code>HttpServletRequest</code>.
     *
     * @param request HTTP servlet request.
     * @return the user from <code>HttpServletRequest</code>.
     */
public static String getUser(HttpServletRequest request) {
    Object ssoToken = null;
    try {
        SessionProvider sessionProvider = SessionManager.getProvider();
        ssoToken = sessionProvider.getSession(request);
        if (ssoToken != null && sessionProvider.isValid(ssoToken)) {
            debug.message("LibertyManager: getUser: token is valid");
            return sessionProvider.getPrincipalName(ssoToken);
        }
        return null;
    } catch (SessionException ssoe) {
        debug.error("LibertyManager: getUser: SessionException: ", ssoe);
        return null;
    }
}
Also used : SessionException(com.sun.identity.plugin.session.SessionException) SessionProvider(com.sun.identity.plugin.session.SessionProvider)

Example 5 with SessionProvider

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

the class LibertyManagerClient method getDiscoveryResourceOffering.

/**
     * Returns the discovery service bootstrap resource offering. 
     * @param token Single Sign On Token.
     * @param hostProviderID Hosted <code>ProviderID</code>.
     * @return <code>ResourceOffering</code> Discovery Service bootstrap
     *  resource offering.
     * @exception FSException if any failure.
     */
public ResourceOffering getDiscoveryResourceOffering(Object token, String hostProviderID) throws FSException {
    try {
        SessionProvider sessionProvider = SessionManager.getProvider();
        String tokenID = sessionProvider.getSessionID(token);
        String cacheKey = tokenID + DISCO_RO;
        ResourceOffering ro = (ResourceOffering) bootStrapCache.get(cacheKey);
        if (ro != null) {
            return ro;
        }
        String[] objs = { tokenID, hostProviderID };
        String resourceOffering = (String) client.send("getDiscoveryResourceOffering", objs, null, null);
        if ((resourceOffering == null) || (resourceOffering.length() == 0)) {
            if (FSUtils.debug.messageEnabled()) {
                FSUtils.debug.message("LibertyManagerClient.getDiscovery" + "ResourceOffering: ResouceOffering is null or empty");
            }
            return null;
        }
        Document doc = XMLUtils.toDOMDocument(resourceOffering, FSUtils.debug);
        ro = new ResourceOffering(doc.getDocumentElement());
        sessionProvider.addListener(token, new LibertyClientSSOTokenListener());
        bootStrapCache.put(cacheKey, ro);
        return ro;
    } catch (SessionException se) {
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("LibertyManagerClient.getDiscovery" + "ResourceOffering: InvalidSessionToken", se);
        }
        throw new FSException(FSUtils.bundle.getString("invalidSSOToken"));
    } catch (DiscoveryException de) {
        FSUtils.debug.error("LibertyManagerClient.getDiscovery" + "ResourceOffering: Invalid ResourceOffering", de);
        throw new FSException(FSUtils.bundle.getString("invalidResourceOffering"));
    } catch (Exception ex) {
        FSUtils.debug.error("LibertyManagerClient.getDiscovery" + "ResourceOffering: SOAPClient Exception", ex);
        throw new FSException(FSUtils.bundle.getString("soapException"));
    }
}
Also used : ResourceOffering(com.sun.identity.liberty.ws.disco.ResourceOffering) FSException(com.sun.identity.federation.common.FSException) SessionException(com.sun.identity.plugin.session.SessionException) Document(org.w3c.dom.Document) DiscoveryException(com.sun.identity.liberty.ws.disco.DiscoveryException) DiscoveryException(com.sun.identity.liberty.ws.disco.DiscoveryException) SessionException(com.sun.identity.plugin.session.SessionException) FSException(com.sun.identity.federation.common.FSException) 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