Skip to content

Package: MyUserInfo

MyUserInfo

nameinstructionbranchcomplexitylinemethod
MyUserInfo()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getPassphrase()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getPassword()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
promptKeyboardInteractive(String, String, String, String[], boolean[])
M: 53 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 16 C: 0
0%
M: 1 C: 0
0%
promptPassphrase(String)
M: 46 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 15 C: 0
0%
M: 1 C: 0
0%
promptPassword(String)
M: 46 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 15 C: 0
0%
M: 1 C: 0
0%
promptYesNo(String)
M: 61 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 20 C: 0
0%
M: 1 C: 0
0%
showMessage(String)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%

Coverage

1: package update.remote.ssh;
2:
3: import java.io.BufferedReader;
4: import java.io.IOException;
5: import java.io.InputStreamReader;
6: import java.nio.charset.Charset;
7:
8: import com.jcraft.jsch.UIKeyboardInteractive;
9: import com.jcraft.jsch.UserInfo;
10:
11: /**
12: * A UserInfo implementation for authentication. To be used with commandline, no gui. PMD is
13: * supressed because this class is only a modified class by us, written by some other guys.
14: *
15: * @author Muri
16: */
17: @SuppressWarnings("PMD")
18: public class MyUserInfo implements UserInfo, UIKeyboardInteractive {
19:         /**
20:          * UTF-8.
21:          */
22:         private static final String UTF_8 = "UTF-8";
23:         /**
24:          * Type nothing to abort.
25:          */
26:         private static final String TYPE_NOTHING_TO_ABORT = " Type nothing to abort.";
27:
28:         @Override
29:         public String getPassword() {
30:                 return passwd;
31:         }
32:
33:         @Override
34:         public boolean promptYesNo(final String str) {
35:                 final BufferedReader bufferRead =
36:                                 new BufferedReader(new InputStreamReader(System.in, Charset.forName(UTF_8)));
37:                 boolean foo = false;
38:                 String s = "";
39:                 System.out.println(str + " (y/n)");
40:                 boolean done = false;
41:•                while (!done) {
42:                         try {
43:                                 // TODO Check if null really is a problem
44:                                 s = bufferRead.readLine(); // Can be null. Really?
45:•                                if (s == null) {
46:                                         s = "";
47:                                 }
48:•                                if (s.equals("y")) {
49:                                         foo = true;
50:                                         done = true;
51:•                                } else if (s.equals("n")) {
52:                                         done = true;
53:                                 } else {
54:                                         System.out.println("Please provide a value of y|n");
55:                                 }
56:                         } catch (final IOException e) {
57:                                 e.printStackTrace();
58:                         }
59:
60:                 }
61:                 return foo;
62:         }
63:
64:         /**
65:          * password.
66:          */
67:         private String passwd;
68:         /**
69:          * passphrase.
70:          */
71:         private String passphrase;
72:
73:         @Override
74:         public String getPassphrase() {
75:                 return this.passphrase;
76:         }
77:
78:         @Override
79:         public boolean promptPassphrase(final String message) {
80:                 final BufferedReader bufferRead =
81:                                 new BufferedReader(new InputStreamReader(System.in, Charset.forName(UTF_8)));
82:                 String s = "";
83:                 boolean foo = false;
84:                 System.out.println(message + TYPE_NOTHING_TO_ABORT);
85:                 try {
86:                         // TODO Check if null really is a problem
87:                         s = bufferRead.readLine(); // Can be null. Really?
88:•                        if (s == null) {
89:                                 s = "";
90:                         }
91:•                        if (!s.equals("")) {
92:                                 this.passphrase = s;
93:                                 foo = true;
94:                         }
95:                 } catch (final IOException e) {
96:                         e.printStackTrace();
97:                 }
98:                 return foo;
99:         }
100:
101:         @Override
102:         public boolean promptPassword(final String message) {
103:                 final BufferedReader bufferRead =
104:                                 new BufferedReader(new InputStreamReader(System.in, Charset.forName(UTF_8)));
105:                 String s = "";
106:                 boolean foo = false;
107:                 System.out.println(message + TYPE_NOTHING_TO_ABORT);
108:                 try {
109:                         // TODO Check if null really is a problem
110:                         s = bufferRead.readLine(); // Can be null. Really?
111:•                        if (s == null) {
112:                                 s = "";
113:                         }
114:•                        if (!s.equals("")) {
115:                                 this.passwd = s;
116:                                 foo = true;
117:                         }
118:                 } catch (final IOException e) {
119:                         e.printStackTrace();
120:                 }
121:                 return foo;
122:         }
123:
124:         @Override
125:         public void showMessage(final String message) {
126:                 System.out.println(message);
127:         }
128:
129:         @Override
130:         public String[] promptKeyboardInteractive(final String destination, final String name,
131:                         final String instruction, final String[] prompt, final boolean[] echo) {
132:
133:                 System.out.println(instruction);
134:                 final String[] response = new String[prompt.length];
135:•                for (int i = 0; i < prompt.length; i++) {
136:                         final BufferedReader bufferRead =
137:                                         new BufferedReader(new InputStreamReader(System.in, Charset.forName(UTF_8)));
138:                         String s = "";
139:                         System.out.println(prompt[i]);
140:                         try {
141:                                 // TODO Check if null really is a problem
142:                                 s = bufferRead.readLine(); // Can be null. Really?
143:•                                if (s == null) {
144:                                         s = "";
145:                                 }
146:•                                if (!s.equals("")) {
147:                                         response[i] = s;
148:                                 }
149:                         } catch (final IOException e) {
150:                                 e.printStackTrace();
151:                         }
152:                 }
153:                 return response;
154:         }
155: }