Repository: camel Updated Branches: refs/heads/master 8ea12ce75 -> 69d450ece
Fixed the build error of camel-example-reportincident-wssecurity after upgrade CXF version to 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/69d450ec Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/69d450ec Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/69d450ec Branch: refs/heads/master Commit: 69d450ece75e487816879dbf5cb96e2d7f445d3b Parents: 8ea12ce Author: Willem Jiang <[email protected]> Authored: Tue May 20 23:27:20 2014 +0800 Committer: Willem Jiang <[email protected]> Committed: Tue May 20 23:27:20 2014 +0800 ---------------------------------------------------------------------- .../reportincident/UTPasswordCallback.java | 56 +++++++++++++++++--- 1 file changed, 50 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/69d450ec/examples/camel-example-reportincident-wssecurity/src/main/java/org/apache/camel/example/reportincident/UTPasswordCallback.java ---------------------------------------------------------------------- diff --git a/examples/camel-example-reportincident-wssecurity/src/main/java/org/apache/camel/example/reportincident/UTPasswordCallback.java b/examples/camel-example-reportincident-wssecurity/src/main/java/org/apache/camel/example/reportincident/UTPasswordCallback.java index bf4bbb4..9b9bbea 100644 --- a/examples/camel-example-reportincident-wssecurity/src/main/java/org/apache/camel/example/reportincident/UTPasswordCallback.java +++ b/examples/camel-example-reportincident-wssecurity/src/main/java/org/apache/camel/example/reportincident/UTPasswordCallback.java @@ -17,13 +17,14 @@ package org.apache.camel.example.reportincident; import java.io.IOException; +import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; + import javax.security.auth.callback.Callback; import javax.security.auth.callback.CallbackHandler; import javax.security.auth.callback.UnsupportedCallbackException; -import org.apache.ws.security.WSPasswordCallback; /** * Callback handler to handle passwords @@ -47,19 +48,41 @@ public class UTPasswordCallback implements CallbackHandler { String user = ""; for (Callback callback : callbacks) { - WSPasswordCallback pc = (WSPasswordCallback) callback; - user = pc.getIdentifier(); - - String pass = passwords.get(user); + String pass = passwords.get(getIdentifier(callback)); if (pass != null) { - pc.setPassword(pass); + setPassword(callback, pass); return; } + } // Password not found throw new IOException("Password does not exist for the user : " + user); } + + 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. @@ -67,4 +90,25 @@ public class UTPasswordCallback implements CallbackHandler { public void setAliasPassword(String alias, String password) { passwords.put(alias, password); } + + private String getPasswordType(Callback pc) { + try { + Method getType = null; + try { + getType = pc.getClass().getMethod("getPasswordType"); + } catch (NoSuchMethodException ex) { + // keep looking + } catch (SecurityException ex) { + // keep looking + } + if (getType == null) { + getType = pc.getClass().getMethod("getType"); + } + String result = (String)getType.invoke(pc); + return result; + + } catch (Exception ex) { + return null; + } + } }
