de.janicke.hj.tools.servlet
Class SimpleUserAdministration

java.lang.Object
  |
  +--de.janicke.hj.tools.servlet.AbstractUserAdministration
        |
        +--de.janicke.hj.tools.servlet.SimpleUserAdministration

public class SimpleUserAdministration
extends AbstractUserAdministration

Handles the user administration with a database.


Field Summary
protected  Database database
           
protected  java.sql.PreparedStatement preSQLAcceptUserById
           
protected  java.sql.PreparedStatement preSQLAcceptUserById_Sid
           
protected  java.sql.PreparedStatement preSQLAcceptUserByNick
           
protected  java.sql.PreparedStatement preSQLAcceptUserByNick_Passwd
           
protected  java.sql.PreparedStatement preSQLAddUser
          Precompiled SQL statement to add a servlet user.
protected  java.sql.PreparedStatement preSQLDeleteUserById
          Precompiled SQL statement to delete a servlet user.
protected  java.sql.PreparedStatement preSQLDeleteUserByNick_Passwd
          Precompiled SQL statement to delete a servlet user.
protected  java.sql.PreparedStatement preSQLEditUser
           
protected  java.sql.PreparedStatement preSQLEditUserPwd
           
protected  java.sql.PreparedStatement preSQLGetUserById
          Precompiled SQL statement to get a servlet user.
protected  java.sql.PreparedStatement preSQLGetUserById_Sid
          Precompiled SQL statement to get a servlet user.
protected  java.sql.PreparedStatement preSQLGetUserByNick
          Precompiled SQL statement to get a servlet user.
protected  java.sql.PreparedStatement preSQLGetUserByNick_Passwd
          Precompiled SQL statement to get a servlet user.
protected  java.sql.PreparedStatement preSQLSetSecureIdentity
           
 
Constructor Summary
SimpleUserAdministration(Database db)
          Sets the database for the UserAdministration.
 
Method Summary
 boolean acceptUser(int id)
          Returns if a user exists in the database.
 boolean acceptUser(int id, java.lang.String sid)
          Returns if a user exists in the database.
 boolean acceptUser(java.lang.String nick)
          Returns if a user exists in the database.
 boolean acceptUser(java.lang.String nick, java.lang.String passwd)
          Returns if a user exists in the database.
 boolean addUser(User user)
          Adds a user to the database.
 boolean deleteUser(int id)
          Deletes an existing user from the database.
 boolean deleteUser(java.lang.String nick, java.lang.String passwd)
          Deletes an existing user from the database.
 User editUser(User user)
          Edits an existing user from the database.
 User editUser(User user, java.lang.String passwd)
          Edits an existing user password from the database.
 User getUser(int id)
          Gets a user from the database.
 User getUser(int id, java.lang.String sid)
          Gets a user from the database.
 User getUser(java.lang.String nick)
          Gets a user from the database.
 User getUser(java.lang.String nick, java.lang.String passwd)
          Gets a user from the database.
 void init()
          Initializes the database.
 User loginUser(java.lang.String nick, java.lang.String passwd)
          Tries to login a new user.
 User loginUser(java.lang.String nick, java.lang.String passwd, javax.servlet.http.HttpServletRequest request)
          Tries to login a new user.
 
Methods inherited from class de.janicke.hj.tools.servlet.AbstractUserAdministration
acceptUser, deleteUser, getRandomSecureId, loginUser
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

database

protected Database database

preSQLSetSecureIdentity

protected java.sql.PreparedStatement preSQLSetSecureIdentity

preSQLAddUser

protected java.sql.PreparedStatement preSQLAddUser
Precompiled SQL statement to add a servlet user.

preSQLDeleteUserByNick_Passwd

protected java.sql.PreparedStatement preSQLDeleteUserByNick_Passwd
Precompiled SQL statement to delete a servlet user.

preSQLDeleteUserById

protected java.sql.PreparedStatement preSQLDeleteUserById
Precompiled SQL statement to delete a servlet user.

preSQLGetUserById

protected java.sql.PreparedStatement preSQLGetUserById
Precompiled SQL statement to get a servlet user.

preSQLGetUserByNick

protected java.sql.PreparedStatement preSQLGetUserByNick
Precompiled SQL statement to get a servlet user.

preSQLGetUserByNick_Passwd

protected java.sql.PreparedStatement preSQLGetUserByNick_Passwd
Precompiled SQL statement to get a servlet user.

preSQLGetUserById_Sid

protected java.sql.PreparedStatement preSQLGetUserById_Sid
Precompiled SQL statement to get a servlet user.

preSQLAcceptUserById

protected java.sql.PreparedStatement preSQLAcceptUserById

preSQLAcceptUserById_Sid

protected java.sql.PreparedStatement preSQLAcceptUserById_Sid

preSQLAcceptUserByNick_Passwd

protected java.sql.PreparedStatement preSQLAcceptUserByNick_Passwd

preSQLAcceptUserByNick

protected java.sql.PreparedStatement preSQLAcceptUserByNick

preSQLEditUser

protected java.sql.PreparedStatement preSQLEditUser

preSQLEditUserPwd

protected java.sql.PreparedStatement preSQLEditUserPwd
Constructor Detail

SimpleUserAdministration

public SimpleUserAdministration(Database db)
Sets the database for the UserAdministration.
Parameters:
db - The used Database.
Method Detail

init

public void init()
          throws java.lang.Exception
Initializes the database. compiles SQL statements.
Throws:
java.lang.Exception - if there is no connect to the database, or the precompile of SQL statements fails.

addUser

public boolean addUser(User user)
Adds a user to the database.
Overrides:
addUser in class AbstractUserAdministration
Parameters:
user - The user to add.
Returns:
true if the adding succesfull, else false.

acceptUser

public boolean acceptUser(java.lang.String nick)
Returns if a user exists in the database.
Overrides:
acceptUser in class AbstractUserAdministration
Parameters:
nick - The nick of the user to check with database.
Returns:
true if the user exist, else false.

acceptUser

public boolean acceptUser(int id,
                          java.lang.String sid)
Returns if a user exists in the database.
Overrides:
acceptUser in class AbstractUserAdministration
Parameters:
id - The userid to check with database.
sid - The secureIdentity of the user to check with database.
Returns:
true if the user exist, else false.

acceptUser

public boolean acceptUser(java.lang.String nick,
                          java.lang.String passwd)
Returns if a user exists in the database.
Overrides:
acceptUser in class AbstractUserAdministration
Parameters:
nick - The nick of the user to check with database.
passwd - The password of the user to check with database.
Returns:
true if the user exist, else false.

acceptUser

public boolean acceptUser(int id)
Returns if a user exists in the database.
Overrides:
acceptUser in class AbstractUserAdministration
Parameters:
id - The userid to check with database.
Returns:
true if the user exist, else false.

deleteUser

public boolean deleteUser(java.lang.String nick,
                          java.lang.String passwd)
                   throws java.lang.Exception
Deletes an existing user from the database.
Overrides:
deleteUser in class AbstractUserAdministration
Parameters:
nick - The nickname of the user to delete.
passwd - The password of the user to delete.
Returns:
true if the user exist and was successfully deleted, if user does not exists it returns false.
Throws:
java.lang.Exception - if user exists, but cannot be delted from database.

deleteUser

public boolean deleteUser(int id)
                   throws java.lang.Exception
Deletes an existing user from the database.
Overrides:
deleteUser in class AbstractUserAdministration
Parameters:
id - The userid to delete.
Returns:
true if the user exist and was successfully deleted, if user does not exists it returns false.
Throws:
java.lang.Exception - if user exists, but cannot be delted from database.

editUser

public User editUser(User user)
              throws java.lang.Exception
Edits an existing user from the database.
Overrides:
editUser in class AbstractUserAdministration
Parameters:
user - The user to edit.
Returns:
If the user exist and was successfully updated the old user will be returned.
Throws:
java.sql.SQLException - if database cannot be reached or problems with the SQL statements.
java.lang.Exception - if user does not exists.

editUser

public User editUser(User user,
                     java.lang.String passwd)
              throws java.lang.Exception
Edits an existing user password from the database.
Overrides:
editUser in class AbstractUserAdministration
Parameters:
user - The user to edit.
passwd - The new password.
Returns:
If the user exist and password was successfully updated the old user will be returned.
Throws:
java.sql.SQLException - if database cannot be reached or problems with the SQL statements.
java.lang.Exception - if user does not exists.

loginUser

public User loginUser(java.lang.String nick,
                      java.lang.String passwd)
               throws java.lang.Exception
Tries to login a new user.
Overrides:
loginUser in class AbstractUserAdministration
Parameters:
nick - The nickname of the user who wants to login
passwd - The password of the user who wants to login
Returns:
It returns the existing user object from the database if it exists, else null.
Throws:
java.lang.Exception - if user exists but secureIdentity could not be set.

loginUser

public User loginUser(java.lang.String nick,
                      java.lang.String passwd,
                      javax.servlet.http.HttpServletRequest request)
               throws java.lang.Exception
Tries to login a new user.
Parameters:
nick - The nickname of the user who wants to login
passwd - The password of the user who wants to login
request - The HttpServletRequest.
Returns:
It returns the existing user object from the database if it exists, else null.
Throws:
java.lang.Exception - if user exists but secureIdentity could not be set.

getUser

public User getUser(int id)
             throws java.sql.SQLException
Gets a user from the database.
Overrides:
getUser in class AbstractUserAdministration
Parameters:
id - The id of the user to get.
Returns:
The user from the database chooesen by the id, if not exists it returns null.
Throws:
java.sql.SQLException - if there is no conection to the database or problems with the SQL statements.

getUser

public User getUser(java.lang.String nick)
             throws java.sql.SQLException
Gets a user from the database.
Overrides:
getUser in class AbstractUserAdministration
Parameters:
nick - The nickname of the user to get.
Returns:
The user from the database choosen by the nickname, if not exists it returns null.
Throws:
java.sql.SQLException - if there is no conection to the database or problems with the SQL statements.

getUser

public User getUser(int id,
                    java.lang.String sid)
             throws java.sql.SQLException
Gets a user from the database.
Overrides:
getUser in class AbstractUserAdministration
Parameters:
id - The id of the user to get.
sid - The secureIdentity of the user to get,
Returns:
The user from the database choosen by the id and secureIdentity, if not exists it returns null.
Throws:
java.sql.SQLException - if there is no conection to the database or problems with the SQL statements.

getUser

public User getUser(java.lang.String nick,
                    java.lang.String passwd)
             throws java.sql.SQLException
Gets a user from the database.
Overrides:
getUser in class AbstractUserAdministration
Parameters:
nick - The nickname of the user to get.
passwd - The password of the user to get.
Returns:
The user from the database choosen by the nickname and password, if not exists it returns null.
Throws:
java.sql.SQLException - if there is no conection to the database or problems with the SQL statements.