Search in sources :

Example 16 with AttributeQuery

use of com.sun.identity.saml2.protocol.AttributeQuery in project OpenAM by OpenRock.

the class AttributeQueryUtil method getUserAttributes.

public static List getUserAttributes(String userId, AttributeQuery attrQuery, String attrAuthorityEntityID, String realm) throws SAML2Exception {
    String requestedEntityID = attrQuery.getIssuer().getValue();
    Map configMap = SAML2Utils.getConfigAttributeMap(realm, requestedEntityID, SAML2Constants.SP_ROLE);
    if (SAML2Utils.debug.messageEnabled()) {
        SAML2Utils.debug.message("AttributeQueryUtil.getUserAttributes: " + "remote SP attribute map = " + configMap);
    }
    if (configMap == null || configMap.isEmpty()) {
        configMap = SAML2Utils.getConfigAttributeMap(realm, attrAuthorityEntityID, SAML2Constants.IDP_ROLE);
        if (configMap == null || configMap.isEmpty()) {
            if (SAML2Utils.debug.messageEnabled()) {
                SAML2Utils.debug.message("AttributeQueryUtil.getUserAttributes:" + "Configuration map is not defined.");
            }
            return null;
        }
        if (SAML2Utils.debug.messageEnabled()) {
            SAML2Utils.debug.message("AttributeQueryUtil.getUserAttributes: " + "hosted IDP attribute map=" + configMap);
        }
    }
    List attributes = new ArrayList();
    Set localAttributes = new HashSet();
    localAttributes.addAll(configMap.values());
    Map valueMap = null;
    try {
        valueMap = dsProvider.getAttributes(userId, localAttributes);
    } catch (DataStoreProviderException dse) {
        if (SAML2Utils.debug.warningEnabled()) {
            SAML2Utils.debug.warning("AttributeQueryUtil.getUserAttributes:", dse);
        }
    }
    Iterator iter = configMap.keySet().iterator();
    while (iter.hasNext()) {
        String samlAttribute = (String) iter.next();
        String localAttribute = (String) configMap.get(samlAttribute);
        String[] localAttributeValues = null;
        if ((valueMap != null) && (!valueMap.isEmpty())) {
            Set values = (Set) valueMap.get(localAttribute);
            if ((values == null) || values.isEmpty()) {
                if (SAML2Utils.debug.messageEnabled()) {
                    SAML2Utils.debug.message("AttributeQueryUtil.getUserAttributes:" + " user profile does not have value for " + localAttribute);
                }
            } else {
                localAttributeValues = (String[]) values.toArray(new String[values.size()]);
            }
        }
        if ((localAttributeValues == null) || (localAttributeValues.length == 0)) {
            if (SAML2Utils.debug.messageEnabled()) {
                SAML2Utils.debug.message("AttributeQueryUtil.getUserAttributes:" + " user does not have " + localAttribute);
            }
            continue;
        }
        Attribute attr = SAML2Utils.getSAMLAttribute(samlAttribute, localAttributeValues);
        attributes.add(attr);
    }
    return attributes;
}
Also used : DataStoreProviderException(com.sun.identity.plugin.datastore.DataStoreProviderException) Set(java.util.Set) HashSet(java.util.HashSet) Attribute(com.sun.identity.saml2.assertion.Attribute) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Aggregations

SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)12 Issuer (com.sun.identity.saml2.assertion.Issuer)5 AttributeAuthorityDescriptorElement (com.sun.identity.saml2.jaxb.metadata.AttributeAuthorityDescriptorElement)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Attribute (com.sun.identity.saml2.assertion.Attribute)4 EncryptedID (com.sun.identity.saml2.assertion.EncryptedID)4 Subject (com.sun.identity.saml2.assertion.Subject)4 Response (com.sun.identity.saml2.protocol.Response)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 Set (java.util.Set)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 DataStoreProviderException (com.sun.identity.plugin.datastore.DataStoreProviderException)3 Assertion (com.sun.identity.saml2.assertion.Assertion)3 EncryptedAssertion (com.sun.identity.saml2.assertion.EncryptedAssertion)3 NameID (com.sun.identity.saml2.assertion.NameID)3 SAML2MetaException (com.sun.identity.saml2.meta.SAML2MetaException)3 AttributeQuery (com.sun.identity.saml2.protocol.AttributeQuery)3 X509Certificate (java.security.cert.X509Certificate)3