use of com.salesmanager.core.model.user.Group in project shopizer by shopizer-ecommerce.
the class SecurityApi method listPermissions.
@ResponseStatus(HttpStatus.OK)
@GetMapping({ "/private/{group}/permissions" })
@ApiOperation(httpMethod = "GET", value = "Get permissions by group", notes = "", produces = MediaType.APPLICATION_JSON_VALUE, response = List.class)
public List<ReadablePermission> listPermissions(@PathVariable String group) {
Group g = null;
try {
g = groupService.findByName(group);
if (g == null) {
throw new ResourceNotFoundException("Group [" + group + "] does not exist");
}
} catch (Exception e) {
LOGGER.error("An error occured while getting group [" + group + "]", e);
throw new ServiceRuntimeException("An error occured while getting group [" + group + "]");
}
Set<Permission> permissions = g.getPermissions();
List<ReadablePermission> readablePermissions = new ArrayList<ReadablePermission>();
for (Permission permission : permissions) {
ReadablePermission readablePermission = new ReadablePermission();
readablePermission.setName(permission.getPermissionName());
readablePermission.setId(permission.getId());
readablePermissions.add(readablePermission);
}
return readablePermissions;
}
use of com.salesmanager.core.model.user.Group in project shopizer by shopizer-ecommerce.
the class CustomerFacadeImpl method setCustomerModelDefaultProperties.
@Override
public void setCustomerModelDefaultProperties(Customer customer, MerchantStore store) throws Exception {
Validate.notNull(customer, "Customer object cannot be null");
if (customer.getId() == null || customer.getId() == 0) {
if (StringUtils.isBlank(customer.getNick())) {
String userName = customer.getEmailAddress();
customer.setNick(userName);
}
if (StringUtils.isBlank(customer.getPassword())) {
String password = new String(UUID.generateRandomBytes());
String encodedPassword = passwordEncoder.encode(password);
customer.setPassword(encodedPassword);
}
}
if (CollectionUtils.isEmpty(customer.getGroups())) {
List<Group> groups = getListOfGroups(GroupType.CUSTOMER);
for (Group group : groups) {
if (group.getGroupName().equals(Constants.GROUP_CUSTOMER)) {
customer.getGroups().add(group);
}
}
}
}
use of com.salesmanager.core.model.user.Group in project shopizer by shopizer-ecommerce.
the class CustomerFacadeImpl method convertPersistableCustomerToCustomer.
private Customer convertPersistableCustomerToCustomer(PersistableCustomer customer, MerchantStore store) {
Customer cust = new Customer();
try {
customerPopulator.populate(customer, cust, store, store.getDefaultLanguage());
} catch (ConversionException e) {
throw new ConversionRuntimeException(e);
}
List<Group> groups = getListOfGroups(GroupType.CUSTOMER);
cust.setGroups(groups);
String password = customer.getPassword();
if (StringUtils.isBlank(password)) {
password = new String(UUID.generateRandomBytes());
customer.setPassword(password);
}
return cust;
}
use of com.salesmanager.core.model.user.Group in project shopizer by shopizer-ecommerce.
the class SecurityFacadeImpl method getPermissions.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public List<ReadablePermission> getPermissions(List<String> groups) {
List<Group> userGroups = null;
try {
userGroups = groupService.listGroupByNames(groups);
List<Integer> ids = new ArrayList<Integer>();
for (Group g : userGroups) {
ids.add(g.getId());
}
PermissionCriteria criteria = new PermissionCriteria();
criteria.setGroupIds(new HashSet(ids));
PermissionList permissions = permissionService.listByCriteria(criteria);
throw new ServiceRuntimeException("Not implemented");
} catch (ServiceException e) {
e.printStackTrace();
}
return null;
}
use of com.salesmanager.core.model.user.Group in project shopizer by shopizer-ecommerce.
the class InitializationDatabaseImpl method createSecurityGroups.
private void createSecurityGroups() throws ServiceException {
// create permissions
// Map name object
Map<String, Permission> permissionKeys = new HashMap<String, Permission>();
Permission AUTH = new Permission("AUTH");
permissionService.create(AUTH);
permissionKeys.put(AUTH.getPermissionName(), AUTH);
Permission SUPERADMIN = new Permission("SUPERADMIN");
permissionService.create(SUPERADMIN);
permissionKeys.put(SUPERADMIN.getPermissionName(), SUPERADMIN);
Permission ADMIN = new Permission("ADMIN");
permissionService.create(ADMIN);
permissionKeys.put(ADMIN.getPermissionName(), ADMIN);
Permission PRODUCTS = new Permission("PRODUCTS");
permissionService.create(PRODUCTS);
permissionKeys.put(PRODUCTS.getPermissionName(), PRODUCTS);
Permission ORDER = new Permission("ORDER");
permissionService.create(ORDER);
permissionKeys.put(ORDER.getPermissionName(), ORDER);
Permission CONTENT = new Permission("CONTENT");
permissionService.create(CONTENT);
permissionKeys.put(CONTENT.getPermissionName(), CONTENT);
Permission STORE = new Permission("STORE");
permissionService.create(STORE);
permissionKeys.put(STORE.getPermissionName(), STORE);
Permission TAX = new Permission("TAX");
permissionService.create(TAX);
permissionKeys.put(TAX.getPermissionName(), TAX);
Permission PAYMENT = new Permission("PAYMENT");
permissionService.create(PAYMENT);
permissionKeys.put(PAYMENT.getPermissionName(), PAYMENT);
Permission CUSTOMER = new Permission("CUSTOMER");
permissionService.create(CUSTOMER);
permissionKeys.put(CUSTOMER.getPermissionName(), CUSTOMER);
Permission SHIPPING = new Permission("SHIPPING");
permissionService.create(SHIPPING);
permissionKeys.put(SHIPPING.getPermissionName(), SHIPPING);
Permission AUTH_CUSTOMER = new Permission("AUTH_CUSTOMER");
permissionService.create(AUTH_CUSTOMER);
permissionKeys.put(AUTH_CUSTOMER.getPermissionName(), AUTH_CUSTOMER);
SecurityGroupsBuilder groupBuilder = new SecurityGroupsBuilder();
groupBuilder.addGroup("SUPERADMIN", GroupType.ADMIN).addPermission(permissionKeys.get("AUTH")).addPermission(permissionKeys.get("SUPERADMIN")).addPermission(permissionKeys.get("ADMIN")).addPermission(permissionKeys.get("PRODUCTS")).addPermission(permissionKeys.get("ORDER")).addPermission(permissionKeys.get("CONTENT")).addPermission(permissionKeys.get("STORE")).addPermission(permissionKeys.get("TAX")).addPermission(permissionKeys.get("PAYMENT")).addPermission(permissionKeys.get("CUSTOMER")).addPermission(permissionKeys.get("SHIPPING")).addGroup("ADMIN", GroupType.ADMIN).addPermission(permissionKeys.get("AUTH")).addPermission(permissionKeys.get("ADMIN")).addPermission(permissionKeys.get("PRODUCTS")).addPermission(permissionKeys.get("ORDER")).addPermission(permissionKeys.get("CONTENT")).addPermission(permissionKeys.get("STORE")).addPermission(permissionKeys.get("TAX")).addPermission(permissionKeys.get("PAYMENT")).addPermission(permissionKeys.get("CUSTOMER")).addPermission(permissionKeys.get("SHIPPING")).addGroup("ADMIN_RETAILER", GroupType.ADMIN).addPermission(permissionKeys.get("AUTH")).addPermission(permissionKeys.get("ADMIN")).addPermission(permissionKeys.get("PRODUCTS")).addPermission(permissionKeys.get("ORDER")).addPermission(permissionKeys.get("CONTENT")).addPermission(permissionKeys.get("STORE")).addPermission(permissionKeys.get("TAX")).addPermission(permissionKeys.get("PAYMENT")).addPermission(permissionKeys.get("CUSTOMER")).addPermission(permissionKeys.get("SHIPPING")).addGroup("ADMIN_STORE", GroupType.ADMIN).addPermission(permissionKeys.get("AUTH")).addPermission(permissionKeys.get("CONTENT")).addPermission(permissionKeys.get("STORE")).addPermission(permissionKeys.get("TAX")).addPermission(permissionKeys.get("PAYMENT")).addPermission(permissionKeys.get("CUSTOMER")).addPermission(permissionKeys.get("SHIPPING")).addGroup("ADMIN_CATALOGUE", GroupType.ADMIN).addPermission(permissionKeys.get("AUTH")).addPermission(permissionKeys.get("PRODUCTS")).addGroup("ADMIN_ORDER", GroupType.ADMIN).addPermission(permissionKeys.get("AUTH")).addPermission(permissionKeys.get("ORDER")).addGroup("ADMIN_CONTENT", GroupType.ADMIN).addPermission(permissionKeys.get("AUTH")).addPermission(permissionKeys.get("CONTENT")).addGroup("CUSTOMER", GroupType.CUSTOMER).addPermission(permissionKeys.get("AUTH")).addPermission(permissionKeys.get("AUTH_CUSTOMER"));
for (Group g : groupBuilder.build()) {
groupService.create(g);
}
}
Aggregations