use of com.sun.identity.saml.assertion.Attribute in project OpenAM by OpenRock.
the class DefaultIDPAttributeMapper method getSAMLAttribute.
/**
* Returns the SAML <code>Attribute</code> object.
* @param name attribute name.
* @param values attribute values.
* @exception WSFederationException if any failure.
*/
protected Attribute getSAMLAttribute(String name, String[] values) throws WSFederationException {
if (name == null) {
throw new WSFederationException(bundle.getString("nullInput"));
}
List list = new ArrayList();
if (values != null) {
for (int i = 0; i < values.length; i++) {
// Make the AttributeValue element 'by hand', since Attribute
// constructor below is expecting a list of AttributeValue
// elements
String attrValueString = SAMLUtils.makeStartElementTagXML("AttributeValue", true, true) + (XMLUtils.escapeSpecialCharacters(values[i])) + SAMLUtils.makeEndElementTagXML("AttributeValue", true);
list.add(XMLUtils.toDOMDocument(attrValueString, SAMLUtils.debug).getDocumentElement());
}
}
Attribute attribute = null;
try {
attribute = new Attribute(name, WSFederationConstants.CLAIMS_URI, list);
} catch (SAMLException se) {
throw new WSFederationException(se);
}
return attribute;
}
use of com.sun.identity.saml.assertion.Attribute in project OpenAM by OpenRock.
the class DefaultLibrarySPAccountMapper method getAttribute.
/**
* Returns the attribute name.
*/
private Set getAttribute(AttributeStatement statement, String attributeName, String realm, String hostEntityID) {
if (debug.messageEnabled()) {
debug.message("DefaultLibrarySPAccountMapper.getAttribute: attribute" + "Name =" + attributeName);
}
List list = statement.getAttribute();
for (Iterator iter = list.iterator(); iter.hasNext(); ) {
Attribute attribute = (Attribute) iter.next();
if (!attributeName.equalsIgnoreCase(attribute.getAttributeName())) {
continue;
}
List values = null;
try {
values = attribute.getAttributeValue();
} catch (SAMLException se) {
// Just ignore it and carry on - getAttributeValue doesn't
// really throw an exception - it just says it does
}
if (values == null || values.size() == 0) {
return null;
}
Set set = new HashSet();
set.addAll(values);
return set;
}
return null;
}
use of com.sun.identity.saml.assertion.Attribute in project OpenAM by OpenRock.
the class DefaultSPAttributeMapper method getAttributes.
/**
* Returns attribute map for the given list of <code>Attribute</code>
* objects.
* @param attributes list <code>Attribute</code>objects.
* @param userID universal identifier or distinguished name(DN) of the user.
* @param hostEntityID <code>EntityID</code> of the hosted provider.
* @param remoteEntityID <code>EntityID</code> of the remote provider.
* @param realm realm name.
* @return a map of mapped attribute value pair. This map has the
* key as the attribute name and the value as the attribute value
* @exception WSFederationException if any failure.
*/
public Map getAttributes(List attributes, String userID, String hostEntityID, String remoteEntityID, String realm) throws WSFederationException {
if (attributes == null || attributes.size() == 0) {
throw new WSFederationException(bundle.getString("nullAttributes"));
}
if (hostEntityID == null) {
throw new WSFederationException(bundle.getString("nullHostEntityID"));
}
if (realm == null) {
throw new WSFederationException(bundle.getString("nullRealm"));
}
Map<String, Set<String>> map = new HashMap<String, Set<String>>();
Map configMap = getConfigAttributeMap(realm, hostEntityID);
for (Iterator iter = attributes.iterator(); iter.hasNext(); ) {
Attribute attribute = (Attribute) iter.next();
Set<String> values = new HashSet();
try {
List attrValues = attribute.getAttributeValue();
for (Iterator iter2 = attrValues.iterator(); iter2.hasNext(); ) {
Element attrValue = (Element) iter2.next();
values.add(XMLUtils.getElementValue(attrValue));
}
} catch (SAMLException se) {
throw new WSFederationException(se);
}
String attributeName = attribute.getAttributeName();
String localAttribute = (String) configMap.get(attributeName);
if (localAttribute == null || localAttribute.length() == 0) {
localAttribute = attributeName;
}
Set<String> existingValues = map.get(localAttribute);
if (existingValues != null) {
existingValues.addAll(values);
} else {
map.put(localAttribute, values);
}
}
return map;
}
use of com.sun.identity.saml.assertion.Attribute in project OpenAM by OpenRock.
the class SAMLUtils method addEnvParamsFromAssertion.
/**
* Returns attributes included in <code>AttributeStatement</code> of the
* assertion.
* @param envParameters return map which includes name value pairs of
* attributes included in <code>AttributeStatement</code> of the assertion
* @param assertion an <code>Assertion</code> object which contains
* <code>AttributeStatement</code>
* @param subject the <code>Subject</code> instance from
* <code>AuthenticationStatement</code>. The <code>Subject</code>
* included in <code>AttributeStatement</code> must match this
* <code>Subject</code> instance.
*/
public static void addEnvParamsFromAssertion(Map envParameters, Assertion assertion, com.sun.identity.saml.assertion.Subject subject) {
Set statements = assertion.getStatement();
Statement statement = null;
Iterator stmtIter = null;
List attrs = null;
Iterator attrIter = null;
Attribute attribute = null;
Element attrValue = null;
List attrValues = null;
String attrName = null;
String attrValueString = null;
if ((statements != null) && (!statements.isEmpty())) {
stmtIter = statements.iterator();
while (stmtIter.hasNext()) {
statement = (Statement) stmtIter.next();
if (statement.getStatementType() == Statement.ATTRIBUTE_STATEMENT) {
// check for subject
if (!subject.equals(((AttributeStatement) statement).getSubject())) {
continue;
}
attrs = ((AttributeStatement) statement).getAttribute();
attrIter = attrs.iterator();
while (attrIter.hasNext()) {
attribute = (Attribute) attrIter.next();
try {
attrValues = attribute.getAttributeValue();
} catch (Exception e) {
debug.error("SAMLUtils.addEnvParamsFromAssertion:" + " cannot obtain attribute value:", e);
continue;
}
attrName = attribute.getAttributeName();
List attrValueList = null;
for (Iterator avIter = attrValues.iterator(); avIter.hasNext(); ) {
attrValue = (Element) avIter.next();
if (!XMLUtils.hasElementChild(attrValue)) {
attrValueString = XMLUtils.getElementValue(attrValue);
if (attrValueList == null) {
attrValueList = new ArrayList();
}
attrValueList.add(attrValueString);
}
}
if (attrValueList != null) {
if (debug.messageEnabled()) {
debug.message("SAMLUtils.addEnvParamsFromAssertion:" + " attrName = " + attrName + " attrValue = " + attrValueList);
}
String[] attrValueStrs = (String[]) attrValueList.toArray(new String[attrValueList.size()]);
try {
envParameters.put(attrName, attrValueStrs);
} catch (Exception ex) {
if (debug.messageEnabled()) {
debug.message("SAMLUtils.addEnvParamsFromAssertion:", ex);
}
}
} else if (debug.messageEnabled()) {
if (debug.messageEnabled()) {
debug.message("SAMLUtils.addEnvParamsFromAssertion:" + " attrName = " + attrName + " has no value");
}
}
}
}
// if it's an attribute statement
}
}
}
Aggregations