public static Map<String, Object> asMap(Set<AttributeStatementType> attributeStatementTypes) { Map<String, Object> attrMap = new HashMap<String, Object>(); if (attributeStatementTypes != null && !attributeStatementTypes.isEmpty()) { attrMap = new HashMap<String, Object>(); for (StatementAbstractType statement : attributeStatementTypes) { if (statement instanceof AttributeStatementType) { AttributeStatementType attrStat = (AttributeStatementType) statement; List<ASTChoiceType> attrs = attrStat.getAttributes(); for (ASTChoiceType attrChoice : attrs) { AttributeType attr = attrChoice.getAttribute(); String attributeName = attr.getFriendlyName(); if (attributeName == null) { attributeName = attr.getName(); } List<Object> values = attr.getAttributeValue(); if (values != null) { if (values.size() == 1) { attrMap.put(attributeName, values.get(0)); } else { attrMap.put(attributeName, values); } } } } } } return attrMap; }
/** * Create an attribute type given a role name * * @param roleName * @return */ public static AttributeType createAttributeForRole(String roleName) { AttributeType att = new AttributeType("role"); att.setFriendlyName("role"); att.setNameFormat(JBossSAMLURIConstants.ATTRIBUTE_FORMAT_BASIC.get()); // rolename att.addAttributeValue(roleName); return att; }
private static AttributeType getX500Attribute(String name) { AttributeType att = new AttributeType(name); att.getOtherAttributes().put(X500_QNAME, "LDAP"); att.setNameFormat(JBossSAMLURIConstants.ATTRIBUTE_FORMAT_URI.get()); return att; } }
/** * Create an attribute type * * @param name Name of the attribute * @param nameFormat name format uri * @param attributeValues an object array of attribute values * @return */ public static AttributeType createAttribute(String name, String nameFormat, Object... attributeValues) { AttributeType att = new AttributeType(name); att.setNameFormat(nameFormat); if (attributeValues != null && attributeValues.length > 0) { for (Object attributeValue : attributeValues) { att.addAttributeValue(attributeValue); } } return att; }
AttributeType attr = obj.getAttribute(); if (roleKeys != null && roleKeys.size() > 0) { if (!roleKeys.contains(attr.getName())) continue; List<Object> attributeValues = attr.getAttributeValue(); if (attributeValues != null) { for (Object attrValue : attributeValues) {
public void writeAttributeTypeWithoutRootTag(AttributeType attributeType) throws ProcessingException { String attributeName = attributeType.getName(); if (attributeName != null) { StaxUtil.writeAttribute(writer, JBossSAMLConstants.NAME.get(), attributeName); String friendlyName = attributeType.getFriendlyName(); if (StringUtil.isNotNull(friendlyName)) { StaxUtil.writeAttribute(writer, JBossSAMLConstants.FRIENDLY_NAME.get(), friendlyName); String nameFormat = attributeType.getNameFormat(); if (StringUtil.isNotNull(nameFormat)) { StaxUtil.writeAttribute(writer, JBossSAMLConstants.NAME_FORMAT.get(), nameFormat); Map<QName, String> otherAttribs = attributeType.getOtherAttributes(); if (otherAttribs != null) { List<String> nameSpacesDealt = new ArrayList<String>(); List<Object> attributeValues = attributeType.getAttributeValue(); if (attributeValues != null) { for (Object attributeValue : attributeValues) {
/** * Create an AttributeStatement given an attribute * @param attributeValue * @return */ public static AttributeStatementType createAttributeStatement(String attributeValue) { AttributeStatementType attribStatement = new AttributeStatementType(); AttributeType att = new AttributeType( attributeValue ); att.addAttributeValue(attributeValue); attribStatement.addAttribute( new ASTChoiceType( att )); return attribStatement; }
attributeType.getOtherAttributes().put(x500EncodingAttr.getName(), StaxParserUtil.getAttributeValue(x500EncodingAttr)); attributeType.setFriendlyName(StaxParserUtil.getAttributeValue(friendlyName)); attributeType.setNameFormat(StaxParserUtil.getAttributeValue(nameFormat)); attributeType.addAttributeValue(attributeValue);
public AttributeStatementType getAttributeStatement() { Subject subject = SecurityActions.getSecurityContext().getSubjectInfo().getAuthenticatedSubject(); if (subject == null) { logger.trace("No authentication Subject found, cannot provide any user roles!"); return null; } else { AttributeStatementType attributeStatement = new AttributeStatementType(); AttributeType rolesAttribute = new AttributeType(tokenRoleAttributeName); attributeStatement.addAttribute(new ASTChoiceType(rolesAttribute)); // List<Object> roles = rolesAttribute.getAttributeValue(); for (Principal rolePrincipal : subject.getPrincipals()) { if (JBOSS_ROLE_PRINCIPAL_NAME.equalsIgnoreCase(rolePrincipal.getName())) { Group simpleGroup = (Group) rolePrincipal; Enumeration<? extends Principal> members = simpleGroup.members(); while (members.hasMoreElements()) { Principal role = members.nextElement(); rolesAttribute.addAttributeValue(role.getName()); // roles.add( role.getName() ); } } } logger .trace("Returning an AttributeStatement with a [" + tokenRoleAttributeName + "] attribute containing: " + rolesAttribute .getAttributeValue().toString()); return attributeStatement; } } }
for (ASTChoiceType obj : attList) { AttributeType attr = obj.getAttribute(); String roleName = (String) attr.getAttributeValue().get(0); roles.add(roleName);
/** * Parse an {@code AttributeType} * @param xmlEventReader * @return * @throws ParsingException */ public static AttributeType parseAttribute(XMLEventReader xmlEventReader) throws ParsingException { StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader); StaxParserUtil.validate(startElement, JBossSAMLConstants.ATTRIBUTE.get()); AttributeType attributeType = null; Attribute name = startElement.getAttributeByName(new QName(JBossSAMLConstants.NAME.get())); if (name == null) throw new RuntimeException(REQD_ATTRIBUTE + "Name"); attributeType = new AttributeType(StaxParserUtil.getAttributeValue(name)); parseAttributeType(xmlEventReader, startElement, JBossSAMLConstants.ATTRIBUTE.get(), attributeType); return attributeType; }
AttributeType attr = obj.getAttribute(); if (roleKeys != null && roleKeys.size() > 0) { if (!roleKeys.contains(attr.getName())) continue; List<Object> attributeValues = attr.getAttributeValue(); if (attributeValues != null) { for (Object attrValue : attributeValues) {
public void writeAttributeTypeWithoutRootTag(AttributeType attributeType) throws ProcessingException { String attributeName = attributeType.getName(); if (attributeName != null) { StaxUtil.writeAttribute(writer, JBossSAMLConstants.NAME.get(), attributeName); String friendlyName = attributeType.getFriendlyName(); if (StringUtil.isNotNull(friendlyName)) { StaxUtil.writeAttribute(writer, JBossSAMLConstants.FRIENDLY_NAME.get(), friendlyName); String nameFormat = attributeType.getNameFormat(); if (StringUtil.isNotNull(nameFormat)) { StaxUtil.writeAttribute(writer, JBossSAMLConstants.NAME_FORMAT.get(), nameFormat); Map<QName, String> otherAttribs = attributeType.getOtherAttributes(); if (otherAttribs != null) { List<String> nameSpacesDealt = new ArrayList<String>(); List<Object> attributeValues = attributeType.getAttributeValue(); if (attributeValues != null) { for (Object attributeValue : attributeValues) {
/** * Create an AttributeStatement given an attribute * * @param attributeValue * * @return */ public static AttributeStatementType createAttributeStatement(String attributeValue) { AttributeStatementType attribStatement = new AttributeStatementType(); AttributeType att = new AttributeType(attributeValue); att.addAttributeValue(attributeValue); attribStatement.addAttribute(new ASTChoiceType(att)); return attribStatement; }
attributeType.getOtherAttributes().put(x500EncodingAttr.getName(), StaxParserUtil.getAttributeValue(x500EncodingAttr)); attributeType.setFriendlyName(StaxParserUtil.getAttributeValue(friendlyName)); attributeType.setNameFormat(StaxParserUtil.getAttributeValue(nameFormat)); attributeType.addAttributeValue(attributeValue);
/** * Create an attribute type * * @param name Name of the attribute * @param nameFormat name format uri * @param attributeValues an object array of attribute values * * @return */ public static AttributeType createAttribute(String name, String nameFormat, Object... attributeValues) { AttributeType att = new AttributeType(name); att.setNameFormat(nameFormat); if (attributeValues != null && attributeValues.length > 0) { for (Object attributeValue : attributeValues) { att.addAttributeValue(attributeValue); } } return att; }
public AttributeStatementType getAttributeStatement() { Subject subject = SecurityActions.getSecurityContext().getSubjectInfo().getAuthenticatedSubject(); if (subject == null) { logger.trace("No authentication Subject found, cannot provide any user roles!"); return null; } else { AttributeStatementType attributeStatement = new AttributeStatementType(); AttributeType rolesAttribute = new AttributeType(tokenRoleAttributeName); attributeStatement.addAttribute(new ASTChoiceType(rolesAttribute)); // List<Object> roles = rolesAttribute.getAttributeValue(); for (Principal rolePrincipal : subject.getPrincipals()) { if (JBOSS_ROLE_PRINCIPAL_NAME.equalsIgnoreCase(rolePrincipal.getName())) { Group simpleGroup = (Group) rolePrincipal; Enumeration<? extends Principal> members = simpleGroup.members(); while (members.hasMoreElements()) { Principal role = members.nextElement(); rolesAttribute.addAttributeValue(role.getName()); // roles.add( role.getName() ); } } } logger .trace("Returning an AttributeStatement with a [" + tokenRoleAttributeName + "] attribute containing: " + rolesAttribute .getAttributeValue().toString()); return attributeStatement; } } }
String roleName = (String) attr.getAttributeValue().get(0); roles.add(roleName);
/** * Parse an {@code AttributeType} * @param xmlEventReader * @return * @throws ParsingException */ public static AttributeType parseAttribute(XMLEventReader xmlEventReader) throws ParsingException { StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader); StaxParserUtil.validate(startElement, JBossSAMLConstants.ATTRIBUTE.get()); AttributeType attributeType = null; Attribute name = startElement.getAttributeByName(new QName(JBossSAMLConstants.NAME.get())); if (name == null) throw new RuntimeException(REQD_ATTRIBUTE + "Name"); attributeType = new AttributeType(StaxParserUtil.getAttributeValue(name)); parseAttributeType(xmlEventReader, startElement, JBossSAMLConstants.ATTRIBUTE.get(), attributeType); return attributeType; }
if (roleKeys != null && roleKeys.size() > 0) if (!roleKeys.contains(attr.getName())) continue; List<Object> attributeValues = attr.getAttributeValue(); if (attributeValues != null)