Search in sources :

Example 1 with Permission

use of com.moon.admin.domain.Permission in project moon by gentoo111.

the class ShiroRealm method doGetAuthorizationInfo.

@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
    log.debug("权限配置");
    SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
    User user = UserUtil.getCurrentUser();
    List<Role> roles = SpringUtil.getBean(RoleDao.class).listByUserId(user.getId());
    Set<String> roleNames = roles.stream().map(Role::getName).collect(Collectors.toSet());
    authorizationInfo.setRoles(roleNames);
    List<Permission> permissionList = SpringUtil.getBean(PermissionDao.class).listByUserId(user.getId());
    UserUtil.setPermissionSession(permissionList);
    Set<String> permissions = permissionList.stream().filter(p -> !StringUtils.isEmpty(p.getPermission())).map(Permission::getPermission).collect(Collectors.toSet());
    authorizationInfo.setStringPermissions(permissions);
    return authorizationInfo;
}
Also used : Role(com.moon.admin.domain.Role) SimpleAuthorizationInfo(org.apache.shiro.authz.SimpleAuthorizationInfo) User(com.moon.admin.domain.User) RoleDao(com.moon.admin.dao.RoleDao) PermissionDao(com.moon.admin.dao.PermissionDao) Permission(com.moon.admin.domain.Permission)

Example 2 with Permission

use of com.moon.admin.domain.Permission in project moon by gentoo111.

the class PermissionController method permissionsCurrent.

@ApiOperation(value = "当前登录用户拥有的权限")
@GetMapping("/current")
public List<Permission> permissionsCurrent() {
    List<Permission> list = UserUtil.getCurrentPermissions();
    if (list == null) {
        User user = UserUtil.getCurrentUser();
        list = permissionService.listByUserId(user.getId());
        UserUtil.setPermissionSession(list);
    }
    final List<Permission> permissions = list.stream().filter(l -> l.getType().equals(1)).collect(Collectors.toList());
    setChild(permissions);
    return permissions.stream().filter(p -> p.getParentId().equals(0L)).collect(Collectors.toList());
}
Also used : User(com.moon.admin.domain.User) PermissionService(com.moon.admin.service.PermissionService) Autowired(org.springframework.beans.factory.annotation.Autowired) Set(java.util.Set) Collectors(java.util.stream.Collectors) Value(org.springframework.beans.factory.annotation.Value) JSONArray(com.alibaba.fastjson.JSONArray) ApiOperation(io.swagger.annotations.ApiOperation) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) List(java.util.List) Lists(com.google.common.collect.Lists) PermissionDao(com.moon.admin.dao.PermissionDao) Permission(com.moon.admin.domain.Permission) Logical(org.apache.shiro.authz.annotation.Logical) Stream(java.util.stream.Stream) CollectionUtils(org.apache.commons.collections.CollectionUtils) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) JSONObject(com.alibaba.fastjson.JSONObject) Api(io.swagger.annotations.Api) LogAnnotation(com.moon.admin.common.utils.LogAnnotation) Collections(java.util.Collections) UserUtil(com.moon.admin.common.utils.UserUtil) StringUtils(org.springframework.util.StringUtils) User(com.moon.admin.domain.User) Permission(com.moon.admin.domain.Permission) ApiOperation(io.swagger.annotations.ApiOperation)

Example 3 with Permission

use of com.moon.admin.domain.Permission in project moon by gentoo111.

the class PermissionController method setPermissionsTree.

/**
 * 菜单树
 *
 * @param pId
 * @param permissionsAll
 * @param array
 */
private void setPermissionsTree(Long pId, List<Permission> permissionsAll, JSONArray array) {
    for (Permission per : permissionsAll) {
        if (per.getParentId().equals(pId)) {
            String string = JSONObject.toJSONString(per);
            JSONObject parent = (JSONObject) JSONObject.parse(string);
            array.add(parent);
            if (permissionsAll.stream().filter(p -> p.getParentId().equals(per.getId())).findAny() != null) {
                JSONArray child = new JSONArray();
                parent.put("child", child);
                setPermissionsTree(per.getId(), permissionsAll, child);
            }
        }
    }
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) Permission(com.moon.admin.domain.Permission) JSONArray(com.alibaba.fastjson.JSONArray)

Example 4 with Permission

use of com.moon.admin.domain.Permission in project moon by gentoo111.

the class PermissionController method permissionsAll.

@GetMapping("/all")
@ApiOperation(value = "所有菜单")
@RequiresPermissions("sys:menu:query")
public JSONArray permissionsAll() {
    List<Permission> permissionsAll = permissionService.listAll();
    JSONArray array = new JSONArray();
    setPermissionsTree(0L, permissionsAll, array);
    return array;
}
Also used : Permission(com.moon.admin.domain.Permission) JSONArray(com.alibaba.fastjson.JSONArray) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

Permission (com.moon.admin.domain.Permission)4 JSONArray (com.alibaba.fastjson.JSONArray)3 JSONObject (com.alibaba.fastjson.JSONObject)2 PermissionDao (com.moon.admin.dao.PermissionDao)2 User (com.moon.admin.domain.User)2 ApiOperation (io.swagger.annotations.ApiOperation)2 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)2 Lists (com.google.common.collect.Lists)1 LogAnnotation (com.moon.admin.common.utils.LogAnnotation)1 UserUtil (com.moon.admin.common.utils.UserUtil)1 RoleDao (com.moon.admin.dao.RoleDao)1 Role (com.moon.admin.domain.Role)1 PermissionService (com.moon.admin.service.PermissionService)1 Api (io.swagger.annotations.Api)1 Collections (java.util.Collections)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 CollectionUtils (org.apache.commons.collections.CollectionUtils)1