Example usage for javax.xml.ws BindingProvider getBinding

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

Introduction

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

Prototype

Binding getBinding();

Source Link

Document

Get the Binding for this binding provider.

Usage

From source file:be.agiv.security.AGIVSecurity.java

/**
 * Enable the AGIV security on the given JAX-WS binding provider. Each
 * JAX-WS port can be casted to a JAX-WS binding provider.
 * <p/>/*from  w w  w  .  j a  v a2s . c  om*/
 * It is no problem to call the enable method multiple times for a certain
 * JAX-WS stub. This method will only decorate the AGIV Security framework
 * once on the given JAX-WS stub. If the JAX-WS stub is already decorated by
 * another AGIVSecurity instance a {@link SecurityException} will be thrown.
 * 
 * @param bindingProvider
 *            the JAX-WS binding provider on which to enable the AGIV
 *            security framework.
 * @param useWsSecureConversation
 *            set to <code>true</code> if WS-SecureConversation should be
 *            used.
 * @param serviceRealm
 *            the optional service realm.
 * @see AGIVSecurity#enable(BindingProvider, String)
 * @see AGIVSecurity#enable(BindingProvider, String, boolean)
 * @see AGIVSecurity#disable(BindingProvider)
 */
public void enable(BindingProvider bindingProvider, boolean useWsSecureConversation, String serviceRealm) {
    Binding binding = bindingProvider.getBinding();
    List<Handler> handlerChain = binding.getHandlerChain();
    for (Handler handler : handlerChain) {
        if (handler instanceof SecureConversationHandler || handler instanceof AuthenticationHandler) {
            LOG.warn("security already enabled");
            SecurityTokenConsumer securityTokenConsumer = (SecurityTokenConsumer) handler;
            if (this != securityTokenConsumer.getSecurityTokenProvider()) {
                throw new SecurityException(
                        "security on JAX-WS stub already enabled by another AGIVSecurity instance");
            }
            return;
        }
    }
    WSSecurityHandler wsSecurityHandler = new WSSecurityHandler();
    if (useWsSecureConversation) {
        handlerChain.add(new SecureConversationHandler(this, wsSecurityHandler, serviceRealm));
    } else {
        handlerChain.add(new AuthenticationHandler(this, wsSecurityHandler, serviceRealm));
    }
    handlerChain.add(wsSecurityHandler);
    handlerChain.add(new LoggingHandler());
    binding.setHandlerChain(handlerChain);
}

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 ww  w  .j  a  va2s .c om*/
 * 
 * @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: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 + "");
    }/*from   ww  w . j  a v a  2s .c  o  m*/

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

From source file:org.apache.juddi.xlt.util.JUDDIServiceProvider.java

private void registerService(BindingProvider bindingProvider) {
    Binding binding = bindingProvider.getBinding();
    List<Handler> handlerChain = binding.getHandlerChain();

    handlerChain.add(new LoggingHandler());

    // set the handler chain again for the changes to take effect
    binding.setHandlerChain(handlerChain);
}

From source file:org.jboss.additional.testsuite.jdkall.present.web.mtom.MtomTestCase.java

@Test
public void mtomTest() throws Exception {
    URL url = new URL("http://localhost:8080/war-mtom?wsdl");
    QName qname = new QName("http://mtom.web.present.jdkall.testsuite.additional.jboss.org/",
            "ImageServerImplService");

    String path = this.getClass().getClassLoader().getResource("").getPath();

    FileInputStream inputStream = new FileInputStream(path + "../" + serverLogPath);
    try {/*from  w  w  w. ja va2s.c  om*/
        String everything = IOUtils.toString(inputStream);
        assertFalse("Testing archive has enabled mtom feature", everything.contains("mtomEnabled=true"));
    } finally {
        inputStream.close();
    }

    Service service = Service.create(url, qname);
    ImageServer imageServer = service.getPort(ImageServer.class);

    //enable MTOM in client
    BindingProvider bp = (BindingProvider) imageServer;
    SOAPBinding binding = (SOAPBinding) bp.getBinding();
    binding.setMTOMEnabled(true);

    Image im = imageServer.downloadImage(path + "rss.png");

    if (im == null) {
        fail();
    }

}

From source file:org.jboss.test.integration.mtom.MtomTestCase.java

@Test
public void mtomTest() throws Exception {
    URL url = new URL("http://localhost:8080/war-mtom?wsdl");
    QName qname = new QName("http://mtom.integration.test.jboss.org/", "ImageServerImplService");

    String path = this.getClass().getClassLoader().getResource("").getPath();

    FileInputStream inputStream = new FileInputStream(path + serverLogPath);
    try {//from  w ww.j  a v a2 s  .  co m
        String everything = IOUtils.toString(inputStream);
        assertFalse("Testing archive has enabled mtom feature", everything.contains("mtomEnabled=true"));
    } finally {
        inputStream.close();
    }

    Service service = Service.create(url, qname);
    ImageServer imageServer = service.getPort(ImageServer.class);

    //enable MTOM in client
    BindingProvider bp = (BindingProvider) imageServer;
    SOAPBinding binding = (SOAPBinding) bp.getBinding();
    binding.setMTOMEnabled(true);

    Image im = imageServer.downloadImage(path + "rss.png");

    if (im == null) {
        fail();
    }

}

From source file:org.openehealth.ipf.commons.ihe.ws.JaxWsClientFactory.java

/**
 * Configures SOAP binding of the given SOAP port.
 *///  w  w  w .j a  v  a  2  s . co  m
private void configureBinding(Object port) {
    BindingProvider bindingProvider = (BindingProvider) port;

    Map<String, Object> reqContext = bindingProvider.getRequestContext();
    reqContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, serviceUrl);

    Binding binding = bindingProvider.getBinding();
    SOAPBinding soapBinding = (SOAPBinding) binding;
    soapBinding.setMTOMEnabled(wsTransactionConfiguration.isMtom());
}

From source file:test.integ.be.agiv.security.ClaimsAwareServiceTest.java

@Test
public void testSecurity() {
    Service service = new Service();
    IService iservice = service.getWS2007FederationHttpBindingIService();

    BindingProvider bindingProvider = (BindingProvider) iservice;
    bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
            ClaimsAwareServiceFactory.SERVICE_LOCATION);

    IPSTSClient ipStsClient = new IPSTSClient(
            "https://auth.beta.agiv.be/ipsts/Services/DaliSecurityTokenServiceConfiguration.svc/IWSTrust13",
            AGIVSecurity.BETA_REALM);/*from  www  . j ava 2s  . co  m*/
    SecurityToken ipStsSecurityToken = ipStsClient.getSecurityToken(this.config.getUsername(),
            this.config.getPassword());

    RSTSClient rStsClient = new RSTSClient(
            "https://auth.beta.agiv.be/sts/Services/SalvadorSecurityTokenServiceConfiguration.svc/IWSTrust13");
    SecurityToken rStsSecurityToken = rStsClient.getSecurityToken(ipStsSecurityToken,
            ClaimsAwareServiceFactory.SERVICE_REALM);

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

    wsAddressingHandler.setAddressing("http://www.agiv.be/IService/GetData",
            ClaimsAwareServiceFactory.SERVICE_LOCATION);
    wsSecurityHandler.setKey(rStsSecurityToken.getKey(), rStsSecurityToken.getAttachedReference(),
            rStsSecurityToken.getToken(), true);

    ArrayOfClaimInfo result = iservice.getData(0);

    List<ClaimInfo> claims = result.getClaimInfo();
    boolean myName = false;
    for (ClaimInfo claim : claims) {
        LOG.debug(claim.getName() + " = " + claim.getValue());
        if (this.config.getUsername().equals(claim.getValue())) {
            myName = true;
        }
    }
    assertTrue(myName);
}

From source file:test.integ.be.agiv.security.ClaimsAwareServiceTest.java

@Test
public void testSecuritySecondaryParameters() throws Exception {
    Service service = new Service();
    IService iservice = service.getWS2007FederationHttpBindingIService();

    BindingProvider bindingProvider = (BindingProvider) iservice;
    bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
            ClaimsAwareServiceFactory.SERVICE_LOCATION);

    InputStream wsdlInputStream = CrabReadTest.class.getResourceAsStream("/ClaimsAwareService.wsdl");
    assertNotNull(wsdlInputStream);/*from   www.j a  v  a  2  s.com*/

    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    documentBuilderFactory.setNamespaceAware(true);
    DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
    Document wsdlDocument = documentBuilder.parse(wsdlInputStream);

    NodeList requestSecurityTokenTemplateNodeList = wsdlDocument
            .getElementsByTagNameNS(WSConstants.WS_SECURITY_POLICY_NAMESPACE, "RequestSecurityTokenTemplate");
    assertEquals(1, requestSecurityTokenTemplateNodeList.getLength());
    Element requestSecurityTokenTemplateElement = (Element) requestSecurityTokenTemplateNodeList.item(0);
    NodeList secondaryParametersNodeList = requestSecurityTokenTemplateElement.getChildNodes();

    IPSTSClient ipStsClient = new IPSTSClient(
            "https://auth.beta.agiv.be/ipsts/Services/DaliSecurityTokenServiceConfiguration.svc/IWSTrust13",
            AGIVSecurity.BETA_REALM, secondaryParametersNodeList);
    SecurityToken ipStsSecurityToken = ipStsClient.getSecurityToken(this.config.getUsername(),
            this.config.getPassword());

    RSTSClient rStsClient = new RSTSClient(
            "https://auth.beta.agiv.be/sts/Services/SalvadorSecurityTokenServiceConfiguration.svc/IWSTrust13");
    SecurityToken rStsSecurityToken = rStsClient.getSecurityToken(ipStsSecurityToken,
            ClaimsAwareServiceFactory.SERVICE_REALM);

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

    wsAddressingHandler.setAddressing("http://www.agiv.be/IService/GetData",
            ClaimsAwareServiceFactory.SERVICE_LOCATION);
    wsSecurityHandler.setKey(rStsSecurityToken.getKey(), rStsSecurityToken.getAttachedReference(),
            rStsSecurityToken.getToken(), true);

    ArrayOfClaimInfo result = iservice.getData(0);

    List<ClaimInfo> claims = result.getClaimInfo();
    boolean myName = false;
    for (ClaimInfo claim : claims) {
        LOG.debug(claim.getName() + " = " + claim.getValue());
        if (this.config.getUsername().equals(claim.getValue())) {
            myName = true;
        }
    }
    assertTrue(myName);
}

From source file:test.integ.be.agiv.security.CrabReadTest.java

@Test
public void testIPSTS() throws Exception {
    InputStream wsdlInputStream = CrabReadTest.class.getResourceAsStream("/CrabReadService.wsdl");
    assertNotNull(wsdlInputStream);/*from   w  ww.  ja  va2 s  . c o m*/

    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    documentBuilderFactory.setNamespaceAware(true);
    DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
    Document wsdlDocument = documentBuilder.parse(wsdlInputStream);

    NodeList requestSecurityTokenTemplateNodeList = wsdlDocument
            .getElementsByTagNameNS(WSConstants.WS_SECURITY_POLICY_NAMESPACE, "RequestSecurityTokenTemplate");
    assertEquals(1, requestSecurityTokenTemplateNodeList.getLength());
    Element requestSecurityTokenTemplateElement = (Element) requestSecurityTokenTemplateNodeList.item(0);
    LOG.debug("RequestSecurityTokenTemplate: " + toString(requestSecurityTokenTemplateElement));
    NodeList secondaryParametersNodeList = requestSecurityTokenTemplateElement.getChildNodes();

    IPSTSClient ipstsClient = new IPSTSClient(
            "https://auth.beta.agiv.be/ipsts/Services/DaliSecurityTokenServiceConfiguration.svc/CertificateMessage",
            AGIVSecurity.BETA_REALM);
    //
    // urn:agiv.be/crab/beta

    SecurityToken ipStsSecurityToken = ipstsClient.getSecuritytoken(this.config.getCertificate(),
            this.config.getPrivateKey());

    RSTSClient rstsClient = new RSTSClient(
            "https://auth.beta.agiv.be/sts/Services/SalvadorSecurityTokenServiceConfiguration.svc/IWSTrust13");
    SecurityToken rStsSecurityToken = rstsClient.getSecurityToken(ipStsSecurityToken, "urn:agiv.be/crab/beta");

    LOG.debug("R-STS token received");

    SecureConversationClient secureConversationClient = new SecureConversationClient(
            "http://crab.beta.agiv.be/Read/CrabReadService.svc/wsfedsc");
    SecurityToken secureConversationToken = secureConversationClient
            .getSecureConversationToken(rStsSecurityToken);

    CrabReadService crabReadService = new CrabReadService();
    ICrabRead iCrabRead = crabReadService.getWS2007FederationHttpBindingICrabRead(new AddressingFeature());

    BindingProvider bindingProvider = (BindingProvider) iCrabRead;
    bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
            "http://crab.beta.agiv.be/Read/CrabReadService.svc/wsfedsc");

    Binding binding = bindingProvider.getBinding();
    List<Handler> handlerChain = binding.getHandlerChain();

    WSSecurityHandler wsSecurityHandler = new WSSecurityHandler();
    SecureConversationTokenTestProvider secureConversationTokenProvider = new SecureConversationTokenTestProvider(
            secureConversationToken);
    handlerChain.add(new SecureConversationHandler(secureConversationTokenProvider, wsSecurityHandler,
            "urn:agiv.be/crab/beta"));
    handlerChain.add(wsSecurityHandler);

    iCrabRead.findStraat("Vilvoorde", "Blaesenbergstraat");
}