Search in sources :

Example 21 with SAMLException

use of com.sun.identity.saml.common.SAMLException in project OpenAM by OpenRock.

the class DefaultSiteAttributeMapper method getAttributes.

/**
     * Returns <code>List</code> of <code>Attribute</code> objects
     *
     * @param token  User's session.
     * @param request The HttpServletRerquest object of the request which
     *                may contains query attributes to be included in the
     *                Assertion. This could be null if unavailable.
     * @param response The HttpServletResponse object. This could be null 
     *                if unavailable.
     * @param targetURL value for TARGET query parameter when the user
     *                  accessing the SAML aware servlet or post profile
     *                  servlet. This could be null if unavailabl
     * @return <code>List</code> if <code>Attribute</code> objects.
     *         <code>Attribute</code> is defined in the SAML SDK as part of
     *         <code>com.sun.identity.saml.assertion</code> package.
     * @throws SAMLException if attributes cannot be obtained.
     */
public List getAttributes(Object token, HttpServletRequest request, HttpServletResponse response, String targetURL) throws SAMLException {
    Map attrMap = (Map) SAMLServiceManager.getAttribute(SAMLConstants.ATTRIBUTE_MAP);
    if ((attrMap == null) || (attrMap.isEmpty())) {
        return null;
    }
    Set localAttrNames = new HashSet();
    localAttrNames.addAll(attrMap.values());
    Map localValueMap = null;
    try {
        DataStoreProvider dsProvider = DataStoreProviderManager.getInstance().getDataStoreProvider(SAMLConstants.SAML);
        localValueMap = dsProvider.getAttributes(SessionManager.getProvider().getPrincipalName(token), localAttrNames);
    } catch (Exception ex) {
        if (SAMLUtils.debug.warningEnabled()) {
            SAMLUtils.debug.warning("DefaultSiteAttributeMapper." + "getAttributes:", ex);
        }
    }
    List samlAttrs = null;
    for (Iterator iter = attrMap.keySet().iterator(); iter.hasNext(); ) {
        String samlAttrName = (String) iter.next();
        String localAttrName = (String) attrMap.get(samlAttrName);
        String attrNamespace = null;
        StringTokenizer tokenizer = new StringTokenizer(samlAttrName, "|");
        int tokenCount = tokenizer.countTokens();
        if (tokenCount == 1) {
            attrNamespace = SAMLConstants.assertionSAMLNameSpaceURI;
        } else if (tokenCount == 2) {
            attrNamespace = tokenizer.nextToken();
            samlAttrName = tokenizer.nextToken();
        } else {
            if (SAMLUtils.debug.messageEnabled()) {
                SAMLUtils.debug.message("DefaultSiteAttributeMapper." + "getAttribute: invalid saml attribute in attribute " + " map. saml attribute = " + samlAttrName + ", the " + " syntax is namespace|attrName.");
            }
            continue;
        }
        String[] localAttrValues = null;
        if ((localValueMap != null) && (!localValueMap.isEmpty())) {
            Set values = (Set) localValueMap.get(localAttrName);
            if ((values == null) || (values.isEmpty())) {
                if (SAMLUtils.debug.messageEnabled()) {
                    SAMLUtils.debug.message("DefaultSiteAttributeMapper." + "getAttribute: user profile does not have " + "value for " + localAttrName + " but is going to check ssotoken:");
                }
            } else {
                localAttrValues = (String[]) values.toArray(new String[values.size()]);
            }
        }
        if (localAttrValues == null) {
            try {
                localAttrValues = SessionManager.getProvider().getProperty(token, localAttrName);
            } catch (SessionException ex) {
                if (SAMLUtils.debug.messageEnabled()) {
                    SAMLUtils.debug.message("DefaultSiteAttributeMapper." + "getAttribute:", ex);
                }
            }
        }
        if ((localAttrValues == null) || (localAttrValues.length == 0)) {
            if (SAMLUtils.debug.messageEnabled()) {
                SAMLUtils.debug.message("DefaultSiteAttributeMapper." + "getAttribute: user does not have " + localAttrName);
            }
        } else {
            Attribute samlAttr = getSAMLAttribute(samlAttrName, attrNamespace, localAttrValues);
            if (samlAttr != null) {
                if (samlAttrs == null) {
                    samlAttrs = new ArrayList();
                }
                samlAttrs.add(samlAttr);
                if (SAMLUtils.debug.messageEnabled()) {
                    SAMLUtils.debug.message("DefaultSiteAttributeMapper." + "getAttribute: add atttribute = " + samlAttrName + ", attrNamespace = " + attrNamespace + ", values = " + localAttrValues);
                }
            }
        }
    }
    return samlAttrs;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Attribute(com.sun.identity.saml.assertion.Attribute) DataStoreProvider(com.sun.identity.plugin.datastore.DataStoreProvider) ArrayList(java.util.ArrayList) SessionException(com.sun.identity.plugin.session.SessionException) SessionException(com.sun.identity.plugin.session.SessionException) SAMLException(com.sun.identity.saml.common.SAMLException) StringTokenizer(java.util.StringTokenizer) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) HashSet(java.util.HashSet)

Example 22 with SAMLException

use of com.sun.identity.saml.common.SAMLException in project OpenAM by OpenRock.

the class AssertionManagerClient method getRemoteStub.

private static SOAPClient getRemoteStub() throws SAMLException {
    SOAPClient remoteStub = null;
    try {
        // Get a valid server from JAXRPCUtil. This throws
        // Exception if no servers are found
        URL u = new URL(JAXRPCHelper.getValidURL(SERVICE_NAME));
        remoteStub = getServiceEndPoint(u.getProtocol(), u.getHost(), Integer.toString(u.getPort()), u.getPath());
        // The following call will check if the JVM contains the
        // the service instance also. If this is a server instance also
        // "short-circuit" will be performed.
        remoteStub.send("checkForLocal", null, null, null);
    } catch (Exception ee) {
        if (SAMLUtils.debug.warningEnabled()) {
            SAMLUtils.debug.warning("AMC:getRemoteStub: generic error: ", ee);
        }
        throw (new SAMLException(ee.getMessage()));
    }
    return (remoteStub);
}
Also used : SOAPClient(com.sun.identity.shared.jaxrpc.SOAPClient) SAMLException(com.sun.identity.saml.common.SAMLException) URL(java.net.URL) SessionException(com.sun.identity.plugin.session.SessionException) SAMLException(com.sun.identity.saml.common.SAMLException)

Example 23 with SAMLException

use of com.sun.identity.saml.common.SAMLException 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 24 with SAMLException

use of com.sun.identity.saml.common.SAMLException 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 25 with SAMLException

use of com.sun.identity.saml.common.SAMLException 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 destID The destination site id requesting the assertion using
     *        the assertion id reference. This String is compared with the
     *        <code>destID</code> that the assertion is created for originally.
     *        This field is not used (could be null) if the assertion was
     *        created without a <code>destID</code> originally. This String can
     *        be obtained from converting the 20 byte site id sequence to char
     *        array, then a new String from the char array.
     * @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, String destID) throws SAMLException {
    if (useLocal) {
        return (assertionManager.getAssertion(idRef, destID));
    }
    String assertion = null;
    try {
        // rpc could not handle destID is null or empty string case
        if (destID == null || destID.length() == 0) {
            destID = " ";
        }
        Object[] args = { idRef.getAssertionIDReference(), Base64.encode(SAMLUtils.stringToByteArray(destID)) };
        assertion = (String) stub.send("getAssertionByIdRef2", 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)

Aggregations

SAMLException (com.sun.identity.saml.common.SAMLException)86 SessionException (com.sun.identity.plugin.session.SessionException)30 FSMsgException (com.sun.identity.federation.message.common.FSMsgException)26 List (java.util.List)23 SAMLResponderException (com.sun.identity.saml.common.SAMLResponderException)19 ArrayList (java.util.ArrayList)19 FSException (com.sun.identity.federation.common.FSException)17 IDFFMetaException (com.sun.identity.federation.meta.IDFFMetaException)17 Iterator (java.util.Iterator)17 XMLSignatureManager (com.sun.identity.saml.xmlsig.XMLSignatureManager)16 SessionProvider (com.sun.identity.plugin.session.SessionProvider)15 Assertion (com.sun.identity.saml.assertion.Assertion)15 Set (java.util.Set)15 Attribute (com.sun.identity.saml.assertion.Attribute)13 Element (org.w3c.dom.Element)13 ParseException (java.text.ParseException)12 Map (java.util.Map)12 Status (com.sun.identity.saml.protocol.Status)11 Document (org.w3c.dom.Document)11 BaseConfigType (com.sun.identity.federation.jaxb.entityconfig.BaseConfigType)10