当前位置: 首页>>代码示例>>Java>>正文


Java Response.getAssertions方法代码示例

本文整理汇总了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;
}
 
开发者ID:mxbossard,项目名称:java-saml2-sp,代码行数:35,代码来源:AuthnResponseQueryProcessor.java

示例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);
}
 
开发者ID:Fivium,项目名称:FOXopen,代码行数:16,代码来源:AuthTypeSAML.java

示例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;
}
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:17,代码来源:SAML2SSOUIAuthenticator.java

示例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;
}
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:21,代码来源:SAML2SSOUIAuthenticator.java

示例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;
}
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:20,代码来源:Util.java

示例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;
}
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:19,代码来源:SAML2SSOAuthenticator.java

示例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;
}
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:16,代码来源:SAML2SSOAuthenticator.java

示例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;
}
 
开发者ID:wso2,项目名称:carbon-commons,代码行数:42,代码来源:SAMLSSORelyingPartyObject.java

示例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);
        }

    }
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:75,代码来源:DefaultSAML2SSOManager.java

示例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);

}
 
开发者ID:wso2,项目名称:carbon-commons,代码行数:62,代码来源:SAMLSSORelyingPartyObject.java


注:本文中的org.opensaml.saml2.core.Response.getAssertions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。