RoleViewController.java
1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package net.ziemers.swxercise.ui;
import net.ziemers.swxercise.lg.model.user.Role;
import net.ziemers.swxercise.lg.user.dto.RoleDto;
import net.ziemers.swxercise.lg.user.enums.RightState;
import net.ziemers.swxercise.lg.user.service.RoleService;
import javax.annotation.security.RolesAllowed;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import java.util.Collection;
/**
* REST-Methoden für die Rollen- und Rechteverwaltung.
*/
@ApplicationScoped
@Path(RoleViewController.webContextPath)
public class RoleViewController {
static final String webContextPath = "/";
@Inject
private RoleService roleService;
/**
* Liefert alle Rollen-Objekte zurück.
* <p>
* Aufruf:
* GET http://localhost:8080/swxercise/rest/v1/roles
*
* @return die Rollen-Objekte, oder ein leeres JSON-Array, falls keine existieren.
*/
@GET
@Path("v1/roles")
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed(RightState.Constants.ADMIN)
public Collection<Role> getAllRoles() {
return roleService.findAllRoles();
}
/**
* Erstellt eine neue Rolle.
*
* @param dto
* @return
*/
@POST
@Path("v1/role")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed(RightState.Constants.ADMIN)
public RestResponse createRole(RoleDto dto) {
Long id = roleService.createRole(dto);
return new RestResponse();
}
}