Search in sources :

Example 1 with ReadablePermission

use of com.salesmanager.shop.model.security.ReadablePermission in project shopizer by shopizer-ecommerce.

the class UserFacadeImpl method convertUserToReadableUser.

private ReadableUser convertUserToReadableUser(Language lang, User user) {
    ReadableUserPopulator populator = new ReadableUserPopulator();
    try {
        ReadableUser readableUser = new ReadableUser();
        readableUser = populator.populate(user, readableUser, user.getMerchantStore(), lang);
        List<Integer> groupIds = readableUser.getGroups().stream().map(ReadableGroup::getId).map(Long::intValue).collect(Collectors.toList());
        List<ReadablePermission> permissions = findPermissionsByGroups(groupIds);
        readableUser.setPermissions(permissions);
        return readableUser;
    } catch (ConversionException e) {
        throw new ConversionRuntimeException(e);
    }
}
Also used : ReadableGroup(com.salesmanager.shop.model.security.ReadableGroup) ReadablePermission(com.salesmanager.shop.model.security.ReadablePermission) ConversionException(com.salesmanager.core.business.exception.ConversionException) ReadableUser(com.salesmanager.shop.model.user.ReadableUser) ReadableUserPopulator(com.salesmanager.shop.populator.user.ReadableUserPopulator) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException)

Example 2 with ReadablePermission

use of com.salesmanager.shop.model.security.ReadablePermission in project shopizer by shopizer-ecommerce.

the class SecurityApi method permissions.

/**
 * Permissions Requires service user authentication
 *
 * @return
 */
@GetMapping("/private/permissions")
public List<ReadablePermission> permissions() {
    List<Permission> permissions = permissionService.list();
    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) ReadablePermission(com.salesmanager.shop.model.security.ReadablePermission) Permission(com.salesmanager.core.model.user.Permission) ArrayList(java.util.ArrayList) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 3 with ReadablePermission

use of com.salesmanager.shop.model.security.ReadablePermission 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 4 with ReadablePermission

use of com.salesmanager.shop.model.security.ReadablePermission in project shopizer by shopizer-ecommerce.

the class UserFacadeImpl method convertPermissionToReadablePermission.

private ReadablePermission convertPermissionToReadablePermission(Permission permission) {
    ReadablePermission readablePermission = new ReadablePermission();
    readablePermission.setId(permission.getId());
    readablePermission.setName(permission.getPermissionName());
    return readablePermission;
}
Also used : ReadablePermission(com.salesmanager.shop.model.security.ReadablePermission)

Aggregations

ReadablePermission (com.salesmanager.shop.model.security.ReadablePermission)4 Permission (com.salesmanager.core.model.user.Permission)2 ReadableGroup (com.salesmanager.shop.model.security.ReadableGroup)2 ArrayList (java.util.ArrayList)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 ConversionException (com.salesmanager.core.business.exception.ConversionException)1 Group (com.salesmanager.core.model.user.Group)1 ReadableUser (com.salesmanager.shop.model.user.ReadableUser)1 ReadableUserPopulator (com.salesmanager.shop.populator.user.ReadableUserPopulator)1 ConversionRuntimeException (com.salesmanager.shop.store.api.exception.ConversionRuntimeException)1 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)1 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1