Search in sources :

Example 1 with IDPAttributeMapper

use of com.sun.identity.saml2.plugins.IDPAttributeMapper in project OpenAM by OpenRock.

the class IDPSSOUtil method getIDPAttributeMapper.

/**
     * Returns an <code>IDPAttributeMapper</code>
     *
     * @param realm       the realm name
     * @param idpEntityID the entity id of the identity provider
     * @return the <code>IDPAttributeMapper</code>
     * @throws SAML2Exception if the operation is not successful
     */
static IDPAttributeMapper getIDPAttributeMapper(String realm, String idpEntityID) throws SAML2Exception {
    String classMethod = "IDPSSOUtil.getIDPAttributeMapper: ";
    String idpAttributeMapperName = null;
    IDPAttributeMapper idpAttributeMapper = null;
    try {
        idpAttributeMapperName = getAttributeValueFromIDPSSOConfig(realm, idpEntityID, SAML2Constants.IDP_ATTRIBUTE_MAPPER);
        if (idpAttributeMapperName == null) {
            idpAttributeMapperName = SAML2Constants.DEFAULT_IDP_ATTRIBUTE_MAPPER_CLASS;
            if (SAML2Utils.debug.messageEnabled()) {
                SAML2Utils.debug.message(classMethod + "use " + SAML2Constants.DEFAULT_IDP_ATTRIBUTE_MAPPER_CLASS);
            }
        }
        idpAttributeMapper = (IDPAttributeMapper) IDPCache.idpAttributeMapperCache.get(idpAttributeMapperName);
        if (idpAttributeMapper == null) {
            idpAttributeMapper = (IDPAttributeMapper) Class.forName(idpAttributeMapperName).newInstance();
            IDPCache.idpAttributeMapperCache.put(idpAttributeMapperName, idpAttributeMapper);
        } else {
            if (SAML2Utils.debug.messageEnabled()) {
                SAML2Utils.debug.message(classMethod + "got the IDPAttributeMapper from cache");
            }
        }
    } catch (Exception ex) {
        SAML2Utils.debug.error(classMethod + "Unable to get IDP Attribute Mapper.", ex);
        throw new SAML2Exception(ex);
    }
    return idpAttributeMapper;
}
Also used : SAML2Exception(com.sun.identity.saml2.common.SAML2Exception) IDPAttributeMapper(com.sun.identity.saml2.plugins.IDPAttributeMapper) SAML2InvalidNameIDPolicyException(com.sun.identity.saml2.common.SAML2InvalidNameIDPolicyException) SessionException(com.sun.identity.plugin.session.SessionException) COTException(com.sun.identity.cot.COTException) SAML2MetaException(com.sun.identity.saml2.meta.SAML2MetaException) SAML2TokenRepositoryException(org.forgerock.openam.federation.saml2.SAML2TokenRepositoryException) IOException(java.io.IOException) SAML2Exception(com.sun.identity.saml2.common.SAML2Exception)

Example 2 with IDPAttributeMapper

use of com.sun.identity.saml2.plugins.IDPAttributeMapper in project OpenAM by OpenRock.

the class IDPSSOUtil method getAttributeStatement.

/**
     * Returns a <code>SAML AttributeStatement</code> object
     *
     * @param session           the user's session
     * @param idpEntityID       the entity id of the identity provider
     * @param recipientEntityID the entity id of the response recipient
     * @param realm             the realm name
     * @return the <code>SAML AttributeStatement</code> object
     * @throws SAML2Exception if the operation is not successful
     */
private static AttributeStatement getAttributeStatement(Object session, String idpEntityID, String recipientEntityID, String realm) throws SAML2Exception {
    IDPAttributeMapper idpAttrMapper = getIDPAttributeMapper(realm, idpEntityID);
    List attributes = idpAttrMapper.getAttributes(session, idpEntityID, recipientEntityID, realm);
    if ((attributes == null) || (attributes.isEmpty())) {
        return null;
    }
    AttributeStatement attrStatement = AssertionFactory.getInstance().createAttributeStatement();
    attrStatement.setAttribute(attributes);
    return attrStatement;
}
Also used : IDPAttributeMapper(com.sun.identity.saml2.plugins.IDPAttributeMapper) AttributeStatement(com.sun.identity.saml2.assertion.AttributeStatement) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

IDPAttributeMapper (com.sun.identity.saml2.plugins.IDPAttributeMapper)2 COTException (com.sun.identity.cot.COTException)1 SessionException (com.sun.identity.plugin.session.SessionException)1 AttributeStatement (com.sun.identity.saml2.assertion.AttributeStatement)1 SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)1 SAML2InvalidNameIDPolicyException (com.sun.identity.saml2.common.SAML2InvalidNameIDPolicyException)1 SAML2MetaException (com.sun.identity.saml2.meta.SAML2MetaException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 SAML2TokenRepositoryException (org.forgerock.openam.federation.saml2.SAML2TokenRepositoryException)1