List of usage examples for javax.xml.ws Binding getHandlerChain
public java.util.List<javax.xml.ws.handler.Handler> getHandlerChain();
From source file:be.fedict.eid.dss.client.DigitalSignatureServiceClient.java
/** * Registers the logging SOAP handler on the given JAX-WS port component. * /*w w w . ja v a 2s. c om*/ * @param logToFile * log to file or not */ protected void registerLoggerHandler(boolean logToFile) { BindingProvider bindingProvider = (BindingProvider) this.port; Binding binding = bindingProvider.getBinding(); List<Handler> handlerChain = binding.getHandlerChain(); handlerChain.add(new LoggingSoapHandler(logToFile)); binding.setHandlerChain(handlerChain); }
From source file:be.fedict.eid.dss.client.DigitalSignatureServiceClient.java
/** * Unregister possible logging SOAP handlers on the given JAX-WS port * component./*from www . jav a 2 s . c om*/ */ protected void removeLoggerHandler() { BindingProvider bindingProvider = (BindingProvider) this.port; Binding binding = bindingProvider.getBinding(); List<Handler> handlerChain = binding.getHandlerChain(); Iterator<Handler> iter = handlerChain.iterator(); while (iter.hasNext()) { Handler handler = iter.next(); if (handler instanceof LoggingSoapHandler) { iter.remove(); } } }
From source file:be.agiv.security.AGIVSecurity.java
/** * Disable the AGIV Security framework on the given JAX-WS port. * <p/>/*from w w w. j a 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.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/>//ww w . ja 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: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 w ww. j ava2 s. c om 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 w w . j a v a 2 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, 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 w w . j av a 2 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"); }
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 ww w. j a va 2s.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); 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(); }