Revision 61371
Added by Konstantinos Spyrou over 2 years ago
UserRoleController.java | ||
---|---|---|
47 | 47 |
* Get the role with the given id. |
48 | 48 |
**/ |
49 | 49 |
@RequestMapping(method = RequestMethod.GET, path = "/role/{id}") |
50 |
// @PreAuthorize("hasAnyAuthority('ROLE_USER', 'ROLE_ADMIN', 'ROLE_PROVIDE_ADMIN')")
|
|
50 |
// @PreAuthorize("hasAnyAuthority('REGISTERED_USER', 'SUPER_ADMINISTRATOR', 'CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR')")
|
|
51 | 51 |
public Response getRole(@RequestParam(value = "type", defaultValue = "datasource") String type, @PathVariable("id") String id) { |
52 | 52 |
int roleId = aaiRegistryService.getCouId(type, id); |
53 | 53 |
return Response.status(HttpStatus.OK.value()).entity(JsonUtils.createResponse("Role id is: " + roleId).toString()).type(MediaType.APPLICATION_JSON).build(); |
... | ... | |
57 | 57 |
* Create a new role with the given name and description. |
58 | 58 |
**/ |
59 | 59 |
@RequestMapping(method = RequestMethod.POST, path = "/role") |
60 |
@PreAuthorize("hasAnyAuthority('ROLE_ADMIN')")
|
|
60 |
@PreAuthorize("hasAnyAuthority('SUPER_ADMINISTRATOR')")
|
|
61 | 61 |
public Response createRole(@RequestBody Role role) { |
62 | 62 |
aaiRegistryService.createRole(role); |
63 | 63 |
return Response.status(HttpStatus.OK.value()).entity(JsonUtils.createResponse("Role has been created").toString()).type(MediaType.APPLICATION_JSON).build(); |
... | ... | |
68 | 68 |
*/ |
69 | 69 |
@ApiOperation(value = "subscribe") |
70 | 70 |
@RequestMapping(method = RequestMethod.POST, path = "/subscribe/{type}/{id}") |
71 |
@PreAuthorize("hasAnyAuthority('ROLE_ADMIN', 'ROLE_PROVIDE_ADMIN')")
|
|
71 |
@PreAuthorize("hasAnyAuthority('SUPER_ADMINISTRATOR', 'CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR')")
|
|
72 | 72 |
public Response subscribe(@PathVariable("type") String type, @PathVariable("id") String id) { |
73 | 73 |
Integer coPersonId = aaiRegistryService.getCoPersonIdByIdentifier(); |
74 | 74 |
if (coPersonId == null) { |
... | ... | |
91 | 91 |
///////////////////////////////////////////////////////////////////////////////////////////// |
92 | 92 |
|
93 | 93 |
@RequestMapping(method = RequestMethod.GET, path = "/users/couid/{id}") |
94 |
@PreAuthorize("hasAnyAuthority('ROLE_ADMIN', 'ROLE_PROVIDE_ADMIN')")
|
|
94 |
@PreAuthorize("hasAnyAuthority('SUPER_ADMINISTRATOR', 'CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR')")
|
|
95 | 95 |
public ResponseEntity<String> getUsersByCouId(@PathVariable("id") Integer id) { |
96 | 96 |
// calls.getUserByCoId() |
97 | 97 |
return ResponseEntity.ok(aaiRegistryService.getUsersByCouId(id).toString()); |
... | ... | |
99 | 99 |
|
100 | 100 |
|
101 | 101 |
@RequestMapping(method = RequestMethod.GET, path = "/users/{email}/roles") |
102 |
@PreAuthorize("hasAnyAuthority('ROLE_ADMIN', 'ROLE_PROVIDE_ADMIN') or hasRole('ROLE_USER') and authentication.userInfo.email==#email")
|
|
102 |
@PreAuthorize("hasAnyAuthority('SUPER_ADMINISTRATOR', 'CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR') or hasAuthority('REGISTERED_USER') and authentication.userInfo.email==#email")
|
|
103 | 103 |
public ResponseEntity<Collection<String>> getRolesByEmail(@PathVariable("email") String email) { |
104 | 104 |
int coPersonId = aaiRegistryService.getCoPersonIdByEmail(email); |
105 | 105 |
List<Integer> list = new ArrayList<>(); |
106 |
// FIXME: getRoles returns all roles of user, requested and active |
|
107 |
for (JsonElement element : aaiRegistryService.getRoles(coPersonId)) { |
|
106 |
for (JsonElement element : aaiRegistryService.getRolesWithStatus(coPersonId, AaiRegistryService.RoleStatus.ACTIVE)) { |
|
108 | 107 |
list.add(element.getAsJsonObject().get("CouId").getAsInt()); |
109 | 108 |
} |
110 | 109 |
return ResponseEntity.ok(aaiRegistryService.getCouNames(list).values()); |
... | ... | |
112 | 111 |
|
113 | 112 |
|
114 | 113 |
@RequestMapping(method = RequestMethod.GET, path = "/user/roles/my") |
115 |
@PreAuthorize("hasRole('ROLE_USER')")
|
|
114 |
@PreAuthorize("hasAuthority('REGISTERED_USER')")
|
|
116 | 115 |
public ResponseEntity<Collection<String>> getRoleNames() { |
117 | 116 |
List<String> roles; |
118 | 117 |
JsonArray entitlements = null; |
Also available in: Unified diff
1. changed user roles defined in the project to authorities given by the aai.
2. created method returning user roles with desired status (active, deleted).