本文整理汇总了Java中org.opensaml.saml2.core.AuthnStatement类的典型用法代码示例。如果您正苦于以下问题:Java AuthnStatement类的具体用法?Java AuthnStatement怎么用?Java AuthnStatement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AuthnStatement类属于org.opensaml.saml2.core包,在下文中一共展示了AuthnStatement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: marshallAttributes
import org.opensaml.saml2.core.AuthnStatement; //导入依赖的package包/类
/** {@inheritDoc} */
protected void marshallAttributes(XMLObject samlObject, Element domElement) throws MarshallingException {
AuthnStatement authnStatement = (AuthnStatement) samlObject;
if (authnStatement.getAuthnInstant() != null) {
String authnInstantStr = Configuration.getSAMLDateFormatter().print(authnStatement.getAuthnInstant());
domElement.setAttributeNS(null, AuthnStatement.AUTHN_INSTANT_ATTRIB_NAME, authnInstantStr);
}
if (authnStatement.getSessionIndex() != null) {
domElement.setAttributeNS(null, AuthnStatement.SESSION_INDEX_ATTRIB_NAME, authnStatement.getSessionIndex());
}
if (authnStatement.getSessionNotOnOrAfter() != null) {
String sessionNotOnOrAfterStr = Configuration.getSAMLDateFormatter().print(
authnStatement.getSessionNotOnOrAfter());
domElement.setAttributeNS(null, AuthnStatement.SESSION_NOT_ON_OR_AFTER_ATTRIB_NAME, sessionNotOnOrAfterStr);
}
}
示例2: createLogoutRequest
import org.opensaml.saml2.core.AuthnStatement; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public LogoutRequest createLogoutRequest(Response resp) {
LogoutRequest lr = ((SAMLObjectBuilder<LogoutRequest>)
_bf.getBuilder(LogoutRequest.DEFAULT_ELEMENT_NAME)).buildObject();
String uid = UUID.randomUUID().toString();
lr.setID(uid);
lr.setIssueInstant(new DateTime());
lr.setVersion(SAMLVersion.VERSION_20);
lr.setIssuer(getIssuer());
// Get NameID and SessionIndex from first assertion from
// Authentication Response object
Assertion asr = resp.getAssertions().get(0);
NameID nid = ((SAMLObjectBuilder<NameID>)
_bf.getBuilder(NameID.DEFAULT_ELEMENT_NAME)).buildObject();
nid.setValue(asr.getSubject().getNameID().getValue());
lr.setNameID(nid);
// Set session index(es)
List<AuthnStatement> ausl = asr.getAuthnStatements();
if (ausl != null) {
for (AuthnStatement aus :ausl) {
SessionIndex sindex = ((SAMLObjectBuilder<SessionIndex>)
_bf.getBuilder(SessionIndex.DEFAULT_ELEMENT_NAME)).buildObject();
sindex.setSessionIndex(aus.getSessionIndex());
lr.getSessionIndexes().add(sindex);
}
}
return lr;
}
示例3: 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;
}
示例4: hasSessionExpired
import org.opensaml.saml2.core.AuthnStatement; //导入依赖的package包/类
/**
* Check whether an assertion contains an expired sessionIndex within a
* AuthnStatement (i.e. [email protected] >= now)
*
* @return <code>true</code>, if the assertion has expired. <code>false</code>
* otherwise.
*/
public boolean hasSessionExpired() {
boolean retVal = false;
if (assertion != null && assertion.getAuthnStatements() != null) {
if (assertion.getAuthnStatements().size() > 0) {
// We only look into the first AuthnStatement
AuthnStatement authnStatement = (AuthnStatement) assertion.getAuthnStatements().get(0);
if (authnStatement.getSessionNotOnOrAfter() != null) {
retVal = authnStatement.getSessionNotOnOrAfter().isBeforeNow();
} else {
retVal = false;
}
}
}
return retVal;
}
示例5: getAuthnContextClassRef
import org.opensaml.saml2.core.AuthnStatement; //导入依赖的package包/类
/**
* Return the value of the /AuthnStatement/AuthnContext/AuthnContextClassRef
* element in an assertion
*
* @return The value. <code>null</code>, if the assertion does not
* contain the element.
*/
public String getAuthnContextClassRef() {
String retVal = null;
if (assertion.getAuthnStatements() != null) {
if (assertion.getAuthnStatements().size() > 0) {
// We only look into the first AuthnStatement
AuthnStatement authnStatement = (AuthnStatement) assertion.getAuthnStatements().get(0);
AuthnContext authnContext = authnStatement.getAuthnContext();
if (authnContext != null) {
AuthnContextClassRef authnContextClassRef = authnContext.getAuthnContextClassRef();
if (authnContextClassRef != null) {
retVal = authnContextClassRef.getAuthnContextClassRef();
}
}
}
}
return retVal;
}
示例6: getAuthnContextClassRef
import org.opensaml.saml2.core.AuthnStatement; //导入依赖的package包/类
@Test
public void getAuthnContextClassRef() {
String expectedAuthnContextClassRefString = "expected string";
AuthnContextClassRef authnContextClassRef = new AuthnContextClassRefStubImpl();
authnContextClassRef.setAuthnContextClassRef(expectedAuthnContextClassRefString);
AuthnContext authnContext = new AuthnContextStubImpl();
authnContext.setAuthnContextClassRef(authnContextClassRef);
AuthnStatement authnStatement= new AuthnStatementStubImpl();
authnStatement.setAuthnContext(authnContext);
List<AuthnStatement> authnStatements = new ArrayList<AuthnStatement>();
authnStatements.add(authnStatement);
Assertion assertion = new AssertionStubImpl(authnStatements);
assertEquals(expectedAuthnContextClassRefString, new OIOAssertion(assertion).getAuthnContextClassRef());
}
示例7: testSubjectFailure
import org.opensaml.saml2.core.AuthnStatement; //导入依赖的package包/类
/**
* Tests absent Subject failure.
*
* @throws ValidationException
*/
public void testSubjectFailure() throws ValidationException {
Assertion assertion = (Assertion) target;
AuthnStatement authnStatement = (AuthnStatement) buildXMLObject(new QName(SAMLConstants.SAML20_NS, AuthnStatement.DEFAULT_ELEMENT_LOCAL_NAME,
SAMLConstants.SAML20_PREFIX));
AuthzDecisionStatement authzDecisionStatement = (AuthzDecisionStatement) buildXMLObject(new QName(SAMLConstants.SAML20_NS, AuthzDecisionStatement.DEFAULT_ELEMENT_LOCAL_NAME,
SAMLConstants.SAML20_PREFIX));
AttributeStatement attributeStatement = (AttributeStatement) buildXMLObject(new QName(SAMLConstants.SAML20_NS, AttributeStatement.DEFAULT_ELEMENT_LOCAL_NAME,
SAMLConstants.SAML20_PREFIX));
assertion.setSubject(null);
assertValidationFail("Subject was null in the absence of statements, should raise a Validation Exception");
assertion.getAuthnStatements().add(authnStatement);
assertValidationFail("Subject was null in the presence of AuthnStatement, should raise a Validation Exception.");
assertion.getAuthnStatements().clear();
assertion.getAuthzDecisionStatements().add(authzDecisionStatement);
assertValidationFail("Subject was null in the presence of AuthzDecisionStatement, should raise a Validation Exception.");
assertion.getAuthzDecisionStatements().clear();
assertion.getAttributeStatements().add(attributeStatement);
assertValidationFail("Subject was null in the presence of AttributeStatement, should raise a Validation Exception.");
}
示例8: testSingleElementOptionalAttributesUnmarshall
import org.opensaml.saml2.core.AuthnStatement; //导入依赖的package包/类
/** {@inheritDoc} */
public void testSingleElementOptionalAttributesUnmarshall() {
AuthnStatement authnStatement = (AuthnStatement) unmarshallElement(singleElementOptionalAttributesFile);
DateTime authnInstant = authnStatement.getAuthnInstant();
assertEquals("AuthnInstant was " + authnInstant + ", expected " + expectedAuthnInstant, expectedAuthnInstant,
authnInstant);
String sessionIndex = authnStatement.getSessionIndex();
assertEquals("SessionIndex was " + sessionIndex + ", expected " + expectedSessionIndex, expectedSessionIndex,
sessionIndex);
DateTime sessionNotOnOrAfter = authnStatement.getSessionNotOnOrAfter();
assertEquals("SessionNotOnOrAfter was " + sessionNotOnOrAfter + ", expected " + expectedSessionNotOnOrAfter,
expectedSessionNotOnOrAfter, sessionNotOnOrAfter);
}
示例9: getSAMLBuilder
import org.opensaml.saml2.core.AuthnStatement; //导入依赖的package包/类
private static XMLObjectBuilderFactory getSAMLBuilder() throws ConfigurationException {
if (builderFactory == null) {
// OpenSAML 2.3
DefaultBootstrap.bootstrap();
builderFactory = Configuration.getBuilderFactory();
nameIdBuilder = (SAMLObjectBuilder) getSAMLBuilder().getBuilder(NameID.DEFAULT_ELEMENT_NAME);
confirmationMethodBuilder = (SAMLObjectBuilder) getSAMLBuilder().getBuilder(SubjectConfirmationData.DEFAULT_ELEMENT_NAME);
subjectConfirmationBuilder = (SAMLObjectBuilder) getSAMLBuilder().getBuilder(SubjectConfirmation.DEFAULT_ELEMENT_NAME);
subjectBuilder = (SAMLObjectBuilder) getSAMLBuilder().getBuilder(Subject.DEFAULT_ELEMENT_NAME);
attrStatementBuilder = (SAMLObjectBuilder) getSAMLBuilder().getBuilder(AttributeStatement.DEFAULT_ELEMENT_NAME);
audienceRestrictionnBuilder = (SAMLObjectBuilder) getSAMLBuilder().getBuilder(AudienceRestriction.DEFAULT_ELEMENT_NAME);
audienceBuilder = (SAMLObjectBuilder) getSAMLBuilder().getBuilder(Audience.DEFAULT_ELEMENT_NAME);
authStatementBuilder = (SAMLObjectBuilder) getSAMLBuilder().getBuilder(AuthnStatement.DEFAULT_ELEMENT_NAME);
authContextBuilder = (SAMLObjectBuilder) getSAMLBuilder().getBuilder(AuthnContext.DEFAULT_ELEMENT_NAME);
authContextClassRefBuilder = (SAMLObjectBuilder) getSAMLBuilder().getBuilder(AuthnContextClassRef.DEFAULT_ELEMENT_NAME);
issuerBuilder = (SAMLObjectBuilder) getSAMLBuilder().getBuilder(Issuer.DEFAULT_ELEMENT_NAME);
assertionBuilder = (SAMLObjectBuilder) getSAMLBuilder().getBuilder(Assertion.DEFAULT_ELEMENT_NAME);
}
return builderFactory;
}
示例10: createAssertion
import org.opensaml.saml2.core.AuthnStatement; //导入依赖的package包/类
private Assertion createAssertion(final DateTime issueDate, Subject subject, Issuer issuer, AuthnStatement authnStatement,
AttributeStatement attributeStatement) {
AssertionBuilder assertionBuilder = new AssertionBuilder();
Assertion assertion = assertionBuilder.buildObject();
assertion.setID(UUID.randomUUID().toString());
assertion.setIssueInstant(issueDate);
assertion.setSubject(subject);
assertion.setIssuer(issuer);
if (authnStatement != null)
assertion.getAuthnStatements().add(authnStatement);
if (attributeStatement != null)
assertion.getAttributeStatements().add(attributeStatement);
return assertion;
}
示例11: 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;
}
示例12: retrieveAuthnStatement
import org.opensaml.saml2.core.AuthnStatement; //导入依赖的package包/类
/**
* Retrieve a unique AuthnStatement in an assertion.
*
* @param assertionsession
* assertion
* @return the AuthnStatement of this assertion (can be null)
* @throws UnsupportedSamlOperation
* if multiple AuthnStatement found
*/
protected AuthnStatement retrieveAuthnStatement(final Assertion assertion) throws UnsupportedSamlOperation {
AuthnStatement authnStatement = null;
if (assertion != null) {
final List<AuthnStatement> authnStatements = assertion.getAuthnStatements();
if (authnStatements.size() > 1) {
throw new UnsupportedSamlOperation(
"This SP does not support multiple AuthnStatement in one assertion !");
} else if (authnStatements.size() == 1) {
authnStatement = authnStatements.iterator().next();
}
}
return authnStatement;
}
示例13: processChildElement
import org.opensaml.saml2.core.AuthnStatement; //导入依赖的package包/类
/** {@inheritDoc} */
protected void processChildElement(XMLObject parentObject, XMLObject childObject) throws UnmarshallingException {
AuthnStatement authnStatement = (AuthnStatement) parentObject;
if (childObject instanceof SubjectLocality) {
authnStatement.setSubjectLocality((SubjectLocality) childObject);
} else if (childObject instanceof AuthnContext) {
authnStatement.setAuthnContext((AuthnContext) childObject);
} else {
super.processChildElement(parentObject, childObject);
}
}
示例14: 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);
}
}
示例15: createUserSession
import org.opensaml.saml2.core.AuthnStatement; //导入依赖的package包/类
private synchronized void createUserSession(HttpServletRequest req,
Assertion asr, String user, String stoken, Object params) {
Session session = createUserSession(req, user, stoken, params);
List<AuthnStatement> ausl = asr.getAuthnStatements();
if (ausl != null)
for (AuthnStatement aus :ausl)
_smap.put(aus.getSessionIndex(), session);
}