Roberto Sánchez
2014-01-13 b78e64a272fac635db7b3301252830488829fefd
securis/src/main/java/net/curisit/securis/db/User.java
....@@ -88,12 +88,23 @@
8888 this.password = password;
8989 }
9090
91
- public int getRoles() {
92
- return roles;
91
+ public List<Integer> getRoles() {
92
+ if (roles == 0)
93
+ return null;
94
+ List<Integer> aux = new ArrayList<>();
95
+ for (int rol : Rol.ALL) {
96
+ if ((roles & rol) != 0) // Each rol is a number with only 1 bit == 1 in binary representation
97
+ aux.add(rol);
98
+ }
99
+ return aux;
93100 }
94101
95
- public void setRoles(int roles) {
96
- this.roles = roles;
102
+ public void setRoles(List<Integer> roles) {
103
+ this.roles = 0;
104
+ if (roles != null)
105
+ for (Integer rol : roles) {
106
+ this.roles |= rol;
107
+ }
97108 }
98109
99110 public String getFirstName() {
....@@ -181,6 +192,8 @@
181192 static public class Rol {
182193 static public final int ADVANCE = 0x01;
183194 static public final int ADMIN = 0x02;
195
+ static public final int[] ALL = new int[]
196
+ { ADVANCE, ADMIN };
184197 }
185198
186199 }