use of com.ganster.cms.core.pojo.Permission in project Ganster-CMS by Gangster-trio.
the class UserShiroRealm method doGetAuthorizationInfo.
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
User user = (User) principals.getPrimaryPrincipal();
List<Group> groupList = groupService.selectByUserId(user.getUserId());
Set<String> groupSet = groupList.stream().map(Group::getGroupName).collect(Collectors.toSet());
Set<String> permissionSet = groupSet.stream().flatMap(group -> permissionService.selectByGroupName(group).stream().map(Permission::getPermissionName)).collect(Collectors.toSet());
SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo();
simpleAuthorizationInfo.setStringPermissions(permissionSet);
simpleAuthorizationInfo.setRoles(groupSet);
return simpleAuthorizationInfo;
}
use of com.ganster.cms.core.pojo.Permission in project Ganster-CMS by Gangster-trio.
the class AllotGroupController method getPermissionName.
public List<String> getPermissionName(String groupName, String permission) {
List<String> permissionName = new ArrayList<>();
PInformationUtil pInformationUtil = new PInformationUtil();
Subject subject = SecurityUtils.getSubject();
Integer id = (Integer) subject.getSession().getAttribute("id");
GroupExample groupExample = new GroupExample();
groupExample.createCriteria().andGroupNameEqualTo(groupName + ":" + id);
List<Group> groupList = groupService.selectByExample(groupExample);
for (Group group : groupList) {
try {
List<Permission> permissionList = permissionService.selectByGroupId(group.getGroupId());
for (Permission i : permissionList) {
int j = 0;
try {
pInformationUtil.dealInfromation(i.getPermissionName());
String name = permission + ":" + pInformationUtil.getId();
permissionName.add(name);
j++;
} catch (Exception e) {
break;
}
}
} catch (GroupNotFountException e) {
e.printStackTrace();
}
}
return permissionName;
}
use of com.ganster.cms.core.pojo.Permission in project Ganster-CMS by Gangster-trio.
the class PermissionUtil method flush.
public static List<Permission> flush(Integer uid) {
List<Permission> permissions;
permissions = permissionUtil.permissionService.selectByUserId(uid);
Set<String> permissionName = new HashSet<>();
for (Permission i : permissions) {
permissionName.add(i.getPermissionName());
}
permissionMap.put(uid, permissionName);
return permissions;
}
use of com.ganster.cms.core.pojo.Permission in project Ganster-CMS by Gangster-trio.
the class UserShiroRealm method doGetAuthorizationInfo.
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
logger.info("进入权限配置");
String username = (String) principals.getPrimaryPrincipal();
UserExample userExample = new UserExample();
userExample.createCriteria().andUserNameEqualTo(username);
List<User> users = userService.selectByExample(userExample);
Integer j = 0;
for (User i : users) {
userId = i.getUserId();
j++;
}
if (j >= 2) {
return null;
}
User user = userService.selectByPrimaryKey(userId);
List<Group> groupList = groupService.selectByUserId(user.getUserId());
Set<String> groupSet = new HashSet<>();
for (Group i : groupList) {
if (!StringUtil.isNullOrEmpty(user.getUserName())) {
groupSet.add(i.getGroupName());
}
}
Set<String> permissionSet = new HashSet<>();
for (Group i : groupList) {
if (!StringUtil.isNullOrEmpty(i.getGroupName())) {
try {
List<Permission> permissions = permissionService.selectByGroupId(i.getGroupId());
for (Permission permission : permissions) {
permissionSet.add(permission.getPermissionName());
}
} catch (GroupNotFountException e) {
logger.info("角色未找到");
}
}
}
SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo();
simpleAuthorizationInfo.setStringPermissions(permissionSet);
simpleAuthorizationInfo.setRoles(groupSet);
return simpleAuthorizationInfo;
}
use of com.ganster.cms.core.pojo.Permission in project Ganster-CMS by Gangster-trio.
the class AllotPermissionController method addPermission.
@RequestMapping("/add")
@RequiresPermissions("add")
public void addPermission(@RequestParam("GroupName") String groupName, @RequestParam("PermissionName") String permissionName) throws PermissionNotFoundException, GroupNotFountException {
PermissionExample permissionExample = new PermissionExample();
permissionExample.createCriteria().andPermissionNameEqualTo(permissionName);
List<Permission> permissions = permissionService.selectByExample(permissionExample);
if (permissions == null)
throw new PermissionNotFoundException();
for (Permission i : permissions) {
// groupService.addCategoryPermissionToGroup(i.getPermissionName(),groupName);
}
}
Aggregations