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.Iterator;
21 import java.util.Map;
22 import java.util.Properties;
23 import javax.security.auth.callback.UnsupportedCallbackException;
24
25 import org.apache.ws.security.WSPasswordCallback;
26 import org.apache.ws.security.WSSecurityException;
27
28 import org.springframework.beans.factory.InitializingBean;
29 import org.springframework.util.Assert;
30
31
32
33
34
35
36
37
38
39
40 public class SimplePasswordValidationCallbackHandler extends AbstractWsPasswordCallbackHandler
41 implements InitializingBean {
42
43 private Properties users = new Properties();
44
45
46 public void setUsers(Properties users) {
47 this.users = users;
48 }
49
50 public void setUsersMap(Map users) {
51 for (Iterator iterator = users.keySet().iterator(); iterator.hasNext();) {
52 String username = (String) iterator.next();
53 String password = (String) users.get(username);
54 this.users.setProperty(username, password);
55 }
56 }
57
58 public void afterPropertiesSet() throws Exception {
59 Assert.notNull(users, "users is required");
60 }
61
62 protected void handleUsernameToken(WSPasswordCallback callback) throws IOException, UnsupportedCallbackException {
63 String identifier = callback.getIdentifier();
64 callback.setPassword(users.getProperty(identifier));
65 }
66
67 protected void handleUsernameTokenUnknown(WSPasswordCallback callback)
68 throws IOException, UnsupportedCallbackException {
69 String identifier = callback.getIdentifier();
70 String storedPassword = users.getProperty(identifier);
71 String givenPassword = callback.getPassword();
72 if (storedPassword == null || !storedPassword.equals(givenPassword)) {
73 throw new WSSecurityException(WSSecurityException.FAILED_AUTHENTICATION);
74 }
75 }
76
77 }