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