@Singleton
public class AuthenticationService
extends java.lang.Object
Authentication
controller and the @Authenticated annotation defined in AuthenticationAction
.
If a user is authenticated (same password as stored in the database) a user session ID is generated and stored in
Play's session cookie and in the the cache. With each subsequent request this session is checked in the
AuthenticationAction.Modifier and Type | Field and Description |
---|---|
static java.lang.String |
LOGGED_IN_USER
Key name used in RequestScope to store the logged-in User
|
static java.lang.String |
SESSION_ID
Parameter name in Play's session cookie: It contains the username of the logged in user
|
static java.lang.String |
SESSION_LAST_ACTIVITY_TIME
Parameter name in Play's session cookie: It contains a timestamp of the
time of the last HTTP request done by the browser with this cookie
|
static java.lang.String |
SESSION_LOGIN_TIME
Parameter name in Play's session cookie: It contains the timestamp of the login time
|
static java.lang.String |
SESSION_USERNAME
Parameter name in Play's session cookie: It contains the username of the logged in user
|
Modifier and Type | Method and Description |
---|---|
boolean |
authenticate(User user,
java.lang.String password)
Authenticates the user with the given password.
|
void |
clearSessionCookie(play.mvc.Http.Session session)
Deletes the session cookie.
|
void |
clearSessionCookieAndSessionCache(play.mvc.Http.Session session,
java.lang.String normalizedUsername,
java.lang.String remoteAddress)
Deletes the session cookie and removes the cache entry.
|
com.google.api.client.googleapis.auth.oauth2.GoogleIdToken |
fetchOAuthGoogleIdToken(java.lang.String idTokenString)
Verifies and fetches an ID token from Google OAuth by sending an HTTP POST to Google.
|
User |
getLoggedInUser()
Gets the logged-in user from the RequestScope.
|
User |
getLoggedInUserBySessionCookie(play.mvc.Http.Session session)
Retrieves the logged-in user from Play's session.
|
boolean |
isInactivityTimeout(play.mvc.Http.Session session)
Returns true if the session inactivity time as saved in Play's session
cookie is older than allowed.
|
boolean |
isRepeatedLoginAttempt(java.lang.String normalizedUsername)
Checks the user session cache whether this user tries to login repeatedly
|
boolean |
isSessionTimeout(play.mvc.Http.Session session)
Returns true if the session login time as saved in Play's session cookie
is older than allowed.
|
boolean |
isValidSessionId(play.mvc.Http.Session session,
java.lang.String normalizedUsername,
java.lang.String remoteAddress)
Checks the session ID stored in Play's session cookie whether it is the
same as stored in the cache during the last login.
|
void |
refreshSessionCookie(play.mvc.Http.Session session)
Refreshes the last activity timestamp in Play's session cookie.
|
void |
setLastSeen(java.lang.String normalizedUsername)
Sets the time of the last activity of the given user
|
void |
writeSessionCookieAndSessionCache(play.mvc.Http.Session session,
java.lang.String normalizedUsername,
java.lang.String remoteAddress)
Prepares Play's session cookie and the user session cache for the user
with the given username to be logged-in.
|
public static final java.lang.String SESSION_ID
public static final java.lang.String SESSION_USERNAME
public static final java.lang.String SESSION_LOGIN_TIME
public static final java.lang.String SESSION_LAST_ACTIVITY_TIME
public static final java.lang.String LOGGED_IN_USER
public boolean authenticate(User user, java.lang.String password) throws javax.naming.NamingException
javax.naming.NamingException
public com.google.api.client.googleapis.auth.oauth2.GoogleIdToken fetchOAuthGoogleIdToken(java.lang.String idTokenString) throws java.security.GeneralSecurityException, java.io.IOException
java.security.GeneralSecurityException
java.io.IOException
public boolean isRepeatedLoginAttempt(java.lang.String normalizedUsername)
public User getLoggedInUserBySessionCookie(play.mvc.Http.Session session)
In most cases getLoggedInUser() is faster since it doesn't has to query the database.
public User getLoggedInUser()
public void writeSessionCookieAndSessionCache(play.mvc.Http.Session session, java.lang.String normalizedUsername, java.lang.String remoteAddress)
public void refreshSessionCookie(play.mvc.Http.Session session)
public void clearSessionCookie(play.mvc.Http.Session session)
public void clearSessionCookieAndSessionCache(play.mvc.Http.Session session, java.lang.String normalizedUsername, java.lang.String remoteAddress)
public boolean isValidSessionId(play.mvc.Http.Session session, java.lang.String normalizedUsername, java.lang.String remoteAddress)
public boolean isSessionTimeout(play.mvc.Http.Session session)
public boolean isInactivityTimeout(play.mvc.Http.Session session)
public void setLastSeen(java.lang.String normalizedUsername)