Commit 6a4fd2b798eb5e5662535f19c62f1e5389f5567d
1 parent
5901a972
improvement: Stärkere Kopplung in RightState-Enum
Showing
3 changed files
with
5 additions
and
8 deletions
src/main/java/net/ziemers/swxercise/lg/user/enums/RightState.java
@@ -9,12 +9,14 @@ public enum RightState { | @@ -9,12 +9,14 @@ public enum RightState { | ||
9 | NOT_LOGGED_IN(Constants.NOT_LOGGED_IN), | 9 | NOT_LOGGED_IN(Constants.NOT_LOGGED_IN), |
10 | LOGGED_IN(Constants.LOGGED_IN), | 10 | LOGGED_IN(Constants.LOGGED_IN), |
11 | ADMIN(Constants.ADMIN), | 11 | ADMIN(Constants.ADMIN), |
12 | - SUPERADMIN(Constants.SUPERADMIN), | ||
13 | ; | 12 | ; |
14 | 13 | ||
15 | private String name; | 14 | private String name; |
16 | 15 | ||
17 | RightState(final String name) { | 16 | RightState(final String name) { |
17 | + if (!this.name().equals(name)) { | ||
18 | + throw new ExceptionInInitializerError("Constant string didn't match enum name"); | ||
19 | + } | ||
18 | this.name = name; | 20 | this.name = name; |
19 | } | 21 | } |
20 | 22 | ||
@@ -33,7 +35,6 @@ public enum RightState { | @@ -33,7 +35,6 @@ public enum RightState { | ||
33 | public static final String NOT_LOGGED_IN = "NOT_LOGGED_IN"; | 35 | public static final String NOT_LOGGED_IN = "NOT_LOGGED_IN"; |
34 | public static final String LOGGED_IN = "LOGGED_IN"; | 36 | public static final String LOGGED_IN = "LOGGED_IN"; |
35 | public static final String ADMIN = "ADMIN"; | 37 | public static final String ADMIN = "ADMIN"; |
36 | - public static final String SUPERADMIN = "SUPERADMIN"; | ||
37 | } | 38 | } |
38 | 39 | ||
39 | } | 40 | } |
src/main/java/net/ziemers/swxercise/lg/user/service/UserService.java
@@ -183,10 +183,6 @@ public class UserService { | @@ -183,10 +183,6 @@ public class UserService { | ||
183 | // TODO muss noch implementiert werden | 183 | // TODO muss noch implementiert werden |
184 | return true; | 184 | return true; |
185 | } | 185 | } |
186 | - if (rightsSet.contains(RightState.Constants.SUPERADMIN)) { | ||
187 | - // TODO muss noch implementiert werden | ||
188 | - return true; | ||
189 | - } | ||
190 | } | 186 | } |
191 | return false; | 187 | return false; |
192 | } | 188 | } |
src/main/java/net/ziemers/swxercise/ui/UserViewController.java
@@ -38,7 +38,7 @@ public class UserViewController { | @@ -38,7 +38,7 @@ public class UserViewController { | ||
38 | @GET | 38 | @GET |
39 | @Path("v1/users") | 39 | @Path("v1/users") |
40 | @Produces(MediaType.APPLICATION_JSON) | 40 | @Produces(MediaType.APPLICATION_JSON) |
41 | - @RolesAllowed(RightState.Constants.SUPERADMIN) | 41 | + @RolesAllowed(RightState.Constants.ADMIN) |
42 | public Collection<User> getAllUsers() { | 42 | public Collection<User> getAllUsers() { |
43 | return userService.findAllUsers(); | 43 | return userService.findAllUsers(); |
44 | } | 44 | } |
@@ -55,7 +55,7 @@ public class UserViewController { | @@ -55,7 +55,7 @@ public class UserViewController { | ||
55 | @GET | 55 | @GET |
56 | @Path("v1/user/{id}") | 56 | @Path("v1/user/{id}") |
57 | @Produces(MediaType.APPLICATION_JSON) | 57 | @Produces(MediaType.APPLICATION_JSON) |
58 | - @RolesAllowed(RightState.Constants.SUPERADMIN) | 58 | + @RolesAllowed(RightState.Constants.ADMIN) |
59 | public User getUser(@PathParam("id") Long id) { | 59 | public User getUser(@PathParam("id") Long id) { |
60 | return userService.findUser(id); | 60 | return userService.findUser(id); |
61 | } | 61 | } |