本文整理汇总了Java中org.opensaml.saml2.core.impl.AuthnContextBuilder类的典型用法代码示例。如果您正苦于以下问题:Java AuthnContextBuilder类的具体用法?Java AuthnContextBuilder怎么用?Java AuthnContextBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AuthnContextBuilder类属于org.opensaml.saml2.core.impl包,在下文中一共展示了AuthnContextBuilder类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createAuthnStatement
import org.opensaml.saml2.core.impl.AuthnContextBuilder; //导入依赖的package包/类
private AuthnStatement createAuthnStatement(final DateTime issueDate) {
// create authcontextclassref object
AuthnContextClassRefBuilder classRefBuilder = new AuthnContextClassRefBuilder();
AuthnContextClassRef classRef = classRefBuilder.buildObject();
classRef.setAuthnContextClassRef("urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport");
// create authcontext object
AuthnContextBuilder authContextBuilder = new AuthnContextBuilder();
AuthnContext authnContext = authContextBuilder.buildObject();
authnContext.setAuthnContextClassRef(classRef);
// create authenticationstatement object
AuthnStatementBuilder authStatementBuilder = new AuthnStatementBuilder();
AuthnStatement authnStatement = authStatementBuilder.buildObject();
authnStatement.setAuthnInstant(issueDate);
authnStatement.setAuthnContext(authnContext);
return authnStatement;
}
示例2: buildSAMLAssertion
import org.opensaml.saml2.core.impl.AuthnContextBuilder; //导入依赖的package包/类
/**
* Build SAML Assertion object
*
* @param pRequestContext
* @param pNotOnOrAfter
* @param pRecipient
* @param pAudienceURI
* @param pAssertionAttributes
* @param pSignAssertion
* @param pDigitalCertificateName
* @return SAML Assertion Object
*/
private Assertion buildSAMLAssertion(ActionRequestContext pRequestContext
, DateTime pNotOnOrAfter
, String pRecipient
, String pAudienceURI
, Map<String, String> pAssertionAttributes
, boolean pSignAssertion
, String pDigitalCertificateName
) {
DateTime lCurrentTime = new DateTime();
Assertion lAssertion = new AssertionBuilder().buildObject();
lAssertion.setID(ASSERTION_ID_PREFIX + RandomString.getString(40));
lAssertion.setVersion(SAMLVersion.VERSION_20);
lAssertion.setIssuer(buildIssuer(pRequestContext.getFoxRequest().getHttpRequest().getRequestURL().toString()));
lAssertion.setIssueInstant(lCurrentTime);
Subject lSubject = new SubjectBuilder().buildObject();
SubjectConfirmation lSubjectConfirmation = new SubjectConfirmationBuilder().buildObject();
lSubjectConfirmation.setMethod(SubjectConfirmation.METHOD_BEARER);
SubjectConfirmationData lSubjectConfirmationData = new SubjectConfirmationDataBuilder().buildObject();
if (!XFUtil.isNull(pRecipient)) {
lSubjectConfirmationData.setRecipient(pRecipient);
}
lSubjectConfirmationData.setNotOnOrAfter(pNotOnOrAfter);
lSubjectConfirmation.setSubjectConfirmationData(lSubjectConfirmationData);
lSubject.getSubjectConfirmations().add(lSubjectConfirmation);
NameIDBuilder lNameIDBuilder = new NameIDBuilder();
NameID lNameID = lNameIDBuilder.buildObject();
lNameID.setValue(RandomString.getString(64));
lNameID.setFormat(NameID.TRANSIENT);
lSubject.setNameID(lNameID);
lAssertion.setSubject(lSubject);
AuthnStatement lAuthnStatement = new AuthnStatementBuilder().buildObject();
lAuthnStatement.setAuthnInstant(new DateTime());
AuthnContext lAuthnContext = new AuthnContextBuilder().buildObject();
AuthnContextClassRef lAuthnContextClassRef = new AuthnContextClassRefBuilder().buildObject();
lAuthnContextClassRef.setAuthnContextClassRef(AuthnContext.PASSWORD_AUTHN_CTX);
lAuthnContext.setAuthnContextClassRef(lAuthnContextClassRef);
lAuthnStatement.setAuthnContext(lAuthnContext);
lAssertion.getAuthnStatements().add(lAuthnStatement);
if (pAssertionAttributes != null && pAssertionAttributes.size() > 0) {
lAssertion.getAttributeStatements().add(buildAttributeStatement(pAssertionAttributes));
}
AudienceRestriction lAudienceRestriction = new AudienceRestrictionBuilder().buildObject();
if (!XFUtil.isNull(pAudienceURI)) {
Audience lAudience = new AudienceBuilder().buildObject();
lAudience.setAudienceURI(pAudienceURI);
lAudienceRestriction.getAudiences().add(lAudience);
}
Conditions lConditions = new ConditionsBuilder().buildObject();
lConditions.setNotBefore(lCurrentTime);
lConditions.setNotOnOrAfter(pNotOnOrAfter);
lConditions.getAudienceRestrictions().add(lAudienceRestriction);
lAssertion.setConditions(lConditions);
if (pSignAssertion) {
signSAMLObject(lAssertion, pRequestContext, pDigitalCertificateName);
}
return lAssertion;
}