use of com.sun.identity.saml2.assertion.Attribute in project OpenAM by OpenRock.
the class SAML2Utils method getAllAttributeValueFromSSOConfig.
/**
* Returns all values of specified attribute from SSOConfig.
*
* @param realm realm of hosted entity.
* @param hostEntityId name of hosted entity.
* @param entityRole role of hosted entity.
* @param attrName attribute name for the value.
* @return value of specified attribute from SSOConfig.
*/
public static List<String> getAllAttributeValueFromSSOConfig(String realm, String hostEntityId, String entityRole, String attrName) {
if (debug.messageEnabled()) {
String method = "getAllAttributeValueFromSSOConfig : ";
debug.message(method + "realm - " + realm);
debug.message(method + "hostEntityId - " + hostEntityId);
debug.message(method + "entityRole - " + entityRole);
debug.message(method + "attrName - " + attrName);
}
try {
BaseConfigType config = null;
if (entityRole.equalsIgnoreCase(SAML2Constants.SP_ROLE)) {
config = saml2MetaManager.getSPSSOConfig(realm, hostEntityId);
} else if (entityRole.equalsIgnoreCase(SAML2Constants.IDP_ROLE)) {
config = saml2MetaManager.getIDPSSOConfig(realm, hostEntityId);
} else if (entityRole.equalsIgnoreCase(SAML2Constants.ATTR_AUTH_ROLE)) {
config = saml2MetaManager.getAttributeAuthorityConfig(realm, hostEntityId);
} else if (entityRole.equalsIgnoreCase(SAML2Constants.AUTHN_AUTH_ROLE)) {
config = saml2MetaManager.getAuthnAuthorityConfig(realm, hostEntityId);
} else if (entityRole.equalsIgnoreCase(SAML2Constants.ATTR_QUERY_ROLE)) {
config = saml2MetaManager.getAttributeQueryConfig(realm, hostEntityId);
}
if (config == null) {
return null;
}
Map attrs = SAML2MetaUtils.getAttributes(config);
if (attrs == null) {
return null;
}
return (List) attrs.get(attrName);
} catch (SAML2MetaException e) {
debug.message("get SSOConfig failed:", e);
}
return null;
}
use of com.sun.identity.saml2.assertion.Attribute in project OpenAM by OpenRock.
the class AttributeImpl method toXMLString.
/**
* Returns a String representation of the element.
*
* @param includeNS Determines whether or not the namespace qualifier is
* prepended to the Element when converted
* @param declareNS Determines whether or not the namespace is declared
* within the Element.
* @return A string containing the valid XML for this element
* @throws SAML2Exception if the object does not conform to the schema.
*/
public String toXMLString(boolean includeNS, boolean declareNS) throws SAML2Exception {
if (name == null || name.trim().length() == 0) {
if (SAML2SDKUtils.debug.messageEnabled()) {
SAML2SDKUtils.debug.message("AttributeImpl.toXMLString:" + " missing Attribute Name.");
}
throw new SAML2Exception(SAML2SDKUtils.bundle.getString("missingAttribute"));
}
StringBuffer result = new StringBuffer(1000);
String prefix = "";
String uri = "";
if (includeNS) {
prefix = SAML2Constants.ASSERTION_PREFIX;
}
if (declareNS) {
uri = SAML2Constants.ASSERTION_DECLARE_STR;
}
result.append("<").append(prefix).append("Attribute").append(uri).append(" Name=\"").append(name).append("\"");
if (nameFormat != null && nameFormat.trim().length() != 0) {
result.append(" NameFormat=\"").append(nameFormat).append("\"");
}
if (friendlyName != null && friendlyName.trim().length() != 0) {
result.append(" FriendlyName=\"").append(friendlyName).append("\"");
}
if (anyMap != null) {
Iterator keyIter = anyMap.keySet().iterator();
while (keyIter.hasNext()) {
String key = (String) keyIter.next();
String value = (String) anyMap.get(key);
if (value == null) {
value = "";
}
result.append(" ").append(key).append("=\"").append(value).append("\"");
}
}
result.append(">");
if (attrValues != null) {
Iterator iter = attrValues.iterator();
while (iter.hasNext()) {
result.append((String) iter.next());
}
}
result.append("</").append(prefix).append("Attribute>");
return result.toString();
}
use of com.sun.identity.saml2.assertion.Attribute in project OpenAM by OpenRock.
the class AttributeImpl method parseElement.
// used by the constructors.
private void parseElement(Element element) throws SAML2Exception {
// make sure that the input xml block is not null
if (element == null) {
if (SAML2SDKUtils.debug.messageEnabled()) {
SAML2SDKUtils.debug.message("AttributeImpl.parseElement: " + "Input is null.");
}
throw new SAML2Exception(SAML2SDKUtils.bundle.getString("nullInput"));
}
// Make sure this is an Attribute.
String tag = element.getLocalName();
if ((tag == null) || (!tag.equals("Attribute"))) {
if (SAML2SDKUtils.debug.messageEnabled()) {
SAML2SDKUtils.debug.message("AttributeImpl.parseElement: " + "not Attribute.");
}
throw new SAML2Exception(SAML2SDKUtils.bundle.getString("wrongInput"));
}
// handle the attributes of <Attribute> element
NamedNodeMap atts = ((Node) element).getAttributes();
if (atts != null) {
int length = atts.getLength();
for (int i = 0; i < length; i++) {
Attr attr = (Attr) atts.item(i);
String attrName = attr.getName();
String attrValue = attr.getValue().trim();
if (attrName.equals("Name")) {
name = attrValue;
} else if (attrName.equals("NameFormat")) {
nameFormat = attrValue;
} else if (attrName.equals("FriendlyName")) {
friendlyName = attrValue;
} else {
if (!attrValue.equals(SAML2Constants.ASSERTION_NAMESPACE_URI)) {
if (anyMap == null) {
anyMap = new HashMap();
}
anyMap.put(attrName, attrValue);
}
}
}
}
// handle AttributeValue
NodeList nl = element.getChildNodes();
Node child;
String childName;
int length = nl.getLength();
for (int i = 0; i < length; i++) {
child = nl.item(i);
if ((childName = child.getLocalName()) != null) {
if (childName.equals("AttributeValue")) {
if (attrValues == null) {
attrValues = new ArrayList();
}
attrValues.add(XMLUtils.print(child));
if (valueStrings == null) {
valueStrings = new ArrayList();
}
valueStrings.add(XMLUtils.getChildrenValue((Element) child));
} else {
if (SAML2SDKUtils.debug.messageEnabled()) {
SAML2SDKUtils.debug.message("Attributempl.parseElement" + ": Invalid element:" + childName);
}
throw new SAML2Exception(SAML2SDKUtils.bundle.getString("invalidElement"));
}
}
}
if (name == null || name.trim().length() == 0) {
if (SAML2SDKUtils.debug.messageEnabled()) {
SAML2SDKUtils.debug.message("AttributeImpl.parseElement:" + " missing Name attribute.");
}
throw new SAML2Exception(SAML2SDKUtils.bundle.getString("missingAttribute"));
}
if (attrValues != null) {
attrValues = Collections.unmodifiableList(attrValues);
}
if (valueStrings != null) {
valueStrings = Collections.unmodifiableList(valueStrings);
}
if (anyMap != null) {
anyMap = Collections.unmodifiableMap(anyMap);
}
mutable = false;
}
use of com.sun.identity.saml2.assertion.Attribute in project OpenAM by OpenRock.
the class ConditionsImpl method processElement.
private void processElement(Element element) throws SAML2Exception {
if (element == null) {
SAML2SDKUtils.debug.error("ConditionsImpl.processElement(): invalid root element");
throw new SAML2Exception(SAML2SDKUtils.bundle.getString("invalid_element"));
}
String elemName = element.getLocalName();
if (elemName == null) {
SAML2SDKUtils.debug.error("ConditionsImpl.processElement(): local name missing");
throw new SAML2Exception(SAML2SDKUtils.bundle.getString("missing_local_name"));
}
if (!elemName.equals(CONDITIONS_ELEMENT)) {
SAML2SDKUtils.debug.error("ConditionsImpl.processElement(): invalid local name " + elemName);
throw new SAML2Exception(SAML2SDKUtils.bundle.getString("invalid_local_name"));
}
// starts processing attributes
String attrValue = element.getAttribute(NOT_BEFORE_ATTR);
if ((attrValue != null) && (attrValue.trim().length() != 0)) {
try {
notBefore = DateUtils.stringToDate(attrValue);
} catch (ParseException pe) {
SAML2SDKUtils.debug.error("ConditionsImpl.processElement():" + " invalid NotBefore attribute");
throw new SAML2Exception(SAML2SDKUtils.bundle.getString("invalid_date_format"));
}
}
attrValue = element.getAttribute(NOT_ON_OR_AFTER_ATTR);
if ((attrValue != null) && (attrValue.trim().length() != 0)) {
try {
notOnOrAfter = DateUtils.stringToDate(attrValue);
} catch (ParseException pe) {
SAML2SDKUtils.debug.error("ConditionsImpl.processElement():" + " invalid NotOnORAfter attribute");
throw new SAML2Exception(SAML2SDKUtils.bundle.getString("invalid_date_format"));
}
}
// starts processing subelements
NodeList nodes = element.getChildNodes();
int numOfNodes = nodes.getLength();
int nextElem = 0;
while (nextElem < numOfNodes) {
Node child = (Node) nodes.item(nextElem);
if (child.getNodeType() == Node.ELEMENT_NODE) {
String childName = child.getLocalName();
if (childName != null) {
if (childName.equals(CONDITION_ELEMENT)) {
conditions.add(AssertionFactory.getInstance().createCondition((Element) child));
} else if (childName.equals(AUDIENCE_RESTRICTION_ELEMENT)) {
audienceRestrictions.add(AssertionFactory.getInstance().createAudienceRestriction((Element) child));
} else if (childName.equals(ONETIMEUSE_ELEMENT)) {
oneTimeUses.add(AssertionFactory.getInstance().createOneTimeUse((Element) child));
} else if (childName.equals(PROXY_RESTRICTION_ELEMENT)) {
proxyRestrictions.add(AssertionFactory.getInstance().createProxyRestriction((Element) child));
} else {
SAML2SDKUtils.debug.error("ConditionsImpl." + "processElement(): unexpected subelement " + childName);
throw new SAML2Exception(SAML2SDKUtils.bundle.getString("unexpected_subelement"));
}
}
}
nextElem++;
}
}
use of com.sun.identity.saml2.assertion.Attribute in project OpenAM by OpenRock.
the class AttributeStatementImpl method parseElement.
// used by the constructors.
private void parseElement(Element element) throws SAML2Exception {
// make sure that the input xml block is not null
if (element == null) {
if (SAML2SDKUtils.debug.messageEnabled()) {
SAML2SDKUtils.debug.message("AttributeStatementImpl." + "parseElement: Input is null.");
}
throw new SAML2Exception(SAML2SDKUtils.bundle.getString("nullInput"));
}
// Make sure this is an AttributeStatement.
if (!SAML2SDKUtils.checkStatement(element, "AttributeStatement")) {
if (SAML2SDKUtils.debug.messageEnabled()) {
SAML2SDKUtils.debug.message("AttributeStatementImpl." + "parseElement: not AttributeStatement.");
}
throw new SAML2Exception(SAML2SDKUtils.bundle.getString("wrongInput"));
}
// handle the sub elementsof the AuthnStatment
NodeList nl = element.getChildNodes();
Node child;
String childName;
int length = nl.getLength();
for (int i = 0; i < length; i++) {
child = nl.item(i);
if ((childName = child.getLocalName()) != null) {
if (childName.equals("Attribute")) {
Attribute attr = AssertionFactory.getInstance().createAttribute((Element) child);
if (attrs == null) {
attrs = new ArrayList();
}
attrs.add(attr);
} else if (childName.equals("EncryptedAttribute")) {
EncryptedAttribute encAttr = AssertionFactory.getInstance().createEncryptedAttribute((Element) child);
if (encAttrs == null) {
encAttrs = new ArrayList();
}
encAttrs.add(encAttr);
} else {
if (SAML2SDKUtils.debug.messageEnabled()) {
SAML2SDKUtils.debug.message("AttributeStatementImpl." + "parse Element: Invalid element:" + childName);
}
throw new SAML2Exception(SAML2SDKUtils.bundle.getString("invalidElement"));
}
}
}
validateData();
if (attrs != null) {
attrs = Collections.unmodifiableList(attrs);
}
if (encAttrs != null) {
encAttrs = Collections.unmodifiableList(encAttrs);
}
mutable = false;
}
Aggregations