1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
package issrg.SAWS.callback; |
47 |
|
|
48 |
|
import issrg.SAWS.callback.gui.CreateCertificateDialog; |
49 |
|
import issrg.SAWS.SAWSServer; |
50 |
|
import issrg.SAWS.callback.gui.LongMessagesDialog; |
51 |
|
import issrg.SAWS.callback.gui.inputPassword; |
52 |
|
|
53 |
|
import issrg.SAWS.util.CertificateData; |
54 |
|
|
55 |
|
import issrg.SAWS.util.SAWSLogWriter; |
56 |
|
|
57 |
|
import java.awt.Component; |
58 |
|
|
59 |
|
import javax.security.auth.callback.Callback; |
60 |
|
import javax.security.auth.callback.CallbackHandler; |
61 |
|
import javax.security.auth.callback.UnsupportedCallbackException; |
62 |
|
|
63 |
|
import javax.swing.JOptionPane; |
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
@author |
70 |
|
@version |
71 |
|
|
72 |
|
|
|
|
| 1.2% |
Uncovered Elements: 81 (82) |
Complexity: 18 |
Complexity Density: 0.33 |
|
73 |
|
public class SAWSGUICallbackHandler implements CallbackHandler { |
74 |
|
|
75 |
|
private Component parent = null; |
76 |
|
private static SAWSLogWriter sawsDebugLog = new SAWSLogWriter(SAWSGUICallbackHandler.class.getName()); |
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
81 |
54
|
public SAWSGUICallbackHandler() {... |
82 |
|
} |
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
@param |
89 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
90 |
0
|
public void setParentComponent(Component parent) {... |
91 |
0
|
this.parent = parent; |
92 |
|
} |
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
@param |
97 |
|
@throws |
98 |
|
|
|
|
| 0% |
Uncovered Elements: 78 (78) |
Complexity: 18 |
Complexity Density: 0.3 |
|
99 |
0
|
public void handle(Callback[] callbacks) throws UnsupportedCallbackException {... |
100 |
0
|
if (callbacks == null) { |
101 |
0
|
throw new UnsupportedCallbackException(null, "ERROR: Callbacks can not be null."); |
102 |
|
} |
103 |
|
|
104 |
0
|
for (int i = 0; i < callbacks.length; i++) { |
105 |
0
|
if (callbacks[i] instanceof SAWSTextOutputCallback) { |
106 |
0
|
switch (((SAWSTextOutputCallback)callbacks[i]).getMessageType()) { |
107 |
0
|
case SAWSTextOutputCallback.ERROR: |
108 |
|
|
109 |
0
|
JOptionPane.showMessageDialog(this.parent,((SAWSTextOutputCallback)callbacks[i]).getMessage(), |
110 |
|
"ERROR", JOptionPane.ERROR_MESSAGE); |
111 |
0
|
break; |
112 |
0
|
case SAWSTextOutputCallback.INFORMATION: |
113 |
|
|
114 |
0
|
JOptionPane.showMessageDialog(this.parent,((SAWSTextOutputCallback)callbacks[i]).getMessage(), |
115 |
|
"INFO", JOptionPane.INFORMATION_MESSAGE); |
116 |
0
|
break; |
117 |
0
|
case SAWSTextOutputCallback.WARNING: |
118 |
|
|
119 |
0
|
JOptionPane.showMessageDialog(this.parent,((SAWSTextOutputCallback)callbacks[i]).getMessage(), |
120 |
|
"WARNING", JOptionPane.WARNING_MESSAGE); |
121 |
0
|
break; |
122 |
0
|
case SAWSTextOutputCallback.LONG_MESSAGE: |
123 |
|
|
124 |
0
|
LongMessagesDialog lmd = new LongMessagesDialog(null, "Message", |
125 |
|
true, ((SAWSTextOutputCallback)callbacks[i]).getMessage()); |
126 |
0
|
break; |
127 |
|
} |
128 |
0
|
} else if (callbacks[i] instanceof SAWSPasswordCallback) { |
129 |
0
|
SAWSPasswordCallback pc = (SAWSPasswordCallback)callbacks[i]; |
130 |
0
|
SAWSPasswordCallback pc_new = null; |
131 |
0
|
inputPassword inP = null; |
132 |
0
|
System.out.println("Now please input the password for the " |
133 |
|
+ "keystore in the pop-up window:"); |
134 |
0
|
int j = i + 1; |
135 |
0
|
if ((j < callbacks.length) && (callbacks[j] instanceof SAWSPasswordCallback)) { |
136 |
0
|
pc_new = (SAWSPasswordCallback)callbacks[j]; |
137 |
0
|
inP = new inputPassword("Password", |
138 |
|
pc.getPrompt(), true); |
139 |
0
|
pc_new.setPassword(inP.getPassword().toCharArray()); |
140 |
0
|
i = j; |
141 |
|
} else { |
142 |
0
|
inP = new inputPassword("Password", |
143 |
|
pc.getPrompt()); |
144 |
|
} |
145 |
|
|
146 |
0
|
pc.setPassword(inP.getPassword().toCharArray()); |
147 |
|
|
148 |
0
|
} else if (callbacks[i] instanceof CertificateDataCallback) { |
149 |
0
|
CertificateDataCallback cdc = (CertificateDataCallback) callbacks[i]; |
150 |
0
|
System.out.println("Now please input the data for the digital certificate in the pop-up window:"); |
151 |
0
|
CreateCertificateDialog dialog = new CreateCertificateDialog(cdc.getType()); |
152 |
0
|
dialog.setVisible(true); |
153 |
0
|
CertificateData cd = null; |
154 |
|
|
155 |
0
|
if (dialog.getSelectedOption() == CreateCertificateDialog.CONFIRM) { |
156 |
0
|
cd = dialog.getCertificateData(); |
157 |
0
|
cdc.setCertData(cd); |
158 |
|
} |
159 |
0
|
} else if (callbacks[i] instanceof SAWSChoiceCallback) { |
160 |
0
|
SAWSChoiceCallback cc = (SAWSChoiceCallback) callbacks[i]; |
161 |
|
|
162 |
0
|
int type = -1; |
163 |
0
|
switch (cc.getMessageType()) { |
164 |
0
|
case SAWSChoiceCallback.WARNING: |
165 |
0
|
type = JOptionPane.WARNING_MESSAGE; |
166 |
0
|
break; |
167 |
0
|
case SAWSChoiceCallback.ERROR: |
168 |
0
|
type = JOptionPane.ERROR_MESSAGE; |
169 |
0
|
break; |
170 |
0
|
case SAWSChoiceCallback.INFORMATION: |
171 |
0
|
type = JOptionPane.INFORMATION_MESSAGE; |
172 |
0
|
break; |
173 |
|
} |
174 |
|
|
175 |
0
|
int choice = JOptionPane.showOptionDialog(this.parent, cc.getPrompt(), "Select one option", |
176 |
|
JOptionPane.DEFAULT_OPTION, type, |
177 |
|
null, cc.getOptions(), cc.getOptions()[cc.getDefaultOption()]); |
178 |
|
|
179 |
0
|
cc.setSelectedIndex(choice); |
180 |
0
|
} else if (callbacks[i] instanceof SAWSTextInputCallback) { |
181 |
0
|
System.out.println("Please input the value on the pop-up window."); |
182 |
0
|
SAWSTextInputCallback cc = (SAWSTextInputCallback) callbacks[i]; |
183 |
|
|
184 |
0
|
String value = JOptionPane.showInputDialog(this.parent, cc.getPrompt(), "Input a value", |
185 |
|
JOptionPane.QUESTION_MESSAGE); |
186 |
0
|
cc.setText(value); |
187 |
|
|
188 |
|
} else { |
189 |
0
|
throw new UnsupportedCallbackException |
190 |
|
(callbacks[i], "ERROR: Unrecognized Callback."); |
191 |
|
} |
192 |
|
} |
193 |
|
} |
194 |
|
} |