use of org.opensaml.saml.saml2.core.impl.AudienceRestrictionBuilder in project MaxKey by dromara.
the class ConditionsGenerator method builderAudienceRestriction.
public AudienceRestriction builderAudienceRestriction(String audienceUrl) {
AudienceRestriction audienceRestriction = new AudienceRestrictionBuilder().buildObject();
Audience audience = new AudienceBuilder().buildObject();
audience.setAudienceURI(audienceUrl);
audienceRestriction.getAudiences().add(audience);
logger.debug("Audience URL " + audienceUrl);
return audienceRestriction;
}
use of org.opensaml.saml.saml2.core.impl.AudienceRestrictionBuilder in project OpenUnison by TremoloSecurity.
the class Saml2Assertion method generateAssertion.
private Assertion generateAssertion(String id2) {
byte[] idBytes = new byte[20];
random.nextBytes(idBytes);
StringBuffer b = new StringBuffer();
b.append('f').append(Hex.encodeHexString(idBytes));
String id = b.toString();
AssertionBuilder assertionBuilder = new AssertionBuilder();
Assertion assertion = assertionBuilder.buildObject();
assertion.setID(id);
IssuerBuilder issuerBuilder = new IssuerBuilder();
Issuer issuer = issuerBuilder.buildObject();
issuer.setValue(this.issuer);
assertion.setIssuer(issuer);
// Get the subject builder based on the subject element name
SubjectBuilder builder = new SubjectBuilder();
// Create the subject
Subject subject = builder.buildObject();
SubjectConfirmationBuilder scb = new SubjectConfirmationBuilder();
SubjectConfirmation sc = scb.buildObject();
sc.setMethod(SubjectConfirmation.METHOD_BEARER);
SubjectConfirmationDataBuilder scdb = new SubjectConfirmationDataBuilder();
SubjectConfirmationData scd = scdb.buildObject();
scd.setNotOnOrAfter(this.notAfter);
scd.setRecipient(this.recepient);
sc.setSubjectConfirmationData(scd);
subject.getSubjectConfirmations().add(sc);
NameIDBuilder nameIDBuilder = new NameIDBuilder();
NameID nameID = nameIDBuilder.buildObject();
nameID.setValue(this.subject);
nameID.setFormat(this.nameIDFormat);
// Added an NameID and two SubjectConfirmation items - creation of these items is not shown
subject.setNameID(nameID);
assertion.setSubject(subject);
AuthnStatementBuilder authnStmtBuilder = new AuthnStatementBuilder();
AuthnStatement authn = authnStmtBuilder.buildObject();
authn.setAuthnInstant(this.issueInstant);
AuthnContextBuilder authnCtxBuilder = new AuthnContextBuilder();
AuthnContext authnCtx = authnCtxBuilder.buildObject();
AuthnContextClassRefBuilder accrb = new AuthnContextClassRefBuilder();
AuthnContextClassRef accrf = accrb.buildObject();
accrf.setURI(this.authnContextRef);
authnCtx.setAuthnContextClassRef(accrf);
authn.setAuthnContext(authnCtx);
// AuthnContextClassRefBuilder accrb = new AuthnContextClassRefBuilder();
// AuthnContextClassRef accr = accrb.buildObject();
// accr.setAuthnContextClassRef("urn:oasis:names:tc:SAML:2.0:ac:classes:unspecified");
authn.setSessionIndex(id);
// authnCtx.setAuthnContextClassRef(accr);
// authn.setAuthnContext(authnCtx);
assertion.getAuthnStatements().add(authn);
AttributeStatementBuilder attrb = new AttributeStatementBuilder();
AttributeStatement attrStmt = attrb.buildObject();
boolean addAttrs = false;
Iterator<Attribute> attrs = this.attribs.iterator();
while (attrs.hasNext()) {
Attribute attrib = attrs.next();
AttributeBuilder attrBuilder = new AttributeBuilder();
org.opensaml.saml.saml2.core.Attribute samlAttrib = attrBuilder.buildObject();
samlAttrib.setName(attrib.getName());
Iterator<String> attrVals = attrib.getValues().iterator();
while (attrVals.hasNext()) {
XSStringBuilder sb = new XSStringBuilder();
XSString val = sb.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME);
val.setValue(attrVals.next());
samlAttrib.getAttributeValues().add(val);
addAttrs = true;
}
attrStmt.getAttributes().add(samlAttrib);
}
if (addAttrs) {
assertion.getAttributeStatements().add(attrStmt);
}
ConditionsBuilder cb = new ConditionsBuilder();
Conditions conditions = cb.buildObject();
conditions.setNotBefore(this.notBefore);
conditions.setNotOnOrAfter(this.notAfter);
AudienceRestrictionBuilder arb = new AudienceRestrictionBuilder();
AudienceRestriction ar = arb.buildObject();
AudienceBuilder ab = new AudienceBuilder();
Audience a = ab.buildObject();
a.setURI(this.audience);
ar.getAudiences().add(a);
conditions.getAudienceRestrictions().add(ar);
assertion.setConditions(conditions);
assertion.setIssueInstant(this.issueInstant);
return assertion;
}
Aggregations