Creating login session.
I have a database which holds all my user information including login credentials (username, password)...
Here is how I thought of doing it...
Create a container managed entity of the table which holds the login credentials. Implement a custom finder method using ejb-ql, which in turn returns the user information, based on username and password.
Create a session bean which gathers the username and password, creates and instance of the entity bean and calls the custom finder method, passing the username and password as arguments.
Is this method corect? Also do I have to set anything special in the descriptors?
Below are the deployment descriptor values and source code...
session
display-name: Login
ejb-name: Login
home: XXX.XXXXXXXXXX.LoginHome
remote: XXX.XXXXXXXXXX.Login
ejb-class: XXX.XXXXXXXXXX.LoginBean
session-type: Stateful
transaction-type: Container
entity
display-name: MerchantInfo
ejb-name: MerchantInfo
home: XXX.XXXXXXXXXX.MerchantInfoRemoteHome
remote: XXX.XXXXXXXXXX.MerchantInfoRemote
ejb-class: XXX.XXXXXXXXXX.MerchantInfoBean
persistence-type: Container
prim-key-class: java.lang.Integer
reentrant: False
cmp-version: 2.x
abstract-schema-name: MerchantInfo
... Field mapings here.
Is the login method corect? By returning true or false? Should I track any other states etc...?
[source]
public class LoginBean implements SessionBean, SessionSynchronization
{
SessionContext sessionContext;
javax.naming.Context loginContext;
MerchantInfoRemoteHome home;
MerchantInfoRemote merchantInfo;
public void ejbCreate() throws CreateException {
try
{
loginContext = new javax.naming.InitialContext();
Object objref = loginContext.lookup("MerchantInfo");
home = (MerchantInfoRemoteHome) javax.rmi.PortableRemoteObject.narrow(objref, MerchantInfoRemoteHome.class);
}
catch(Exception ex)
{
}
}
public void ejbRemove()
{
}
public void ejbActivate()
{
}
public void ejbPassivate()
{
}
public void setSessionContext(SessionContext sessionContext)
{
this.sessionContext = sessionContext;
}
public void afterBegin()
{
}
public void beforeCompletion()
{
}
public void afterCompletion(boolean committed)
{
}
public boolean login(java.lang.Integer mid, java.lang.String uName, java.lang.String pass)
{
try
{
merchantInfo = home.findByMerchantCredentials(mid, uName, pass);
}
catch(Exception ex)
{
return(false);
}
return(true);
}
[/source]

