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;
}
Aggregations