|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.boylesoftware.cb2.BLObject com.boylesoftware.cb2.commons.user.UserBLO
Generic implementation of an application user account business entity. This BLO allows to login/logout users and manage their accounts.
This BLO requires the following initialization parameters:
UserBasicDM
or derived from it.UserBasicDM
or derived from it.This BLO implements SecurityBLI
interface so it can
be used with CB2's support for Servlet Specification user
authentication/authorization when deployed under name "user".
UserBasicDM
,
AuthenticationListener
,
Serialized FormField Summary | |
static int |
ERR_ALREADY_LOGGEDIN
Error code indicating that the user is already logged in and you are trying to log in again. |
protected static int |
ERR_BASE
Base value for error codes. |
static int |
ERR_INVALID_PASSWORD
Error code indicating that the password was invalid. |
static int |
ERR_INVALID_USERNAME
Error code indicating that the login name was invalid. |
protected java.lang.String |
fetchUserDetailsByLoginNameQN
Name of the select query in the configuration file which is used for getting a user details data model by the user's login name. |
protected UserBasicDM |
loggedInUserDM
DM of the logged in user or null if no user is
logged in. |
Fields inherited from class com.boylesoftware.cb2.BLObject |
bloc, log |
Constructor Summary | |
UserBLO()
|
Method Summary | |
void |
addUserSessionStateListener(UserSessionStateListener listener)
Registers the specified listener for user session state events. |
protected void |
destroy()
Free all used by the BLO resources. |
protected void |
fireUserLoggedInEvent(long userId)
Call userLoggedIn() method on all registered user
session state event listeners. |
protected void |
fireUserLoggedOutEvent(long userId)
Call userLoggedOut() method on all registered user
session state event listeners. |
protected void |
init()
Initializes the BLO. |
boolean |
isInRole(java.lang.String role)
Returns true if currently logged in user is in the
specified by name role. |
boolean |
isLoggedIn()
Returns true if a user is authenticated and
successfully logged in meaning that the BLO is in authenticated
mode. |
boolean |
login(java.lang.String username,
java.lang.String password)
Tries to log in the specified by login name user. |
void |
logout()
Logs out the currently logged in user. |
void |
processUserLogin(java.security.Principal principal)
Notify the BLO about a user login event. |
void |
processUserLogout()
Notify the BLO about a user logout event. |
protected void |
registerLogin(UserBasicDM dm)
Performes all internal BLO operations for a user login action. |
void |
removeUserSessionStateListener(UserSessionStateListener listener)
Removes the specified listener for user session state events from the internal list of listeners. |
Methods inherited from class com.boylesoftware.cb2.BLObject |
activate, getApplicationContext, getBLO, getBLOContainer, getDAO, getDAO, getDAOConfig, getDAOConfig, getDeploymentName, getInitParameter, getLastErrors, isRollbackOnly, setErrors, setRollbackOnly |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static final int ERR_BASE
public static final int ERR_INVALID_USERNAME
public static final int ERR_INVALID_PASSWORD
public static final int ERR_ALREADY_LOGGEDIN
protected java.lang.String fetchUserDetailsByLoginNameQN
protected UserBasicDM loggedInUserDM
null
if no user is
logged in.
Constructor Detail |
public UserBLO()
Method Detail |
protected void init() throws BLException
init
in class BLObject
BLException
- indicates a serious error, the BLO can not
be initialized.protected void destroy()
destroy
in class BLObject
public void addUserSessionStateListener(UserSessionStateListener listener)
listener
- instance of your listener which will be
receiving the notifications.public void removeUserSessionStateListener(UserSessionStateListener listener)
listener
- instance of the listener to be removed from the
notification list.protected void fireUserLoggedInEvent(long userId) throws BLException
userLoggedIn()
method on all registered user
session state event listeners.
userId
- id of the user logged in.
BLException
- if any of the listeners threw it on
userLoggedIn()
method call.protected void fireUserLoggedOutEvent(long userId) throws BLException
userLoggedOut()
method on all registered user
session state event listeners.
userId
- id of the user logged out.
BLException
- if any of the listeners threw it on
userLoggedOut()
method call.public boolean login(java.lang.String username, java.lang.String password) throws BLException
false
use getLastErrors()
method to get the reason why login was unsuccessful. Possible
error codes this method sets are
ERR_INVALID_USERNAME
,
ERR_INVALID_PASSWORD
and
ERR_ALREADY_LOGGEDIN
.
Use this method only if you implement user
authentication/authorization yourself. If you use Servlet
Specification security, that is an
SecurityAuthenticator
implementation - use the
SecurityBLI
interface instead.
username
- login name of the user to log in.password
- password to be used for log in.
true
if the user was successfully
authenticated and logged in.
BLException
- indicates a serious problem in the system.public void logout()
public boolean isLoggedIn()
true
if a user is authenticated and
successfully logged in meaning that the BLO is in authenticated
mode.
true
if the user is logged in.public boolean isInRole(java.lang.String role)
true
if currently logged in user is in the
specified by name role. If no user is currently logged in this
method always returns false
. Also, if a user is
logged in this method always returns true
for role
"user".
role
- name of the role to check. Note that the role name
is case-sensitive.
true
if the user is in the specified role.public void processUserLogin(java.security.Principal principal) throws BLException
fetchUserDetailsByLoginNameQN
init parameter) and registers the login by a
registerLogin
method call.
processUserLogin
in interface AuthenticationListener
principal
- the logged in principal.
BLException
- if an error happened and the user cannot be
logged in.public void processUserLogout()
logout
.
processUserLogout
in interface AuthenticationListener
protected void registerLogin(UserBasicDM dm) throws BLException
loggedInUserDM
internal field and fires "user logged in" event by calling
fireUserLoggedInEvent
protected method.
dm
- the logged in user's DM.
BLException
- if the login could not be processed.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |