View Javadoc
1   /*
2    * Created on Jun 6, 2005
3    *
4    * The SecurityFacade provides a simplified and unified interface to the
5    * underlying Users/Roles/Permissions model.
6    */
7   package net.sf.mindoro.domain;
8   
9   import net.sf.mindoro.dao.UserDao;
10  import net.sf.mindoro.model.SystemUser;
11  
12  /***
13   * The SecurityFacade provides a simplified and unified interface to the
14   * underlying Users/Roles/Permissions model.
15   * 
16   * @author aisrael
17   */
18  public class SecurityFacade {
19  
20      private final UserDao userDao;
21  
22      /***
23       * @param userDao
24       *            UserDao
25       */
26      public SecurityFacade(final UserDao userDao) {
27          this.userDao = userDao;
28      }
29  
30      /***
31       * Attempt to authenticate the given SystemUser.
32       * 
33       * @param user
34       *            SystemUser
35       * @return a SystemUser object from the database if the given user's credentials
36       *         are ok, null otherwise
37       */
38      public final SystemUser authenticate(final SystemUser user) {
39          SystemUser result = null;
40          final SystemUser foundUser = userDao.findUserByLogin(user.getLogin());
41          if (null != foundUser) {
42              if (foundUser.getLogin().equals(user.getLogin())
43                      && foundUser.getPasswordHash().equals(user.getPasswordHash())) {
44                  result = foundUser;
45              }
46          }
47          return result;
48      }
49  
50  }