本文整理汇总了Java中org.opensaml.saml2.core.Response类的典型用法代码示例。如果您正苦于以下问题:Java Response类的具体用法?Java Response怎么用?Java Response使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Response类属于org.opensaml.saml2.core包,在下文中一共展示了Response类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readObject
import org.opensaml.saml2.core.Response; //导入依赖的package包/类
private void readObject(java.io.ObjectInputStream stream)
throws IOException, ClassNotFoundException, SSOAgentException {
subjectId = (String) stream.readObject();
responseString = (String) stream.readObject();
if (responseString != null && !EMPTY_STRING.equals(responseString)) {
response = (Response) SSOAgentUtils.unmarshall(responseString);
}
assertionString = (String) stream.readObject();
if (responseString != null && !EMPTY_STRING.equals(assertionString)) {
assertion = (Assertion) SSOAgentUtils.unmarshall(assertionString);
}
sessionIndex = (String) stream.readObject();
String accessTokenResponseBeanString = (String) stream.readObject();
if (!EMPTY_STRING.equals(accessTokenResponseBeanString)) {
accessTokenResponseBean = accessTokenResponseBean.deSerialize(accessTokenResponseBeanString);
} else {
accessTokenResponseBean = null;
}
subjectAttributes = (Map) stream.readObject();
}
示例2: createLogoutRequest
import org.opensaml.saml2.core.Response; //导入依赖的package包/类
public LogoutRequest createLogoutRequest(Session session)
throws IOException, SignatureException, MarshallingException {
if (_logout == null)
return null;
// Retrieve initial authn response
Response resp = (Response)session.getCustomParams();
LogoutRequest lr = createLogoutRequest(resp);
// Create signature and add to auth Request
LogoutRequestMarshaller marshaller = new LogoutRequestMarshaller();
Signature sig = getSignature();
lr.setSignature(sig);
// Marshall object to prepare for signature
marshaller.marshall(lr);
Signer.signObject(sig);
return lr;
}
示例3: buildResponse
import org.opensaml.saml2.core.Response; //导入依赖的package包/类
protected WebRequestSettings buildResponse(String status, int assuranceLevel) throws Exception {
Document document = TestHelper.parseBase64Encoded(Utils.getParameter("SAMLRequest", handler.url.toString()));
AuthnRequest ar = (AuthnRequest) Configuration.getUnmarshallerFactory().getUnmarshaller(document.getDocumentElement()).unmarshall(document.getDocumentElement());
Assertion assertion = TestHelper.buildAssertion(spMetadata.getDefaultAssertionConsumerService().getLocation(), spMetadata.getEntityID());
assertion.getAttributeStatements().get(0).getAttributes().clear();
assertion.getAttributeStatements().get(0).getAttributes().add(AttributeUtil.createAssuranceLevel(assuranceLevel));
Response r = TestHelper.buildResponse(assertion);
r.setStatus(SAMLUtil.createStatus(status));
r.setInResponseTo(ar.getID());
OIOResponse response = new OIOResponse(r);
response.sign(credential);
WebRequestSettings req = new WebRequestSettings(new URL(BASE + "/saml/SAMLAssertionConsumer"), SubmitMethod.POST);
req.setRequestParameters(Arrays.asList(
new NameValuePair("SAMLResponse", response.toBase64()),
new NameValuePair("RelayState", Utils.getParameter("RelayState", handler.url.toString()))));
return req;
}
示例4: validateResponse
import org.opensaml.saml2.core.Response; //导入依赖的package包/类
private void validateResponse(Response response) throws SamlException {
try {
new ResponseSchemaValidator().validate(response);
} catch (ValidationException ex) {
throw new SamlException("The response schema validation failed", ex);
}
if (!response.getIssuer().getValue().equals(responseIssuer)) {
throw new SamlException("The response issuer didn't match the expected value");
}
String statusCode = response.getStatus().getStatusCode().getValue();
if (!statusCode.equals("urn:oasis:names:tc:SAML:2.0:status:Success")) {
throw new SamlException("Invalid status code: " + statusCode);
}
}
示例5: validateAssertion
import org.opensaml.saml2.core.Response; //导入依赖的package包/类
private void validateAssertion(Response response) throws SamlException {
if (response.getAssertions().size() != 1) {
throw new SamlException("The response doesn't contain exactly 1 assertion");
}
Assertion assertion = response.getAssertions().get(0);
if (!assertion.getIssuer().getValue().equals(responseIssuer)) {
throw new SamlException("The assertion issuer didn't match the expected value");
}
if (assertion.getSubject().getNameID() == null) {
throw new SamlException(
"The NameID value is missing from the SAML response; this is likely an IDP configuration issue");
}
enforceConditions(assertion.getConditions());
}
示例6: validateSignature
import org.opensaml.saml2.core.Response; //导入依赖的package包/类
/**
* Validate the signature of a SAML2 Response and Assertion
*
* @param response SAML2 Response
* @return true, if signature is valid.
*/
protected void validateSignature(Response response, Assertion assertion) throws SSOAgentException {
if (SSOAgentDataHolder.getInstance().getSignatureValidator() != null) {
//Custom implemetation of signature validation
SAMLSignatureValidator signatureValidatorUtility = (SAMLSignatureValidator) SSOAgentDataHolder
.getInstance().getSignatureValidator();
signatureValidatorUtility.validateSignature(response, assertion, ssoAgentConfig);
} else {
//If custom implementation not found, Execute the default implementation
if (ssoAgentConfig.getSAML2().isResponseSigned()) {
if (response.getSignature() == null) {
throw new SSOAgentException("SAML2 Response signing is enabled, but signature element not found in SAML2 Response element");
} else {
validateSignature(response.getSignature());
}
}
if (ssoAgentConfig.getSAML2().isAssertionSigned()) {
if (assertion.getSignature() == null) {
throw new SSOAgentException("SAML2 Assertion signing is enabled, but signature element not found in SAML2 Assertion element");
} else {
validateSignature(assertion.getSignature());
}
}
}
}
示例7: executeQuery
import org.opensaml.saml2.core.Response; //导入依赖的package包/类
public OIOAssertion executeQuery(SOAPClient client, Credential credential, String username, String password, boolean ignoreCertPath, Collection<? extends Certificate> idpCertificates, boolean allowUnencryptedAssertion) throws IOException {
try {
sign(credential);
Audit.log(Operation.ATTRIBUTEQUERY, true, getID(), toXML());
XMLObject res = client.wsCall(this, getDestination(), username, password, ignoreCertPath);
if (!(res instanceof Response)) throw new IllegalStateException("Received wrong type from IdP (expected Response): " + res);
OIOResponse oiores = new OIOResponse((Response) res);
if (log.isDebugEnabled()) log.debug("Received attribute query response: " + oiores.toXML());
Audit.log(Operation.ATTRIBUTEQUERY, false, getID(), oiores.toXML());
oiores.decryptAssertion(credential, allowUnencryptedAssertion);
oiores.validateResponse(null, idpCertificates, false);
return oiores.getAssertion();
} catch (ValidationException e) {
Audit.logError(Operation.ATTRIBUTEQUERY, false, getID(), e);
throw e;
}
}
示例8: extract
import org.opensaml.saml2.core.Response; //导入依赖的package包/类
public OIOResponse extract(HttpServletRequest request) {
String samlResponse = request.getParameter(Constants.SAML_SAMLRESPONSE);
if (samlResponse == null) {
throw new IllegalStateException("SAMLResponse parameter cannot be null");
}
if (log.isDebugEnabled()) log.debug("SAMLResponse: " + samlResponse);
try {
String xml = new String(Base64.decode(samlResponse), "UTF-8");
XMLObject obj = SAMLUtil.unmarshallElementFromString(xml);
if (!(obj instanceof Response)) {
throw new IllegalArgumentException("SAMLResponse must be of type Response. Was " + obj);
}
return new OIOResponse((Response) obj);
} catch (UnsupportedEncodingException e) {
throw new WrappedException(Layer.BUSINESS, e);
}
}
示例9: testExecuteQuery
import org.opensaml.saml2.core.Response; //导入依赖的package包/类
@Test
public void testExecuteQuery() throws Exception {
q.addAttribute("uid", null);
Assertion assertion = TestHelper.buildAssertion(null, spMetadata.getEntityID());
final Response response = TestHelper.buildResponse(assertion);
new OIOResponse(response).sign(credential);
final SOAPClient client = context.mock(SOAPClient.class);
context.checking(new Expectations() {{
one(client).wsCall(with(same(q)), with(equal(dest)), with(equal("username")), with(equal("password")), with(equal(true)));
will(returnValue(response));
}});
OIOAssertion res = q.executeQuery(client, credential, "username", "password", true, idpMetadata.getFirstMetadata().getCertificates(), true);
assertNotNull(res);
}
示例10: getAssertionAttributeStringValueList
import org.opensaml.saml2.core.Response; //导入依赖的package包/类
/**
* Get a list of string values for each value under a named Attribute in an Assertion from the SAML Response
*
* @param pSamlResponse Response with one assertion in it containing 0 or more attributes
* @param pAttributeName Name of the attribute to get a list of values from
* @return List of values for SAMLResponse/Assertion/Attribute[name=pAttributeName]
*/
private List<String> getAssertionAttributeStringValueList(Response pSamlResponse, String pAttributeName) {
List<Attribute> lAttributesList = getResponseAttributes(pSamlResponse);
for (Attribute lAttribute : lAttributesList) {
if (!pAttributeName.equals(lAttribute.getName())) {
continue;
}
List<XMLObject> lAttributeValues = lAttribute.getAttributeValues();
return lAttributeValues.stream()
// This could deserialise lXMLObject into a typed attribute but all attribute values we're interested in should just have plain text content
.map(lAttrVal -> lAttrVal.getDOM().getTextContent())
.collect(Collectors.toList());
}
return Collections.emptyList();
}
示例11: buildResponse
import org.opensaml.saml2.core.Response; //导入依赖的package包/类
public Response buildResponse(SAMLSSOAuthnReqDTO authReqDTO, Assertion assertion)
throws IdentityException {
if (log.isDebugEnabled()) {
log.debug("Building SAML Response for the consumer '"
+ authReqDTO.getAssertionConsumerURL() + "'");
}
Response response = new org.opensaml.saml2.core.impl.ResponseBuilder().buildObject();
response.setIssuer(SAMLSSOUtil.getIssuer());
response.setID(SAMLSSOUtil.createID());
response.setInResponseTo(authReqDTO.getId());
response.setDestination(authReqDTO.getAssertionConsumerURL());
response.setStatus(buildStatus(SAMLSSOConstants.StatusCodes.SUCCESS_CODE, null));
response.setVersion(SAMLVersion.VERSION_20);
DateTime issueInstant = new DateTime();
response.setIssueInstant(issueInstant);
response.getAssertions().add(assertion);
if (authReqDTO.isDoSignResponse()) {
SAMLSSOUtil.setSignature(response, authReqDTO.getSigningAlgorithmUri(), authReqDTO.getDigestAlgorithmUri
(), new SignKeyDataHolder(authReqDTO.getUser().getAuthenticatedSubjectIdentifier()));
}
return response;
}
示例12: buildResponse
import org.opensaml.saml2.core.Response; //导入依赖的package包/类
/**
* Build the error response
*
* @param inResponseToID
* @param statusCodes
* @param statusMsg
* @return
*/
public Response buildResponse(String inResponseToID, List<String> statusCodes, String statusMsg,
String destination) throws IdentityException {
if (statusCodes == null || statusCodes.isEmpty()) {
throw IdentityException.error("No Status Values");
}
response.setIssuer(SAMLSSOUtil.getIssuer());
Status status = new StatusBuilder().buildObject();
StatusCode statusCode = null;
for (String statCode : statusCodes) {
statusCode = buildStatusCode(statCode, statusCode);
}
status.setStatusCode(statusCode);
buildStatusMsg(status, statusMsg);
response.setStatus(status);
response.setVersion(SAMLVersion.VERSION_20);
response.setID(SAMLSSOUtil.createID());
if (inResponseToID != null) {
response.setInResponseTo(inResponseToID);
}
if (destination != null) {
response.setDestination(destination);
}
response.setIssueInstant(new DateTime());
return response;
}
示例13: generateErrorneousResponse
import org.opensaml.saml2.core.Response; //导入依赖的package包/类
public static String generateErrorneousResponse() {
Response response = new ResponseBuilder().buildObject();
response.setIssuer(getIssuer());
response.setStatus(buildStatus());
response.setVersion(SAMLVersion.VERSION_20);
response.setID(UIDGenerator.generateUID());
try {
return encode(marshall(response));
} catch (IdentityException e) {
if (log.isDebugEnabled()) {
log.debug("Error while encoding.", e);
}
return null;
}
}
示例14: getEndpointURL
import org.opensaml.saml2.core.Response; //导入依赖的package包/类
/**
* Gets the response URL from the relying party endpoint. If the SAML message is a {@link Response} and the relying
* party endpoint contains a response location then that location is returned otherwise the normal endpoint location
* is returned.
*
* @param messageContext current message context
*
* @return response URL from the relying party endpoint
*
* @throws MessageEncodingException throw if no relying party endpoint is available
*/
protected String getEndpointURL(SAMLMessageContext messageContext) throws MessageEncodingException {
Endpoint endpoint = messageContext.getPeerEntityEndpoint();
if (endpoint == null) {
throw new MessageEncodingException("Endpoint for relying party was null.");
}
if (messageContext.getOutboundMessage() instanceof Response
&& !DatatypeHelper.isEmpty(endpoint.getResponseLocation())) {
return endpoint.getResponseLocation();
} else {
if (DatatypeHelper.isEmpty(endpoint.getLocation())) {
throw new MessageEncodingException("Relying party endpoint location was null or empty.");
}
return endpoint.getLocation();
}
}
示例15: 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;
}