|
1 /* |
|
2 * @author Walther Neuper, member of the ISAC-team, |
|
3 * Copyright (c) 2005 by Walther Neuper |
|
4 * created Mar 12, 2005 8:09:42 AM |
|
5 * Institute for Softwaretechnology, Graz University of Technology, Austria. |
|
6 * |
|
7 * Use is subject to PGPL license terms. |
|
8 */ |
|
9 package isac.util.users; |
|
10 |
|
11 import java.io.FileInputStream; |
|
12 import java.io.FileNotFoundException; |
|
13 import java.io.FileOutputStream; |
|
14 import java.io.IOException; |
|
15 import java.util.Enumeration; |
|
16 import java.util.Properties; |
|
17 |
|
18 /** |
|
19 * @author Walther Neuper |
|
20 * |
|
21 * contains passwords looking forward to handle security issues elsewhere |
|
22 * (outside isac) |
|
23 */ |
|
24 public class Accounts extends Properties { |
|
25 |
|
26 public Accounts(String userpath) { |
|
27 String filename = userpath + "accounts.txt"; |
|
28 try { |
|
29 FileInputStream propInFile = new FileInputStream(filename); |
|
30 this.load(propInFile); |
|
31 this.list(System.out); |
|
32 } catch (FileNotFoundException e) { |
|
33 System.err.println("Can?t find " + filename); |
|
34 } catch (IOException e) { |
|
35 System.err.println("I/O failed."); |
|
36 } |
|
37 } |
|
38 |
|
39 public boolean exists(String username) { |
|
40 Enumeration keys = this.propertyNames();//WN050311 how better ? |
|
41 String key = null; |
|
42 while (keys.hasMoreElements()) { |
|
43 key = (String) keys.nextElement(); |
|
44 if (key.compareTo(username) == 0) |
|
45 return true; |
|
46 } |
|
47 return false; |
|
48 } |
|
49 |
|
50 //WN050311 just for creation of the first file |
|
51 //beware of the fix path ! |
|
52 public static void main(String[] args) { |
|
53 Accounts acs = new Accounts("isac/xmldata/users"); |
|
54 acs.setProperty("x", "x"); |
|
55 acs.setProperty("y", "y"); |
|
56 acs.setProperty("anonymous", "anonymous"); |
|
57 |
|
58 String filename = "isac/xmldata/users/accounts.txt"; |
|
59 try { |
|
60 FileOutputStream propOutFile = new FileOutputStream(filename); |
|
61 acs.store(propOutFile, "the list of isac users"); |
|
62 |
|
63 } catch (IOException e) { |
|
64 System.err.println("I/O failed."); |
|
65 } |
|
66 } |
|
67 |
|
68 } |