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 javax.security.auth.callback.Callback;
21 import javax.security.auth.callback.UnsupportedCallbackException;
22
23 import org.springframework.ws.soap.security.callback.AbstractCallbackHandler;
24 import org.springframework.ws.soap.security.callback.CleanupCallback;
25
26 import org.apache.ws.security.WSPasswordCallback;
27
28
29
30
31
32
33
34
35 public abstract class AbstractWsPasswordCallbackHandler extends AbstractCallbackHandler {
36
37
38
39
40
41
42
43
44
45 @Override
46 protected final void handleInternal(Callback callback) throws IOException, UnsupportedCallbackException {
47 if (callback instanceof WSPasswordCallback) {
48 WSPasswordCallback passwordCallback = (WSPasswordCallback) callback;
49 switch (passwordCallback.getUsage()) {
50 case WSPasswordCallback.DECRYPT:
51 handleDecrypt(passwordCallback);
52 break;
53 case WSPasswordCallback.USERNAME_TOKEN:
54 handleUsernameToken(passwordCallback);
55 break;
56 case WSPasswordCallback.SIGNATURE:
57 handleSignature(passwordCallback);
58 break;
59 case WSPasswordCallback.SECURITY_CONTEXT_TOKEN:
60 handleSecurityContextToken(passwordCallback);
61 break;
62 case WSPasswordCallback.CUSTOM_TOKEN:
63 handleCustomToken(passwordCallback);
64 break;
65 case WSPasswordCallback.SECRET_KEY:
66 handleSecretKey(passwordCallback);
67 break;
68 default:
69 throw new UnsupportedCallbackException(callback,
70 "Unknown usage [" + passwordCallback.getUsage() + "]");
71 }
72 }
73 else if (callback instanceof CleanupCallback) {
74 handleCleanup((CleanupCallback) callback);
75 }
76 else if (callback instanceof UsernameTokenPrincipalCallback) {
77 handleUsernameTokenPrincipal((UsernameTokenPrincipalCallback) callback);
78 }
79 else {
80 throw new UnsupportedCallbackException(callback);
81 }
82 }
83
84
85
86
87
88
89
90
91
92
93
94 protected void handleDecrypt(WSPasswordCallback callback) throws IOException, UnsupportedCallbackException {
95 throw new UnsupportedCallbackException(callback);
96 }
97
98
99
100
101
102
103
104
105 protected void handleUsernameToken(WSPasswordCallback callback) throws IOException, UnsupportedCallbackException {
106 throw new UnsupportedCallbackException(callback);
107 }
108
109
110
111
112
113
114
115
116
117
118 protected void handleSignature(WSPasswordCallback callback) throws IOException, UnsupportedCallbackException {
119 throw new UnsupportedCallbackException(callback);
120 }
121
122
123
124
125
126
127
128
129 protected void handleSecurityContextToken(WSPasswordCallback callback)
130 throws IOException, UnsupportedCallbackException {
131 throw new UnsupportedCallbackException(callback);
132 }
133
134
135
136
137
138
139 protected void handleCustomToken(WSPasswordCallback callback) throws IOException, UnsupportedCallbackException {
140 throw new UnsupportedCallbackException(callback);
141 }
142
143
144
145
146
147
148 protected void handleSecretKey(WSPasswordCallback callback) throws IOException, UnsupportedCallbackException {
149 throw new UnsupportedCallbackException(callback);
150 }
151
152
153
154
155
156
157 protected void handleCleanup(CleanupCallback callback) throws IOException, UnsupportedCallbackException {
158 throw new UnsupportedCallbackException(callback);
159 }
160
161
162
163
164
165
166 protected void handleUsernameTokenPrincipal(UsernameTokenPrincipalCallback callback)
167 throws IOException, UnsupportedCallbackException {
168 throw new UnsupportedCallbackException(callback);
169 }
170 }