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


Java BasicSAMLMessageContext.setPeerEntityEndpoint方法代码示例

本文整理汇总了Java中org.opensaml.common.binding.BasicSAMLMessageContext.setPeerEntityEndpoint方法的典型用法代码示例。如果您正苦于以下问题:Java BasicSAMLMessageContext.setPeerEntityEndpoint方法的具体用法?Java BasicSAMLMessageContext.setPeerEntityEndpoint怎么用?Java BasicSAMLMessageContext.setPeerEntityEndpoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.opensaml.common.binding.BasicSAMLMessageContext的用法示例。


在下文中一共展示了BasicSAMLMessageContext.setPeerEntityEndpoint方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: redirectUserWithRequest

import org.opensaml.common.binding.BasicSAMLMessageContext; //导入方法依赖的package包/类
private void redirectUserWithRequest(HttpServletResponse httpServletResponse, AuthnRequest authnRequest) {
    HttpServletResponseAdapter responseAdapter = new HttpServletResponseAdapter(httpServletResponse, true);
    BasicSAMLMessageContext<SAMLObject, AuthnRequest, SAMLObject> context = new BasicSAMLMessageContext<SAMLObject, AuthnRequest, SAMLObject>();
    context.setPeerEntityEndpoint(getIPDEndpoint());
    context.setOutboundSAMLMessage(authnRequest);
    context.setOutboundMessageTransport(responseAdapter);
    context.setOutboundSAMLMessageSigningCredential(SPCredentials.getCredential());

    HTTPRedirectDeflateEncoder encoder = new HTTPRedirectDeflateEncoder();
    logger.info("AuthnRequest: ");
    OpenSAMLUtils.logSAMLObject(authnRequest);

    logger.info("Redirecting to IDP");
    try {
        encoder.encode(context);
    } catch (MessageEncodingException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:rasmusson,项目名称:webprofile-ref-project,代码行数:20,代码来源:AccessFilter.java

示例2: testEncoding

import org.opensaml.common.binding.BasicSAMLMessageContext; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void testEncoding() throws Exception {
    SAMLObjectBuilder<Response> requestBuilder = (SAMLObjectBuilder<Response>) builderFactory
            .getBuilder(Response.DEFAULT_ELEMENT_NAME);
    Response samlMessage = requestBuilder.buildObject();
    samlMessage.setID("foo");
    samlMessage.setIssueInstant(new DateTime(0));
    samlMessage.setVersion(SAMLVersion.VERSION_11);

    SAMLObjectBuilder<Endpoint> endpointBuilder = (SAMLObjectBuilder<Endpoint>) builderFactory
            .getBuilder(AssertionConsumerService.DEFAULT_ELEMENT_NAME);
    Endpoint samlEndpoint = endpointBuilder.buildObject();
    samlEndpoint.setLocation("http://example.org");
    samlEndpoint.setResponseLocation("http://example.org/response");

    HTTPPostEncoder encoder = new HTTPPostEncoder(velocityEngine,
    "/templates/saml1-post-binding.vm");

    MockHttpServletResponse response = new MockHttpServletResponse();
    BasicSAMLMessageContext messageContext = new BasicSAMLMessageContext();
    messageContext.setOutboundMessageTransport(new HttpServletResponseAdapter(response, false));
    messageContext.setPeerEntityEndpoint(samlEndpoint);
    messageContext.setOutboundSAMLMessage(samlMessage);
    messageContext.setRelayState("relay");
    
    encoder.encode(messageContext);

    assertEquals("Unexpected content type", "text/html", response.getContentType());
    assertEquals("Unexpected character encoding", response.getCharacterEncoding(), "UTF-8");
    assertEquals("Unexpected cache controls", "no-cache, no-store", response.getHeader("Cache-control"));
    assertEquals(-608085328, response.getContentAsString().hashCode());
}
 
开发者ID:apigee,项目名称:java-opensaml2,代码行数:33,代码来源:HTTPPostEncoderTest.java

示例3: testEncoding

import org.opensaml.common.binding.BasicSAMLMessageContext; //导入方法依赖的package包/类
/** Tests encoding a simple SAML message. */
@SuppressWarnings("unchecked")
public void testEncoding() throws Exception {
    SAMLObjectBuilder<Request> requestBuilder = (SAMLObjectBuilder<Request>) builderFactory
            .getBuilder(Request.DEFAULT_ELEMENT_NAME);
    Request request = requestBuilder.buildObject();
    request.setID("foo");
    request.setIssueInstant(new DateTime(0));
    request.setVersion(SAMLVersion.VERSION_11);

    SAMLObjectBuilder<Endpoint> endpointBuilder = (SAMLObjectBuilder<Endpoint>) builderFactory
            .getBuilder(AssertionConsumerService.DEFAULT_ELEMENT_NAME);
    Endpoint samlEndpoint = endpointBuilder.buildObject();
    samlEndpoint.setLocation("http://example.org");
    samlEndpoint.setResponseLocation("http://example.org/response");

    MockHttpServletResponse response = new MockHttpServletResponse();
    BasicSAMLMessageContext messageContext = new BasicSAMLMessageContext();
    messageContext.setOutboundMessageTransport(new HttpServletResponseAdapter(response, false));
    messageContext.setPeerEntityEndpoint(samlEndpoint);
    messageContext.setOutboundSAMLMessage(request);
    messageContext.setRelayState("relay");
    
    HTTPSOAP11Encoder encoder = new HTTPSOAP11Encoder();
    encoder.encode(messageContext);

    assertEquals("Unexpected content type", "text/xml", response.getContentType());
    assertEquals("Unexpected character encoding", response.getCharacterEncoding(), "UTF-8");
    assertEquals("Unexpected cache controls", "no-cache, no-store", response.getHeader("Cache-control"));
    assertEquals("http://www.oasis-open.org/committees/security", response.getHeader("SOAPAction"));
    assertEquals(-280457420, response.getContentAsString().hashCode());
}
 
开发者ID:apigee,项目名称:java-opensaml2,代码行数:33,代码来源:HTTPSOAP11EncoderTest.java

示例4: testRequestEncoding

import org.opensaml.common.binding.BasicSAMLMessageContext; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void testRequestEncoding() throws Exception {
    SAMLObjectBuilder<AuthnRequest> responseBuilder = (SAMLObjectBuilder<AuthnRequest>) builderFactory
            .getBuilder(AuthnRequest.DEFAULT_ELEMENT_NAME);
    AuthnRequest samlMessage = responseBuilder.buildObject();
    samlMessage.setID("foo");
    samlMessage.setVersion(SAMLVersion.VERSION_20);
    samlMessage.setIssueInstant(new DateTime(0));

    SAMLObjectBuilder<Endpoint> endpointBuilder = (SAMLObjectBuilder<Endpoint>) builderFactory
            .getBuilder(AssertionConsumerService.DEFAULT_ELEMENT_NAME);
    Endpoint samlEndpoint = endpointBuilder.buildObject();
    samlEndpoint.setLocation("http://example.org");
    samlEndpoint.setResponseLocation("http://example.org/response");

    MockHttpServletResponse response = new MockHttpServletResponse();
    HttpServletResponseAdapter outTransport = new HttpServletResponseAdapter(response, false);
    
    BasicSAMLMessageContext messageContext = new BasicSAMLMessageContext();
    messageContext.setOutboundMessageTransport(outTransport);
    messageContext.setPeerEntityEndpoint(samlEndpoint);
    messageContext.setOutboundSAMLMessage(samlMessage);
    messageContext.setRelayState("relay");

    HTTPPostEncoder encoder = new HTTPPostEncoder(velocityEngine,
    "/templates/saml2-post-binding.vm");
    encoder.encode(messageContext);

    assertEquals("Unexpected content type", "text/html", response.getContentType());
    assertEquals("Unexpected character encoding", response.getCharacterEncoding(), "UTF-8");
    assertEquals("Unexpected cache controls", "no-cache, no-store", response.getHeader("Cache-control"));
    assertEquals(-243324550, response.getContentAsString().hashCode());
}
 
开发者ID:apigee,项目名称:java-opensaml2,代码行数:34,代码来源:HTTPPostEncoderTest.java

示例5: testRequestEncoding

import org.opensaml.common.binding.BasicSAMLMessageContext; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void testRequestEncoding() throws Exception {
    SAMLObjectBuilder<AuthnRequest> responseBuilder = (SAMLObjectBuilder<AuthnRequest>) builderFactory
            .getBuilder(AuthnRequest.DEFAULT_ELEMENT_NAME);
    AuthnRequest samlMessage = responseBuilder.buildObject();
    samlMessage.setID("foo");
    samlMessage.setVersion(SAMLVersion.VERSION_20);
    samlMessage.setIssueInstant(new DateTime(0));

    SAMLObjectBuilder<Endpoint> endpointBuilder = (SAMLObjectBuilder<Endpoint>) builderFactory
            .getBuilder(AssertionConsumerService.DEFAULT_ELEMENT_NAME);
    Endpoint samlEndpoint = endpointBuilder.buildObject();
    samlEndpoint.setLocation("http://example.org");
    samlEndpoint.setResponseLocation("http://example.org/response");

    MockHttpServletResponse response = new MockHttpServletResponse();
    HttpServletResponseAdapter outTransport = new HttpServletResponseAdapter(response, false);
    
    BasicSAMLMessageContext messageContext = new BasicSAMLMessageContext();
    messageContext.setOutboundMessageTransport(outTransport);
    messageContext.setPeerEntityEndpoint(samlEndpoint);
    messageContext.setOutboundSAMLMessage(samlMessage);
    messageContext.setRelayState("relay");

    HTTPPostSimpleSignEncoder encoder = new HTTPPostSimpleSignEncoder(velocityEngine,
    "/templates/saml2-post-simplesign-binding.vm");
    encoder.encode(messageContext);

    assertEquals("Unexpected content type", "text/html", response.getContentType());
    assertEquals("Unexpected character encoding", response.getCharacterEncoding(), "UTF-8");
    assertEquals("Unexpected cache controls", "no-cache, no-store", response.getHeader("Cache-control"));
    assertEquals(-1110321790, response.getContentAsString().hashCode());
}
 
开发者ID:apigee,项目名称:java-opensaml2,代码行数:34,代码来源:HTTPPostSimpleSignEncoderTest.java

示例6: buildInTransport

import org.opensaml.common.binding.BasicSAMLMessageContext; //导入方法依赖的package包/类
/** {@inheritDoc} */
protected InTransport buildInTransport() {
    //
    // Encode the "outbound" message context, with simple signature
    //
    MockHttpServletResponse response = new MockHttpServletResponse();
    HttpServletResponseAdapter outTransport = new HttpServletResponseAdapter(response, false);
    
    SAMLObjectBuilder<Endpoint> endpointBuilder = (SAMLObjectBuilder<Endpoint>) builderFactory
    .getBuilder(AssertionConsumerService.DEFAULT_ELEMENT_NAME);
    Endpoint samlEndpoint = endpointBuilder.buildObject();
    samlEndpoint.setLocation("http://example.org");
    samlEndpoint.setResponseLocation("http://example.org/response");
    
    BasicSAMLMessageContext outboundMessgeContext = new BasicSAMLMessageContext();
    outboundMessgeContext.setOutboundMessageTransport(outTransport);
    outboundMessgeContext.setOutboundSAMLMessage(buildInboundSAMLMessage());
    outboundMessgeContext.setRelayState(expectedRelayValue);
    outboundMessgeContext.setPeerEntityEndpoint(samlEndpoint);
    outboundMessgeContext.setOutboundSAMLMessageSigningCredential(signingX509Cred);
    
    HTTPRedirectDeflateEncoder encoder = new HTTPRedirectDeflateEncoder();
    try {
        encoder.encode(outboundMessgeContext);
    } catch (MessageEncodingException e) {
        fail("Could not encode outbound message context");
    }
    
    // Now populate the new "inbound" message context with the "outbound" encoded info
    MockHttpServletRequest request = new MockHttpServletRequest();
    HTTPInTransport inTransport = new HttpServletRequestAdapter(request);
    
    request.setMethod("GET");
    
    // The Spring mock object doesn't convert between the query params and the getParameter apparently,
    // so have to set them both ways.
    URLBuilder urlBuilder = new URLBuilder(response.getRedirectedUrl());
    request.setQueryString(urlBuilder.buildQueryString());
    for (Pair<String, String> param : urlBuilder.getQueryParams()) {
        request.setParameter(param.getFirst(), param.getSecond());
    }
    
    return inTransport;
}
 
开发者ID:apigee,项目名称:java-opensaml2,代码行数:45,代码来源:SAML2HTTPRedirectDeflateSignatureSecurityPolicyRuleTest.java

示例7: testResponseEncoding

import org.opensaml.common.binding.BasicSAMLMessageContext; //导入方法依赖的package包/类
/**
 * Tests encoding a SAML message to an servlet response.
 * 
 * @throws Exception
 */
@SuppressWarnings("unchecked")
public void testResponseEncoding() throws Exception {
    SAMLObjectBuilder<StatusCode> statusCodeBuilder = (SAMLObjectBuilder<StatusCode>) builderFactory
            .getBuilder(StatusCode.DEFAULT_ELEMENT_NAME);
    StatusCode statusCode = statusCodeBuilder.buildObject();
    statusCode.setValue(StatusCode.SUCCESS_URI);

    SAMLObjectBuilder<Status> statusBuilder = (SAMLObjectBuilder<Status>) builderFactory
            .getBuilder(Status.DEFAULT_ELEMENT_NAME);
    Status responseStatus = statusBuilder.buildObject();
    responseStatus.setStatusCode(statusCode);

    SAMLObjectBuilder<Response> responseBuilder = (SAMLObjectBuilder<Response>) builderFactory
            .getBuilder(Response.DEFAULT_ELEMENT_NAME);
    Response samlMessage = responseBuilder.buildObject();
    samlMessage.setID("foo");
    samlMessage.setVersion(SAMLVersion.VERSION_20);
    samlMessage.setIssueInstant(new DateTime(0));
    samlMessage.setStatus(responseStatus);

    SAMLObjectBuilder<Endpoint> endpointBuilder = (SAMLObjectBuilder<Endpoint>) builderFactory
            .getBuilder(AssertionConsumerService.DEFAULT_ELEMENT_NAME);
    Endpoint samlEndpoint = endpointBuilder.buildObject();
    samlEndpoint.setLocation("http://example.org");
    samlEndpoint.setResponseLocation("http://example.org/response");

    MockHttpServletResponse response = new MockHttpServletResponse();
    HttpServletResponseAdapter outTransport = new HttpServletResponseAdapter(response, false);
    
    BasicSAMLMessageContext messageContext = new BasicSAMLMessageContext();
    messageContext.setOutboundMessageTransport(outTransport);
    messageContext.setPeerEntityEndpoint(samlEndpoint);
    messageContext.setOutboundSAMLMessage(samlMessage);
    messageContext.setRelayState("relay");

    HTTPPostEncoder encoder = new HTTPPostEncoder(velocityEngine,
    "/templates/saml2-post-binding.vm");
    encoder.encode(messageContext);

    assertEquals("Unexpected content type", "text/html", response.getContentType());
    assertEquals("Unexpected character encoding", response.getCharacterEncoding(), "UTF-8");
    assertEquals("Unexpected cache controls", "no-cache, no-store", response.getHeader("Cache-control"));
    assertEquals(762244719, response.getContentAsString().hashCode());
}
 
开发者ID:apigee,项目名称:java-opensaml2,代码行数:50,代码来源:HTTPPostEncoderTest.java

示例8: testResponseEncoding

import org.opensaml.common.binding.BasicSAMLMessageContext; //导入方法依赖的package包/类
/**
 * Tests encoding a SAML message to an servlet response.
 * 
 * @throws Exception
 */
@SuppressWarnings("unchecked")
public void testResponseEncoding() throws Exception {
    SAMLObjectBuilder<StatusCode> statusCodeBuilder = (SAMLObjectBuilder<StatusCode>) builderFactory
            .getBuilder(StatusCode.DEFAULT_ELEMENT_NAME);
    StatusCode statusCode = statusCodeBuilder.buildObject();
    statusCode.setValue(StatusCode.SUCCESS_URI);

    SAMLObjectBuilder<Status> statusBuilder = (SAMLObjectBuilder<Status>) builderFactory
            .getBuilder(Status.DEFAULT_ELEMENT_NAME);
    Status responseStatus = statusBuilder.buildObject();
    responseStatus.setStatusCode(statusCode);

    SAMLObjectBuilder<Response> responseBuilder = (SAMLObjectBuilder<Response>) builderFactory
            .getBuilder(Response.DEFAULT_ELEMENT_NAME);
    Response samlMessage = responseBuilder.buildObject();
    samlMessage.setID("foo");
    samlMessage.setVersion(SAMLVersion.VERSION_20);
    samlMessage.setIssueInstant(new DateTime(0));
    samlMessage.setStatus(responseStatus);

    SAMLObjectBuilder<Endpoint> endpointBuilder = (SAMLObjectBuilder<Endpoint>) builderFactory
            .getBuilder(AssertionConsumerService.DEFAULT_ELEMENT_NAME);
    Endpoint samlEndpoint = endpointBuilder.buildObject();
    samlEndpoint.setLocation("http://example.org");
    samlEndpoint.setResponseLocation("http://example.org/response");

    MockHttpServletResponse response = new MockHttpServletResponse();
    HttpServletResponseAdapter outTransport = new HttpServletResponseAdapter(response, false);
    
    BasicSAMLMessageContext messageContext = new BasicSAMLMessageContext();
    messageContext.setOutboundMessageTransport(outTransport);
    messageContext.setOutboundSAMLMessage(samlMessage);
    messageContext.setPeerEntityEndpoint(samlEndpoint);
    messageContext.setRelayState("relay");
    
    HTTPRedirectDeflateEncoder encoder = new HTTPRedirectDeflateEncoder();
    encoder.encode(messageContext);

    assertEquals("Unexpected character encoding", response.getCharacterEncoding(), "UTF-8");
    assertEquals("Unexpected cache controls", "no-cache, no-store", response.getHeader("Cache-control"));
    assertEquals(406515062, response.getRedirectedUrl().hashCode());
}
 
开发者ID:apigee,项目名称:java-opensaml2,代码行数:48,代码来源:HTTPRedirectDeflateEncoderTest.java

示例9: testResponseEncodingWithSimpleSign

import org.opensaml.common.binding.BasicSAMLMessageContext; //导入方法依赖的package包/类
/**
 * Tests encoding a SAML message to an servlet response with simple sign.
 * 
 * @throws Exception
 */
@SuppressWarnings("unchecked")
public void testResponseEncodingWithSimpleSign() throws Exception {
    SAMLObjectBuilder<StatusCode> statusCodeBuilder = (SAMLObjectBuilder<StatusCode>) builderFactory
            .getBuilder(StatusCode.DEFAULT_ELEMENT_NAME);
    StatusCode statusCode = statusCodeBuilder.buildObject();
    statusCode.setValue(StatusCode.SUCCESS_URI);

    SAMLObjectBuilder<Status> statusBuilder = (SAMLObjectBuilder<Status>) builderFactory
            .getBuilder(Status.DEFAULT_ELEMENT_NAME);
    Status responseStatus = statusBuilder.buildObject();
    responseStatus.setStatusCode(statusCode);

    SAMLObjectBuilder<Response> responseBuilder = (SAMLObjectBuilder<Response>) builderFactory
            .getBuilder(Response.DEFAULT_ELEMENT_NAME);
    Response samlMessage = responseBuilder.buildObject();
    samlMessage.setID("foo");
    samlMessage.setVersion(SAMLVersion.VERSION_20);
    samlMessage.setIssueInstant(new DateTime(0));
    samlMessage.setStatus(responseStatus);

    SAMLObjectBuilder<Endpoint> endpointBuilder = (SAMLObjectBuilder<Endpoint>) builderFactory
            .getBuilder(AssertionConsumerService.DEFAULT_ELEMENT_NAME);
    Endpoint samlEndpoint = endpointBuilder.buildObject();
    samlEndpoint.setLocation("http://example.org");
    samlEndpoint.setResponseLocation("http://example.org/response");

    MockHttpServletResponse response = new MockHttpServletResponse();
    HttpServletResponseAdapter outTransport = new HttpServletResponseAdapter(response, false);
    
    BasicSAMLMessageContext messageContext = new BasicSAMLMessageContext();
    messageContext.setOutboundMessageTransport(outTransport);
    messageContext.setOutboundSAMLMessage(samlMessage);
    messageContext.setPeerEntityEndpoint(samlEndpoint);
    messageContext.setRelayState("relay");
    
    KeyPair kp = SecurityTestHelper.generateKeyPair("RSA", 1024, null);
    messageContext.setOutboundSAMLMessageSigningCredential(
            SecurityHelper.getSimpleCredential(kp.getPublic(), kp.getPrivate()));
    
    HTTPRedirectDeflateEncoder encoder = new HTTPRedirectDeflateEncoder();
    encoder.encode(messageContext);
    
    String queryString = new URL(response.getRedirectedUrl()).getQuery();
    
    assertNotNull("Signature parameter was not found", 
            HTTPTransportUtils.getRawQueryStringParameter(queryString, "Signature"));
    assertNotNull("SigAlg parameter was not found", 
            HTTPTransportUtils.getRawQueryStringParameter(queryString, "SigAlg"));
    
    // Note: to test that actual signature is cryptographically correct, really need a known good test vector.
    // Need to verify that we're signing over the right data in the right byte[] encoded form.
}
 
开发者ID:apigee,项目名称:java-opensaml2,代码行数:58,代码来源:HTTPRedirectDeflateEncoderTest.java

示例10: testResponseEncoding

import org.opensaml.common.binding.BasicSAMLMessageContext; //导入方法依赖的package包/类
/**
 * Tests encoding a SAML message to an servlet response.
 * 
 * @throws Exception
 */
@SuppressWarnings("unchecked")
public void testResponseEncoding() throws Exception {
    SAMLObjectBuilder<StatusCode> statusCodeBuilder = (SAMLObjectBuilder<StatusCode>) builderFactory
            .getBuilder(StatusCode.DEFAULT_ELEMENT_NAME);
    StatusCode statusCode = statusCodeBuilder.buildObject();
    statusCode.setValue(StatusCode.SUCCESS_URI);

    SAMLObjectBuilder<Status> statusBuilder = (SAMLObjectBuilder<Status>) builderFactory
            .getBuilder(Status.DEFAULT_ELEMENT_NAME);
    Status responseStatus = statusBuilder.buildObject();
    responseStatus.setStatusCode(statusCode);

    SAMLObjectBuilder<Response> responseBuilder = (SAMLObjectBuilder<Response>) builderFactory
            .getBuilder(Response.DEFAULT_ELEMENT_NAME);
    Response samlMessage = responseBuilder.buildObject();
    samlMessage.setID("foo");
    samlMessage.setVersion(SAMLVersion.VERSION_20);
    samlMessage.setIssueInstant(new DateTime(0));
    samlMessage.setStatus(responseStatus);

    SAMLObjectBuilder<Endpoint> endpointBuilder = (SAMLObjectBuilder<Endpoint>) builderFactory
            .getBuilder(AssertionConsumerService.DEFAULT_ELEMENT_NAME);
    Endpoint samlEndpoint = endpointBuilder.buildObject();
    samlEndpoint.setLocation("http://example.org");
    samlEndpoint.setResponseLocation("http://example.org/response");

    MockHttpServletResponse response = new MockHttpServletResponse();
    HttpServletResponseAdapter outTransport = new HttpServletResponseAdapter(response, false);
    
    BasicSAMLMessageContext messageContext = new BasicSAMLMessageContext();
    messageContext.setOutboundMessageTransport(outTransport);
    messageContext.setPeerEntityEndpoint(samlEndpoint);
    messageContext.setOutboundSAMLMessage(samlMessage);
    messageContext.setRelayState("relay");
    
    HTTPSOAP11Encoder encoder = new HTTPSOAP11Encoder();
    encoder.encode(messageContext);

    assertEquals("Unexpected content type", "text/xml", response.getContentType());
    assertEquals("Unexpected character encoding", response.getCharacterEncoding(), "UTF-8");
    assertEquals("Unexpected cache controls", "no-cache, no-store", response.getHeader("Cache-control"));
    assertEquals("http://www.oasis-open.org/committees/security", response.getHeader("SOAPAction"));
    assertEquals(1568886506, response.getContentAsString().hashCode());
}
 
开发者ID:apigee,项目名称:java-opensaml2,代码行数:50,代码来源:HTTPSOAP11EncoderTest.java

示例11: testResponseEncoding

import org.opensaml.common.binding.BasicSAMLMessageContext; //导入方法依赖的package包/类
/**
 * Tests encoding a SAML message to an servlet response.
 * 
 * @throws Exception
 */
@SuppressWarnings("unchecked")
public void testResponseEncoding() throws Exception {
    SAMLObjectBuilder<StatusCode> statusCodeBuilder = (SAMLObjectBuilder<StatusCode>) builderFactory
            .getBuilder(StatusCode.DEFAULT_ELEMENT_NAME);
    StatusCode statusCode = statusCodeBuilder.buildObject();
    statusCode.setValue(StatusCode.SUCCESS_URI);

    SAMLObjectBuilder<Status> statusBuilder = (SAMLObjectBuilder<Status>) builderFactory
            .getBuilder(Status.DEFAULT_ELEMENT_NAME);
    Status responseStatus = statusBuilder.buildObject();
    responseStatus.setStatusCode(statusCode);

    SAMLObjectBuilder<Response> responseBuilder = (SAMLObjectBuilder<Response>) builderFactory
            .getBuilder(Response.DEFAULT_ELEMENT_NAME);
    Response samlMessage = responseBuilder.buildObject();
    samlMessage.setID("foo");
    samlMessage.setVersion(SAMLVersion.VERSION_20);
    samlMessage.setIssueInstant(new DateTime(0));
    samlMessage.setStatus(responseStatus);

    SAMLObjectBuilder<Endpoint> endpointBuilder = (SAMLObjectBuilder<Endpoint>) builderFactory
            .getBuilder(AssertionConsumerService.DEFAULT_ELEMENT_NAME);
    Endpoint samlEndpoint = endpointBuilder.buildObject();
    samlEndpoint.setLocation("http://example.org");
    samlEndpoint.setResponseLocation("http://example.org/response");

    MockHttpServletResponse response = new MockHttpServletResponse();
    HttpServletResponseAdapter outTransport = new HttpServletResponseAdapter(response, false);
    
    BasicSAMLMessageContext messageContext = new BasicSAMLMessageContext();
    messageContext.setOutboundMessageTransport(outTransport);
    messageContext.setPeerEntityEndpoint(samlEndpoint);
    messageContext.setOutboundSAMLMessage(samlMessage);
    messageContext.setRelayState("relay");

    HTTPPostSimpleSignEncoder encoder = new HTTPPostSimpleSignEncoder(velocityEngine,
    "/templates/saml2-post-simplesign-binding.vm");
    encoder.encode(messageContext);

    assertEquals("Unexpected content type", "text/html", response.getContentType());
    assertEquals("Unexpected character encoding", response.getCharacterEncoding(), "UTF-8");
    assertEquals("Unexpected cache controls", "no-cache, no-store", response.getHeader("Cache-control"));
    assertEquals(-1652577171, response.getContentAsString().hashCode());
}
 
开发者ID:apigee,项目名称:java-opensaml2,代码行数:50,代码来源:HTTPPostSimpleSignEncoderTest.java

示例12: testRequestEncodingWithSimpleSign

import org.opensaml.common.binding.BasicSAMLMessageContext; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void testRequestEncodingWithSimpleSign() throws Exception {
    SAMLObjectBuilder<AuthnRequest> responseBuilder = (SAMLObjectBuilder<AuthnRequest>) builderFactory
            .getBuilder(AuthnRequest.DEFAULT_ELEMENT_NAME);
    AuthnRequest samlMessage = responseBuilder.buildObject();
    samlMessage.setID("foo");
    samlMessage.setVersion(SAMLVersion.VERSION_20);
    samlMessage.setIssueInstant(new DateTime(0));

    SAMLObjectBuilder<Endpoint> endpointBuilder = (SAMLObjectBuilder<Endpoint>) builderFactory
            .getBuilder(AssertionConsumerService.DEFAULT_ELEMENT_NAME);
    Endpoint samlEndpoint = endpointBuilder.buildObject();
    samlEndpoint.setLocation("http://example.org");
    samlEndpoint.setResponseLocation("http://example.org/response");

    MockHttpServletResponse response = new MockHttpServletResponse();
    HttpServletResponseAdapter outTransport = new HttpServletResponseAdapter(response, false);
    
    BasicSAMLMessageContext messageContext = new BasicSAMLMessageContext();
    messageContext.setOutboundMessageTransport(outTransport);
    messageContext.setPeerEntityEndpoint(samlEndpoint);
    messageContext.setOutboundSAMLMessage(samlMessage);
    messageContext.setRelayState("relay");
    
    KeyPair kp = SecurityTestHelper.generateKeyPair("RSA", 1024, null);
    messageContext.setOutboundSAMLMessageSigningCredential(
            SecurityHelper.getSimpleCredential(kp.getPublic(), kp.getPrivate()));

    HTTPPostSimpleSignEncoder encoder = new HTTPPostSimpleSignEncoder(velocityEngine,
    "/templates/saml2-post-simplesign-binding.vm");
    encoder.encode(messageContext);
    
    // Not elegant, but works ok for basic sanity check.
    String form = response.getContentAsString();
    int start;
    
    start = form.indexOf("name=\"Signature\"");
    assertTrue("Signature parameter not found in form control data", start != -1);
    
    start = form.indexOf("name=\"SigAlg\"");
    assertTrue("SigAlg parameter not found in form control data", start != -1);
    
    start = form.indexOf("name=\"KeyInfo\"");
    assertTrue("KeyInfo parameter not found in form control data", start != -1);
    
    // Note: to test that actual signature is cryptographically correct, really need a known good test vector.
    // Need to verify that we're signing over the right data in the right byte[] encoded form.
}
 
开发者ID:apigee,项目名称:java-opensaml2,代码行数:49,代码来源:HTTPPostSimpleSignEncoderTest.java


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