本文整理汇总了Java中org.opensaml.saml2.core.AuthnStatement.setAuthnInstant方法的典型用法代码示例。如果您正苦于以下问题:Java AuthnStatement.setAuthnInstant方法的具体用法?Java AuthnStatement.setAuthnInstant怎么用?Java AuthnStatement.setAuthnInstant使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.opensaml.saml2.core.AuthnStatement
的用法示例。
在下文中一共展示了AuthnStatement.setAuthnInstant方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildAssertion
import org.opensaml.saml2.core.AuthnStatement; //导入方法依赖的package包/类
public static Assertion buildAssertion(String recipient, String audience) {
Assertion assertion = SAMLUtil.buildXMLObject(Assertion.class);
assertion.setID(Utils.generateUUID());
assertion.setSubject(SAMLUtil.createSubject("joetest", recipient, new DateTime().plusHours(1)));
assertion.setIssueInstant(new DateTime());
assertion.setIssuer(SAMLUtil.createIssuer("idp1.test.oio.dk"));
assertion.setConditions(SAMLUtil.createAudienceCondition(audience));
assertion.getConditions().setNotOnOrAfter(new DateTime().plus(10000));
AuthnContext context = SAMLUtil.createAuthnContext("urn:oasis:names:tc:SAML:2.0:ac:classes:Password");
AuthnStatement authnStatement = SAMLUtil.buildXMLObject(AuthnStatement.class);
authnStatement.setAuthnContext(context);
authnStatement.setAuthnInstant(new DateTime());
authnStatement.setSessionIndex(Utils.generateUUID());
assertion.getAuthnStatements().add(authnStatement);
AttributeStatement as = SAMLUtil.buildXMLObject(AttributeStatement.class);
as.getAttributes().add(AttributeUtil.createAssuranceLevel(2));
assertion.getAttributeStatements().add(as);
return assertion;
}
示例2: createAuthnStatement
import org.opensaml.saml2.core.AuthnStatement; //导入方法依赖的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;
}
示例3: processAttribute
import org.opensaml.saml2.core.AuthnStatement; //导入方法依赖的package包/类
/** {@inheritDoc} */
protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException {
AuthnStatement authnStatement = (AuthnStatement) samlObject;
if (attribute.getLocalName().equals(AuthnStatement.AUTHN_INSTANT_ATTRIB_NAME)
&& !DatatypeHelper.isEmpty(attribute.getValue())) {
authnStatement.setAuthnInstant(new DateTime(attribute.getValue(), ISOChronology.getInstanceUTC()));
} else if (attribute.getLocalName().equals(AuthnStatement.SESSION_INDEX_ATTRIB_NAME)) {
authnStatement.setSessionIndex(attribute.getValue());
} else if (attribute.getLocalName().equals(AuthnStatement.SESSION_NOT_ON_OR_AFTER_ATTRIB_NAME)
&& !DatatypeHelper.isEmpty(attribute.getValue())) {
authnStatement.setSessionNotOnOrAfter(new DateTime(attribute.getValue(), ISOChronology.getInstanceUTC()));
} else {
super.processAttribute(samlObject, attribute);
}
}
示例4: populateRequiredData
import org.opensaml.saml2.core.AuthnStatement; //导入方法依赖的package包/类
/** {@inheritDoc} */
protected void populateRequiredData() {
super.populateRequiredData();
AuthnStatement authnStatement = (AuthnStatement) target;
AuthnContext authnContext = (AuthnContext) buildXMLObject(new QName(SAMLConstants.SAML20_NS,
AuthnContext.DEFAULT_ELEMENT_LOCAL_NAME, SAMLConstants.SAML20_PREFIX));
authnStatement.setAuthnInstant(new DateTime(1984, 8, 26, 10, 01, 30, 43, ISOChronology.getInstanceUTC()));
authnStatement.setAuthnContext(authnContext);
}
示例5: testIssuerFailure
import org.opensaml.saml2.core.AuthnStatement; //导入方法依赖的package包/类
/**
* Tests absent AuthnInstant failure.
*
* @throws ValidationException
*/
public void testIssuerFailure() throws ValidationException {
AuthnStatement authnStatement = (AuthnStatement) target;
authnStatement.setAuthnInstant(null);
try {
validator.validate(authnStatement);
fail("AuthnInstant was null, should raise a Validation Exception");
} catch (ValidationException e) {
}
}
示例6: testSingleElementMarshall
import org.opensaml.saml2.core.AuthnStatement; //导入方法依赖的package包/类
/** {@inheritDoc} */
public void testSingleElementMarshall() {
QName qname = new QName(SAMLConstants.SAML20_NS, AuthnStatement.DEFAULT_ELEMENT_LOCAL_NAME, SAMLConstants.SAML20_PREFIX);
AuthnStatement authnStatement = (AuthnStatement) buildXMLObject(qname);
authnStatement.setAuthnInstant(expectedAuthnInstant);
assertEquals(expectedDOM, authnStatement);
}
示例7: testSingleElementOptionalAttributesMarshall
import org.opensaml.saml2.core.AuthnStatement; //导入方法依赖的package包/类
/** {@inheritDoc} */
public void testSingleElementOptionalAttributesMarshall() {
QName qname = new QName(SAMLConstants.SAML20_NS, AuthnStatement.DEFAULT_ELEMENT_LOCAL_NAME, SAMLConstants.SAML20_PREFIX);
AuthnStatement authnStatement = (AuthnStatement) buildXMLObject(qname);
authnStatement.setAuthnInstant(expectedAuthnInstant);
authnStatement.setSessionIndex(expectedSessionIndex);
authnStatement.setSessionNotOnOrAfter(expectedSessionNotOnOrAfter);
assertEquals(expectedOptionalAttributesDOM, authnStatement);
}
示例8: buildAuthnStatement
import org.opensaml.saml2.core.AuthnStatement; //导入方法依赖的package包/类
private AuthnStatement buildAuthnStatement() throws IllegalAccessException {
AuthnStatement authnStatement = buildXMLObjectDefaultName(AuthnStatement.class);
AuthnContext authnContext = buildXMLObjectDefaultName(AuthnContext.class);
AuthnContextClassRef authnContextClassRef = buildXMLObjectDefaultName(AuthnContextClassRef.class);
authnContextClassRef.setAuthnContextClassRef("urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport");
authnContext.setAuthnContextClassRef(authnContextClassRef);
authnStatement.setAuthnContext(authnContext);
authnStatement.setAuthnInstant(new DateTime());
return authnStatement;
}
示例9: buildSAMLAssertion
import org.opensaml.saml2.core.AuthnStatement; //导入方法依赖的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;
}
示例10: createAuthnStatement
import org.opensaml.saml2.core.AuthnStatement; //导入方法依赖的package包/类
private static AuthnStatement createAuthnStatement() {
AuthnStatement authnStatement = null;
AuthnContext authnContext = null;
SubjectLocality subjectLocality = null;
if (samlResponseData.getAuthnContextClassRef() != null
&& samlResponseData.getAuthnContextClassRef().length() > 0) {
authnContext = create(AuthnContext.DEFAULT_ELEMENT_NAME);
AuthnContextClassRef authnContextClassRef = create(AuthnContextClassRef.DEFAULT_ELEMENT_NAME);
if (samlResponseData.getAuthnContextClassRef().equals(
SamlResponseData.REPLACE_WITH_AUTHN_REQUEST)) {
authnContextClassRef.setAuthnContextClassRef(authnRequest
.getRequestedAuthnContext().getAuthnContextClassRefs()
.get(0).getAuthnContextClassRef());
} else {
authnContextClassRef.setAuthnContextClassRef(samlResponseData
.getAuthnContextClassRef());
}
authnContext.setAuthnContextClassRef(authnContextClassRef);
}
if (samlResponseData.getSubjectLocalityAddress() != null
&& samlResponseData.getSubjectLocalityAddress().length() > 0) {
subjectLocality = create(SubjectLocality.DEFAULT_ELEMENT_NAME);
subjectLocality.setAddress(samlResponseData
.getSubjectLocalityAddress());
}
if (samlResponseData.getSubjectLocalityDNSName() != null
&& samlResponseData.getSubjectLocalityDNSName().length() > 0) {
if (subjectLocality == null)
subjectLocality = create(SubjectLocality.DEFAULT_ELEMENT_NAME);
subjectLocality.setDNSName(samlResponseData
.getSubjectLocalityDNSName());
}
if (authnContext != null || subjectLocality != null
|| samlResponseData.getAuthnInstant() != null) {
authnStatement = create(AuthnStatement.DEFAULT_ELEMENT_NAME);
if (samlResponseData.getAuthnInstant() != null) {
authnStatement.setAuthnInstant(startTime
.plusMinutes(samlResponseData.getAuthnInstant()));
}
authnStatement.setSessionIndex(GENERATOR.generateIdentifier());
authnStatement.setAuthnContext(authnContext);
authnStatement.setSubjectLocality(subjectLocality);
}
return authnStatement;
}