📄 loginworkflowbean.java
字号:
package com.wiley.compBooks.EJwithUML.TimeCardWorkflow;
import com.wiley.compBooks.EJwithUML.Base.EjbUtil.*;
import com.wiley.compBooks.EJwithUML.TimeCardDomain.*;
import com.wiley.compBooks.EJwithUML.Base.ApplicationExceptions.*;
import java.util.*;
import java.rmi.*;
import javax.ejb.*;
import javax.naming.*;
/**
* The LoginWorkflow allows client objects to validate users and update their
* paswords. LoginWorkflowBean is the actual session bean implementation.
*/
public class LoginWorkflowBean extends BasicSessionBean
{
public void ejbCreate() throws CreateException
{
System.out.println("in ejbCreate() of LoginWorkflowBean!");
}
public void ejbPostCreate()
{
System.out.println("in ejbPostCreate() of LoginWorkflowBean!");
}
/** Answers true if the password is correct for the specified user. */
public boolean isUserValid(String username, String password) throws DataNotFoundException
{
UserLocal user = findUser(username);
return user.isPasswordValid(password);
}
/** Answers true if the password is due to be changed. */
public boolean isPasswordChangeRequired(String username) throws DataNotFoundException
{
UserLocal user = findUser(username);
return user.isPasswordChangeRequired();
}
/** Sets the password, if the old password is valid. */
public void setPassword(String username, String oldPassword, String newPassword)
throws InvalidDataException, DataNotFoundException
{
UserLocal user = findUser(username);
if (!user.isPasswordValid(oldPassword))
{
throw new InvalidDataException(Origin.LOGIN_WORKFLOW, "Old password is invalid.");
}
user.setPassword(newPassword);
}
private UserLocal findUser(String username) throws DataNotFoundException
{
try
{
Context initialContext = getInitialContext();
UserLocalHome uhome = (UserLocalHome)initialContext.lookup(EjbReferenceNames.USER_HOME);
Collection users = uhome.findByUserName(username);
UserLocal user = null;
if (users.isEmpty())
{
throw new DataNotFoundException(Origin.LOGIN_WORKFLOW, "User(" + username + ") Not Found");
}
else
{
user = (UserLocal) users.iterator().next();
}
return user;
}
catch (NamingException e)
{
throw new DataNotFoundException(Origin.LOGIN_WORKFLOW, e, "User Bean Not Found");
}
catch (FinderException e)
{
throw new DataNotFoundException(Origin.LOGIN_WORKFLOW, e, "User(" + username + ") Not Found");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -