Example usage for javax.xml.ws Binding setHandlerChain

List of usage examples for javax.xml.ws Binding setHandlerChain

Introduction

In this page you can find the example usage for javax.xml.ws Binding setHandlerChain.

Prototype

public void setHandlerChain(java.util.List<javax.xml.ws.handler.Handler> chain);

Source Link

Document

Sets the handler chain for the protocol binding instance.

Usage

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

/**
 * Disable the AGIV Security framework on the given JAX-WS port.
 * <p/>//from  ww w . ja v a 2 s. c o  m
 * Can be used when the JAX-WS stubs are managed by some container and the
 * container strategy is to pool JAX-WS stub instances.
 * 
 * @param bindingProvider
 *            the JAX-WS port.
 * @see AGIVSecurity#enable(BindingProvider)
 * @see AGIVSecurity#enable(BindingProvider, String)
 */
public void disable(BindingProvider bindingProvider) {
    LOG.debug("disabling AGIV security...");
    Binding binding = bindingProvider.getBinding();
    List<Handler> handlerChain = binding.getHandlerChain();
    Iterator<Handler> handlerIterator = handlerChain.iterator();
    while (handlerIterator.hasNext()) {
        Handler handler = handlerIterator.next();
        if (handler instanceof AGIVSOAPHandler) {
            handlerIterator.remove();
            continue;
        }
    }
    binding.setHandlerChain(handlerChain);
}

From source file:be.e_contract.dssp.client.DigitalSignatureServiceClient.java

/**
 * Main constructor./*from  ww w. j a v  a  2s.  c  o  m*/
 * 
 * @param address
 *            the location of the DSSP web service.
 */
public DigitalSignatureServiceClient(String address) {
    DigitalSignatureService digitalSignatureService = DigitalSignatureServiceFactory.newInstance();
    this.dssPort = digitalSignatureService.getDigitalSignatureServicePort();

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

    Binding binding = bindingProvider.getBinding();
    List<Handler> handlerChain = binding.getHandlerChain();
    this.attachmentsSOAPHandler = new AttachmentsLogicalHandler();
    handlerChain.add(this.attachmentsSOAPHandler);
    this.wsSecuritySOAPHandler = new WSSecuritySOAPHandler();
    handlerChain.add(this.wsSecuritySOAPHandler);
    this.wsTrustSOAPHandler = new WSTrustSOAPHandler();
    handlerChain.add(this.wsTrustSOAPHandler);
    // cannot add LoggingSOAPHandler here, else we break SOAP with
    // attachments on Apache CXF
    binding.setHandlerChain(handlerChain);

    this.objectFactory = new ObjectFactory();
    this.wstObjectFactory = new be.e_contract.dssp.ws.jaxb.wst.ObjectFactory();
    this.dsObjectFactory = new be.e_contract.dssp.ws.jaxb.xmldsig.ObjectFactory();
    this.asyncObjectFactory = new be.e_contract.dssp.ws.jaxb.dss.async.ObjectFactory();
    this.wsseObjectFactory = new be.e_contract.dssp.ws.jaxb.wsse.ObjectFactory();
    this.vrObjectFactory = new be.e_contract.dssp.ws.jaxb.dss.vr.ObjectFactory();

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

    try {
        this.certificateFactory = CertificateFactory.getInstance("X.509");
    } catch (CertificateException e) {
        throw new RuntimeException(e);
    }
}

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/>/*  w ww. jav a  2  s . c o  m*/
 * 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: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: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  ww  w .ja  v a 2  s .  com
    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 w ww.  j a  va  2s .  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.GipodTest.java

@Test
public void testGipodManualSecurity() throws Exception {
    InputStream wsdlInputStream = CrabReadTest.class.getResourceAsStream("/GipodService.wsdl");
    assertNotNull(wsdlInputStream);/*from   w ww .  j a  v  a2  s.co 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);
    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, "urn:agiv.be/gipodbeta");
    // "https://wsgipod.beta.agiv.be/SOAP/GipodService.svc");

    WSSecurityHandler wsSecurityHandler = new WSSecurityHandler();
    TestSecurityTokenProvider securityTokenProvider = new TestSecurityTokenProvider();
    securityTokenProvider.addSecurityToken("https://wsgipod.beta.agiv.be/SOAP/GipodService.svc",
            rStsSecurityToken);
    AuthenticationHandler authenticationHandler = new AuthenticationHandler(securityTokenProvider,
            wsSecurityHandler, null);

    GipodService service = new GipodService();
    IGipodService iGipodService = service.getWS2007FederationHttpBindingIGipodService(new AddressingFeature());

    BindingProvider bindingProvider = (BindingProvider) iGipodService;
    bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
            "https://wsgipod.beta.agiv.be/SOAP/GipodService.svc");
    Binding binding = bindingProvider.getBinding();
    List<Handler> handlerChain = binding.getHandlerChain();
    handlerChain.add(authenticationHandler);
    handlerChain.add(wsSecurityHandler);
    binding.setHandlerChain(handlerChain);

    iGipodService.getListLand();
}