Search in sources :

Example 41 with RolesAllowed

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)
@Transactional
@RolesAllowed({ ADMIN, STORE_ADMIN })
public Catalog modify(@Context SecurityContext securityContext, Catalog catalogToModify) {
    Catalog originalCatalog = entityManager.find(Catalog.class, catalogToModify.getId());
    checkNotNull(originalCatalog);
    if (!isAdminUser(securityContext) && !isOwner(securityContext, originalCatalog.getOwner()))
        throw new WebApplicationException(Response.Status.FORBIDDEN);
    if (catalogToModify.getRootCategoriesIds() != null) {
        List<Category> newCategories = new ArrayList<>();
        catalogToModify.getRootCategoriesIds().forEach(categoryId -> newCategories.add(entityManager.find(Category.class, categoryId)));
        catalogToModify.setRootCategories(newCategories);
    } else {
        catalogToModify.setRootCategories(originalCatalog.getRootCategories());
    }
    catalogToModify.setPresentationByLocale(originalCatalog.getPresentationByLocale());
    return entityManager.merge(catalogToModify);
}
Also used : Category(org.rembx.jeeshop.catalog.model.Category) WebApplicationException(org.rembx.jeeshop.rest.WebApplicationException) ArrayList(java.util.ArrayList) Catalog(org.rembx.jeeshop.catalog.model.Catalog) RolesAllowed(javax.annotation.security.RolesAllowed) Transactional(javax.transaction.Transactional)

Example 42 with RolesAllowed

use of javax.annotation.security.RolesAllowed in project jeeshop by remibantos.

the class Products method findPresentationsLocales.

@GET
@Path("/{productId}/presentationslocales")
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({ ADMIN, STORE_ADMIN, ADMIN_READONLY })
public Set<String> findPresentationsLocales(@Context SecurityContext securityContext, @PathParam("productId") @NotNull Long productId) {
    Product product = entityManager.find(Product.class, productId);
    checkNotNull(product);
    if (!isAdminUser(securityContext) && !isOwner(securityContext, product.getOwner()))
        throw new WebApplicationException(Response.Status.FORBIDDEN);
    return product.getPresentationByLocale().keySet();
}
Also used : WebApplicationException(org.rembx.jeeshop.rest.WebApplicationException) RolesAllowed(javax.annotation.security.RolesAllowed)

Example 43 with RolesAllowed

use of javax.annotation.security.RolesAllowed in project jeeshop by remibantos.

the class Stores method findPresentationsLocales.

@GET
@Path("/{storeId}/presentationslocales")
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({ ADMIN, STORE_ADMIN, ADMIN_READONLY })
public Set<String> findPresentationsLocales(@Context SecurityContext securityContext, @PathParam("storeId") @NotNull Long storeId) {
    Store loadedStore = entityManager.find(Store.class, storeId);
    checkNotNull(loadedStore);
    if (!isAdminUser(securityContext) && !isOwner(securityContext, loadedStore.getOwner()))
        throw new WebApplicationException(Response.Status.FORBIDDEN);
    return loadedStore.getPresentationByLocale().keySet();
}
Also used : WebApplicationException(org.rembx.jeeshop.rest.WebApplicationException) Store(org.rembx.jeeshop.catalog.model.Store) RolesAllowed(javax.annotation.security.RolesAllowed)

Example 44 with RolesAllowed

use of javax.annotation.security.RolesAllowed in project jeeshop by remibantos.

the class Categories method delete.

@DELETE
@Transactional
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({ ADMIN, STORE_ADMIN })
@Path("/{categoryId}")
public void delete(@Context SecurityContext securityContext, @PathParam("categoryId") Long categoryId) {
    Category category = entityManager.find(Category.class, categoryId);
    checkNotNull(category);
    if (!isOwner(securityContext, category.getOwner()) && !isAdminUser(securityContext))
        throw new WebApplicationException(Response.Status.FORBIDDEN);
    else {
        List<Category> categoryHolders = catalogItemFinder.findForeignHolder(QCategory.category, QCategory.category.childCategories, category);
        for (Category categoryHolder : categoryHolders) {
            categoryHolder.getChildCategories().remove(category);
        }
        List<Catalog> catalogHolders = catalogItemFinder.findForeignHolder(QCatalog.catalog, QCatalog.catalog.rootCategories, category);
        for (Catalog catalogHolder : catalogHolders) {
            catalogHolder.getRootCategories().remove(category);
        }
        entityManager.remove(category);
    }
}
Also used : WebApplicationException(org.rembx.jeeshop.rest.WebApplicationException) RolesAllowed(javax.annotation.security.RolesAllowed) Transactional(javax.transaction.Transactional)

Example 45 with RolesAllowed

use of javax.annotation.security.RolesAllowed in project jeeshop by remibantos.

the class Discounts method findPresentationsLocales.

@GET
@Path("/{discountId}/presentationslocales")
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({ ADMIN, STORE_ADMIN, ADMIN_READONLY })
public Set<String> findPresentationsLocales(@Context SecurityContext securityContext, @PathParam("discountId") @NotNull Long discountId) {
    Discount discount = entityManager.find(Discount.class, discountId);
    checkNotNull(discount);
    if (!isAdminUser(securityContext) && !isOwner(securityContext, discount.getOwner()))
        throw new WebApplicationException(Response.Status.FORBIDDEN);
    return discount.getPresentationByLocale().keySet();
}
Also used : WebApplicationException(org.rembx.jeeshop.rest.WebApplicationException) RolesAllowed(javax.annotation.security.RolesAllowed)

Aggregations

RolesAllowed (javax.annotation.security.RolesAllowed)191 Path (javax.ws.rs.Path)127 Produces (javax.ws.rs.Produces)110 Consumes (javax.ws.rs.Consumes)55 GET (javax.ws.rs.GET)54 POST (javax.ws.rs.POST)40 PUT (javax.ws.rs.PUT)35 HashMap (java.util.HashMap)34 ArrayList (java.util.ArrayList)32 IOException (java.io.IOException)30 ApiOperation (io.swagger.annotations.ApiOperation)29 ApiResponses (io.swagger.annotations.ApiResponses)29 Response (javax.ws.rs.core.Response)28 Adapter (nl.nn.adapterframework.core.Adapter)21 DELETE (javax.ws.rs.DELETE)19 WebApplicationException (org.rembx.jeeshop.rest.WebApplicationException)19 LinkedHashMap (java.util.LinkedHashMap)16 Locale (java.util.Locale)16 Map (java.util.Map)12 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)12