Search in sources :

Example 16 with UnauthorizedException

use of com.salesmanager.shop.store.api.exception.UnauthorizedException in project shopizer by shopizer-ecommerce.

the class TaxFacadeImpl method updateTaxClass.

@Override
public void updateTaxClass(Long id, PersistableTaxClass taxClass, MerchantStore store, Language language) {
    Validate.notNull(taxClass, "TaxClass cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(store.getCode(), "MerchantStore code cannot be null");
    try {
        TaxClass model = taxClassService.getById(id);
        if (model == null) {
            throw new ResourceNotFoundException("TaxClass not found [" + id + "] for store [" + store.getCode() + "]");
        } else {
            if (!model.getMerchantStore().getCode().equals(store.getCode())) {
                throw new UnauthorizedException("MerchantStore [" + store.getCode() + "] cannot update tax class [" + taxClass.getCode() + "]");
            }
        }
        model = persistableTaxClassMapper.convert(taxClass, store, language);
        taxClassService.saveOrUpdate(model);
    } catch (ServiceException e) {
        LOGGER.error("Error while saving taxClass [" + taxClass.getCode() + "] for store [" + store.getCode() + "]", e);
        throw new ServiceRuntimeException("Error while saving taxClass [" + taxClass.getCode() + "] for store [" + store.getCode() + "]", e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) TaxClass(com.salesmanager.core.model.tax.taxclass.TaxClass) ReadableTaxClass(com.salesmanager.shop.model.tax.ReadableTaxClass) PersistableTaxClass(com.salesmanager.shop.model.tax.PersistableTaxClass) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 17 with UnauthorizedException

use of com.salesmanager.shop.store.api.exception.UnauthorizedException in project shopizer by shopizer-ecommerce.

the class UserFacadeImpl method authorizedGroups.

@Override
public void authorizedGroups(String authenticatedUser, PersistableUser user) {
    Validate.notNull(authenticatedUser, "Required authenticated user");
    Validate.notNull(user, "Required persistable user");
    try {
        User currentUser = userService.getByUserName(authenticatedUser);
        boolean isSuperAdmin = false;
        for (Group g : currentUser.getGroups()) {
            if (g.getGroupName().equals("SUPERADMIN")) {
                isSuperAdmin = true;
                break;
            }
        }
        for (PersistableGroup g : user.getGroups()) {
            if (g.getName().equals("SUPERADMIN")) {
                if (!isSuperAdmin) {
                    throw new UnauthorizedException("Superadmin group not allowed");
                }
            }
        }
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Error while looking for authorization", e);
    }
}
Also used : ReadableGroup(com.salesmanager.shop.model.security.ReadableGroup) PersistableGroup(com.salesmanager.shop.model.security.PersistableGroup) Group(com.salesmanager.core.model.user.Group) PersistableGroup(com.salesmanager.shop.model.security.PersistableGroup) ReadableUser(com.salesmanager.shop.model.user.ReadableUser) User(com.salesmanager.core.model.user.User) PersistableUser(com.salesmanager.shop.model.user.PersistableUser) ServiceException(com.salesmanager.core.business.exception.ServiceException) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 18 with UnauthorizedException

use of com.salesmanager.shop.store.api.exception.UnauthorizedException in project shopizer by shopizer-ecommerce.

the class CategoryFacadeImpl method getById.

private Category getById(MerchantStore store, Long id) throws Exception {
    Validate.notNull(id, "category id must not be null");
    Validate.notNull(store, "MerchantStore must not be null");
    Category category = categoryService.getById(id, store.getId());
    if (category == null) {
        throw new ResourceNotFoundException("Category with id [" + id + "] not found");
    }
    if (category.getMerchantStore().getId().intValue() != store.getId().intValue()) {
        throw new UnauthorizedException("Unauthorized");
    }
    return category;
}
Also used : Category(com.salesmanager.core.model.catalog.category.Category) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) PersistableCategory(com.salesmanager.shop.model.catalog.category.PersistableCategory) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException)

Example 19 with UnauthorizedException

use of com.salesmanager.shop.store.api.exception.UnauthorizedException in project shopizer by shopizer-ecommerce.

the class AuthenticateCustomerApi method setPassword.

@RequestMapping(value = "/private/customer/password", method = RequestMethod.PUT, produces = { "application/json" })
@ApiOperation(httpMethod = "PUT", value = "Change customer password", notes = "Change password request object is {\"username\":\"test@email.com\"}", response = ResponseEntity.class)
public ResponseEntity<?> setPassword(@RequestBody @Valid AuthenticationRequest authenticationRequest, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) {
    String authenticatedUser = userFacade.authenticatedUser();
    if (authenticatedUser == null) {
        throw new UnauthorizedException();
    }
    userFacade.authorizedGroup(authenticatedUser, Stream.of(Constants.GROUP_SUPERADMIN, Constants.GROUP_ADMIN, Constants.GROUP_ADMIN_RETAIL).collect(Collectors.toList()));
    Customer customer = customerFacade.getCustomerByUserName(authenticationRequest.getUsername(), merchantStore);
    if (customer == null) {
        return ResponseEntity.notFound().build();
    }
    customerFacade.changePassword(customer, authenticationRequest.getPassword());
    return ResponseEntity.ok(Void.class);
}
Also used : Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

UnauthorizedException (com.salesmanager.shop.store.api.exception.UnauthorizedException)19 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)10 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)10 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)8 ServiceException (com.salesmanager.core.business.exception.ServiceException)7 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)7 ApiOperation (io.swagger.annotations.ApiOperation)6 GetMapping (org.springframework.web.bind.annotation.GetMapping)5 Category (com.salesmanager.core.model.catalog.category.Category)4 ReadableUser (com.salesmanager.shop.model.user.ReadableUser)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 Product (com.salesmanager.core.model.catalog.product.Product)3 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)3 TaxClass (com.salesmanager.core.model.tax.taxclass.TaxClass)3 PersistableTaxClass (com.salesmanager.shop.model.tax.PersistableTaxClass)3 ReadableTaxClass (com.salesmanager.shop.model.tax.ReadableTaxClass)3 IOException (java.io.IOException)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 MerchantStoreCriteria (com.salesmanager.core.model.merchant.MerchantStoreCriteria)2 LightPersistableProduct (com.salesmanager.shop.model.catalog.product.LightPersistableProduct)2