View Javadoc

1   /*
2   Copyright 2010 James Pether Sörling Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 
3   	$Id
4   */
5   
6   package com.hack23.cia.service.dao;
7   
8   import java.util.List;
9   
10  import org.hibernate.criterion.DetachedCriteria;
11  import org.hibernate.criterion.Restrictions;
12  import org.springframework.transaction.annotation.Transactional;
13  
14  import com.hack23.cia.model.application.impl.common.User;
15  
16  /***
17   * The Class UserDAOImpl.
18   */
19  public class UserDAOImpl extends GenericHibernateDAO<User, Long> implements
20          UserDAO {
21  
22      /***
23       * Instantiates a new user dao impl.
24       */
25      public UserDAOImpl() {
26          super(User.class);
27      }
28  
29      /*
30       * (non-Javadoc)
31       * 
32       * @see com.hack23.cia.service.dao.UserDAO#getIfValidUser(java.lang.String,
33       * java.lang.String)
34       */
35      @Override
36  	@SuppressWarnings("unchecked")
37  	@Transactional(readOnly = true)
38      public final User getIfValidUser(final String username,
39              final String encodedPassword) {
40          final DetachedCriteria findUserByName = DetachedCriteria.forClass(User.class);
41          findUserByName.add(Restrictions.eq("username", username)); //$NON-NLS-1$
42          findUserByName.add(Restrictions.eq("password", encodedPassword)); //$NON-NLS-1$
43  
44          final List<User> result = this.getHibernateTemplate().findByCriteria(
45                  findUserByName);
46  
47          User user = null;
48          if (!result.isEmpty()) {
49              user = result.get(0);
50          }
51          return user;
52      }
53  
54  }