/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/wssecurity/server/CxfServer.java

https://github.com/jatin-28/camel · Java · 102 lines · 47 code · 24 blank · 31 comment · 2 complexity · 247fc05140d0eeb757818796bd0a837b MD5 · raw file

  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package org.apache.camel.component.cxf.wssecurity.server;
  18. import java.util.HashMap;
  19. import java.util.Map;
  20. import org.apache.cxf.endpoint.Server;
  21. import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
  22. import org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor;
  23. import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
  24. public class CxfServer {
  25. //private static final String WSU_NS
  26. // = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd";
  27. private String address;
  28. private Server server;
  29. public CxfServer(int port) throws Exception {
  30. Object implementor = new GreeterImpl();
  31. address = "http://localhost:" + port + "/WSSecurityRouteTest/GreeterPort";
  32. JaxWsServerFactoryBean bean = new JaxWsServerFactoryBean();
  33. bean.setAddress(address);
  34. bean.setServiceBean(implementor);
  35. bean.getInInterceptors().add(getWSS4JInInterceptor());
  36. bean.getOutInterceptors().add(getWSS4JOutInterceptor());
  37. server = bean.create();
  38. }
  39. public void stop() {
  40. if (server != null) {
  41. server.start();
  42. }
  43. }
  44. public static WSS4JOutInterceptor getWSS4JOutInterceptor() throws Exception {
  45. Map<String, Object> outProps = new HashMap<String, Object>();
  46. outProps.put("action", "Signature");
  47. //outProps.put("action", "UsernameToken Timestamp Signature Encrypt");
  48. outProps.put("passwordType", "PasswordText");
  49. outProps.put("user", "serverx509v1");
  50. outProps.put("passwordCallbackClass", "org.apache.camel.component.cxf.wssecurity.server.UTPasswordCallback");
  51. //If you are using the patch WSS-194, then uncomment below two lines and
  52. //comment the above "user" prop line.
  53. //outProps.put("user", "Alice");
  54. //outProps.put("signatureUser", "serverx509v1");
  55. //outProps.put("encryptionUser", "clientx509v1");
  56. //outProps.put("encryptionPropFile", "wssecurity/etc/Server_SignVerf.properties");
  57. //outProps.put("encryptionKeyIdentifier", "IssuerSerial");
  58. //outProps.put("encryptionParts", "{Element}{" + WSU_NS + "}Timestamp;"
  59. // + "{Content}{http://schemas.xmlsoap.org/soap/envelope/}Body");
  60. outProps.put("signaturePropFile", "wssecurity/etc/Server_Decrypt.properties");
  61. outProps.put("signatureKeyIdentifier", "DirectReference");
  62. outProps.put("signatureParts", //"{Element}{" + WSU_NS + "}Timestamp;"
  63. "{Element}{http://schemas.xmlsoap.org/soap/envelope/}Body");
  64. return new WSS4JOutInterceptor(outProps);
  65. }
  66. public static WSS4JInInterceptor getWSS4JInInterceptor() throws Exception {
  67. Map<String, Object> inProps = new HashMap<String, Object>();
  68. //inProps.put("action", "UsernameToken Timestamp Signature Encrypt");
  69. inProps.put("action", "Signature");
  70. inProps.put("passwordType", "PasswordDigest");
  71. inProps.put("passwordCallbackClass", "org.apache.camel.component.cxf.wssecurity.server.UTPasswordCallback");
  72. //inProps.put("decryptionPropFile", "wssecurity/etc/Server_Decrypt.properties");
  73. //inProps.put("encryptionKeyIdentifier", "IssuerSerial");
  74. inProps.put("signaturePropFile", "wssecurity/etc/Server_SignVerf.properties");
  75. inProps.put("signatureKeyIdentifier", "DirectReference");
  76. return new WSS4JInInterceptor(inProps);
  77. }
  78. }