1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.extras.wssecurity.callbackhandlers; |
12 | |
|
13 | |
import org.mule.MuleException; |
14 | |
import org.mule.MuleManager; |
15 | |
import org.mule.config.i18n.CoreMessages; |
16 | |
import org.mule.umo.manager.ObjectNotFoundException; |
17 | |
|
18 | |
import java.io.IOException; |
19 | |
import java.util.Properties; |
20 | |
|
21 | |
import javax.security.auth.callback.Callback; |
22 | |
import javax.security.auth.callback.CallbackHandler; |
23 | |
import javax.security.auth.callback.UnsupportedCallbackException; |
24 | |
|
25 | |
import org.apache.ws.security.WSPasswordCallback; |
26 | |
|
27 | |
public class MuleWsSecurityCallbackHandler implements CallbackHandler |
28 | |
{ |
29 | |
private Properties passwords; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
public MuleWsSecurityCallbackHandler() throws MuleException |
38 | 0 | { |
39 | |
PasswordContainer pass; |
40 | |
try |
41 | |
{ |
42 | 0 | pass = (PasswordContainer)MuleManager.getInstance().getContainerContext().getComponent( |
43 | |
"passwords"); |
44 | 0 | passwords = pass.getPasswords(); |
45 | |
} |
46 | 0 | catch (ObjectNotFoundException e) |
47 | |
{ |
48 | 0 | throw new MuleException(CoreMessages.authNoCredentials(), e); |
49 | 0 | } |
50 | 0 | } |
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException |
57 | |
{ |
58 | 0 | for (int i = 0; i < callbacks.length; i++) |
59 | |
{ |
60 | 0 | WSPasswordCallback pc = (WSPasswordCallback)callbacks[i]; |
61 | |
|
62 | 0 | String pass = (String)passwords.get(pc.getIdentifer()); |
63 | 0 | if (pass != null) |
64 | |
{ |
65 | 0 | pc.setPassword(pass); |
66 | |
} |
67 | |
} |
68 | 0 | } |
69 | |
} |