use of javax.annotation.security.RolesAllowed in project jersey by jersey.
the class RolesAllowedDynamicFeature method configure.
@Override
public void configure(final ResourceInfo resourceInfo, final FeatureContext configuration) {
final AnnotatedMethod am = new AnnotatedMethod(resourceInfo.getResourceMethod());
// DenyAll on the method take precedence over RolesAllowed and PermitAll
if (am.isAnnotationPresent(DenyAll.class)) {
configuration.register(new RolesAllowedRequestFilter());
return;
}
// RolesAllowed on the method takes precedence over PermitAll
RolesAllowed ra = am.getAnnotation(RolesAllowed.class);
if (ra != null) {
configuration.register(new RolesAllowedRequestFilter(ra.value()));
return;
}
// PermitAll takes precedence over RolesAllowed on the class
if (am.isAnnotationPresent(PermitAll.class)) {
// Do nothing.
return;
}
// DenyAll can't be attached to classes
// RolesAllowed on the class takes precedence over PermitAll
ra = resourceInfo.getResourceClass().getAnnotation(RolesAllowed.class);
if (ra != null) {
configuration.register(new RolesAllowedRequestFilter(ra.value()));
}
}
use of javax.annotation.security.RolesAllowed in project jeeshop by remibantos.
the class Catalogs method modify.
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed(ADMIN)
public Catalog modify(Catalog catalog) {
Catalog originalCatalog = entityManager.find(Catalog.class, catalog.getId());
checkNotNull(originalCatalog);
if (catalog.getRootCategoriesIds() != null) {
List<Category> newCategories = new ArrayList<>();
catalog.getRootCategoriesIds().forEach(categoryId -> newCategories.add(entityManager.find(Category.class, categoryId)));
catalog.setRootCategories(newCategories);
} else {
catalog.setRootCategories(originalCatalog.getRootCategories());
}
catalog.setPresentationByLocale(originalCatalog.getPresentationByLocale());
return entityManager.merge(catalog);
}
use of javax.annotation.security.RolesAllowed in project jeeshop by remibantos.
the class Catalogs method findPresentationsLocales.
@GET
@Path("/{catalogId}/presentationslocales")
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({ ADMIN, ADMIN_READONLY })
public Set<String> findPresentationsLocales(@PathParam("catalogId") @NotNull Long catalogId) {
Catalog catalog = entityManager.find(Catalog.class, catalogId);
checkNotNull(catalog);
return catalog.getPresentationByLocale().keySet();
}
use of javax.annotation.security.RolesAllowed in project jeeshop by remibantos.
the class Orders method find.
@GET
@Path("/{orderId}")
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({ ADMIN, ADMIN_READONLY, USER })
public Order find(@PathParam("orderId") @NotNull Long orderId, @QueryParam("enhanced") Boolean enhanced) {
Order order = entityManager.find(Order.class, orderId);
if (sessionContext.isCallerInRole(USER) && !sessionContext.isCallerInRole(ADMIN)) {
User authenticatedUser = userFinder.findByLogin(sessionContext.getCallerPrincipal().getName());
if (!order.getUser().equals(authenticatedUser)) {
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
}
}
if (enhanced != null && enhanced) {
orderFinder.enhanceOrder(order);
}
checkNotNull(order);
return order;
}
use of javax.annotation.security.RolesAllowed in project Payara by payara.
the class CdiExtension method findRoles.
/**
* Find all the roles used by the <code>@RolesAllowed</code> annotation, so these can be programmatically
* declared later on.
*/
public <T> void findRoles(@Observes ProcessManagedBean<T> eventIn, BeanManager beanManager) {
// JDK8 u60 workaround
ProcessManagedBean<T> event = eventIn;
if (event instanceof ProcessSessionBean) {
// @RolesAllowed on session beans is already handled
return;
}
List<Annotated> annotatedElements = new ArrayList<>(event.getAnnotatedBeanClass().getMethods());
annotatedElements.add(event.getAnnotatedBeanClass());
for (Annotated annotated : annotatedElements) {
RolesAllowed rolesAllowed = annotated.getAnnotation(RolesAllowed.class);
if (rolesAllowed != null) {
roles.addAll(Arrays.asList(rolesAllowed.value()));
}
}
}
Aggregations