use of org.opensaml.saml2.core.NameID in project verify-hub by alphagov.
the class AuthnResponseFactory method buildNameID.
private NameID buildNameID(String id) {
NameID nameId = new OpenSamlXmlObjectFactory().createNameId(id);
nameId.setFormat(NameIDType.PERSISTENT);
return nameId;
}
use of org.opensaml.saml2.core.NameID in project cxf by apache.
the class OnBehalfOfValidator method validate.
@Override
public Credential validate(Credential credential, RequestData data) throws WSSecurityException {
Credential validatedCredential = super.validate(credential, data);
SamlAssertionWrapper assertion = validatedCredential.getSamlAssertion();
Assertion saml2Assertion = assertion.getSaml2();
if (saml2Assertion == null) {
throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "invalidSAMLsecurity");
}
List<AttributeStatement> attributeStatements = saml2Assertion.getAttributeStatements();
if (attributeStatements == null || attributeStatements.isEmpty()) {
throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "invalidSAMLsecurity");
}
Subject subject = saml2Assertion.getSubject();
NameID nameID = subject.getNameID();
String subjectName = nameID.getValue();
if ("alice".equals(subjectName) || "bob".equals(subjectName)) {
return validatedCredential;
}
throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "invalidSAMLsecurity");
}
use of org.opensaml.saml2.core.NameID in project cxf by apache.
the class SAMLUtils method getSubject.
public static Subject getSubject(Message message, SamlAssertionWrapper assertionW) {
if (assertionW.getSaml2() != null) {
org.opensaml.saml.saml2.core.Subject s = assertionW.getSaml2().getSubject();
Subject subject = new Subject();
NameID nameId = s.getNameID();
subject.setNameQualifier(nameId.getNameQualifier());
// if format is transient then we may need to use STSClient
// to request an alternate name from IDP
subject.setNameFormat(nameId.getFormat());
subject.setName(nameId.getValue());
subject.setSpId(nameId.getSPProvidedID());
subject.setSpQualifier(nameId.getSPNameQualifier());
return subject;
} else if (assertionW.getSaml1() != null) {
org.opensaml.saml.saml1.core.Subject s = getSaml1Subject(assertionW);
if (s != null) {
Subject subject = new Subject();
NameIdentifier nameId = s.getNameIdentifier();
subject.setNameQualifier(nameId.getNameQualifier());
// if format is transient then we may need to use STSClient
// to request an alternate name from IDP
subject.setNameFormat(nameId.getFormat());
subject.setName(nameId.getValue());
return subject;
}
}
return null;
}
Aggregations