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);
}
}
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);
}
}
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;
}
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);
}
Aggregations