Files
Athou_commafeed/src/main/java/com/commafeed/backend/dao/UserService.java

34 lines
905 B
Java
Raw Normal View History

2013-03-20 20:33:42 +01:00
package com.commafeed.backend.dao;
import java.util.List;
import javax.ejb.Stateless;
2013-03-20 20:33:42 +01:00
import javax.inject.Inject;
2013-03-23 16:17:19 +01:00
import com.commafeed.backend.model.User;
2013-03-20 20:33:42 +01:00
import com.commafeed.backend.security.PasswordEncryptionService;
import com.commafeed.frontend.utils.ModelFactory.MF;
import com.google.common.collect.Iterables;
@Stateless
2013-03-25 12:24:00 +01:00
@SuppressWarnings("serial")
2013-03-20 20:33:42 +01:00
public class UserService extends GenericDAO<User, Long> {
@Inject
PasswordEncryptionService encryptionService;
public User login(String name, String password) {
List<User> users = findByField(MF.i(MF.p(User.class).getName()), name);
User user = Iterables.getFirst(users, null);
2013-03-29 12:59:21 +01:00
if (user != null && !user.isDisabled()) {
2013-03-20 20:33:42 +01:00
boolean authenticated = encryptionService.authenticate(password,
user.getPassword(), user.getSalt());
if (authenticated) {
return user;
}
}
return null;
}
}