Example usage for javax.xml.ws BindingProvider getRequestContext

List of usage examples for javax.xml.ws BindingProvider getRequestContext

Introduction

In this page you can find the example usage for javax.xml.ws BindingProvider getRequestContext.

Prototype

Map<String, Object> getRequestContext();

Source Link

Document

Get the context that is used to initialize the message context for request messages.

Usage

From source file:be.agiv.security.client.RSTSClient.java

/**
 * Main constructor.//from w ww.j  ava 2 s  . co m
 * 
 * @param location
 *            the location of the R-STS WS-Trust web service.
 */
public RSTSClient(String location) {
    this.location = location;
    SecurityTokenService_Service service = SecurityTokenServiceFactory.getInstance();
    this.port = service.getSecurityTokenServicePort();
    BindingProvider bindingProvider = (BindingProvider) this.port;
    bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, location);

    Binding binding = bindingProvider.getBinding();
    List<Handler> handlerChain = binding.getHandlerChain();
    this.wsTrustHandler = new WSTrustHandler();
    handlerChain.add(this.wsTrustHandler);
    this.wsAddressingHandler = new WSAddressingHandler();
    handlerChain.add(this.wsAddressingHandler);
    this.wsSecurityHandler = new WSSecurityHandler();
    handlerChain.add(this.wsSecurityHandler);
    handlerChain.add(new LoggingHandler());
    binding.setHandlerChain(handlerChain);

    this.objectFactory = new ObjectFactory();
    this.policyObjectFactory = new be.agiv.security.jaxb.wspolicy.ObjectFactory();
    this.addrObjectFactory = new be.agiv.security.jaxb.wsaddr.ObjectFactory();

}

From source file:be.e_contract.mycarenet.ehbox.EHealthBoxConsultationClient.java

@SuppressWarnings("unchecked")
private void configureBindingProvider(BindingProvider bindingProvider, String location) {
    bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, location);

    Binding binding = bindingProvider.getBinding();
    @SuppressWarnings("rawtypes")
    List handlerChain = binding.getHandlerChain();
    handlerChain.add(this.wsSecuritySOAPHandler);
    handlerChain.add(this.inboundAttachmentsSOAPHandler);
    // handlerChain.add(new LoggingHandler());
    // LoggingHandler makes CXF fail on the attachments.
    // https://issues.apache.org/jira/browse/CXF-5496
    binding.setHandlerChain(handlerChain);
}

From source file:be.agiv.security.client.SecureConversationClient.java

/**
 * Main constructor. The given location is the same as where the actual
 * business web service is running./*  www. j a  v a2  s.c om*/
 * 
 * @param location
 *            the location of the WS-SecureConversation enabled web service.
 */
public SecureConversationClient(String location) {
    this.location = location;
    SecurityTokenService_Service service = SecurityTokenServiceFactory.getInstance();
    this.port = service.getSecurityTokenServicePort();
    BindingProvider bindingProvider = (BindingProvider) this.port;
    bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, location);

    Binding binding = bindingProvider.getBinding();
    List<Handler> handlerChain = binding.getHandlerChain();
    this.wsTrustHandler = new WSTrustHandler();
    handlerChain.add(this.wsTrustHandler);
    this.wsAddressingHandler = new WSAddressingHandler();
    handlerChain.add(this.wsAddressingHandler);
    this.wsSecurityHandler = new WSSecurityHandler();
    handlerChain.add(this.wsSecurityHandler);
    handlerChain.add(new LoggingHandler());
    binding.setHandlerChain(handlerChain);

    this.objectFactory = new ObjectFactory();
    this.wssObjectFactory = new be.agiv.security.jaxb.wsse.ObjectFactory();

    this.secureRandom = new SecureRandom();
    this.secureRandom.setSeed(System.currentTimeMillis());
}

From source file:be.fedict.hsm.client.HSMProxyClient.java

/**
 * Main constructor. To access the HSM Proxy web service, you need to have a
 * valid credential.//from w w w . java 2  s.  c o m
 * 
 * @param endpointAddress
 *            the HSM Proxy web service endpoint address.
 * @param credentialPrivateKey
 *            the credential private key.
 * @param credentialCertificate
 *            the corresponding credential X509 certificate.
 */
public HSMProxyClient(String endpointAddress, PrivateKey credentialPrivateKey,
        X509Certificate credentialCertificate) {
    this.endpointAddress = endpointAddress;

    DigitalSignatureService digitalSignatureService = DigitalSignatureServiceFactory.getInstance();
    this.dssPort = digitalSignatureService.getDigitalSignatureServicePort();

    BindingProvider bindingProvider = (BindingProvider) this.dssPort;
    bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointAddress);

    this.dssObjectFactory = new ObjectFactory();
    this.dsObjectFactory = new be.fedict.hsm.ws.jaxb.xmldsig.ObjectFactory();
    this.hsmObjectFactory = new be.fedict.hsm.ws.jaxb.hsm.ObjectFactory();

    try {
        this.certificateFactory = CertificateFactory.getInstance("X.509");
    } catch (CertificateException e) {
        throw new RuntimeException("X509 certificate factory error: " + e.getMessage(), e);
    }

    Binding binding = bindingProvider.getBinding();
    List<Handler> handlerChain = binding.getHandlerChain();
    handlerChain.add(new WSSecuritySOAPHandler(credentialPrivateKey, credentialCertificate));
    binding.setHandlerChain(handlerChain);
}

From source file:org.apache.cxf.systest.http_jetty.JettyDigestAuthTest.java

private void doTest(boolean async) throws Exception {
    setupClient(async);//  www  . ja va  2 s.  c  om
    assertEquals("Hello Alice", greeter.greetMe("Alice"));
    assertEquals("Hello Bob", greeter.greetMe("Bob"));

    try {
        BindingProvider bp = (BindingProvider) greeter;
        if (async) {
            UsernamePasswordCredentials creds = new UsernamePasswordCredentials("blah", "foo");
            bp.getRequestContext().put(Credentials.class.getName(), creds);
        } else {
            bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "blah");
            bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "foo");
        }
        greeter.greetMe("Alice");
        fail("Password was wrong, should have failed");
    } catch (WebServiceException wse) {
        //ignore - expected
    }
}

From source file:be.e_contract.mycarenet.xkms2.XKMS2Client.java

/**
 * Main constructor.//from ww  w.  j ava 2  s.  c o  m
 * 
 * @param location
 *            the URL of the MyCareNet XKMS 2.0 web service.
 */
public XKMS2Client(String location) {
    XMLKeyManagementService service = XKMS2ServiceFactory.newInstance();
    this.keyServicePort = service.getKeyServiceSoapPort();
    BindingProvider bindingProvider = (BindingProvider) this.keyServicePort;
    bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, location);

    Binding binding = bindingProvider.getBinding();
    @SuppressWarnings("rawtypes")
    List<Handler> handlerChain = binding.getHandlerChain();
    this.proofOfPossessionSignatureSOAPHandler = new ProofOfPossessionSignatureSOAPHandler();
    handlerChain.add(new LoggingHandler());
    handlerChain.add(this.proofOfPossessionSignatureSOAPHandler);
    this.keyBindingAuthenticationSignatureSOAPHandler = new KeyBindingAuthenticationSignatureSOAPHandler();
    handlerChain.add(this.keyBindingAuthenticationSignatureSOAPHandler);
    handlerChain.add(new LoggingHandler());
    binding.setHandlerChain(handlerChain);

    this.objectFactory = new ObjectFactory();
    this.xmldsigObjectFactory = new be.e_contract.mycarenet.jaxb.xmldsig.ObjectFactory();
    try {
        this.datatypeFactory = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException e) {
        throw new RuntimeException("DatatypeFactory error: " + e.getMessage(), e);
    }

}

From source file:at.gv.egiz.pdfas.moa.MOAConnector.java

public byte[] sign(byte[] input, int[] byteRange, SignParameter parameter,
        RequestedSignature requestedSignature) throws PdfAsException {

    logger.info("signing with MOA @ " + this.moaEndpoint);
    /*//from ww  w  . j  a v  a  2 s .  co m
     * URL moaUrl; try { moaUrl = new URL(this.moaEndpoint+"?wsdl"); } catch
     * (MalformedURLException e1) { throw new
     * PdfAsException("Invalid MOA endpoint!", e1); }
     */
    SignatureCreationService service = new SignatureCreationService();

    SignatureCreationPortType creationPort = service.getSignatureCreationPort();
    BindingProvider provider = (BindingProvider) creationPort;
    provider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, this.moaEndpoint);

    CreateCMSSignatureRequest request = new CreateCMSSignatureRequest();
    request.setKeyIdentifier(this.keyIdentifier.trim());
    SingleSignatureInfo sigInfo = new SingleSignatureInfo();
    sigInfo.setSecurityLayerConformity(Boolean.TRUE);
    DataObjectInfo dataObjectInfo = new DataObjectInfo();
    dataObjectInfo.setStructure("detached");
    DataObject dataObject = new DataObject();
    MetaInfoType metaInfoType = new MetaInfoType();

    if (parameter.getConfiguration().hasValue(IConfigurationConstants.SIG_PADES_FORCE_FLAG)) {
        if (IConfigurationConstants.TRUE.equalsIgnoreCase(
                parameter.getConfiguration().getValue(IConfigurationConstants.SIG_PADES_FORCE_FLAG))) {
            metaInfoType.setMimeType("application/pdf");
            sigInfo.setPAdESConformity(true);
        } else {
            metaInfoType.setMimeType("application/pdf");
        }
    } else {
        metaInfoType.setMimeType("application/pdf");
    }
    dataObject.setMetaInfo(metaInfoType);

    CMSContentBaseType content = new CMSContentBaseType();
    content.setBase64Content(input);

    dataObject.setContent(content);

    dataObjectInfo.setDataObject(dataObject);
    sigInfo.setDataObjectInfo(dataObjectInfo);
    request.getSingleSignatureInfo().add(sigInfo);

    requestedSignature.getStatus().getMetaInformations().put(ErrorConstants.STATUS_INFO_SIGDEVICE,
            SIGNATURE_DEVICE);
    // TODO: Find a way to get MOA-SPSS Version
    requestedSignature.getStatus().getMetaInformations().put(ErrorConstants.STATUS_INFO_SIGDEVICEVERSION,
            "UNKNOWN");

    CreateCMSSignatureResponseType response;
    try {
        response = creationPort.createCMSSignature(request);
    } catch (MOAFault e) {
        logger.warn("MOA signing failed!", e);
        if (e.getFaultInfo() != null) {
            throw new PdfAsMOAException(e.getFaultInfo().getErrorCode().toString(), e.getFaultInfo().getInfo(),
                    "", "");
        } else {
            throw new PdfAsMOAException("", e.getMessage(), "", "");
        }
    }

    if (response.getCMSSignatureOrErrorResponse().size() != 1) {
        throw new PdfAsException(
                "Invalid Response Count [" + response.getCMSSignatureOrErrorResponse().size() + "] from MOA!");
    }

    Object resp = response.getCMSSignatureOrErrorResponse().get(0);
    if (resp instanceof byte[]) {
        // done the signature!
        byte[] cmsSignatureData = (byte[]) resp;

        VerifyResult verifyResult;
        try {
            verifyResult = SignatureUtils.verifySignature(cmsSignatureData, input);
            if (SettingsUtils.getBooleanValue(requestedSignature.getStatus().getSettings(),
                    IConfigurationConstants.KEEP_INVALID_SIGNATURE, false)) {
                Base64 b64 = new Base64();
                requestedSignature.getStatus().getMetaInformations().put(ErrorConstants.STATUS_INFO_INVALIDSIG,
                        b64.encodeToString(cmsSignatureData));
            }
        } catch (PDFASError e) {
            throw new PdfAsErrorCarrier(e);
        }

        if (!StreamUtils.dataCompare(requestedSignature.getCertificate().getFingerprintSHA(),
                ((X509Certificate) verifyResult.getSignerCertificate()).getFingerprintSHA())) {
            throw new PdfAsSignatureException("Certificates missmatch!");
        }

        return cmsSignatureData;
    } else if (resp instanceof ErrorResponseType) {
        ErrorResponseType err = (ErrorResponseType) resp;

        throw new PdfAsMOAException("", "", err.getInfo(), err.getErrorCode().toString());

    } else {
        throw new PdfAsException("MOA response is not byte[] nor error but: " + resp.getClass().getName());
    }
}

From source file:be.fedict.eid.idp.sp.protocol.saml2.artifact.ArtifactServiceClient.java

private void setEndpointAddress(String sslHostname) {

    LOG.debug("ws location: " + location);
    if (null == location) {
        throw new IllegalArgumentException("SAML Artifact " + "Service location URL cannot be null");
    }/* w w  w .j ava2 s .  c o m*/

    BindingProvider bindingProvider = (BindingProvider) this.port;
    bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, location);
    bindingProvider.getRequestContext().put(JAXWSProperties.HOSTNAME_VERIFIER,
            new CustomHostnameVerifier(sslHostname));

}

From source file:com.clustercontrol.util.EndpointUnit.java

private void setBindingProvider(Object o, String url) {
    BindingProvider bp = (BindingProvider) o;
    bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
    bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, userId);
    bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
    bp.getRequestContext().put(JAXWSProperties.HTTP_CLIENT_STREAMING_CHUNK_SIZE, 8192);

    // Maximum time between establishing a connection and receiving data from the connection (ms)
    int httpRequestTimeout = EndpointManager.getHttpRequestTimeout();
    bp.getRequestContext().put(BindingProviderProperties.REQUEST_TIMEOUT, httpRequestTimeout);
    if (m_log.isTraceEnabled()) {
        m_log.trace("ws timeout updated : requestTimeout = " + httpRequestTimeout + "");
    }/* ww w . j a v  a 2  s . c o m*/

    ((SOAPBinding) bp.getBinding()).setMTOMEnabled(true);
}

From source file:org.apache.cxf.systest.http_jetty.JettyDigestAuthTest.java

private HTTPConduit setupClient(boolean async) throws Exception {
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    greeter = new SOAPService(wsdl, SERVICE_NAME).getPort(Greeter.class);
    BindingProvider bp = (BindingProvider) greeter;
    ClientProxy.getClient(greeter).getInInterceptors().add(new LoggingInInterceptor());
    ClientProxy.getClient(greeter).getOutInterceptors().add(new LoggingOutInterceptor());
    bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, ADDRESS);
    HTTPConduit cond = (HTTPConduit) ClientProxy.getClient(greeter).getConduit();
    HTTPClientPolicy client = new HTTPClientPolicy();
    cond.setClient(client);/*from   w w  w .  ja v  a2s .c  o m*/
    if (async) {
        if (cond instanceof AsyncHTTPConduit) {
            UsernamePasswordCredentials creds = new UsernamePasswordCredentials("ffang", "pswd");
            bp.getRequestContext().put(Credentials.class.getName(), creds);
            bp.getRequestContext().put(AsyncHTTPConduit.USE_ASYNC, Boolean.TRUE);
            client.setAutoRedirect(true);
        } else {
            fail("Not an async conduit");
        }
    } else {
        bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "ffang");
        bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "pswd");
        cond.setAuthSupplier(new DigestAuthSupplier());
    }

    ClientProxy.getClient(greeter).getOutInterceptors()
            .add(new AbstractPhaseInterceptor<Message>(Phase.PRE_STREAM_ENDING) {

                public void handleMessage(Message message) throws Fault {
                    Map<String, ?> headers = CastUtils.cast((Map<?, ?>) message.get(Message.PROTOCOL_HEADERS));
                    if (headers.containsKey("Proxy-Authorization")) {
                        throw new RuntimeException("Should not have Proxy-Authorization");
                    }
                }
            });
    client.setAllowChunking(false);
    return cond;
}