/** * Validates that the attribute has at least one attribute value. * * @param attribute attribute to validate * * @throws ValidationException thrown if the attribute does not have any values */ protected void validateAttributeValue(Attribute attribute) throws ValidationException { if (attribute.getAttributeValues().size() == 0) { throw new ValidationException("No AttributeValue elements present"); } } }
/** {@inheritDoc} */ protected void processChildElement(XMLObject parentSAMLObject, XMLObject childSAMLObject) throws UnmarshallingException { Attribute attribute = (Attribute) parentSAMLObject; QName childQName = childSAMLObject.getElementQName(); if (childQName.getLocalPart().equals("AttributeValue") && childQName.getNamespaceURI().equals(SAMLConstants.SAML1_NS)) { attribute.getAttributeValues().add(childSAMLObject); } else { super.processChildElement(parentSAMLObject, childSAMLObject); } } }
/** {@inheritDoc} */ public Attribute encode(BaseAttribute attribute) throws AttributeEncodingException { Attribute samlAttribute = attributeBuilder.buildObject(); populateAttribute(samlAttribute); XSAny samlAttributeValue; for (Object o : attribute.getValues()) { if (o == null || !(o instanceof XMLObject)) { continue; } samlAttributeValue = attributeValueBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME); samlAttributeValue.getUnknownXMLObjects().add((XMLObject) o); samlAttribute.getAttributeValues().add(samlAttributeValue); } List<XMLObject> attributeValues = samlAttribute.getAttributeValues(); if (attributeValues == null || attributeValues.isEmpty()) { log.debug("Unable to encode {} attribute. It does not contain any values", attribute.getId()); return null; } return samlAttribute; }
/** {@inheritDoc} */ public Attribute encode(BaseAttribute attribute) throws AttributeEncodingException { Attribute samlAttribute = attributeBuilder.buildObject(); samlAttribute.setAttributeName(getAttributeName()); samlAttribute.setAttributeNamespace(getNamespace()); samlAttribute.getAttributeValues() .addAll(encodeAttributeValues(AttributeValue.DEFAULT_ELEMENT_NAME, attribute)); List<XMLObject> attributeValues = samlAttribute.getAttributeValues(); if (attributeValues == null || attributeValues.isEmpty()) { log.debug("Unable to encode {} attribute. It does not contain any values", attribute.getId()); return null; } return samlAttribute; }
String name = attr.getAttributeNamespace() + "/" + attr.getAttributeName(); List attributeValues = attr.getAttributeValues(); Iterator values = attributeValues.iterator(); StringBuilder buffer = new StringBuilder();
/** {@inheritDoc} */ public Attribute encode(BaseAttribute attribute) { Attribute samlAttribute = attributeBuilder.buildObject(); populateAttribute(samlAttribute); byte[] attributeValue; XSString samlAttributeValue; for (Object o : attribute.getValues()) { if (o == null || !(o instanceof byte[])) { log.debug("Skipping attribute value because it is either null or not a byte[]"); continue; } attributeValue = (byte[]) o; samlAttributeValue = stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME); samlAttributeValue.setValue(Base64.encodeBytes(attributeValue)); samlAttribute.getAttributeValues().add(samlAttributeValue); } List<XMLObject> attributeValues = samlAttribute.getAttributeValues(); if (attributeValues == null || attributeValues.isEmpty()) { log.debug("Unable to encode {} attribute. It does not contain any values", attribute.getId()); return null; } return samlAttribute; }
final Collection<?> c = (Collection<?>) e.getValue(); for (final Object value : c) { attribute.getAttributeValues().add(newAttributeValue(value, attrStatement)); attribute.getAttributeValues().add(newAttributeValue(e.getValue(), attrStatement)); attribute.setAttributeName(this.rememberMeAttributeName); attribute.setAttributeNamespace(NAMESPACE); attribute.getAttributeValues().add(newAttributeValue(REMEMBER_ME_ATTRIBUTE_VALUE, attrStatement)); attrStatement.getAttributes().add(attribute);
/** {@inheritDoc} */ public Attribute encode(BaseAttribute attribute) { Attribute samlAttribute = attributeBuilder.buildObject(); populateAttribute(samlAttribute); String attributeValue; XSString samlAttributeValue; for (Object o : attribute.getValues()) { if (o == null) { continue; } attributeValue = o.toString(); if (!DatatypeHelper.isEmpty(attributeValue)) { samlAttributeValue = stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME); samlAttributeValue.setValue(attributeValue); samlAttribute.getAttributeValues().add(samlAttributeValue); } } List<XMLObject> attributeValues = samlAttribute.getAttributeValues(); if (attributeValues == null || attributeValues.isEmpty()) { log.debug("Unable to encode {} attribute. It does not contain any values", attribute.getId()); return null; } return samlAttribute; }
stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME); attribute1.setValue((String)value); attribute.getAttributeValues().add(attribute1); } else if (value instanceof XMLObject) { attribute.getAttributeValues().add((XMLObject)value);
stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME); attribute1.setValue((String)value); attribute.getAttributeValues().add(attribute1); } else if (value instanceof XMLObject) { attribute.getAttributeValues().add((XMLObject)value);
attributeValueBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME); stringValue.setValue(claim.getValue()); attribute.getAttributeValues().add(stringValue);
attributeValueBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME); stringValue.setValue(claim.getValue()); attribute.getAttributeValues().add(stringValue);
/** * Creates a SAML attribute similar to following, * <pre> <saml:Attribute * AttributeName="MemberLevel" * AttributeNamespace="http://www.oasis.open.org/Catalyst2002/attributes"> * <saml:AttributeValue>gold</saml:AttributeValue> * </saml:Attribute></pre> * @param name attribute name * @param namespace attribute namespace. * @param value attribute value. * @return OpenSAML representation of the attribute. * @throws org.apache.rahas.TrustException If unable to find the appropriate builder. */ public static Attribute createAttribute(String name, String namespace, String value) throws TrustException { Attribute attribute = (Attribute)CommonUtil.buildXMLObject(Attribute.DEFAULT_ELEMENT_NAME); attribute.setAttributeName(name); attribute.setAttributeNamespace(namespace); XSStringBuilder attributeValueBuilder = (XSStringBuilder)Configuration.getBuilderFactory(). getBuilder(XSString.TYPE_NAME); XSString stringValue = attributeValueBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME); stringValue.setValue(value); attribute.getAttributeValues().add(stringValue); return attribute; }