本文整理汇总了Java中org.opensaml.saml2.core.Response.getAssertions方法的典型用法代码示例。如果您正苦于以下问题:Java Response.getAssertions方法的具体用法?Java Response.getAssertions怎么用?Java Response.getAssertions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.opensaml.saml2.core.Response
的用法示例。
在下文中一共展示了Response.getAssertions方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: retrieveAllAssertions
import org.opensaml.saml2.core.Response; //导入方法依赖的package包/类
/**
* Retrieve all assertions, normal ones and encrypted ones if a private key was provided.
*
* @param samlResponse
* the saml response containing the assertions.
* @return the list of all assertions.
* @throws DecryptionException
* in case of decryption problem.
* @throws UnsupportedSamlOperation
*/
protected List<Assertion> retrieveAllAssertions(final Response samlResponse) throws DecryptionException,
UnsupportedSamlOperation {
final List<Assertion> allAssertions = new ArrayList<Assertion>();
if (samlResponse != null) {
// Normal Assertions
final List<Assertion> normalAssertions = samlResponse.getAssertions();
if (!CollectionUtils.isEmpty(normalAssertions)) {
allAssertions.addAll(normalAssertions);
}
// Encrypted Assertions
final List<EncryptedAssertion> encAssertions = samlResponse.getEncryptedAssertions();
if (!CollectionUtils.isEmpty(encAssertions)) {
for (final EncryptedAssertion encAssertion : samlResponse.getEncryptedAssertions()) {
final Assertion assertion = this.decryptAssertion(encAssertion);
allAssertions.add(assertion);
}
}
}
return allAssertions;
}
示例2: getResponseAssertion
import org.opensaml.saml2.core.Response; //导入方法依赖的package包/类
/**
* Get the assertion from a SAML response
*
* @param pSamlResponse SAMl Response with 1 Assertion object in it
* @return SAML Assertion object from pSamlResponse
*/
private Assertion getResponseAssertion(Response pSamlResponse) {
List lAssertions = pSamlResponse.getAssertions();
if (lAssertions.size() != 1) {
throw new ExInternal("Expected 1 assertion in the SAML response, found: " + lAssertions.size());
}
return (Assertion)lAssertions.get(0);
}
示例3: getUsernameFromResponse
import org.opensaml.saml2.core.Response; //导入方法依赖的package包/类
/**
* Get the username from the SAML2 Response
*
* @param response SAML2 Response
* @return username username contained in the SAML Response
*/
private String getUsernameFromResponse(Response response) {
List<Assertion> assertions = response.getAssertions();
Assertion assertion = null;
if (assertions != null && assertions.size() > 0) {
// There can be only one assertion in a SAML Response, so get the first one
assertion = assertions.get(0);
return assertion.getSubject().getNameID().getValue();
}
return null;
}
示例4: getSessionIndexFromResponse
import org.opensaml.saml2.core.Response; //导入方法依赖的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: getUsernameFromResponse
import org.opensaml.saml2.core.Response; //导入方法依赖的package包/类
/**
* Get the username from the SAML2 Response
*
* @param response SAML2 Response
* @return username username contained in the SAML Response
*/
public static String getUsernameFromResponse(Response response) {
List<Assertion> assertions = response.getAssertions();
Assertion assertion = null;
if (assertions != null && assertions.size() > 0) {
// There can be only one assertion in a SAML Response, so get the
// first one
assertion = assertions.get(0);
return getUsernameFromAssertion(assertion);
}
return null;
}
示例6: getAssertionFromResponse
import org.opensaml.saml2.core.Response; //导入方法依赖的package包/类
/**
* Get the Assertion from the SAML2 Response
*
* @param response SAML2 Response
* @return assertion
*/
private Assertion getAssertionFromResponse(Response response) {
Assertion assertion = null;
if (response != null) {
List<Assertion> assertions = response.getAssertions();
if (assertions != null && assertions.size() > 0) {
assertion = assertions.get(0);
} else {
log.error("SAML2 Response doesn't contain Assertions");
}
}
return assertion;
}
示例7: getRolesFromResponse
import org.opensaml.saml2.core.Response; //导入方法依赖的package包/类
/**
* Get roles from the SAML2 Response
*
* @param response SAML2 Response
* @return roles array
*/
private String[] getRolesFromResponse(Response response) {
List<Assertion> assertions = response.getAssertions();
Assertion assertion = null;
if (assertions != null && assertions.size() > 0) {
assertion = assertions.get(0);
return getRolesFromAssertion(assertion);
}
return null;
}
示例8: jsFunction_getSAMLResponseNameId
import org.opensaml.saml2.core.Response; //导入方法依赖的package包/类
/**
* Extract the name of authenticated user from SAML response.
*
* @param cx
* @param thisObj
* @param args
* @param funObj
* @return
* @throws Exception
*/
public static String jsFunction_getSAMLResponseNameId(Context cx, Scriptable thisObj,
Object[] args,
Function funObj)
throws Exception {
int argLength = args.length;
if (argLength != 1 || !(args[0] instanceof String)) {
throw new ScriptException("Invalid argument. The SAML response is missing.");
}
String decodedString = Util.decode((String) args[0]);
XMLObject samlObject = Util.unmarshall(decodedString);
String username = null;
if (samlObject instanceof Response) {
Response samlResponse = (Response) samlObject;
List<Assertion> assertions = samlResponse.getAssertions();
// 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 (username == null) {
throw new Exception("Failed to get subject assertion from SAML response.");
}
return username;
}
示例9: processSSOResponse
import org.opensaml.saml2.core.Response; //导入方法依赖的package包/类
private void processSSOResponse(HttpServletRequest request) throws SAMLSSOException {
Response samlResponse = (Response) unmarshall(new String(Base64.decode(request.getParameter(
SSOConstants.HTTP_POST_PARAM_SAML2_RESP))));
Assertion assertion = null;
if (SSOUtils.isAssertionEncryptionEnabled(properties)) {
List<EncryptedAssertion> encryptedAssertions = samlResponse.getEncryptedAssertions();
EncryptedAssertion encryptedAssertion = null;
if (CollectionUtils.isNotEmpty(encryptedAssertions)) {
encryptedAssertion = encryptedAssertions.get(0);
try {
assertion = getDecryptedAssertion(encryptedAssertion);
} catch (Exception e) {
throw new SAMLSSOException("Unable to decrypt the SAML Assertion", e);
}
}
} else {
List<Assertion> assertions = samlResponse.getAssertions();
if (CollectionUtils.isNotEmpty(assertions)) {
assertion = assertions.get(0);
}
}
if (assertion == null) {
if (samlResponse.getStatus() != null &&
samlResponse.getStatus().getStatusCode() != null &&
samlResponse.getStatus().getStatusCode().getValue().equals(
SSOConstants.StatusCodes.IDENTITY_PROVIDER_ERROR) &&
samlResponse.getStatus().getStatusCode().getStatusCode() != null &&
samlResponse.getStatus().getStatusCode().getStatusCode().getValue().equals(
SSOConstants.StatusCodes.NO_PASSIVE)) {
return;
}
throw new SAMLSSOException("SAML Assertion not found in the Response");
}
// Get the subject name from the Response Object and forward it to login_action.jsp
String subject = null;
String nameQualifier = null;
String spNameQualifier = null;
if (assertion.getSubject() != null && assertion.getSubject().getNameID() != null) {
subject = assertion.getSubject().getNameID().getValue();
}
if (subject == null) {
throw new SAMLSSOException("SAML Response does not contain the name of the subject");
}
request.getSession().setAttribute("username", subject); // get the subject
nameQualifier = assertion.getSubject().getNameID().getNameQualifier();
spNameQualifier = assertion.getSubject().getNameID().getSPNameQualifier();
// validate audience restriction
validateAudienceRestriction(assertion);
// validate signature this SP only looking for assertion signature
validateSignature(samlResponse, assertion);
request.getSession(false).setAttribute("samlssoAttributes", getAssertionStatements(assertion));
//For removing the session when the single sign out request made by the SP itself
if (SSOUtils.isLogoutEnabled(properties)) {
String sessionId = assertion.getAuthnStatements().get(0).getSessionIndex();
if (sessionId == null) {
throw new SAMLSSOException("Single Logout is enabled but IdP Session ID not found in SAML Assertion");
}
request.getSession().setAttribute(SSOConstants.IDP_SESSION, sessionId);
request.getSession().setAttribute(SSOConstants.LOGOUT_USERNAME, nameQualifier);
request.getSession().setAttribute(SSOConstants.SP_NAME_QUALIFIER, spNameQualifier);
}
}
示例10: jsFunction_setSessionAuthenticated
import org.opensaml.saml2.core.Response; //导入方法依赖的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);
}