1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.soap.security.wss4j.callback;
18
19 import java.io.IOException;
20 import java.util.HashMap;
21 import java.util.Map;
22 import java.util.Properties;
23 import javax.security.auth.callback.UnsupportedCallbackException;
24
25 import org.springframework.beans.factory.InitializingBean;
26 import org.springframework.util.Assert;
27
28 import org.apache.ws.security.WSPasswordCallback;
29
30
31
32
33
34
35
36
37
38
39 public class SimplePasswordValidationCallbackHandler extends AbstractWsPasswordCallbackHandler
40 implements InitializingBean {
41
42 private Map<String, String > users = new HashMap<String, String>();
43
44
45 public void setUsers(Properties users) {
46 for (Map.Entry<Object, Object> entry : users.entrySet()) {
47 if (entry.getKey() instanceof String && entry.getValue() instanceof String) {
48 this.users.put((String) entry.getKey(), (String) entry.getValue());
49 }
50 }
51 }
52
53 public void setUsersMap(Map<String, String> users) {
54 this.users = users;
55 }
56
57 public void afterPropertiesSet() throws Exception {
58 Assert.notNull(users, "users is required");
59 }
60
61 @Override
62 protected void handleUsernameToken(WSPasswordCallback callback) throws IOException, UnsupportedCallbackException {
63 String identifier = callback.getIdentifier();
64 callback.setPassword(users.get(identifier));
65 }
66
67 }