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; }
/** QName for the attribute resource */ public static Attribute createAttribute(String name, String friendlyName,String nameFormat) { Attribute attribute = new AttributeBuilder().buildObject(); attribute.setName(name); attribute.setFriendlyName(friendlyName); attribute.setNameFormat(nameFormat); return attribute; }
/** * Create an Attribute object. * * @param friendlyName of type String * @param name of type String * @param nameFormat of type String * @return an Attribute object */ @SuppressWarnings("unchecked") public static Attribute createAttribute(String friendlyName, String name, String nameFormat) { if (attributeBuilder == null) { attributeBuilder = (SAMLObjectBuilder<Attribute>) builderFactory.getBuilder(Attribute.DEFAULT_ELEMENT_NAME); } Attribute attribute = attributeBuilder.buildObject(); attribute.setFriendlyName(friendlyName); if (nameFormat == null) { attribute.setNameFormat(SAML2Constants.ATTRNAME_FORMAT_URI); } else { attribute.setNameFormat(nameFormat); } attribute.setName(name); return attribute; }
@SuppressWarnings("unchecked") private static Attribute getAttribute(String attributeName, GregorianCalendar attributeValue) { Attribute attribute = buildXMLObject(Attribute.class, Attribute.DEFAULT_ELEMENT_NAME); attribute.setName(attributeName); XMLObjectBuilder<XSDateTime> builder = Configuration .getBuilderFactory().getBuilder(XSDateTime.TYPE_NAME); XSDateTime xmlAttributeValue = builder.buildObject( AttributeValue.DEFAULT_ELEMENT_NAME, XSDateTime.TYPE_NAME); // convert to Zulu timezone int day = attributeValue.get(Calendar.DAY_OF_MONTH); int month = attributeValue.get(Calendar.MONTH); int year = attributeValue.get(Calendar.YEAR); LOG.debug("day: " + day + " month: " + month + " year: " + year); DateTime zulu = new DateTime(year, month + 1, day, 0, 0, 0, 0, ISOChronology.getInstanceUTC()); xmlAttributeValue.setValue(zulu); attribute.getAttributeValues().add(xmlAttributeValue); LOG.debug("XmlAttributeValue: " + xmlAttributeValue.getValue()); return attribute; }
/** * Create an Attribute object. * * @param friendlyName of type String * @param name of type String * @param nameFormat of type String * @return an Attribute object */ @SuppressWarnings("unchecked") public static Attribute createAttribute(String friendlyName, String name, String nameFormat) { if (attributeBuilder == null) { attributeBuilder = (SAMLObjectBuilder<Attribute>) builderFactory.getBuilder(Attribute.DEFAULT_ELEMENT_NAME); } Attribute attribute = attributeBuilder.buildObject(); attribute.setFriendlyName(friendlyName); if (nameFormat == null) { attribute.setNameFormat(SAML2Constants.ATTRNAME_FORMAT_URI); } else { attribute.setNameFormat(nameFormat); } attribute.setName(name); return attribute; }
@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 an Attribute model. * * @param friendlyName of type String * @param name of type String * @param nameFormat of type String * @return an Attribute model */ @SuppressWarnings("unchecked") public static Attribute createAttribute(String friendlyName, String name, String nameFormat) { if (attributeBuilder == null) { attributeBuilder = (SAMLObjectBuilder<Attribute>) builderFactory.getBuilder(Attribute.DEFAULT_ELEMENT_NAME); } Attribute attribute = attributeBuilder.buildObject(); attribute.setFriendlyName(friendlyName); if (nameFormat == null) { attribute.setNameFormat(SamlConstants.ATTRNAME_FORMAT_URI); } else { attribute.setNameFormat(nameFormat); } attribute.setName(name); 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(); Iterator<String> ite = claims.keySet().iterator(); for (int i = 0; i < claims.size(); i++) { Attribute attrib = new AttributeBuilder().buildObject(); String claimUri = ite.next(); 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(claims.get(claimUri)); attrib.getAttributeValues().add(stringValue); attStmt.getAttributes().add(attrib); } } return attStmt; }
/** * Populates the attribute with attribute name, name format, and friendly name information. * * @param attribute to populate */ protected void populateAttribute(Attribute attribute) { attribute.setName(getAttributeName()); attribute.setNameFormat(getNameFormat()); attribute.setFriendlyName(getFriendlyName()); } }
@SuppressWarnings("unchecked") private static Attribute getAttribute(String attributeName, Integer attributeValue) { Attribute attribute = buildXMLObject(Attribute.class, Attribute.DEFAULT_ELEMENT_NAME); attribute.setName(attributeName); XMLObjectBuilder<XSInteger> builder = Configuration.getBuilderFactory() .getBuilder(XSInteger.TYPE_NAME); XSInteger xmlAttributeValue = builder.buildObject( AttributeValue.DEFAULT_ELEMENT_NAME, XSInteger.TYPE_NAME); xmlAttributeValue.setValue(attributeValue); attribute.getAttributeValues().add(xmlAttributeValue); return attribute; }
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; }
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); }
/** {@inheritDoc} */ protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException { Attribute attrib = (Attribute) samlObject; if (attribute.getLocalName().equals(Attribute.NAME_ATTTRIB_NAME)) { attrib.setName(attribute.getValue()); } else if (attribute.getLocalName().equals(Attribute.NAME_FORMAT_ATTRIB_NAME)) { attrib.setNameFormat(attribute.getValue()); } else if (attribute.getLocalName().equals(Attribute.FRIENDLY_NAME_ATTRIB_NAME)) { attrib.setFriendlyName(attribute.getValue()); } else { QName attribQName = XMLHelper.getNodeQName(attribute); if (attribute.isId()) { attrib.getUnknownAttributes().registerID(attribQName); } attrib.getUnknownAttributes().put(attribQName, attribute.getValue()); } } }
@SuppressWarnings("unchecked") private static Attribute getAttribute(String attributeName, byte[] attributeValue) { Attribute attribute = buildXMLObject(Attribute.class, Attribute.DEFAULT_ELEMENT_NAME); attribute.setName(attributeName); XMLObjectBuilder<XSBase64Binary> builder = Configuration .getBuilderFactory().getBuilder(XSBase64Binary.TYPE_NAME); XSBase64Binary xmlAttributeValue = builder.buildObject( AttributeValue.DEFAULT_ELEMENT_NAME, XSBase64Binary.TYPE_NAME); xmlAttributeValue.setValue(Base64.encodeBytes(attributeValue)); attribute.getAttributeValues().add(xmlAttributeValue); return attribute; }
@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; }
private void addAttribute(AttributeStatement attributeStatement, Attributes attribute, byte[] value) { if (null == value) { return; } XMLObjectBuilder<XSBase64Binary> builder = Configuration .getBuilderFactory().getBuilder(XSBase64Binary.TYPE_NAME); Attribute samlAttribute = buildXMLObject(Attribute.class, Attribute.DEFAULT_ELEMENT_NAME); samlAttribute.setName(attribute.getName()); XSBase64Binary attributeValue = builder.buildObject( AttributeValue.DEFAULT_ELEMENT_NAME, XSBase64Binary.TYPE_NAME); attributeValue.setValue(Base64.encode(value)); samlAttribute.getAttributeValues().add(attributeValue); attributeStatement.getAttributes().add(samlAttribute); }
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; }
/** {@inheritDoc} */ public Attribute encode(BaseAttribute attribute) throws AttributeEncodingException { Attribute samlAttribute = attributeBuilder.buildObject(); samlAttribute.setName(getAttributeName()); samlAttribute.setNameFormat(getNameFormat()); samlAttribute.setFriendlyName(getFriendlyName()); 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; } }
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; }
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); } }