Added method isInRole to User in order to make it more coherent with SecurityUtils.isUserInRole.
FEA: ItEr60S04ValidacionEProbasFuncionaisItEr59S04
This commit is contained in:
parent
332bbe583d
commit
b889574640
2 changed files with 18 additions and 5 deletions
|
|
@ -24,7 +24,6 @@ import java.math.BigDecimal;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.hibernate.Query;
|
||||
|
|
@ -184,9 +183,8 @@ public class OrderDAO extends IntegrationEntityDAO<Order> implements
|
|||
|
||||
@Override
|
||||
public List<Order> getOrdersByReadAuthorization(User user) {
|
||||
Set<UserRole> roles = user.getAllRoles();
|
||||
if (roles.contains(UserRole.ROLE_READ_ALL_ORDERS) ||
|
||||
roles.contains(UserRole.ROLE_EDIT_ALL_ORDERS)) {
|
||||
if (user.isInRole(UserRole.ROLE_READ_ALL_ORDERS) ||
|
||||
user.isInRole(UserRole.ROLE_EDIT_ALL_ORDERS)) {
|
||||
return getOrders();
|
||||
}
|
||||
else {
|
||||
|
|
@ -209,7 +207,7 @@ public class OrderDAO extends IntegrationEntityDAO<Order> implements
|
|||
|
||||
@Override
|
||||
public List<Order> getOrdersByWriteAuthorization(User user) {
|
||||
if (user.getAllRoles().contains(UserRole.ROLE_EDIT_ALL_ORDERS)) {
|
||||
if (user.isInRole(UserRole.ROLE_EDIT_ALL_ORDERS)) {
|
||||
return getOrders();
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
|
|
@ -122,6 +122,21 @@ public class User extends BaseEntity {
|
|||
return allRoles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if current user is in the requested role
|
||||
*/
|
||||
public boolean isInRole(UserRole role) {
|
||||
if (roles.contains(role)) {
|
||||
return true;
|
||||
}
|
||||
for (Profile profile : profiles) {
|
||||
if (profile.getRoles().contains(role)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue