src/java/isac/util/users/Accounts.java
branchjava_rename_format
changeset 3922 fcd5648113ca
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/java/isac/util/users/Accounts.java	Wed Jun 15 18:31:02 2005 +0200
     1.3 @@ -0,0 +1,68 @@
     1.4 +/*
     1.5 + * @author Walther Neuper, member of the ISAC-team, 
     1.6 + * Copyright (c) 2005 by Walther Neuper 
     1.7 + * created Mar 12, 2005 8:09:42 AM
     1.8 + * Institute for Softwaretechnology, Graz University of Technology, Austria.
     1.9 + * 
    1.10 + * Use is subject to PGPL license terms.
    1.11 + */
    1.12 +package isac.util.users;
    1.13 +
    1.14 +import java.io.FileInputStream;
    1.15 +import java.io.FileNotFoundException;
    1.16 +import java.io.FileOutputStream;
    1.17 +import java.io.IOException;
    1.18 +import java.util.Enumeration;
    1.19 +import java.util.Properties;
    1.20 +
    1.21 +/**
    1.22 + * @author Walther Neuper
    1.23 + * 
    1.24 + * contains passwords looking forward to handle security issues elsewhere
    1.25 + * (outside isac)
    1.26 + */
    1.27 +public class Accounts extends Properties {
    1.28 +
    1.29 +    public Accounts(String userpath) {
    1.30 +        String filename = userpath + "accounts.txt";
    1.31 +        try {
    1.32 +            FileInputStream propInFile = new FileInputStream(filename);
    1.33 +            this.load(propInFile);
    1.34 +            this.list(System.out);
    1.35 +        } catch (FileNotFoundException e) {
    1.36 +            System.err.println("Can?t find " + filename);
    1.37 +        } catch (IOException e) {
    1.38 +            System.err.println("I/O failed.");
    1.39 +        }
    1.40 +    }
    1.41 +
    1.42 +    public boolean exists(String username) {
    1.43 +        Enumeration keys = this.propertyNames();//WN050311 how better ?
    1.44 +        String key = null;
    1.45 +        while (keys.hasMoreElements()) {
    1.46 +            key = (String) keys.nextElement();
    1.47 +            if (key.compareTo(username) == 0)
    1.48 +                return true;
    1.49 +        }
    1.50 +        return false;
    1.51 +    }
    1.52 +
    1.53 +    //WN050311 just for creation of the first file
    1.54 +    //beware of the fix path !
    1.55 +    public static void main(String[] args) {
    1.56 +        Accounts acs = new Accounts("isac/xmldata/users");
    1.57 +        acs.setProperty("x", "x");
    1.58 +        acs.setProperty("y", "y");
    1.59 +        acs.setProperty("anonymous", "anonymous");
    1.60 +
    1.61 +        String filename = "isac/xmldata/users/accounts.txt";
    1.62 +        try {
    1.63 +            FileOutputStream propOutFile = new FileOutputStream(filename);
    1.64 +            acs.store(propOutFile, "the list of isac users");
    1.65 +
    1.66 +        } catch (IOException e) {
    1.67 +            System.err.println("I/O failed.");
    1.68 +        }
    1.69 +    }
    1.70 +
    1.71 +}
    1.72 \ No newline at end of file