Change roles to MSRead, MSWrite
This commit is contained in:
parent
56d8f7fca7
commit
16041ef050
@ -11,7 +11,6 @@ import java.net.URI;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Path("/movie")
|
@Path("/movie")
|
||||||
@RolesAllowed("MoviesUserRole")
|
|
||||||
public class MovieResource {
|
public class MovieResource {
|
||||||
@Inject
|
@Inject
|
||||||
private MoviesService moviesService;
|
private MoviesService moviesService;
|
||||||
@ -24,6 +23,7 @@ public class MovieResource {
|
|||||||
MediaType.APPLICATION_JSON,
|
MediaType.APPLICATION_JSON,
|
||||||
MediaType.APPLICATION_XML
|
MediaType.APPLICATION_XML
|
||||||
})
|
})
|
||||||
|
@RolesAllowed("MSRead")
|
||||||
public List<Movie> retrieveAll() {
|
public List<Movie> retrieveAll() {
|
||||||
return moviesService.findAll();
|
return moviesService.findAll();
|
||||||
}
|
}
|
||||||
@ -33,6 +33,7 @@ public class MovieResource {
|
|||||||
MediaType.APPLICATION_JSON,
|
MediaType.APPLICATION_JSON,
|
||||||
MediaType.APPLICATION_XML
|
MediaType.APPLICATION_XML
|
||||||
})
|
})
|
||||||
|
@RolesAllowed("MSRead")
|
||||||
@Path("/{id}")
|
@Path("/{id}")
|
||||||
public Movie retrieve(@PathParam("id") long id) {
|
public Movie retrieve(@PathParam("id") long id) {
|
||||||
return moviesService.findById(id);
|
return moviesService.findById(id);
|
||||||
@ -40,6 +41,7 @@ public class MovieResource {
|
|||||||
|
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("/{id}")
|
@Path("/{id}")
|
||||||
|
@RolesAllowed("MSWrite")
|
||||||
public void delete(@PathParam("id") long id) {
|
public void delete(@PathParam("id") long id) {
|
||||||
moviesService.removeById(id);
|
moviesService.removeById(id);
|
||||||
}
|
}
|
||||||
@ -49,6 +51,7 @@ public class MovieResource {
|
|||||||
MediaType.APPLICATION_JSON,
|
MediaType.APPLICATION_JSON,
|
||||||
MediaType.APPLICATION_XML
|
MediaType.APPLICATION_XML
|
||||||
})
|
})
|
||||||
|
@RolesAllowed("MSWrite")
|
||||||
public Response create(Movie movie) {
|
public Response create(Movie movie) {
|
||||||
movie.setId(null); // Make sure that a new movie is added, not overwriting existing one
|
movie.setId(null); // Make sure that a new movie is added, not overwriting existing one
|
||||||
List<Movie> newMovies = moviesService.save(List.of(movie));
|
List<Movie> newMovies = moviesService.save(List.of(movie));
|
||||||
@ -64,6 +67,7 @@ public class MovieResource {
|
|||||||
MediaType.APPLICATION_XML
|
MediaType.APPLICATION_XML
|
||||||
})
|
})
|
||||||
@Path("/{id}")
|
@Path("/{id}")
|
||||||
|
@RolesAllowed("MSWrite")
|
||||||
public void update(@PathParam("id") long id, Movie movie) {
|
public void update(@PathParam("id") long id, Movie movie) {
|
||||||
movie.setId(id); // Make sure that a new movie is added, not overwriting existing one
|
movie.setId(id); // Make sure that a new movie is added, not overwriting existing one
|
||||||
moviesService.save(List.of(movie));
|
moviesService.save(List.of(movie));
|
||||||
|
@ -7,8 +7,8 @@ import javax.security.enterprise.identitystore.DatabaseIdentityStoreDefinition;
|
|||||||
|
|
||||||
@BasicAuthenticationMechanismDefinition(realmName = "MoviesWebApp")
|
@BasicAuthenticationMechanismDefinition(realmName = "MoviesWebApp")
|
||||||
@DeclareRoles({
|
@DeclareRoles({
|
||||||
"MoviesAdminRole",
|
"MSRead",
|
||||||
"MoviesUerRole"
|
"MSWrite"
|
||||||
})
|
})
|
||||||
@DatabaseIdentityStoreDefinition(
|
@DatabaseIdentityStoreDefinition(
|
||||||
dataSourceLookup = "java:jboss/datasources/MoviesDS",
|
dataSourceLookup = "java:jboss/datasources/MoviesDS",
|
||||||
|
@ -14,7 +14,6 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
@Stateless
|
@Stateless
|
||||||
@TransactionManagement(value=TransactionManagementType.CONTAINER)
|
@TransactionManagement(value=TransactionManagementType.CONTAINER)
|
||||||
@RolesAllowed("MoviesUserRole")
|
|
||||||
public class MoviesService {
|
public class MoviesService {
|
||||||
private static final Logger LOGGER = Logger.getLogger(MoviesService.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(MoviesService.class.getName());
|
||||||
|
|
||||||
@ -27,6 +26,7 @@ public class MoviesService {
|
|||||||
@Inject
|
@Inject
|
||||||
private SecurityContext securityContext;
|
private SecurityContext securityContext;
|
||||||
|
|
||||||
|
@RolesAllowed("MSRead")
|
||||||
public Movie findById(long id) {
|
public Movie findById(long id) {
|
||||||
LOGGER.info("findById() >> id=" + id);
|
LOGGER.info("findById() >> id=" + id);
|
||||||
|
|
||||||
@ -38,6 +38,7 @@ public class MoviesService {
|
|||||||
return movie;
|
return movie;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RolesAllowed("MSRead")
|
||||||
public List<Movie> findByTitle(String title) {
|
public List<Movie> findByTitle(String title) {
|
||||||
LOGGER.info("findByTitle() >> title=" + title);
|
LOGGER.info("findByTitle() >> title=" + title);
|
||||||
|
|
||||||
@ -46,6 +47,7 @@ public class MoviesService {
|
|||||||
.getResultList();
|
.getResultList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RolesAllowed("MSRead")
|
||||||
public List<Movie> findAll() {
|
public List<Movie> findAll() {
|
||||||
LOGGER.info("findAll()");
|
LOGGER.info("findAll()");
|
||||||
|
|
||||||
@ -56,6 +58,7 @@ public class MoviesService {
|
|||||||
.getResultList();
|
.getResultList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RolesAllowed("MSWrite")
|
||||||
public void removeById(long id) {
|
public void removeById(long id) {
|
||||||
LOGGER.info("removeById() >> id=" + id);
|
LOGGER.info("removeById() >> id=" + id);
|
||||||
|
|
||||||
@ -63,6 +66,7 @@ public class MoviesService {
|
|||||||
em.remove(movie); //managed news required
|
em.remove(movie); //managed news required
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RolesAllowed("MSRead")
|
||||||
public List<Actor> findAllActors() {
|
public List<Actor> findAllActors() {
|
||||||
LOGGER.info("findAllActors)");
|
LOGGER.info("findAllActors)");
|
||||||
|
|
||||||
@ -70,6 +74,7 @@ public class MoviesService {
|
|||||||
.getResultList();
|
.getResultList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RolesAllowed("MSRead")
|
||||||
public List<Studio> findAllStudios() {
|
public List<Studio> findAllStudios() {
|
||||||
LOGGER.info("findAllStudios)");
|
LOGGER.info("findAllStudios)");
|
||||||
|
|
||||||
@ -77,6 +82,7 @@ public class MoviesService {
|
|||||||
.getResultList();
|
.getResultList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RolesAllowed("MSRead")
|
||||||
public Studio findStudioById(long id) {
|
public Studio findStudioById(long id) {
|
||||||
LOGGER.info("findStudioById() >> id=" + id);
|
LOGGER.info("findStudioById() >> id=" + id);
|
||||||
|
|
||||||
@ -88,8 +94,8 @@ public class MoviesService {
|
|||||||
return studio;
|
return studio;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO maybe check if the movie already exists?
|
|
||||||
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
|
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
|
||||||
|
@RolesAllowed("MSWrite")
|
||||||
public List<Movie> save(List<Movie> movies) {
|
public List<Movie> save(List<Movie> movies) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -11,7 +11,6 @@ import java.net.URI;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Path("/studio")
|
@Path("/studio")
|
||||||
@RolesAllowed("MoviesUserRole")
|
|
||||||
public class StudioResource {
|
public class StudioResource {
|
||||||
@Inject
|
@Inject
|
||||||
private MoviesService moviesService;
|
private MoviesService moviesService;
|
||||||
@ -24,6 +23,7 @@ public class StudioResource {
|
|||||||
MediaType.APPLICATION_JSON,
|
MediaType.APPLICATION_JSON,
|
||||||
MediaType.APPLICATION_XML
|
MediaType.APPLICATION_XML
|
||||||
})
|
})
|
||||||
|
@RolesAllowed("MSRead")
|
||||||
public List<Studio> retrieveAll() {
|
public List<Studio> retrieveAll() {
|
||||||
return moviesService.findAllStudios();
|
return moviesService.findAllStudios();
|
||||||
}
|
}
|
||||||
@ -34,6 +34,7 @@ public class StudioResource {
|
|||||||
MediaType.APPLICATION_XML
|
MediaType.APPLICATION_XML
|
||||||
})
|
})
|
||||||
@Path("/{id}")
|
@Path("/{id}")
|
||||||
|
@RolesAllowed("MSRead")
|
||||||
public Studio retrieve(@PathParam("id") long id) {
|
public Studio retrieve(@PathParam("id") long id) {
|
||||||
return moviesService.findStudioById(id);
|
return moviesService.findStudioById(id);
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,11 @@ CREATE TABLE t_user_role (
|
|||||||
INSERT INTO t_user (id, username, password) VALUES (1, 'moviesadmin', SHA2('topsecret', 512));
|
INSERT INTO t_user (id, username, password) VALUES (1, 'moviesadmin', SHA2('topsecret', 512));
|
||||||
INSERT INTO t_user (id, username, password) VALUES (2, 'moviesuser', SHA2('topsecret', 512));
|
INSERT INTO t_user (id, username, password) VALUES (2, 'moviesuser', SHA2('topsecret', 512));
|
||||||
|
|
||||||
INSERT INTO t_role (id, rolename) VALUES (1, 'MoviesAdminRole');
|
INSERT INTO t_role (id, rolename) VALUES (1, 'MSWrite');
|
||||||
INSERT INTO t_role (id, rolename) VALUES (2, 'MoviesUserRole');
|
INSERT INTO t_role (id, rolename) VALUES (2, 'MSRead');
|
||||||
|
|
||||||
INSERT INTO t_user_role (id, userid, roleid) VALUES (1, 1, 1);
|
-- TODO: Would be nice to add a trigger which automatically adds MSWrite users into MSRead
|
||||||
INSERT INTO t_user_role (id, userid, roleid) VALUES (2, 2, 2);
|
|
||||||
|
INSERT INTO t_user_role (id, userid, roleid) VALUES (1, 1, 1); -- Admin can write
|
||||||
|
INSERT INTO t_user_role (id, userid, roleid) VALUES (2, 1, 2); -- Admin can read
|
||||||
|
INSERT INTO t_user_role (id, userid, roleid) VALUES (3, 2, 2); -- User can read
|
Loading…
x
Reference in New Issue
Block a user