Search in sources :

Example 1 with Permission

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;
}
Also used : PermissionService(com.ganster.cms.core.service.PermissionService) Logger(org.slf4j.Logger) org.apache.shiro.authc(org.apache.shiro.authc) AuthorizationInfo(org.apache.shiro.authz.AuthorizationInfo) LoggerFactory(org.slf4j.LoggerFactory) Resource(javax.annotation.Resource) Permission(com.ganster.cms.core.pojo.Permission) Set(java.util.Set) Collectors(java.util.stream.Collectors) UserService(com.ganster.cms.core.service.UserService) List(java.util.List) Subject(org.apache.shiro.subject.Subject) UserExample(com.ganster.cms.core.pojo.UserExample) User(com.ganster.cms.core.pojo.User) AuthorizingRealm(org.apache.shiro.realm.AuthorizingRealm) Group(com.ganster.cms.core.pojo.Group) GroupService(com.ganster.cms.core.service.GroupService) PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) SimpleAuthorizationInfo(org.apache.shiro.authz.SimpleAuthorizationInfo) SecurityUtils(org.apache.shiro.SecurityUtils) Group(com.ganster.cms.core.pojo.Group) User(com.ganster.cms.core.pojo.User) SimpleAuthorizationInfo(org.apache.shiro.authz.SimpleAuthorizationInfo) Permission(com.ganster.cms.core.pojo.Permission)

Example 2 with Permission

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;
}
Also used : Group(com.ganster.cms.core.pojo.Group) GroupNotFountException(com.ganster.cms.core.exception.GroupNotFountException) ArrayList(java.util.ArrayList) PInformationUtil(com.ganster.cms.auth.util.PInformationUtil) Subject(org.apache.shiro.subject.Subject) GroupNotFountException(com.ganster.cms.core.exception.GroupNotFountException) PermissionNotFoundException(com.ganster.cms.core.exception.PermissionNotFoundException) UserNotFoundException(com.ganster.cms.core.exception.UserNotFoundException) InformationException(com.ganster.cms.auth.Exception.InformationException) GroupExample(com.ganster.cms.core.pojo.GroupExample) Permission(com.ganster.cms.core.pojo.Permission)

Example 3 with Permission

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;
}
Also used : Permission(com.ganster.cms.core.pojo.Permission)

Example 4 with Permission

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;
}
Also used : Group(com.ganster.cms.core.pojo.Group) User(com.ganster.cms.core.pojo.User) GroupNotFountException(com.ganster.cms.core.exception.GroupNotFountException) SimpleAuthorizationInfo(org.apache.shiro.authz.SimpleAuthorizationInfo) UserExample(com.ganster.cms.core.pojo.UserExample) Permission(com.ganster.cms.core.pojo.Permission)

Example 5 with Permission

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);
    }
}
Also used : Permission(com.ganster.cms.core.pojo.Permission) PermissionNotFoundException(com.ganster.cms.core.exception.PermissionNotFoundException) PermissionExample(com.ganster.cms.core.pojo.PermissionExample) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Permission (com.ganster.cms.core.pojo.Permission)7 Group (com.ganster.cms.core.pojo.Group)5 GroupNotFountException (com.ganster.cms.core.exception.GroupNotFountException)3 GroupExample (com.ganster.cms.core.pojo.GroupExample)3 ArrayList (java.util.ArrayList)3 PermissionNotFoundException (com.ganster.cms.core.exception.PermissionNotFoundException)2 User (com.ganster.cms.core.pojo.User)2 UserExample (com.ganster.cms.core.pojo.UserExample)2 SimpleAuthorizationInfo (org.apache.shiro.authz.SimpleAuthorizationInfo)2 Subject (org.apache.shiro.subject.Subject)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 AjaxData (com.ganster.cms.admin.dto.AjaxData)1 GroupWithPermission (com.ganster.cms.admin.dto.GroupWithPermission)1 InformationException (com.ganster.cms.auth.Exception.InformationException)1 PInformationUtil (com.ganster.cms.auth.util.PInformationUtil)1 UserNotFoundException (com.ganster.cms.core.exception.UserNotFoundException)1 PermissionExample (com.ganster.cms.core.pojo.PermissionExample)1 GroupService (com.ganster.cms.core.service.GroupService)1 PermissionService (com.ganster.cms.core.service.PermissionService)1 UserService (com.ganster.cms.core.service.UserService)1