|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.jfw.authentication.Authentication
public class Authentication
Used in the authentication phase.
The methods are logically divided in two categories:
Authentication authentication = new Authentication();
UserData userData = authentication.authenticate(request, response);
if(userData != null)
System.out.println("user is authenticated");
else
{
System.out.println("user is not authenticated");
System.out.println("- username and/or password not found in request");
System.out.println("- username and password found in request but not belong at a registered user");
}
Field Summary | |
---|---|
static java.lang.String |
PASSWORD_IN_REQUEST_KEY
The request parameter name of password field. |
static java.lang.String |
USER_DATA_IN_REQUEST_KEY
The request attribute key associated with UserData object. |
static java.lang.String |
USER_DATA_IN_SESSION_KEY
The session attribute key associated with UserData object. |
static java.lang.String |
USER_PROFILE_IN_REQUEST_KEY
The request attribute key associated with UserProfile object. |
static java.lang.String |
USER_PROFILE_IN_SESSION_KEY
The session attribute key associated with UserProfile object. |
static java.lang.String |
USERNAME_IN_REQUEST_KEY
The request parameter name of username field. |
Constructor Summary | |
---|---|
Authentication()
Create an instance. |
|
Authentication(java.lang.String connectionResourceName)
Create an instance. |
Method Summary | |
---|---|
static void |
addUserDataInCookie(javax.servlet.http.HttpServletResponse response,
UserData userData)
Create a cookie with username and user id. |
static void |
addUserDataInSession(javax.servlet.http.HttpSession session,
UserData userData)
Add in session: the UserData object with key
USER_DATA_IN_SESSION_KEY
the UserProfile object with key
USER_PROFILE_IN_SESSION_KEY . |
UserData |
authenticate(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
User authentication. |
boolean |
existUserInRequest(javax.servlet.http.HttpServletRequest request)
Check if parameters username and password found in HttpServletRequest. |
static java.lang.String |
getPasswordFromRequest(javax.servlet.http.HttpServletRequest request)
Return the value of request parameter password. |
static UserData |
getUserDataFromCookie(javax.servlet.http.HttpServletRequest request)
Get user credentials from the authentication cookie. |
static UserData |
getUserDataFromDB(java.lang.String username,
java.lang.String password,
java.lang.String userId)
Call method getUserDataFromDB(String,String,String,HashMap) ,
the value of parameter outputdata is null. |
static UserData |
getUserDataFromDB(java.lang.String username,
java.lang.String password,
java.lang.String userId,
java.util.HashMap outputdata)
Get user data from database. |
static java.lang.String |
getUsernameFromRequest(javax.servlet.http.HttpServletRequest request)
Return the value of request parameter username. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String USER_DATA_IN_SESSION_KEY
UserData
object.
public static final java.lang.String USER_DATA_IN_REQUEST_KEY
UserData
object.
public static final java.lang.String USER_PROFILE_IN_SESSION_KEY
UserProfile
object.
public static final java.lang.String USER_PROFILE_IN_REQUEST_KEY
UserProfile
object.
public static final java.lang.String USERNAME_IN_REQUEST_KEY
public static final java.lang.String PASSWORD_IN_REQUEST_KEY
Constructor Detail |
---|
public Authentication()
public Authentication(java.lang.String connectionResourceName)
connectionResourceName
- the database resource to use.Method Detail |
---|
public UserData authenticate(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.lang.Exception
request
- an HttpServletRequest object.response
- an HttpServletResponse object.
UserData
object exist in
HttpSession (associated with key USER_DATA_IN_SESSION_KEY
).
AuthenticationCookie.write(javax.servlet.http.HttpServletResponse, com.jfw.authentication.UserData, java.lang.String, java.lang.String, java.lang.String, java.lang.String, int)
with name
AuthenticationCookie.COOKIE_NAME
found and
contains credential data of an existing user.java.lang.Exception
public boolean existUserInRequest(javax.servlet.http.HttpServletRequest request)
request
- an HttpServletRequest object.
public static java.lang.String getUsernameFromRequest(javax.servlet.http.HttpServletRequest request)
request
- an HttpServletRequest object.
public static java.lang.String getPasswordFromRequest(javax.servlet.http.HttpServletRequest request)
request
- an HttpServletRequest object.
public static UserData getUserDataFromDB(java.lang.String username, java.lang.String password, java.lang.String userId, java.util.HashMap outputdata) throws java.lang.Exception
username
- the username to use. null is a valid value
if userId is not null.password
- the password to use. null is a valid value
if userId is not null.userId
- the user id to use. null is a valid value
if username and password are not null.outputdata
- the HashMap to use for save data readed from database.
See UserDataDB.execute(java.util.HashMap)
.
UserData
object or null
if user not found in database.
java.lang.Exception
UserDataDB
public static UserData getUserDataFromDB(java.lang.String username, java.lang.String password, java.lang.String userId) throws java.lang.Exception
getUserDataFromDB(String,String,String,HashMap)
,
the value of parameter outputdata is null.
username
- the username to use. null is a valid value
if userId is not null.password
- the password to use. null is a valid value
if userId is not null.userId
- the user id to use. null is a valid value
if username and password are not null.
java.lang.Exception
public static UserData getUserDataFromCookie(javax.servlet.http.HttpServletRequest request) throws java.lang.Exception
getUserDataFromDB(java.lang.String, java.lang.String, java.lang.String, java.util.HashMap)
and set:
request
- an HttpServletRequest object.
getUserDataFromDB(java.lang.String, java.lang.String, java.lang.String, java.util.HashMap)
.
java.lang.Exception
AuthenticationCookie
public static void addUserDataInSession(javax.servlet.http.HttpSession session, UserData userData)
UserData
object with key
USER_DATA_IN_SESSION_KEY
UserProfile
object with key
USER_PROFILE_IN_SESSION_KEY
.
session
- an HttpSession object.userData
- an UserData
object.public static void addUserDataInCookie(javax.servlet.http.HttpServletResponse response, UserData userData)
response
- an HttpServletResponse object.userData
- an UserData
object.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |