Clover Coverage Report
Coverage timestamp: Sun Mar 23 2008 08:24:39 GMT
61   194   18   20.33
18   103   0.33   3
3     6.67  
1    
 
 
  SAWSGUICallbackHandler       Line # 73 61 18 1.2% 0.0121951215
 
No Tests
 
1    /*
2    * Copyright (c) 2006, University of Kent
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions are met:
7    *
8    * Redistributions of source code must retain the above copyright notice, this
9    * list of conditions and the following disclaimer.
10    *
11    * Redistributions in binary form must reproduce the above copyright notice,
12    * this list of conditions and the following disclaimer in the documentation
13    * and/or other materials provided with the distribution.
14    *
15    * 1. Neither the name of the University of Kent nor the names of its
16    * contributors may be used to endorse or promote products derived from this
17    * software without specific prior written permission.
18    *
19    * 2. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20    * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21    * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22    * PURPOSE ARE DISCLAIMED.
23    *
24    * 3. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25    * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26    * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27    * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29    * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31    * POSSIBILITY OF SUCH DAMAGE.
32    *
33    * 4. YOU AGREE THAT THE EXCLUSIONS IN PARAGRAPHS 2 AND 3 ABOVE ARE REASONABLE
34    * IN THE CIRCUMSTANCES. IN PARTICULAR, YOU ACKNOWLEDGE (1) THAT THIS
35    * SOFTWARE HAS BEEN MADE AVAILABLE TO YOU FREE OF CHARGE, (2) THAT THIS
36    * SOFTWARE IS NOT "PRODUCT" QUALITY, BUT HAS BEEN PRODUCED BY A RESEARCH
37    * GROUP WHO DESIRE TO MAKE THIS SOFTWARE FREELY AVAILABLE TO PEOPLE WHO WISH
38    * TO USE IT, AND (3) THAT BECAUSE THIS SOFTWARE IS NOT OF "PRODUCT" QUALITY
39    * IT IS INEVITABLE THAT THERE WILL BE BUGS AND ERRORS, AND POSSIBLY MORE
40    * SERIOUS FAULTS, IN THIS SOFTWARE.
41    *
42    * 5. This license is governed, except to the extent that local laws
43    * necessarily apply, by the laws of England and Wales.
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    * This class represents the callback handler that uses graphical components
67    * to interact with the user.
68    *
69    * @author E. Silva
70    * @version 1.0, Feb. 2007
71    */
72   
 
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    * Constructor of the class.
80    */
 
81  54 toggle public SAWSGUICallbackHandler() {
82    }
83   
84    /**
85    * Method that sets the parent component for the pop-up windows opened by
86    * this handler during the execution of 'handle' method.
87    *
88    * @param parent The parent component.
89    */
 
90  0 toggle public void setParentComponent(Component parent) {
91  0 this.parent = parent;
92    }
93   
94    /**
95    * Method that handles the callbacks sent as parameter.
96    * @param callbacks The list of callbacks to be handled.
97    * @throws UnsupportedCallbackException If one of the callbacks are not known (supported).
98    */
 
99  0 toggle 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    /*show message in a dialog window */
109  0 JOptionPane.showMessageDialog(this.parent,((SAWSTextOutputCallback)callbacks[i]).getMessage(),
110    "ERROR", JOptionPane.ERROR_MESSAGE);
111  0 break;
112  0 case SAWSTextOutputCallback.INFORMATION:
113    /*show message in a dialog window */
114  0 JOptionPane.showMessageDialog(this.parent,((SAWSTextOutputCallback)callbacks[i]).getMessage(),
115    "INFO", JOptionPane.INFORMATION_MESSAGE);
116  0 break;
117  0 case SAWSTextOutputCallback.WARNING:
118    /*show message in a dialog window */
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    /*show message in a dialog window */
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    }