Example usage for javax.xml.ws.handler MessageContext get

List of usage examples for javax.xml.ws.handler MessageContext get

Introduction

In this page you can find the example usage for javax.xml.ws.handler MessageContext get.

Prototype

V get(Object key);

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:org.taverna.server.master.localworker.SecurityContextDelegateImpl.java

@Override
public void initializeSecurityFromSOAPContext(MessageContext context) {
    // does nothing
    @SuppressWarnings("unchecked")
    Map<String, List<String>> headers = (Map<String, List<String>>) context.get(HTTP_REQUEST_HEADERS);
    if (factory.supportHelioToken && headers.containsKey(HELIO_CIS_TOKEN))
        helioToken = headers.get(HELIO_CIS_TOKEN).get(0);
}

From source file:test.unit.be.e_contract.dssp.client.DigitalSignatureServiceTestPort.java

@Override
public SignResponse sign(SignRequest signRequest) {
    MessageContext messageContext = this.webServiceContext.getMessageContext();
    Map<String, DataHandler> attachments = (Map<String, DataHandler>) messageContext
            .get(MessageContext.INBOUND_MESSAGE_ATTACHMENTS);
    LOG.debug("attachments: " + attachments.keySet());
    if (attachments.size() != 0) {
        receivedAttachment = true;//ww  w.  j  a  v  a2  s.co m
    }

    SignResponse signResponse = this.objectFactory.createSignResponse();

    Result result = this.objectFactory.createResult();
    signResponse.setResult(result);
    result.setResultMajor(DigitalSignatureServiceConstants.PENDING_RESULT_MAJOR);

    AnyType optionalOutputs = this.objectFactory.createAnyType();
    signResponse.setOptionalOutputs(optionalOutputs);

    optionalOutputs.getAny().add(this.asyncObjectFactory.createResponseID("response identifier"));

    RequestSecurityTokenResponseCollectionType requestSecurityTokenResponseCollection = this.wstObjectFactory
            .createRequestSecurityTokenResponseCollectionType();
    optionalOutputs.getAny().add(this.wstObjectFactory
            .createRequestSecurityTokenResponseCollection(requestSecurityTokenResponseCollection));
    RequestSecurityTokenResponseType requestSecurityTokenResponse = this.wstObjectFactory
            .createRequestSecurityTokenResponseType();
    requestSecurityTokenResponseCollection.getRequestSecurityTokenResponse().add(requestSecurityTokenResponse);
    RequestedSecurityTokenType requestedSecurityToken = this.wstObjectFactory
            .createRequestedSecurityTokenType();
    requestSecurityTokenResponse.getAny()
            .add(this.wstObjectFactory.createRequestedSecurityToken(requestedSecurityToken));
    SecurityContextTokenType securityContextToken = this.wsscObjectFactory.createSecurityContextTokenType();
    requestedSecurityToken.setAny(this.wsscObjectFactory.createSecurityContextToken(securityContextToken));
    securityContextToken.setId("token-reference");
    securityContextToken.getAny().add(this.wsscObjectFactory.createIdentifier("token-identifier"));
    EntropyType entropy = this.wstObjectFactory.createEntropyType();
    requestSecurityTokenResponse.getAny().add(this.wstObjectFactory.createEntropy(entropy));
    BinarySecretType binarySecret = this.wstObjectFactory.createBinarySecretType();
    entropy.getAny().add(this.wstObjectFactory.createBinarySecret(binarySecret));
    byte[] nonce = new byte[256 / 8];
    SecureRandom secureRandom = new SecureRandom();
    secureRandom.nextBytes(nonce);
    binarySecret.setValue(nonce);

    return signResponse;
}

From source file:test.unit.be.e_contract.dssp.client.DigitalSignatureServiceTestPort.java

private String addAttachment(String mimetype, String contentId, byte[] data) {
    LOG.debug("adding attachment: " + contentId);
    DataSource dataSource = new ByteArrayDataSource(data, mimetype);
    DataHandler dataHandler = new DataHandler(dataSource);
    MessageContext messageContext = this.webServiceContext.getMessageContext();

    Map<String, DataHandler> outputMessageAttachments = (Map<String, DataHandler>) messageContext
            .get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
    outputMessageAttachments.put(contentId, dataHandler);
    messageContext.put(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS, outputMessageAttachments);

    return contentId;
}

From source file:test.unit.be.fedict.eid.idp.protocol.ws_federation.sts.SecurityTokenServicePortImplTest.java

@Test
public void testValidation() throws Exception {
    // setup/*w  w  w. j  av a2s .co m*/
    InputStream requestInputStream = SecurityTokenServicePortImplTest.class
            .getResourceAsStream("/sts-validation-request.xml");
    assertNotNull(requestInputStream);

    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    documentBuilderFactory.setNamespaceAware(true);
    DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
    Document document = documentBuilder.parse(requestInputStream);

    Element requestSecurityTokenElement = (Element) document
            .getElementsByTagNameNS("http://docs.oasis-open.org/ws-sx/ws-trust/200512", "RequestSecurityToken")
            .item(0);

    Element x509Certificate = (Element) document
            .getElementsByTagNameNS("http://www.w3.org/2000/09/xmldsig#", "X509Certificate").item(0);
    CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
    X509Certificate certificate = (X509Certificate) certificateFactory.generateCertificate(
            new ByteArrayInputStream(Base64.decodeBase64(x509Certificate.getFirstChild().getNodeValue())));
    List<X509Certificate> certificateChain = Collections.singletonList(certificate);

    JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class,
            be.fedict.eid.idp.wstrust.jaxb.wspolicy.ObjectFactory.class,
            be.fedict.eid.idp.wstrust.jaxb.wsaddr.ObjectFactory.class);
    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();

    JAXBElement<RequestSecurityTokenType> resultElement = (JAXBElement<RequestSecurityTokenType>) unmarshaller
            .unmarshal(requestSecurityTokenElement);
    RequestSecurityTokenType requestSecurityToken = resultElement.getValue();

    SecurityTokenServicePortImpl testedInstance = new SecurityTokenServicePortImpl();

    WebServiceContext mockWebServiceContext = EasyMock.createMock(WebServiceContext.class);
    injectResource(mockWebServiceContext, testedInstance);

    MessageContext mockMessageContext = EasyMock.createMock(MessageContext.class);

    EasyMock.expect(mockWebServiceContext.getMessageContext()).andStubReturn(mockMessageContext);

    ServletContext mockServletContext = EasyMock.createMock(ServletContext.class);

    EasyMock.expect(mockMessageContext.get(MessageContext.SERVLET_CONTEXT)).andReturn(mockServletContext);

    IdentityProviderConfiguration mockIdentityProviderConfiguration = EasyMock
            .createMock(IdentityProviderConfiguration.class);

    EasyMock.expect(mockServletContext.getAttribute(
            IdentityProviderConfigurationFactory.IDENTITY_PROVIDER_CONFIGURATION_CONTEXT_ATTRIBUTE))
            .andReturn(mockIdentityProviderConfiguration);

    EasyMock.expect(mockIdentityProviderConfiguration.getIdentityCertificateChain())
            .andReturn(certificateChain);

    EasyMock.expect(mockIdentityProviderConfiguration.getDefaultIssuer()).andReturn("e-contract-2012");

    Element samlElement = (Element) document
            .getElementsByTagNameNS(WSTrustConstants.SAML2_NAMESPACE, "Assertion").item(0);
    EasyMock.expect(mockMessageContext.get(WSSecuritySoapHandler.class.getName() + ".samlToken"))
            .andStubReturn(samlElement);

    // prepare
    EasyMock.replay(mockWebServiceContext, mockMessageContext, mockServletContext,
            mockIdentityProviderConfiguration);

    // operate
    RequestSecurityTokenResponseCollectionType result = testedInstance
            .requestSecurityToken(requestSecurityToken);

    // verify
    EasyMock.verify(mockWebServiceContext, mockMessageContext, mockServletContext,
            mockIdentityProviderConfiguration);
    assertNotNull(result);

    List<RequestSecurityTokenResponseType> resultList = result.getRequestSecurityTokenResponse();
    assertEquals(1, resultList.size());
    RequestSecurityTokenResponseType requestSecurityTokenResponse = resultList.get(0);
    List<Object> responseObjects = requestSecurityTokenResponse.getAny();
    boolean valid = false;
    String reason = null;
    for (Object responseObject : responseObjects) {
        LOG.debug("response object type: " + responseObject);
        if (responseObject instanceof JAXBElement) {
            JAXBElement jaxbElement = (JAXBElement) responseObject;
            QName qname = jaxbElement.getName();
            LOG.debug("qname: " + qname);
            if (new QName(WSTrustConstants.WS_TRUST_NAMESPACE, "Status").equals(qname)) {
                StatusType status = (StatusType) jaxbElement.getValue();
                String code = status.getCode();
                LOG.debug("status code: " + code);
                if (WSTrustConstants.VALID_STATUS_CODE.equals(code)) {
                    valid = true;
                }
                reason = status.getReason();
            }
        }
    }
    LOG.debug("status reason: " + reason);
    assertTrue(reason.indexOf("policy") != -1);
}