Search in sources :

Example 26 with SessionProvider

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

the class AssertionManagerClient method getAssertion.

/**
     * Returns the <code>Assertion</code> based on the 
     * <code>AssertionIDReference</code>.
     *
     * @param idRef The <code>AssertionIDReference</code> which references to an
     *        Assertion.
     * @param token User session that is allowed to obtain the assertion.
     *        This token must have top level administrator role.
     * @return the Assertion referenced by the
     *         <code>AssertionIDReference</code>.
     * @throws SAMLException If an error occurred during the process; or
     *         the assertion could not be found.
     */
public Assertion getAssertion(AssertionIDReference idRef, Object token) throws SAMLException {
    if (useLocal) {
        return (assertionManager.getAssertion(idRef, token));
    }
    String assertion = null;
    try {
        SessionProvider sessionProvider = SessionManager.getProvider();
        Object[] args = { idRef.getAssertionIDReference(), sessionProvider.getSessionID(token) };
        assertion = (String) stub.send("getAssertionByIdRefToken", args, null, null);
        return (new Assertion(XMLUtils.toDOMDocument(assertion, SAMLUtils.debug).getDocumentElement()));
    } catch (Exception re) {
        if (SAMLUtils.debug.warningEnabled()) {
            SAMLUtils.debug.warning("AMC:getAssertion: " + idRef, re);
        }
        throw (new SAMLException(re.getMessage()));
    }
}
Also used : Assertion(com.sun.identity.saml.assertion.Assertion) SAMLException(com.sun.identity.saml.common.SAMLException) SessionException(com.sun.identity.plugin.session.SessionException) SAMLException(com.sun.identity.saml.common.SAMLException) SessionProvider(com.sun.identity.plugin.session.SessionProvider)

Example 27 with SessionProvider

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

the class AssertionManagerClient method createAssertion.

/** 
     * Returns an assertion that contains an authentication statement.
     * @param token User session that contains authentication
     *        information which is needed to create the authentication
     *        statement. 
     * @return the created assertion.
     * @throws SAMLException if the assertion cannot be created.
     */
public Assertion createAssertion(Object token) throws SAMLException {
    if (useLocal) {
        return (assertionManager.createAssertion(token));
    }
    String assertion = null;
    try {
        SessionProvider sessionProvider = SessionManager.getProvider();
        Object[] args = { sessionProvider.getSessionID(token) };
        assertion = (String) stub.send("createAssertion", args, null, null);
        return (new Assertion(XMLUtils.toDOMDocument(assertion, SAMLUtils.debug).getDocumentElement()));
    } catch (Exception re) {
        if (SAMLUtils.debug.warningEnabled()) {
            SAMLUtils.debug.warning("AMC:createAssertion(SSO)", re);
        }
        throw (new SAMLException(re.getMessage()));
    }
}
Also used : Assertion(com.sun.identity.saml.assertion.Assertion) SAMLException(com.sun.identity.saml.common.SAMLException) SessionException(com.sun.identity.plugin.session.SessionException) SAMLException(com.sun.identity.saml.common.SAMLException) SessionProvider(com.sun.identity.plugin.session.SessionProvider)

Example 28 with SessionProvider

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

the class AssertionManagerClient method createAssertion.

/**
     * Returns an assertion that contains an authentication and attribute
     * statement.
     * @param token User session that contains authentication
     *        information which is needed to create the authentication
     *        statement for the assertion.
     * @param attributes A list of attribute objects which are used to create
     *        the attribute statement.
     * @return The created assertion.
     * @throws SAMLException If the Assertion cannot be created.
     */
public Assertion createAssertion(Object token, List attributes) throws SAMLException {
    if (useLocal) {
        return (assertionManager.createAssertion(token, attributes));
    }
    // Check for null or empty attributes
    if (attributes == null || attributes.isEmpty())
        return (createAssertion(token));
    String assertion = null;
    try {
        List attrs = new LinkedList();
        for (Iterator iter = attributes.iterator(); iter.hasNext(); ) {
            Attribute attribute = (Attribute) iter.next();
            attrs.add(attribute.toString(true, true));
        }
        SessionProvider sessionProvider = SessionManager.getProvider();
        Object[] args = { sessionProvider.getSessionID(token), attrs };
        assertion = (String) stub.send("createAssertion2", args, null, null);
        return (new Assertion(XMLUtils.toDOMDocument(assertion, SAMLUtils.debug).getDocumentElement()));
    } catch (Exception re) {
        if (SAMLUtils.debug.warningEnabled()) {
            SAMLUtils.debug.warning("AMC:createAssertion(SSO, attrs)", re);
        }
        throw (new SAMLException(re.getMessage()));
    }
}
Also used : Attribute(com.sun.identity.saml.assertion.Attribute) Assertion(com.sun.identity.saml.assertion.Assertion) SAMLException(com.sun.identity.saml.common.SAMLException) SessionException(com.sun.identity.plugin.session.SessionException) SAMLException(com.sun.identity.saml.common.SAMLException) SessionProvider(com.sun.identity.plugin.session.SessionProvider)

Example 29 with SessionProvider

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

the class MultiProtocolUtils method usedInProtocol.

/**
     * Returns true if the session is used in the specified federation protocol.
     * @param request HttpServlet object
     * @param protocol Protocol of the caller. Value is one of the following:
     *   <code>SingleLogoutManager.IDFF</code>
     *   <code>SingleLogoutManager.SAML2</code> 
     *   <code>SingleLogoutManager.WS_FED</code>
     * @return true if the session is used in this federation protocol, 
     *  false otherwise.
     */
public static boolean usedInProtocol(HttpServletRequest request, String protocol) {
    try {
        SessionProvider provider = SessionManager.getProvider();
        Object session = provider.getSession(request);
        return usedInProtocol(session, protocol);
    } catch (SessionException ex) {
        SingleLogoutManager.debug.message("MPUtils.usedInProtocol?", ex);
        return false;
    }
}
Also used : SessionException(com.sun.identity.plugin.session.SessionException) SessionProvider(com.sun.identity.plugin.session.SessionProvider)

Example 30 with SessionProvider

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

the class MultiProtocolUtils method usedInProtocol.

/**
     * Returns true if the session is used in the specified federation protocol.
     * @param session Session object
     * @param protocol Protocol of the caller. Value is one of the following:
     *   <code>SingleLogoutManager.IDFF</code>
     *   <code>SingleLogoutManager.SAML2</code> 
     *   <code>SingleLogoutManager.WS_FED</code>
     * @return true if the session is used in this federation protocol, 
     *  false otherwise.
     */
public static boolean usedInProtocol(Object session, String protocol) {
    SingleLogoutManager.debug.message("MultiProtocolUtils.usedInProtocol");
    if ((session == null) || (protocol == null)) {
        return false;
    }
    if (SingleLogoutManager.debug.messageEnabled()) {
        SingleLogoutManager.debug.message("MultiProtocolUtils.usedInProto:" + " protocol=" + protocol + ", session=" + session);
    }
    try {
        SessionProvider provider = SessionManager.getProvider();
        String[] vals = provider.getProperty(session, SingleLogoutManager.FEDERATION_PROTOCOLS);
        if (SingleLogoutManager.debug.messageEnabled()) {
            SingleLogoutManager.debug.message("MultiProtocolUtils.usedInProtocol: protocols=" + vals);
        }
        if ((vals != null) && (vals.length != 0)) {
            for (int i = 0; i < vals.length; i++) {
                if (protocol.equals(vals[i])) {
                    return true;
                }
            }
        }
        return false;
    } catch (SessionException ex) {
        SingleLogoutManager.debug.message("MPUtils.usedInProtocol", ex);
    } catch (UnsupportedOperationException ex) {
        SingleLogoutManager.debug.message("MPUtils.usedInProtocol", ex);
    }
    return false;
}
Also used : SessionException(com.sun.identity.plugin.session.SessionException) 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