本文整理汇总了Java中org.opensaml.saml2.core.AuthnStatement.getSessionIndex方法的典型用法代码示例。如果您正苦于以下问题:Java AuthnStatement.getSessionIndex方法的具体用法?Java AuthnStatement.getSessionIndex怎么用?Java AuthnStatement.getSessionIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.opensaml.saml2.core.AuthnStatement
的用法示例。
在下文中一共展示了AuthnStatement.getSessionIndex方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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);
}
示例3: getSessionIndex
import org.opensaml.saml2.core.AuthnStatement; //导入方法依赖的package包/类
/**
* Return the value of the /[email protected] element in an assertion
*
* @return The value. <code>null</code>, if the assertion does not
* contain the element.
*/
public String getSessionIndex() {
String retVal = null;
if (assertion != null && assertion.getAuthnStatements() != null) {
if (assertion.getAuthnStatements().size() > 0) {
// We only look into the first AuthnStatement
AuthnStatement authnStatement = assertion.getAuthnStatements().get(0);
retVal = authnStatement.getSessionIndex();
}
}
return retVal;
}
示例4: getSessionIndexFromResponse
import org.opensaml.saml2.core.AuthnStatement; //导入方法依赖的package包/类
/**
* Read the session index from a Response
*
* @param response SAML Response
* @return Session Index value contained in the Response
*/
private String getSessionIndexFromResponse(Response response) {
List<Assertion> assertions = response.getAssertions();
String sessionIndex = null;
if (assertions != null && assertions.size() > 0) {
// There can be only one assertion in a SAML Response, so get the first one
List<AuthnStatement> authnStatements = assertions.get(0).getAuthnStatements();
if (authnStatements != null && authnStatements.size() > 0) {
// There can be only one authentication stmt inside the SAML assertion of a SAML Response
AuthnStatement authStmt = authnStatements.get(0);
sessionIndex = authStmt.getSessionIndex();
}
}
return sessionIndex;
}
示例5: jsFunction_setSessionAuthenticated
import org.opensaml.saml2.core.AuthnStatement; //导入方法依赖的package包/类
/**
* Set the current session as authenticated by mapping with current session id to session index.
*
* @param cx
* @param thisObj
* @param args -args[0]- current session id, args[1]-SAML response
* @param funObj
* @throws Exception
*/
public static void jsFunction_setSessionAuthenticated(Context cx, Scriptable thisObj,
Object[] args,
Function funObj)
throws Exception {
int argLength = args.length;
if (argLength != 2 || !(args[0] instanceof String) || !(args[1] instanceof String)) {
throw new ScriptException("Invalid argument. Current session id and SAML response are missing.");
}
String decodedString = Util.decode((String) args[1]);
SAMLSSORelyingPartyObject relyingPartyObject = (SAMLSSORelyingPartyObject) thisObj;
XMLObject samlObject = Util.unmarshall(decodedString);
String sessionIndex = null;
String username = null;
if (samlObject instanceof Response) {
Response samlResponse = (Response) samlObject;
List<Assertion> assertions = samlResponse.getAssertions();
// extract the session index
if (assertions != null && assertions.size() > 0) {
List<AuthnStatement> authenticationStatements = assertions.get(0).getAuthnStatements();
AuthnStatement authnStatement = authenticationStatements.get(0);
if (authnStatement != null) {
if (authnStatement.getSessionIndex() != null) {
sessionIndex = authnStatement.getSessionIndex();
}
}
}
// extract the username
if (assertions != null && assertions.size() > 0) {
Subject subject = assertions.get(0).getSubject();
if (subject != null) {
if (subject.getNameID() != null) {
username = subject.getNameID().getValue();
}
}
}
}
if (sessionIndex == null) {
throw new Exception("Failed to get session index from authentication statement in SAML response.");
}
if (username == null) {
throw new Exception("Failed to get subject assertion from SAML response.");
}
SessionInfo sessionInfo = new SessionInfo((String) args[0]);
sessionInfo.setSessionIndex(sessionIndex);
sessionInfo.setLoggedInUser(username);
sessionInfo.setSamlToken((String) args[1]);//We expect an encoded SamlToken here.
relyingPartyObject.addSessionInfo(sessionInfo);
}