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