AttributeStatement attributeStatement = ((SAMLObjectBuilder<AttributeStatement>) builderFactory
.getBuilder(AttributeStatement.DEFAULT_ELEMENT_NAME))
.buildObject();
if (ssoStartPage != null) {
XSString ssoStartPageAttributeValue = ((XSStringBuilder) Configuration
.getBuilderFactory().getBuilder(XSString.TYPE_NAME))
.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME,
XSString.TYPE_NAME);
ssoStartPageAttributeValue.setValue(ssoStartPage);
Attribute ssoStartPageAttribute = ((SAMLObjectBuilder<Attribute>) builderFactory
.getBuilder(Attribute.DEFAULT_ELEMENT_NAME)).buildObject();
ssoStartPageAttribute.setName("ssoStartPage");
ssoStartPageAttribute
.setNameFormat("urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified");
ssoStartPageAttribute.getAttributeValues().add(
ssoStartPageAttributeValue);
attributeStatement.getAttributes().add(ssoStartPageAttribute);
}
if (logoutURL != null) {
XSString logoutUrlAttributeValue = ((XSStringBuilder) Configuration
.getBuilderFactory().getBuilder(XSString.TYPE_NAME))
.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME,
XSString.TYPE_NAME);
logoutUrlAttributeValue.setValue(logoutURL);
Attribute logoutUrlAttribute = ((SAMLObjectBuilder<Attribute>) builderFactory
.getBuilder(Attribute.DEFAULT_ELEMENT_NAME)).buildObject();
logoutUrlAttribute.setName("logoutURL");
logoutUrlAttribute
.setNameFormat("urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified");
logoutUrlAttribute.getAttributeValues()
.add(logoutUrlAttributeValue);
attributeStatement.getAttributes().add(logoutUrlAttribute);
}
if (EnumSet.of(UserType.PORTAL, UserType.SITE).contains(userType)) {
XSString orgIdAttributeValue = ((XSStringBuilder) Configuration
.getBuilderFactory().getBuilder(XSString.TYPE_NAME))
.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME,
XSString.TYPE_NAME);
orgIdAttributeValue.setValue(orgId);
Attribute orgIdAttribute = ((SAMLObjectBuilder<Attribute>) builderFactory
.getBuilder(Attribute.DEFAULT_ELEMENT_NAME)).buildObject();
orgIdAttribute.setName("organization_id");
orgIdAttribute
.setNameFormat("urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified");
orgIdAttribute.getAttributeValues().add(orgIdAttributeValue);
attributeStatement.getAttributes().add(orgIdAttribute);
XSString portalIdAttributeValue = ((XSStringBuilder) Configuration
.getBuilderFactory().getBuilder(XSString.TYPE_NAME))
.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME,
XSString.TYPE_NAME);
portalIdAttributeValue.setValue(portalId);
Attribute portalIdAttribute = ((SAMLObjectBuilder<Attribute>) builderFactory
.getBuilder(Attribute.DEFAULT_ELEMENT_NAME)).buildObject();
portalIdAttribute.setName("portal_id");
portalIdAttribute
.setNameFormat("urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified");
portalIdAttribute.getAttributeValues().add(portalIdAttributeValue);
attributeStatement.getAttributes().add(portalIdAttribute);
}
if (userType == UserType.SITE) {
XSString siteURLAttributeValue = ((XSStringBuilder) Configuration
.getBuilderFactory().getBuilder(XSString.TYPE_NAME))
.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME,
XSString.TYPE_NAME);
siteURLAttributeValue.setValue(siteURL);
Attribute siteURLAttribute = ((SAMLObjectBuilder<Attribute>) builderFactory
.getBuilder(Attribute.DEFAULT_ELEMENT_NAME)).buildObject();
siteURLAttribute.setName("siteurl");
siteURLAttribute
.setNameFormat("urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified");
siteURLAttribute.getAttributeValues().add(siteURLAttributeValue);
attributeStatement.getAttributes().add(siteURLAttribute);
}
if (basicAttributes != null) {
attributeStatement.getAttributes().addAll(basicAttributes);
}
if (additionalAttributes != null) {
String attribs = additionalAttributes.trim();
String key = "";
String val = "";
StringTokenizer st = new StringTokenizer(attribs, "=;");
while( st.hasMoreTokens() ) {
key = st.nextToken();
val = st.nextToken();
logger.debug("Key/value pair:" + "key" + "/" + val);
XSString additionalAttributeValue = ((XSStringBuilder) Configuration
.getBuilderFactory().getBuilder(XSString.TYPE_NAME))
.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME,
XSString.TYPE_NAME);
additionalAttributeValue.setValue(val);
Attribute additionalAttribute = ((SAMLObjectBuilder<Attribute>) builderFactory
.getBuilder(Attribute.DEFAULT_ELEMENT_NAME)).buildObject();
additionalAttribute.setName(key);
additionalAttribute.setNameFormat("urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified");