mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
add a disabled state to users
This commit is contained in:
@@ -78,6 +78,20 @@ public abstract class GenericDAO<T, K> implements Serializable {
|
||||
return criteria.getResultList();
|
||||
}
|
||||
|
||||
public List<T> findAll(int startIndex, int count, String orderBy,
|
||||
boolean asc) {
|
||||
EasyCriteria<T> criteria = EasyCriteriaFactory.createQueryCriteria(em,
|
||||
getType());
|
||||
criteria.setMaxResults(count);
|
||||
criteria.setFirstResult(startIndex);
|
||||
if (asc) {
|
||||
criteria.orderByAsc(orderBy);
|
||||
} else {
|
||||
criteria.orderByDesc(orderBy);
|
||||
}
|
||||
return criteria.getResultList();
|
||||
}
|
||||
|
||||
public long getCount() {
|
||||
CriteriaBuilder builder = em.getCriteriaBuilder();
|
||||
CriteriaQuery<Long> query = builder.createQuery(Long.class);
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
package com.commafeed.backend.dao;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ejb.Stateless;
|
||||
|
||||
import com.commafeed.backend.model.User;
|
||||
import com.commafeed.backend.model.UserRole;
|
||||
import com.commafeed.frontend.utils.ModelFactory.MF;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
@Stateless
|
||||
public class UserRoleService extends GenericDAO<UserRole, Long> {
|
||||
|
||||
public List<String> getRoles(User user) {
|
||||
List<String> list = Lists.newArrayList();
|
||||
public Set<String> getRoles(User user) {
|
||||
Set<String> list = Sets.newHashSet();
|
||||
for (UserRole role : findByField(MF.i(proxy().getUser()), user)) {
|
||||
list.add(role.getRole());
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public class UserService extends GenericDAO<User, Long> {
|
||||
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);
|
||||
if (user != null) {
|
||||
if (user != null && !user.isDisabled()) {
|
||||
boolean authenticated = encryptionService.authenticate(password,
|
||||
user.getPassword(), user.getSalt());
|
||||
if (authenticated) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.Set;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@@ -27,7 +28,10 @@ public class User extends AbstractModel {
|
||||
@Column(length = 8, nullable = false)
|
||||
private byte[] salt;
|
||||
|
||||
@OneToMany(mappedBy = "user", cascade = CascadeType.PERSIST)
|
||||
@Column(nullable = false)
|
||||
private boolean disabled;
|
||||
|
||||
@OneToMany(mappedBy = "user", cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
|
||||
private Set<UserRole> roles = Sets.newHashSet();
|
||||
|
||||
public String getName() {
|
||||
@@ -62,4 +66,12 @@ public class User extends AbstractModel {
|
||||
this.roles = roles;
|
||||
}
|
||||
|
||||
public boolean isDisabled() {
|
||||
return disabled;
|
||||
}
|
||||
|
||||
public void setDisabled(boolean disabled) {
|
||||
this.disabled = disabled;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user