public Attribute buildStringAttribute(String name, List<String> values) { @SuppressWarnings("unchecked") SAMLObjectBuilder<Attribute> attributeBuilder = (SAMLObjectBuilder<Attribute>) builderFactory .getBuilder(Attribute.DEFAULT_ELEMENT_NAME); Attribute attribute = (Attribute) attributeBuilder.buildObject(); attribute.setName(name); @SuppressWarnings("unchecked") XMLObjectBuilder<XSString> xsStringBuilder = (XMLObjectBuilder<XSString>) builderFactory .getBuilder(XSString.TYPE_NAME); for (String value : values) { // Set custom Attributes XSString attributeValue = xsStringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME); attributeValue.setValue(value); attribute.getAttributeValues().add(attributeValue); } return attribute; }
/** {@inheritDoc} */ protected void processElementContent(XMLObject xmlObject, String elementContent) { XSString xsiString = (XSString) xmlObject; xsiString.setValue(elementContent); } }
/** {@inheritDoc} */ protected void processElementContent(XMLObject xmlObject, String elementContent) { XSString xsiString = (XSString) xmlObject; xsiString.setValue(elementContent); } }
private static Attribute buildAttribute(String name, List<String> values) { XSStringBuilder stringBuilder = (XSStringBuilder) Configuration.getBuilderFactory().getBuilder(XSString.TYPE_NAME); Attribute attribute = buildSAMLObject(Attribute.class, Attribute.DEFAULT_ELEMENT_NAME); attribute.setName(name); attribute.setNameFormat("urn:oasis:names:tc:SAML:2.0:attrname-format:uri"); List<XSString> xsStringList = values.stream().map(value -> { XSString stringValue = stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME); stringValue.setValue(value); return stringValue; }).collect(toList()); attribute.getAttributeValues().addAll(xsStringList); return attribute; }
/** * Create a SAML2 Attribute * * @param friendlyName of type String * @param name of type String * @param nameFormat of type String * @param values of type ArrayList * @return a SAML2 Attribute */ public static Attribute createAttribute( String friendlyName, String name, String nameFormat, List<String> values ) { if (stringBuilder == null) { stringBuilder = (XSStringBuilder)builderFactory.getBuilder(XSString.TYPE_NAME); } Attribute attribute = createAttribute(friendlyName, name, nameFormat); for (String value : values) { XSString attributeValue = stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME); attributeValue.setValue(value); attribute.getAttributeValues().add(attributeValue); } return attribute; } /**
/** {@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; }
@SuppressWarnings("unchecked") private static Attribute getAttribute(String attributeName, String attributeValue) { Attribute attribute = buildXMLObject(Attribute.class, Attribute.DEFAULT_ELEMENT_NAME); attribute.setName(attributeName); XMLObjectBuilder<XSString> builder = Configuration.getBuilderFactory() .getBuilder(XSString.TYPE_NAME); XSString xmlAttributeValue = builder.buildObject( AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME); xmlAttributeValue.setValue(attributeValue); attribute.getAttributeValues().add(xmlAttributeValue); return attribute; }
/** * Create a SAML2 Attribute * * @param friendlyName of type String * @param name of type String * @param nameFormat of type String * @param values of type ArrayList * @return a SAML2 Attribute */ public static Attribute createAttribute( String friendlyName, String name, String nameFormat, List<?> values ) { if (stringBuilder == null) { stringBuilder = (XSStringBuilder)builderFactory.getBuilder(XSString.TYPE_NAME); } Attribute attribute = createAttribute(friendlyName, name, nameFormat); for (Object value : values) { if (value instanceof String) { XSString attributeValue = stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME); attributeValue.setValue((String)value); attribute.getAttributeValues().add(attributeValue); } else if (value instanceof XMLObject) { attribute.getAttributeValues().add((XMLObject)value); } } return 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; }
/** {@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; }
/** * Create a SAML2 Attribute * * @param friendlyName of type String * @param name of type String * @param nameFormat of type String * @param values of type ArrayList * @return a SAML2 Attribute */ public static Attribute createAttribute( String friendlyName, String name, String nameFormat, List<?> values ) { if (stringBuilder == null) { stringBuilder = (XSStringBuilder)builderFactory.getBuilder(XSString.TYPE_NAME); } Attribute attribute = createAttribute(friendlyName, name, nameFormat); for (Object value : values) { if (value instanceof String) { XSString attributeValue = stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME); attributeValue.setValue((String)value); attribute.getAttributeValues().add(attributeValue); } else if (value instanceof XMLObject) { attribute.getAttributeValues().add((XMLObject)value); } } return 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; }
private void addAttribute(AttributeStatement attributeStatement, Attributes attribute, String value) { if (null == value) { return; } XMLObjectBuilder<XSString> builder = Configuration.getBuilderFactory() .getBuilder(XSString.TYPE_NAME); Attribute samlAttribute = buildXMLObject(Attribute.class, Attribute.DEFAULT_ELEMENT_NAME); samlAttribute.setName(attribute.getName()); XSString attributeValue = builder.buildObject( AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME); attributeValue.setValue(value); samlAttribute.getAttributeValues().add(attributeValue); attributeStatement.getAttributes().add(samlAttribute); }
@Override public Attribute build() { Attribute attribute = new AttributeBuilder().buildObject(); XSString xsString = new XSStringBuilder().buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME); attribute.setName(attributeName); attribute.setNameFormat(attributeFormat); xsString.setValue(attributeValue); attribute.getAttributeValues().add(xsString); return attribute; }
/** * Build Attribute Statement * * @param claims * @return AttributeStatement */ private AttributeStatement buildAttributeStatement(Map<String, String> claims) { AttributeStatement attStmt = null; if (claims != null) { attStmt = new AttributeStatementBuilder().buildObject(); for (Map.Entry<String, String> claimEntry : claims.entrySet()) { Attribute attrib = new AttributeBuilder().buildObject(); String claimUri = claimEntry.getKey(); attrib.setName(claimUri); // look // https://wiki.shibboleth.net/confluence/display/OpenSAML/OSTwoUsrManJavaAnyTypes XSStringBuilder stringBuilder = (XSStringBuilder) Configuration.getBuilderFactory() .getBuilder(XSString.TYPE_NAME); XSString stringValue = stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME); stringValue.setValue(claimEntry.getValue()); attrib.getAttributeValues().add(stringValue); attStmt.getAttributes().add(attrib); } } return attStmt; }
protected void buildAttributeStatement(Set<Claim> claims, Assertion assertion, SAML2SSOContext saml2SSOContext, ResponseBuilderConfig config, AuthenticationContext context) { AttributeStatement attStmt = new AttributeStatementBuilder().buildObject(); Iterator<Claim> iterator = claims.iterator(); while (iterator.hasNext()) { Claim claim = iterator.next(); String claimUri = claim.getClaimUri(); String claimValue = claim.getValue(); Attribute attribute = new AttributeBuilder().buildObject(); attribute.setName(claimUri); //setting NAMEFORMAT attribute value to basic attribute profile attribute.setNameFormat(Attribute.BASIC); // look // https://wiki.shibboleth.net/confluence/display/OpenSAML/OSTwoUsrManJavaAnyTypes XSStringBuilder stringBuilder = (XSStringBuilder) Configuration.getBuilderFactory(). getBuilder(XSString.TYPE_NAME); XSString stringValue = stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString .TYPE_NAME); stringValue.setValue(claimValue); attribute.getAttributeValues().add(stringValue); attStmt.getAttributes().add(attribute); } if (attStmt != null) { assertion.getAttributeStatements().add(attStmt); } }
private Attribute getSAML2Attribute(String name, String value, String namespace) { XMLObjectBuilderFactory builderFactory = null; SAMLObjectBuilder<Attribute> attrBuilder = null; Attribute attribute = null; XSStringBuilder attributeValueBuilder = null; XSString stringValue = null; builderFactory = Configuration.getBuilderFactory(); attrBuilder = (SAMLObjectBuilder<Attribute>) builderFactory.getBuilder(Attribute.DEFAULT_ELEMENT_NAME); attribute = attrBuilder.buildObject(); attribute.setName(name); attribute.setNameFormat(namespace); attributeValueBuilder = (XSStringBuilder) builderFactory.getBuilder(XSString.TYPE_NAME); stringValue = attributeValueBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME); stringValue.setValue(value); attribute.getAttributeValues().add(stringValue); return attribute; }
private Attribute getSAML2Attribute(String name, String value, String namespace) { XMLObjectBuilderFactory builderFactory = null; SAMLObjectBuilder<Attribute> attrBuilder = null; Attribute attribute = null; XSStringBuilder attributeValueBuilder = null; XSString stringValue = null; builderFactory = Configuration.getBuilderFactory(); attrBuilder = (SAMLObjectBuilder<Attribute>) builderFactory.getBuilder(Attribute.DEFAULT_ELEMENT_NAME); attribute = attrBuilder.buildObject(); attribute.setName(name); attribute.setNameFormat(namespace); attributeValueBuilder = (XSStringBuilder) builderFactory.getBuilder(XSString.TYPE_NAME); stringValue = attributeValueBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME); stringValue.setValue(value); attribute.getAttributeValues().add(stringValue); return attribute; }
XSString attribute1 = stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME); attribute1.setValue((String)value); attribute.getAttributeValues().add(attribute1); } else if (value instanceof XMLObject) {
/** * 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; }