Search in sources :

Example 11 with Group

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;
}
Also used : ReadablePermission(com.salesmanager.shop.model.security.ReadablePermission) Group(com.salesmanager.core.model.user.Group) ReadableGroup(com.salesmanager.shop.model.security.ReadableGroup) ReadablePermission(com.salesmanager.shop.model.security.ReadablePermission) Permission(com.salesmanager.core.model.user.Permission) ArrayList(java.util.ArrayList) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(io.swagger.annotations.ApiOperation)

Example 12 with Group

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);
            }
        }
    }
}
Also used : Group(com.salesmanager.core.model.user.Group)

Example 13 with 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;
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) Group(com.salesmanager.core.model.user.Group) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException)

Example 14 with Group

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;
}
Also used : PermissionCriteria(com.salesmanager.core.model.user.PermissionCriteria) Group(com.salesmanager.core.model.user.Group) ServiceException(com.salesmanager.core.business.exception.ServiceException) PermissionList(com.salesmanager.core.model.user.PermissionList) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 15 with Group

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);
    }
}
Also used : Group(com.salesmanager.core.model.user.Group) HashMap(java.util.HashMap) Permission(com.salesmanager.core.model.user.Permission) SecurityGroupsBuilder(com.salesmanager.core.business.utils.SecurityGroupsBuilder)

Aggregations

Group (com.salesmanager.core.model.user.Group)22 ArrayList (java.util.ArrayList)10 Permission (com.salesmanager.core.model.user.Permission)9 ReadableGroup (com.salesmanager.shop.model.security.ReadableGroup)9 ServiceException (com.salesmanager.core.business.exception.ServiceException)8 User (com.salesmanager.core.model.user.User)6 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)6 ConversionException (com.salesmanager.core.business.exception.ConversionException)5 PersistableGroup (com.salesmanager.shop.model.security.PersistableGroup)5 PersistableUser (com.salesmanager.shop.model.user.PersistableUser)5 ReadableUser (com.salesmanager.shop.model.user.ReadableUser)5 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)4 Language (com.salesmanager.core.model.reference.language.Language)3 GrantedAuthority (org.springframework.security.core.GrantedAuthority)3 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)3 Email (com.salesmanager.core.business.modules.email.Email)2 MerchantStoreService (com.salesmanager.core.business.services.merchant.MerchantStoreService)2 LanguageService (com.salesmanager.core.business.services.reference.language.LanguageService)2 EmailService (com.salesmanager.core.business.services.system.EmailService)2 PermissionService (com.salesmanager.core.business.services.user.PermissionService)2