de.dpunkt.security.jaas.UserFileLoginModule: 32.26%
Overview
Search Parameters
- plot: false
- chromosome_length: 40
- static_hack: false
- tournament_size: 10
- max_int: 2048
- string_length: 20
- crossover_rate: 0.75
- max_attempts: 1000
- CP: bin
- check_parents_length: true
- PREFIX: de.dpunkt.security.jaas
- stopping_condition: MaxStatements
- max_recursion: 10
- primitive_pool: 0.5
- selection_function: Rank
- generations: 1000000
- primitive_reuse_probability: 0.5
- test_excludes: test.excludes
- bloat_factor: 2
- object_reuse_probability: 0.9
- minimize: true
- html: true
- null_probability: 0.1
- strategy: EvoSuite
- elite: 1
- check_best_length: true
- num_tests: 2
- PROJECT_PREFIX: de.dpunkt.security.jaas
- OUTPUT_DIR: evosuite-files
- algorithm: SteadyStateGA
- string_replacement: false
- crossover_function: SinglePointRelative
- report_dir: evosuite-report
- test_includes: test.includes
- output_dir: evosuite-files
- criterion: branch
- rank_bias: 1.7
- timeout: 5000
- population: 100
- test_dir: evosuite-tests
- max_size: 100
- check_max_length: true
- TARGET_CLASS: de.dpunkt.security.jaas.UserFileLoginModule
- check_rank_length: true
- max_length: 5000
EvoSuite Parameters
- plot: false
- chromosome_length: 40
- static_hack: false
- tournament_size: 10
- max_int: 2048
- string_length: 20
- crossover_rate: 0.75
- max_attempts: 1000
- CP: bin
- check_parents_length: true
- PREFIX: de.dpunkt.security.jaas
- stopping_condition: MaxStatements
- max_recursion: 10
- primitive_pool: 0.5
- selection_function: Rank
- generations: 1000000
- primitive_reuse_probability: 0.5
- test_excludes: test.excludes
- bloat_factor: 2
- object_reuse_probability: 0.9
- minimize: true
- html: true
- null_probability: 0.1
- strategy: EvoSuite
- elite: 1
- check_best_length: true
- num_tests: 2
- PROJECT_PREFIX: de.dpunkt.security.jaas
- OUTPUT_DIR: evosuite-files
- algorithm: SteadyStateGA
- string_replacement: false
- crossover_function: SinglePointRelative
- report_dir: evosuite-report
- test_includes: test.includes
- output_dir: evosuite-files
- criterion: branch
- rank_bias: 1.7
- timeout: 5000
- population: 100
- test_dir: evosuite-tests
- max_size: 100
- check_max_length: true
- TARGET_CLASS: de.dpunkt.security.jaas.UserFileLoginModule
- check_rank_length: true
- max_length: 5000
Old Parameters
- Algorithm: SteadyStateGA
- Population size: 100
- Initial test length: 40
- Stopping condition: MaxStatements: null
- Bloat control factor: 2
- Random seed: 0
Statistics
- Start time: 2010-10-19 08:53:03
- End time: 2010-10-19 08:53:46
- Fitness evaluations: 165866
- Tests executed: 92709
- Statements executed: 1000042
- Generations: 1659
- Number of tests before minimization: 2
- Number of tests after minimization: 2
- Length of tests before minimization: 18
- Length of tests after minimization: 14
- Total predicates: 27
- Total branches: 54
- Covered branches: 12
- Total methods: 8
- Covered methods: 8
- Methods without branches: 2
- Total coverage goal: 62
- Covered goals: 20
- Time for search: 0:00:42
- Time for minimization: 0:00:00
- Total time: 0:00:42
Test suite
Test case 1
1: UserFileLoginModule var0 = new de.dpunkt.security.jaas.UserFileLoginModule();;
2: try {
3: var0.readUserFile();
4: } catch(NullPointerException e) {} // Raised exceptioncatch(LoginException e) {} // Declared exception
5: byte[] var2 = new byte[16];;
6: byte var3 = -116;;
7: var2[5] = var3;;
8: byte var5 = 122;;
9: var2[12] = var5;;
10: String var7 = var7 = var0.getDigestAsHexString(var2);;
Test case 2
1: UserFileLoginModule var0 = new de.dpunkt.security.jaas.UserFileLoginModule();;
2: boolean var1 = null;
3: try {
4: var1 = var0.logout();
5: } catch(LoginException e) {} // Raised exception
6: boolean var2 = null;
7: try {
8: var2 = var0.login();
9: } catch(LoginException e) {} // Raised exception
10: boolean var3 = null;
11: try {
12: var3 = var0.abort();
13: } catch(LoginException e) {} // Raised exception
14: boolean var4 = null;
15: try {
16: var4 = var0.commit();
17: } catch(LoginException e) {} // Raised exception
18: try {
19: var0.initialize((Subject) null, (CallbackHandler) null, (Map) null, (Map) null);
20: } catch(NullPointerException e) {} // Raised exception
Source Code
1:
2: package de.dpunkt.security.jaas;
3:
4: import java.io.BufferedReader;
5: import java.io.FileReader;
6: import java.io.IOException;
7:
8: import java.util.Hashtable;
9: import java.util.Map;
10:
11: import java.security.MessageDigest;
12: import java.security.NoSuchAlgorithmException;
13:
14: import javax.security.auth.Subject;
15:
16: import javax.security.auth.callback.Callback;
17: import javax.security.auth.callback.CallbackHandler;
18: import javax.security.auth.callback.NameCallback;
19: import javax.security.auth.callback.PasswordCallback;
20: import javax.security.auth.callback.UnsupportedCallbackException;
21:
22: import javax.security.auth.login.LoginException;
23: import javax.security.auth.login.FailedLoginException;
24:
25: import javax.security.auth.spi.LoginModule;
26:
27: public class UserFileLoginModule implements LoginModule {
28: private String userFileName;
29: private Hashtable userTable;
30:
31: private Subject subject;
32: private CallbackHandler callbackHandler;
33: private Map sharedState;
34: private Map options;
35: private boolean debug = true;
36:
37: private String userID;
38:
39: private UserFilePrincipal userFilePrincipal;
40: private boolean succeeded = false;
41: private boolean commitSucceeded = false;
42:
43:
44: protected String getDigestAsHexString(byte[] digestBytes) {
45: StringBuffer digestString = new StringBuffer();
46: for(int i = 0; i < digestBytes.length; i++) {
47: String hexString = Integer.toHexString(digestBytes[i]);
48: if (hexString.length() == 1)
49: hexString = "0"+hexString;
50: else if (hexString.length() == 8)
51: hexString = hexString.substring(6);
52: digestString.append(hexString);
53: }
54: return digestString.toString();
55: }
56:
57:
58: public void initialize(Subject subject, CallbackHandler callbackHandler,
59: Map sharedState, Map options) {
60: this.subject = subject;
61: this.callbackHandler = callbackHandler;
62: this.sharedState = sharedState;
63: this.options = options;
64: userFileName = (String)options.get("userfile");
65: userTable = new Hashtable();
66: }
67:
68:
69: protected void readUserFile() throws LoginException {
70: BufferedReader userFile;
71:
72: try {
73: userFile = new BufferedReader(new FileReader(userFileName));
74: String line;
75: if (debug)
76: System.out.println("\t\t[UserFileLoginModule] reading user file:");
77: while ((line = userFile.readLine()) != null) {
78: String[] splittedLine = line.split(":");
79: userTable.put(splittedLine[0], splittedLine[1]);
80: if (debug)
81: System.out.println("\t\t\t"+splittedLine[0]+":"+splittedLine[1]);
82: }
83: userFile.close();
84: }
85: catch(IOException e) {
86: throw new LoginException("Error opening/reading user file.");
87: }
88: }
89:
90:
91: public boolean login() throws LoginException {
92: char[] password;
93:
94: if (callbackHandler == null)
95: throw new LoginException("Error: no CallbackHandler available");
96:
97: if (userFileName == null)
98: throw new LoginException("Error: no user file specified");
99: readUserFile();
100: if (succeeded) {
101: throw new LoginException();
102: }
103: userID = "duke";
104: char[] tmpPassword = new char[] {'j','a','v','a'};
105: if (tmpPassword == null) {
106: tmpPassword = new char[0];
107: }
108: password = new char[tmpPassword.length];
109: System.arraycopy(tmpPassword, 0,
110: password, 0, tmpPassword.length);
111: MessageDigest md;
112: String pwdHash, calculatedPwdHashStr;
113: byte[] calculatedPwdHash;
114: try {
115: md = MessageDigest.getInstance("SHA1");
116: }
117: catch(NoSuchAlgorithmException e) {
118: throw new LoginException("no SHA-1 implementation found");
119: }
120: md.update(userID.getBytes());
121: md.update(String.valueOf(password).getBytes());
122: calculatedPwdHash = md.digest();
123: for (int i = 0; i < password.length; i++)
124: password[i] = ' ';
125: password = null;
126:
127: pwdHash = (String)userTable.get(userID);
128: if (pwdHash == null) {
129: succeeded = false;
130: } else {
131: calculatedPwdHashStr = getDigestAsHexString(calculatedPwdHash);
132: if (debug) {
133: System.out.println("\t\t[UserFileLoginModule]");
134: System.out.println("\t\t hash from file : "+pwdHash);
135: System.out.println("\t\t calculated hash: "+calculatedPwdHashStr);
136: }
137: succeeded = pwdHash.equals(calculatedPwdHashStr);
138: }
139: if (debug) {
140: if (succeeded)
141: System.out.println("\t\t[UserFileLoginModule] authentication succeeded");
142: else
143: System.out.println("\t\t[UserFileLoginModule] authentication failed");
144: }
145: if (!succeeded)
146: throw new FailedLoginException("login failed");
147:
148: return true;
149: }
150:
151:
152: public boolean commit() throws LoginException {
153: if (debug)
154: System.out.println("\t\t[UserFileLoginModule] commit: "+succeeded);
155: if (succeeded == false) {
156: throw new LoginException("Cannot commit because login did not succeed.");
157: } else if (commitSucceeded == true) {
158: throw new LoginException("Already logged in.");
159: } else {
160: userFilePrincipal = new UserFilePrincipal(userID);
161: if (!subject.getPrincipals().contains(userFilePrincipal)) {
162: subject.getPrincipals().add(userFilePrincipal);
163: if (debug)
164: System.out.println("\t\t[UserFileLoginModule] : added principal");
165: }
166:
167: userID = null;
168: commitSucceeded = true;
169: return true;
170: }
171: }
172:
173: public boolean abort() throws LoginException {
174: if (debug)
175: System.out.println("\t\t[UserFileLoginModule] abort: "+succeeded);
176: if (succeeded == false) {
177: throw new LoginException("Was not logged in before.");
178: } else if (succeeded == true && commitSucceeded == false) {
179: succeeded = false;
180: userID = null;
181: userFilePrincipal = null;
182: } else {
183: logout();
184: }
185: return true;
186: }
187:
188:
189: public boolean logout() throws LoginException {
190: if (!succeeded) {
191: throw new LoginException("Was not logged in before.");
192: }
193: subject.getPrincipals().remove(userFilePrincipal);
194: if (debug)
195: System.out.println("\t\t[UserFileLoginModule] : removed principal");
196: commitSucceeded = false;
197: succeeded = false;
198: succeeded = commitSucceeded;
199: userID = null;
200: userFilePrincipal = null;
201: return true;
202: }
203:
204:
205: }
206:
207: