• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Response类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.opensaml.saml1.core.Response的典型用法代码示例。如果您正苦于以下问题:Java Response类的具体用法?Java Response怎么用?Java Response使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Response类属于org.opensaml.saml1.core包,在下文中一共展示了Response类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: prepareResponse

import org.opensaml.saml1.core.Response; //导入依赖的package包/类
@Override
protected void prepareResponse(final Response response, final Map<String, Object> model) {
    final Authentication authentication = getAssertionFrom(model).getPrimaryAuthentication();
    final DateTime issuedAt = response.getIssueInstant();
    final Service service = getAssertionFrom(model).getService();

    final Object o = authentication.getAttributes().get(RememberMeCredential.AUTHENTICATION_ATTRIBUTE_REMEMBER_ME);
    final boolean isRemembered = o == Boolean.TRUE && !getAssertionFrom(model).isFromNewLogin();

    // Build up the SAML assertion containing AuthenticationStatement and AttributeStatement
    final Assertion assertion = newSamlObject(Assertion.class);
    assertion.setID(generateId());
    assertion.setIssueInstant(issuedAt);
    assertion.setIssuer(this.issuer);
    assertion.setConditions(newConditions(issuedAt, service.getId()));
    final AuthenticationStatement authnStatement = newAuthenticationStatement(authentication);
    assertion.getAuthenticationStatements().add(authnStatement);
    final Map<String, Object> attributes = authentication.getPrincipal().getAttributes();
    if (!attributes.isEmpty() || isRemembered) {
        assertion.getAttributeStatements().add(
                newAttributeStatement(newSubject(authentication.getPrincipal().getId()), attributes, isRemembered));
    }
    response.setStatus(newStatus(StatusCode.SUCCESS, null));
    response.getAssertions().add(assertion);
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:26,代码来源:Saml10SuccessResponseView.java


示例2: buildArtifact

import org.opensaml.saml1.core.Response; //导入依赖的package包/类
/** {@inheritDoc} */
public SAML1ArtifactType0001 buildArtifact(
        SAMLMessageContext<RequestAbstractType, Response, NameIdentifier> requestContext, Assertion assertion) {
    try {
        MessageDigest sha1Digester = MessageDigest.getInstance("SHA-1");
        byte[] source = sha1Digester.digest(requestContext.getLocalEntityId().getBytes());

        SecureRandom handleGenerator = SecureRandom.getInstance("SHA1PRNG");
        byte[] assertionHandle = new byte[20];
        handleGenerator.nextBytes(assertionHandle);

        return new SAML1ArtifactType0001(source, assertionHandle);
    } catch (NoSuchAlgorithmException e) {
        log.error("JVM does not support required cryptography algorithms.", e);
        throw new InternalError("JVM does not support required cryptography algorithms: SHA-1 and/or SHA1PRNG.");
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:SAML1ArtifactType0001Builder.java


示例3: buildArtifact

import org.opensaml.saml1.core.Response; //导入依赖的package包/类
/** {@inheritDoc} */
public SAML1ArtifactType0002 buildArtifact(
        SAMLMessageContext<RequestAbstractType, Response, NameIdentifier> requestContext, Assertion assertion) {
    try {
        String sourceLocation = getSourceLocation(requestContext);
        if (sourceLocation == null) {
            return null;
        }

        SecureRandom handleGenerator = SecureRandom.getInstance("SHA1PRNG");
        byte[] assertionHandle = new byte[20];
        handleGenerator.nextBytes(assertionHandle);
        return new SAML1ArtifactType0002(assertionHandle, sourceLocation);
    } catch (NoSuchAlgorithmException e) {
        log.error("JVM does not support required cryptography algorithms: SHA1PRNG.", e);
        throw new InternalError("JVM does not support required cryptography algorithms: SHA1PRNG.");
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:SAML1ArtifactType0002Builder.java


示例4: getSourceLocation

import org.opensaml.saml1.core.Response; //导入依赖的package包/类
/**
 * Gets the source location used to for the artifacts created by this encoder.
 * 
 * @param requestContext current request context
 * 
 * @return source location used to for the artifacts created by this encoder
 */
protected String getSourceLocation(SAMLMessageContext<RequestAbstractType, Response, NameIdentifier> requestContext) {
    BasicEndpointSelector selector = new BasicEndpointSelector();
    selector.setEndpointType(ArtifactResolutionService.DEFAULT_ELEMENT_NAME);
    selector.getSupportedIssuerBindings().add(SAMLConstants.SAML1_SOAP11_BINDING_URI);
    selector.setMetadataProvider(requestContext.getMetadataProvider());
    selector.setEntityMetadata(requestContext.getLocalEntityMetadata());
    selector.setEntityRoleMetadata(requestContext.getLocalEntityRoleMetadata());

    Endpoint acsEndpoint = selector.selectEndpoint();

    if (acsEndpoint == null) {
        log.error("Unable to select source location for artifact.  No artifact resolution service defined for issuer.");
        return null;
    }

    return acsEndpoint.getLocation();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:SAML1ArtifactType0002Builder.java


示例5: populateMessageIdIssueInstantIssuer

import org.opensaml.saml1.core.Response; //导入依赖的package包/类
/**
 * Extracts the message ID, issue instant, and issuer from the incoming SAML message and populates the message
 * context with it.
 * 
 * @param messageContext current message context
 * 
 * @throws MessageDecodingException thrown if there is a problem populating the message context
 */
protected void populateMessageIdIssueInstantIssuer(SAMLMessageContext messageContext)
        throws MessageDecodingException {
    SAMLObject samlMsg = messageContext.getInboundSAMLMessage();
    if (samlMsg == null) {
        return;
    }

    if (samlMsg instanceof RequestAbstractType) {
        log.debug("Extracting ID, issuer and issue instant from request");
        extractRequestInfo(messageContext, (RequestAbstractType) samlMsg);
    } else if (samlMsg instanceof Response) {
        log.debug("Extracting ID, issuer and issue instant from response");
        extractResponseInfo(messageContext, (Response) samlMsg);
    } else {
        throw new MessageDecodingException("SAML 1.x message was not a request or a response");
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:BaseSAML1MessageDecoder.java


示例6: prepareResponse

import org.opensaml.saml1.core.Response; //导入依赖的package包/类
@Override
protected void prepareResponse(final Response response, final Map<String, Object> model) {
    final Authentication authentication = getAssertionFrom(model).getChainedAuthentications().get(0);
    final DateTime issuedAt = response.getIssueInstant();
    final Service service = getAssertionFrom(model).getService();

    final Object o = authentication.getAttributes().get(RememberMeCredential.AUTHENTICATION_ATTRIBUTE_REMEMBER_ME);
    final boolean isRemembered = o == Boolean.TRUE && !getAssertionFrom(model).isFromNewLogin();

    // Build up the SAML assertion containing AuthenticationStatement and AttributeStatement
    final Assertion assertion = newSamlObject(Assertion.class);
    assertion.setID(generateId());
    assertion.setIssueInstant(issuedAt);
    assertion.setIssuer(this.issuer);
    assertion.setConditions(newConditions(issuedAt, service.getId()));
    final AuthenticationStatement authnStatement = newAuthenticationStatement(authentication);
    assertion.getAuthenticationStatements().add(authnStatement);
    final Map<String, Object> attributes = authentication.getPrincipal().getAttributes();
    if (!attributes.isEmpty() || isRemembered) {
        assertion.getAttributeStatements().add(
                newAttributeStatement(newSubject(authentication.getPrincipal().getId()), attributes, isRemembered));
    }
    response.setStatus(newStatus(StatusCode.SUCCESS, null));
    response.getAssertions().add(assertion);
}
 
开发者ID:kevin3061,项目名称:cas-4.0.1,代码行数:26,代码来源:Saml10SuccessResponseView.java


示例7: ResponseTest

import org.opensaml.saml1.core.Response; //导入依赖的package包/类
/**
 * Constructor
 */
public ResponseTest() {
    expectedID = "ident";
    singleElementFile = "/data/org/opensaml/saml1/impl/singleResponse.xml";
    singleElementOptionalAttributesFile = "/data/org/opensaml/saml1/impl/singleResponseAttributes.xml";
    childElementsFile = "/data/org/opensaml/saml1/impl/ResponseWithChildren.xml";
    //
    // IssueInstant="1970-01-01T00:00:00.100Z"
    //
    expectedIssueInstant = new DateTime(1970, 1, 1, 0, 0, 0, 100, ISOChronology.getInstanceUTC());

    expectedInResponseTo="inresponseto";
    expectedMinorVersion=1;
    expectedRecipient="recipient";
    
    qname = Response.DEFAULT_ELEMENT_NAME;
}
 
开发者ID:apigee,项目名称:java-opensaml2,代码行数:20,代码来源:ResponseTest.java


示例8: testSingleElementUnmarshall

import org.opensaml.saml1.core.Response; //导入依赖的package包/类
/** {@inheritDoc} */
public void testSingleElementUnmarshall() {

    Response response = (Response) unmarshallElement(singleElementFile);

    String id = response.getID();
    assertNull("ID attribute has value " + id + "expected no value", id);
   
    assertNull("IssueInstant attribute has a value of " + response.getIssueInstant() 
            + ", expected no value", response.getIssueInstant());

    assertEquals("Assertion elements count", 0, response.getAssertions().size());

    Status status;
    status = response.getStatus();
    assertNull("Status element has a value of " + status + ", expected no value", status);
}
 
开发者ID:apigee,项目名称:java-opensaml2,代码行数:18,代码来源:ResponseTest.java


示例9: renderMergedOutputModel

import org.opensaml.saml1.core.Response; //导入依赖的package包/类
@Override
protected void renderMergedOutputModel(
        final Map<String, Object> model, final HttpServletRequest request, final HttpServletResponse response) throws Exception {

    response.setCharacterEncoding(this.encoding);

    final WebApplicationService service = this.samlArgumentExtractor.extractService(request);
    final String serviceId = service != null ? service.getId() : "UNKNOWN";

    try {
        final Response samlResponse = newSamlObject(Response.class);
        samlResponse.setID(generateId());
        samlResponse.setIssueInstant(new DateTime());
        samlResponse.setVersion(SAMLVersion.VERSION_11);
        samlResponse.setRecipient(serviceId);
        if (service instanceof SamlService) {
            final SamlService samlService = (SamlService) service;

            if (samlService.getRequestID() != null) {
                samlResponse.setInResponseTo(samlService.getRequestID());
            }
        }
        prepareResponse(samlResponse, model);

        final BasicSAMLMessageContext messageContext = new BasicSAMLMessageContext();
        messageContext.setOutboundMessageTransport(new HttpServletResponseAdapter(response, request.isSecure()));
        messageContext.setOutboundSAMLMessage(samlResponse);
        this.encoder.encode(messageContext);
    } catch (final Exception e) {
        logger.error("Error generating SAML response for service {}.", serviceId);
        throw e;
    }
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:34,代码来源:AbstractSaml10ResponseView.java


示例10: extractResponseInfo

import org.opensaml.saml1.core.Response; //导入依赖的package包/类
/**
 * Extract information from a SAML StatusResponse message.
 * 
 * @param messageContext current message context
 * @param response the SAML message to process
 * 
 * @throws MessageDecodingException thrown if the assertions within the response contain differening issuer IDs
 */
protected void extractResponseInfo(SAMLMessageContext messageContext, Response response)
        throws MessageDecodingException {

    messageContext.setInboundSAMLMessageId(response.getID());
    messageContext.setInboundSAMLMessageIssueInstant(response.getIssueInstant());

    String issuer = null;
    List<Assertion> assertions = ((Response) response).getAssertions();
    if (assertions != null && assertions.size() > 0) {
        log.info("Attempting to extract issuer from enclosed SAML 1.x Assertion(s)");
        for (Assertion assertion : assertions) {
            if (assertion != null && assertion.getIssuer() != null) {
                if (issuer != null && !issuer.equals(assertion.getIssuer())) {
                    throw new MessageDecodingException("SAML 1.x assertions, within response " + response.getID()
                            + " contain different issuer IDs");
                }
                issuer = assertion.getIssuer();
            }
        }
    }

    if (issuer == null) {
        log.warn("Issuer could not be extracted from standard SAML 1.x response message");
    }

    messageContext.setInboundMessageIssuer(issuer);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:36,代码来源:BaseSAML1MessageDecoder.java


示例11: processChildElement

import org.opensaml.saml1.core.Response; //导入依赖的package包/类
/** {@inheritDoc} */
protected void processChildElement(XMLObject parentSAMLObject, XMLObject childSAMLObject)
        throws UnmarshallingException {

    Response response = (Response) parentSAMLObject;

    if (childSAMLObject instanceof Assertion) {
        response.getAssertions().add((Assertion) childSAMLObject);
    } else if (childSAMLObject instanceof Status) {
        response.setStatus((Status) childSAMLObject);
    } else {
        super.processChildElement(parentSAMLObject, childSAMLObject);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:ResponseUnmarshaller.java


示例12: testEncoding

import org.opensaml.saml1.core.Response; //导入依赖的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


示例13: populateRequiredData

import org.opensaml.saml1.core.Response; //导入依赖的package包/类
/** {@inheritDoc} */
protected void populateRequiredData() {
    super.populateRequiredData();
    
    Response response = (Response) target;
    QName qname = new QName(SAMLConstants.SAML10P_NS, Status.DEFAULT_ELEMENT_LOCAL_NAME, SAMLConstants.SAML1P_PREFIX);
    response.setStatus((Status)buildXMLObject(qname));
}
 
开发者ID:apigee,项目名称:java-opensaml2,代码行数:9,代码来源:ResponseSchemaTest.java


示例14: testChildElementsUnmarshall

import org.opensaml.saml1.core.Response; //导入依赖的package包/类
/** {@inheritDoc} */
public void testChildElementsUnmarshall() {
    Response response = (Response) unmarshallElement(childElementsFile);

    assertEquals("No Assertion elements count", 1, response.getAssertions().size());

    Status status;
    status = response.getStatus();
    assertNotNull("No Status element found", status);
}
 
开发者ID:apigee,项目名称:java-opensaml2,代码行数:11,代码来源:ResponseTest.java


示例15: testSingleElementOptionalAttributesMarshall

import org.opensaml.saml1.core.Response; //导入依赖的package包/类
/** {@inheritDoc} */
public void testSingleElementOptionalAttributesMarshall() {
    Response response = (Response) buildXMLObject(qname);

    response.setID(expectedID);
    response.setInResponseTo(expectedInResponseTo);
    response.setIssueInstant(expectedIssueInstant);
    response.setRecipient(expectedRecipient);

    assertEquals(expectedOptionalAttributesDOM, response);
}
 
开发者ID:apigee,项目名称:java-opensaml2,代码行数:12,代码来源:ResponseTest.java


示例16: testSignatureUnmarshall

import org.opensaml.saml1.core.Response; //导入依赖的package包/类
public void testSignatureUnmarshall() {
    Response response = (Response) unmarshallElement("/data/org/opensaml/saml1/impl/ResponseWithSignature.xml");
    
    assertNotNull("Response was null", response);
    assertNotNull("Signature was null", response.getSignature());
    assertNotNull("KeyInfo was null", response.getSignature().getKeyInfo());
}
 
开发者ID:apigee,项目名称:java-opensaml2,代码行数:8,代码来源:ResponseTest.java


示例17: testDOMIDResolutionUnmarshall

import org.opensaml.saml1.core.Response; //导入依赖的package包/类
public void testDOMIDResolutionUnmarshall() {
    Response response = (Response) unmarshallElement("/data/org/opensaml/saml1/impl/ResponseWithSignature.xml");
    
    assertNotNull("Response was null", response);
    assertNotNull("Signature was null", response.getSignature());
    Document document = response.getSignature().getDOM().getOwnerDocument();
    Element idElem = response.getDOM();
    
    assertNotNull("DOM ID resolution returned null", document.getElementById(expectedID));
    assertTrue("DOM elements were not equal", idElem.isSameNode(document.getElementById(expectedID)));
}
 
开发者ID:apigee,项目名称:java-opensaml2,代码行数:12,代码来源:ResponseTest.java


示例18: testDOMIDResolutionMarshall

import org.opensaml.saml1.core.Response; //导入依赖的package包/类
public void testDOMIDResolutionMarshall() throws MarshallingException {
    Response response = (Response) buildXMLObject(Response.DEFAULT_ELEMENT_NAME);
    response.setID(expectedID);
    response.setStatus((Status) buildXMLObject(Status.DEFAULT_ELEMENT_NAME));
    
    marshallerFactory.getMarshaller(response).marshall(response);
    
    Document document = response.getStatus().getDOM().getOwnerDocument();
    Element idElem = response.getDOM();
    
    assertNotNull("DOM ID resolution returned null", document.getElementById(expectedID));
    assertTrue("DOM elements were not equal", idElem.isSameNode(document.getElementById(expectedID)));
}
 
开发者ID:apigee,项目名称:java-opensaml2,代码行数:14,代码来源:ResponseTest.java


示例19: prepareResponse

import org.opensaml.saml1.core.Response; //导入依赖的package包/类
@Override
protected void prepareResponse(final Response response, final Map<String, Object> model) {
    response.setStatus(newStatus(StatusCode.REQUEST_DENIED, (String) model.get("description")));
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:5,代码来源:Saml10FailureResponseView.java


示例20: doEncode

import org.opensaml.saml1.core.Response; //导入依赖的package包/类
/** {@inheritDoc} */
protected void doEncode(MessageContext messageContext) throws MessageEncodingException {
    if (!(messageContext instanceof SAMLMessageContext)) {
        log.error("Invalid message context type, this encoder only support SAMLMessageContext");
        throw new MessageEncodingException(
                "Invalid message context type, this encoder only support SAMLMessageContext");
    }

    if (!(messageContext.getOutboundMessageTransport() instanceof HTTPOutTransport)) {
        log.error("Invalid outbound message transport type, this encoder only support HTTPOutTransport");
        throw new MessageEncodingException(
                "Invalid outbound message transport type, this encoder only support HTTPOutTransport");
    }

    SAMLMessageContext<SAMLObject, Response, NameIdentifier> artifactContext = (SAMLMessageContext) messageContext;
    HTTPOutTransport outTransport = (HTTPOutTransport) artifactContext.getOutboundMessageTransport();

    URLBuilder urlBuilder = getEndpointURL(artifactContext);

    List<Pair<String, String>> params = urlBuilder.getQueryParams();

    params.add(new Pair<String, String>("TARGET", artifactContext.getRelayState()));

    SAML1ArtifactBuilder artifactBuilder;
    if (artifactContext.getOutboundMessageArtifactType() != null) {
        artifactBuilder = Configuration.getSAML1ArtifactBuilderFactory().getArtifactBuilder(
                artifactContext.getOutboundMessageArtifactType());
    } else {
        artifactBuilder = Configuration.getSAML1ArtifactBuilderFactory().getArtifactBuilder(defaultArtifactType);
        artifactContext.setOutboundMessageArtifactType(defaultArtifactType);
    }

    AbstractSAML1Artifact artifact;
    String artifactString;
    for (Assertion assertion : artifactContext.getOutboundSAMLMessage().getAssertions()) {
        artifact = artifactBuilder.buildArtifact(artifactContext, assertion);
        if(artifact == null){
            log.error("Unable to build artifact for message to relying party");
            throw new MessageEncodingException("Unable to builder artifact for message to relying party");
        }

        try {
            artifactMap.put(artifact.base64Encode(), messageContext.getInboundMessageIssuer(), messageContext
                    .getOutboundMessageIssuer(), assertion);
        } catch (MarshallingException e) {
            log.error("Unable to marshall assertion to be represented as an artifact", e);
            throw new MessageEncodingException("Unable to marshall assertion to be represented as an artifact", e);
        }
        artifactString = artifact.base64Encode();
        params.add(new Pair<String, String>("SAMLart", artifactString));
    }

    String redirectUrl = urlBuilder.buildURL();

    log.debug("Sending redirect to URL {} to relying party {}", redirectUrl, artifactContext
            .getInboundMessageIssuer());
    outTransport.sendRedirect(urlBuilder.buildURL());
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:59,代码来源:HTTPArtifactEncoder.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ProjectManager类代码示例发布时间:2022-05-22
下一篇:
Java InitContext类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap