org.opentox.database
Class UsersTable

java.lang.Object
  extended by org.opentox.database.UsersTable
All Implemented Interfaces:
IDataBaseAccess, ITable

public class UsersTable
extends java.lang.Object
implements IDataBaseAccess, ITable

Author:
Sopasakis Pantelis

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.opentox.interfaces.IDataBaseAccess
IDataBaseAccess.CreateTable, IDataBaseAccess.Registration, IDataBaseAccess.Removal
 
Field Summary
private static java.lang.String COL_USER_AUTH
           
private static java.lang.String COL_USER_NAME
           
private static java.lang.String COL_USER_PASSWRD
           
static UsersTable INSTANCE
           
private static UsersTable instanceOfThis
           
protected static java.lang.String USER_ACCOUNTS_TABLE
           
 
Fields inherited from interface org.opentox.interfaces.IDataBaseAccess
DATABASENAME, DB_URL, DRIVER
 
Constructor Summary
private UsersTable()
           
 
Method Summary
 void addUser(java.lang.String UserName, java.lang.String PassWord, Priviledges priviledges)
          This method is used to add a new user to the USERS table.
 void create()
          Generates the table which contains a/a data.
 Priviledges getAuthorizationForUser(java.lang.String username)
           
 java.util.Map<java.lang.String,char[]> getCredentialsAsMap(Priviledges priviledges)
          Returns a Map<String,char[]> for the credentials of a given authorization level.
private static UsersTable getInstance()
           
 void getRidOf()
          Removes completely the table from the database.
 Jterator<java.lang.String> iterator(java.lang.String ColumnName)
          Provides an iterator for all elements in a specified column of the database.
static void main(java.lang.String[] args)
           
 void removeUser(java.lang.String UserName)
          Delete a user.
 Jterator<java.lang.String> search(java.lang.String IterableCoumn, java.lang.String SearchColumn, java.lang.String keyword)
          Performs a search in the table.
 java.lang.String toString()
           
 boolean verifyCredentials(java.lang.String userName, java.lang.String password)
          Verify if a given pair of user name and password are registered in the database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

USER_ACCOUNTS_TABLE

protected static final java.lang.String USER_ACCOUNTS_TABLE
See Also:
Constant Field Values

COL_USER_NAME

private static final java.lang.String COL_USER_NAME
See Also:
Constant Field Values

COL_USER_PASSWRD

private static final java.lang.String COL_USER_PASSWRD
See Also:
Constant Field Values

COL_USER_AUTH

private static final java.lang.String COL_USER_AUTH
See Also:
Constant Field Values

instanceOfThis

private static UsersTable instanceOfThis

INSTANCE

public static final UsersTable INSTANCE
Constructor Detail

UsersTable

private UsersTable()
Method Detail

getInstance

private static UsersTable getInstance()

create

public void create()
Generates the table which contains a/a data. The structure of this table is the following:

 |                       USERS                        |
 |====================================================|
 | USER_NAME (TXT) | USER_PASSWORD (TXT) | AUTH (TXT) |
 |-----------------|---------------------|------------|
 |        *        |           *         |      *     |
 |        *        |           *         |      *     |
 
Passwords are saved as digests!

Specified by:
create in interface ITable

addUser

public void addUser(java.lang.String UserName,
                    java.lang.String PassWord,
                    Priviledges priviledges)
This method is used to add a new user to the USERS table. The username, the password

Parameters:
UserName - username
PassWord - password

removeUser

public void removeUser(java.lang.String UserName)
Delete a user.

Parameters:
UserName -

getAuthorizationForUser

public Priviledges getAuthorizationForUser(java.lang.String username)

verifyCredentials

public boolean verifyCredentials(java.lang.String userName,
                                 java.lang.String password)
Verify if a given pair of user name and password are registered in the database. If yes, returns true, else returns false. Both username and password are case sensitive.

Note: If some credentials correspond to an administrator, then verifyCredentials(userName,pass,Privilegdges.ADMIN), returns true while verifyCredentials(userName,pass,Privilegdges.USER) returns false. Of course an administrator has all the authorization that a simple user has, but this method verifies just if a given triplet of username, password and given provilegdes is valid.

Parameters:
userName - The user name.
password - character array of the password.
Returns:
true/false.

getCredentialsAsMap

public java.util.Map<java.lang.String,char[]> getCredentialsAsMap(Priviledges priviledges)
Returns a Map<String,char[]> for the credentials of a given authorization level.

Parameters:
priviledges -
Returns:
All credentials as a Map.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getRidOf

public void getRidOf()
Description copied from interface: ITable
Removes completely the table from the database. After this operation all data stored in the table will get lost, so make sure that you either really don't need these data or that you have kept backup of your database which is in general highly recommended.

Specified by:
getRidOf in interface ITable

main

public static void main(java.lang.String[] args)

iterator

public Jterator<java.lang.String> iterator(java.lang.String ColumnName)
Description copied from interface: ITable
Provides an iterator for all elements in a specified column of the database.

Specified by:
iterator in interface ITable
Parameters:
ColumnName - The name of the column.
Returns:
An instance of Jterator<String>

search

public Jterator<java.lang.String> search(java.lang.String IterableCoumn,
                                         java.lang.String SearchColumn,
                                         java.lang.String keyword)
Description copied from interface: ITable
Performs a search in the table. Searches the entries of the column defined by SearchColumn to check if its entries resemble a given keyword and returns an iterator over the corresponding entries of the column specified by the argument IterableColumn. The search is performed by a database SQL-type query containing 'LIKE %...%'.

Specified by:
search in interface ITable
Parameters:
IterableCoumn - The column of the table on whose entries the iterator takes values.
SearchColumn - The column of the table which should be searched.
keyword - A keyword
Returns:
An instance of a Jterator (in fact this is an Iterator) which can be used to iterate over the search results.