use of org.opensaml.saml.saml1.core.Attribute in project OpenAttestation by OpenAttestation.
the class SamlGenerator method createBase64BinaryAttribute.
/**
* Creates a base64-encoded attribute
* @param name
* @param value
* @return
* @throws ConfigurationException
*/
private Attribute createBase64BinaryAttribute(String name, byte[] value) throws ConfigurationException {
SAMLObjectBuilder attrBuilder = (SAMLObjectBuilder) builderFactory.getBuilder(Attribute.DEFAULT_ELEMENT_NAME);
Attribute attr = (Attribute) attrBuilder.buildObject();
attr.setName(name);
XMLObjectBuilder xmlBuilder = builderFactory.getBuilder(XSBase64Binary.TYPE_NAME);
XSBase64Binary attrValue = (XSBase64Binary) xmlBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSBase64Binary.TYPE_NAME);
attrValue.setValue(Base64.encodeBase64String(value));
attr.getAttributeValues().add(attrValue);
return attr;
}
use of org.opensaml.saml.saml1.core.Attribute in project OpenAttestation by OpenAttestation.
the class SamlGenerator method createBooleanAttribute.
/**
* This method builds a single-valued boolean attribute such as isTrusted=true
* @param name
* @param value
* @return
* @throws ConfigurationException
*/
private Attribute createBooleanAttribute(String name, boolean value) throws ConfigurationException {
SAMLObjectBuilder attrBuilder = (SAMLObjectBuilder) builderFactory.getBuilder(Attribute.DEFAULT_ELEMENT_NAME);
Attribute attr = (Attribute) attrBuilder.buildObject();
attr.setName(name);
XMLObjectBuilder xmlBuilder = builderFactory.getBuilder(XSAny.TYPE_NAME);
XSAny attrValue = (XSAny) xmlBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSAny.TYPE_NAME);
attrValue.setTextContent(value ? "true" : "false");
attr.getAttributeValues().add(attrValue);
return attr;
}
use of org.opensaml.saml.saml1.core.Attribute in project cloudstack by apache.
the class SAMLUtils method getValueFromAttributeStatements.
public static String getValueFromAttributeStatements(final List<AttributeStatement> attributeStatements, final String attributeKey) {
if (attributeStatements == null || attributeStatements.size() < 1 || attributeKey == null) {
return null;
}
for (AttributeStatement attributeStatement : attributeStatements) {
if (attributeStatement == null || attributeStatements.size() < 1) {
continue;
}
for (Attribute attribute : attributeStatement.getAttributes()) {
if (attribute.getAttributeValues() != null && attribute.getAttributeValues().size() > 0) {
String value = attribute.getAttributeValues().get(0).getDOM().getTextContent();
s_logger.debug("SAML attribute name: " + attribute.getName() + " friendly-name:" + attribute.getFriendlyName() + " value:" + value);
if (attributeKey.equals(attribute.getName()) || attributeKey.equals(attribute.getFriendlyName())) {
return value;
}
}
}
}
return null;
}
use of org.opensaml.saml.saml1.core.Attribute in project ddf by codice.
the class SubjectUtilsTest method getSubjectWithAttributes.
private Subject getSubjectWithAttributes(Map<String, List<String>> attributes) {
Subject subject = mock(Subject.class);
PrincipalCollection pc = mock(PrincipalCollection.class);
SecurityAssertion assertion = mock(SecurityAssertion.class);
AttributeStatement as = mock(AttributeStatement.class);
List<Attribute> attrs = attributes.entrySet().stream().map(this::getAttribute).collect(Collectors.toList());
doReturn(pc).when(subject).getPrincipals();
doReturn(assertion).when(pc).oneByType(SecurityAssertion.class);
doReturn(ImmutableList.of(assertion)).when(pc).byType(SecurityAssertion.class);
doReturn(Collections.singletonList(as)).when(assertion).getAttributeStatements();
doReturn(attrs).when(as).getAttributes();
return subject;
}
use of org.opensaml.saml.saml1.core.Attribute in project ddf by codice.
the class SubjectUtilsTest method getAttribute.
private Attribute getAttribute(Map.Entry<String, List<String>> attribute) {
Attribute attr = mock(Attribute.class);
doReturn(attribute.getKey()).when(attr).getName();
doReturn(attribute.getValue().stream().map(this::getXSString).collect(Collectors.toList())).when(attr).getAttributeValues();
return attr;
}
Aggregations