Repository: camel Updated Branches: refs/heads/master a45fa8998 -> 40ed7b8ae
More updates to support CXF 3.0.0 Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/40ed7b8a Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/40ed7b8a Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/40ed7b8a Branch: refs/heads/master Commit: 40ed7b8aed6e3a237ade0325cc056081d6166e71 Parents: a45fa89 Author: Daniel Kulp <dk...@apache.org> Authored: Mon Mar 10 15:27:57 2014 -0400 Committer: Daniel Kulp <dk...@apache.org> Committed: Mon Mar 10 15:28:38 2014 -0400 ---------------------------------------------------------------------- .../pom.xml | 5 -- parent/pom.xml | 7 --- .../camel/itest/security/GreeterClientTest.java | 4 +- .../security/KeystorePasswordCallback.java | 55 ++++++++++++-------- .../itest/security/MyAuthenticationAdapter.java | 21 ++++++-- 5 files changed, 52 insertions(+), 40 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/40ed7b8a/examples/camel-example-reportincident-wssecurity/pom.xml ---------------------------------------------------------------------- diff --git a/examples/camel-example-reportincident-wssecurity/pom.xml b/examples/camel-example-reportincident-wssecurity/pom.xml index b05b51c..1363ec1 100644 --- a/examples/camel-example-reportincident-wssecurity/pom.xml +++ b/examples/camel-example-reportincident-wssecurity/pom.xml @@ -87,11 +87,6 @@ <!-- cxf --> <dependency> <groupId>org.apache.cxf</groupId> - <artifactId>cxf-rt-core</artifactId> - <version>${cxf-version}</version> - </dependency> - <dependency> - <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-frontend-jaxws</artifactId> <version>${cxf-version}</version> </dependency> http://git-wip-us.apache.org/repos/asf/camel/blob/40ed7b8a/parent/pom.xml ---------------------------------------------------------------------- diff --git a/parent/pom.xml b/parent/pom.xml index 6bc7768..38c858d 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -1849,13 +1849,6 @@ <version>${saxon-version}</version> </dependency> - <!-- optional CXF support --> - <dependency> - <groupId>org.apache.cxf</groupId> - <artifactId>cxf-rt-core</artifactId> - <version>${cxf-version}</version> - </dependency> - <!-- unit testing frameworks --> <dependency> <groupId>junit</groupId> http://git-wip-us.apache.org/repos/asf/camel/blob/40ed7b8a/tests/camel-itest/src/test/java/org/apache/camel/itest/security/GreeterClientTest.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/security/GreeterClientTest.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/security/GreeterClientTest.java index 6229c98..283e354 100644 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/security/GreeterClientTest.java +++ b/tests/camel-itest/src/test/java/org/apache/camel/itest/security/GreeterClientTest.java @@ -28,8 +28,6 @@ import org.apache.cxf.endpoint.Client; import org.apache.cxf.frontend.ClientProxy; import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor; import org.apache.hello_world_soap_http.Greeter; -import org.apache.ws.security.WSConstants; -import org.apache.ws.security.message.token.UsernameToken; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; @@ -72,7 +70,7 @@ public class GreeterClientTest extends AbstractJUnit4SpringContextTests { props.put("user", username); // Set the the password type to be plain text, // so we can keep using the password to authenticate with spring security - props.put(UsernameToken.PASSWORD_TYPE, WSConstants.PW_TEXT); + props.put("passwordType", "PasswordText"); WSS4JOutInterceptor wss4jOut = new WSS4JOutInterceptor(props); client.getOutInterceptors().add(wss4jOut); http://git-wip-us.apache.org/repos/asf/camel/blob/40ed7b8a/tests/camel-itest/src/test/java/org/apache/camel/itest/security/KeystorePasswordCallback.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/security/KeystorePasswordCallback.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/security/KeystorePasswordCallback.java index e577291..cfd6a98 100644 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/security/KeystorePasswordCallback.java +++ b/tests/camel-itest/src/test/java/org/apache/camel/itest/security/KeystorePasswordCallback.java @@ -25,10 +25,6 @@ import javax.security.auth.callback.Callback; import javax.security.auth.callback.CallbackHandler; import javax.security.auth.callback.UnsupportedCallbackException; -import org.apache.ws.security.WSConstants; -import org.apache.ws.security.WSPasswordCallback; - - public class KeystorePasswordCallback implements CallbackHandler { private Map<String, String> passwords = @@ -46,30 +42,47 @@ public class KeystorePasswordCallback implements CallbackHandler { */ public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (Callback callback : callbacks) { - WSPasswordCallback pc = (WSPasswordCallback)callback; - String pass = passwords.get(pc.getIdentifier()); - String type = getPasswordType(pc); - if (WSConstants.PASSWORD_DIGEST.equals(type)) { + String pass = passwords.get(getIdentifier(callback)); + String type = getPasswordType(callback); + if (type.endsWith("#PasswordDigest")) { if (pass != null) { - pc.setPassword(pass); + setPassword(callback, pass); return; } } - if (WSConstants.PASSWORD_TEXT.equals(type)) { + if (type.endsWith("#PasswordText")) { // Code for CXF 2.4.X - if (pc.getPassword() == null) { - pc.setPassword(pass); + if (getPassword(callback) == null) { + setPassword(callback, pass); return; } - // Code for CXF 2.3.x - // As the PasswordType is not PasswordDigest, we need to do the authentication in the call back - if (!pass.equals(pc.getPassword())) { - throw new IOException("Wrong password!"); - } } } } + private void setPassword(Callback callback, String pass) { + try { + callback.getClass().getMethod("setPassword", String.class).invoke(callback, pass); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + private String getPassword(Callback callback) { + try { + return (String)callback.getClass().getMethod("getPassword").invoke(callback); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + private String getIdentifier(Callback cb) { + try { + return (String)cb.getClass().getMethod("getIdentifier").invoke(cb); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + /** * Add an alias/password pair to the callback mechanism. */ @@ -77,20 +90,20 @@ public class KeystorePasswordCallback implements CallbackHandler { passwords.put(alias, password); } - private String getPasswordType(WSPasswordCallback pc) { + private String getPasswordType(Callback pc) { try { Method getType = null; try { - getType = pc.getClass().getMethod("getPasswordType", new Class[0]); + getType = pc.getClass().getMethod("getPasswordType"); } catch (NoSuchMethodException ex) { // keep looking } catch (SecurityException ex) { // keep looking } if (getType == null) { - getType = pc.getClass().getMethod("getType", new Class[0]); + getType = pc.getClass().getMethod("getType"); } - String result = (String)getType.invoke(pc, new Object[0]); + String result = (String)getType.invoke(pc); return result; } catch (Exception ex) { http://git-wip-us.apache.org/repos/asf/camel/blob/40ed7b8a/tests/camel-itest/src/test/java/org/apache/camel/itest/security/MyAuthenticationAdapter.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/security/MyAuthenticationAdapter.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/security/MyAuthenticationAdapter.java index fea4c45..34375c0 100644 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/security/MyAuthenticationAdapter.java +++ b/tests/camel-itest/src/test/java/org/apache/camel/itest/security/MyAuthenticationAdapter.java @@ -17,10 +17,10 @@ package org.apache.camel.itest.security; import java.security.Principal; + import javax.security.auth.Subject; import org.apache.camel.component.spring.security.DefaultAuthenticationAdapter; -import org.apache.ws.security.WSUsernameTokenPrincipal; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; @@ -30,13 +30,26 @@ public class MyAuthenticationAdapter extends DefaultAuthenticationAdapter { protected Authentication convertToAuthentication(Subject subject) { Authentication answer = null; for (Principal principal : subject.getPrincipals()) { - if (principal instanceof WSUsernameTokenPrincipal) { - WSUsernameTokenPrincipal ut = (WSUsernameTokenPrincipal) principal; - answer = new UsernamePasswordAuthenticationToken(ut.getName(), ut.getPassword()); + if (principal.getClass().getName().contains("UsernameToken")) { + answer = new UsernamePasswordAuthenticationToken(getName(principal), getPassword(principal)); break; } } return answer; } + private String getName(Principal p) { + try { + return (String)p.getClass().getMethod("getName").invoke(p); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + private String getPassword(Principal p) { + try { + return (String)p.getClass().getMethod("getPassword").invoke(p); + } catch (Exception e) { + throw new RuntimeException(e); + } + } }