Search in sources :

Example 1 with GroupNotFountException

use of com.ganster.cms.core.exception.GroupNotFountException 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 2 with GroupNotFountException

use of com.ganster.cms.core.exception.GroupNotFountException in project Ganster-CMS by Gangster-trio.

the class AllotGroupController method addGroup.

@RequestMapping("/add")
public void addGroup(@RequestParam(value = "UserId") Integer userId, @RequestParam(value = "GroupName") String groupName) {
    this.index();
    GroupExample groupExample = new GroupExample();
    groupExample.createCriteria().andGroupNameEqualTo(groupName);
    List<Group> groupList = groupService.selectByExample(groupExample);
    if (userId != null) {
        try {
            if (groupList == null) {
                RInformationUtil rInformationUtil = new RInformationUtil();
                rInformationUtil.dealInfromation(groupName);
                Group group = new Group();
                group.setGroupName(groupName);
                groupService.insert(group);
                groupService.addUserToGroup(userId, groupName);
            // groupService.addCategoryPermissionToGroup(groupName,"update:"+group.getGroupId());
            // groupService.addCategoryPermissionToGroup(groupName, "delete:" + group.getGroupId());
            // groupService.addCategoryPermissionToGroup(groupName,"find:"+group.getGroupId());
            } else {
                for (Group i : groupList) {
                    groupService.addUserToGroup(userId, i.getGroupName());
                }
            }
        } catch (UserNotFoundException e) {
            logger.info("用户未找到");
        } catch (GroupNotFountException e) {
            logger.info("用户组未找到");
        } catch (InformationException e) {
            logger.info("用户组信息不正确");
        } catch (PermissionNotFoundException e) {
            logger.info("用户组未找到");
        } catch (Exception e) {
            logger.info("信息错误");
        }
    }
}
Also used : UserNotFoundException(com.ganster.cms.core.exception.UserNotFoundException) InformationException(com.ganster.cms.auth.Exception.InformationException) Group(com.ganster.cms.core.pojo.Group) GroupNotFountException(com.ganster.cms.core.exception.GroupNotFountException) GroupExample(com.ganster.cms.core.pojo.GroupExample) RInformationUtil(com.ganster.cms.auth.util.RInformationUtil) PermissionNotFoundException(com.ganster.cms.core.exception.PermissionNotFoundException) 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) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with GroupNotFountException

use of com.ganster.cms.core.exception.GroupNotFountException in project Ganster-CMS by Gangster-trio.

the class PermissionServiceImplTest method interTest.

@Test
public void interTest() {
    final String userName = "@#$%^&";
    final String siteName = "$%^&&";
    User user = new User();
    user.setUserName(userName);
    userService.insert(user);
    Site site = new Site();
    site.setSiteName(siteName);
    siteService.insert(site);
    Group group = new Group();
    group.setGroupName(userName);
    groupService.insert(group);
    System.out.println(group.getGroupId());
    try {
        groupService.addUserToGroup(user.getUserId(), group.getGroupId());
    } catch (UserNotFoundException | GroupNotFountException e) {
        e.printStackTrace();
    }
    try {
        permissionService.addUserToSite(user.getUserId(), site.getSiteId());
    } catch (UserNotFoundException e) {
        e.printStackTrace();
    }
    List<Site> siteList = permissionService.findAllUserSite(user.getUserId());
    System.out.println(siteList);
    try {
        permissionService.addCategoryPermissionToUser(user.getUserId(), site.getSiteId(), 3, CmsConst.PERMISSION_READ);
    } catch (UserNotFoundException e) {
        e.printStackTrace();
    }
    boolean hasP = permissionService.hasCategoryPermission(user.getUserId(), site.getSiteId(), 3, CmsConst.PERMISSION_READ);
    Assert.assertTrue(hasP);
}
Also used : Site(com.ganster.cms.core.pojo.Site) UserNotFoundException(com.ganster.cms.core.exception.UserNotFoundException) Group(com.ganster.cms.core.pojo.Group) User(com.ganster.cms.core.pojo.User) GroupNotFountException(com.ganster.cms.core.exception.GroupNotFountException) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with GroupNotFountException

use of com.ganster.cms.core.exception.GroupNotFountException 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 GroupNotFountException

use of com.ganster.cms.core.exception.GroupNotFountException in project Ganster-CMS by Gangster-trio.

the class GetPermissionUtil method getPermissionName.

public List<String> getPermissionName(String groupName) {
    List<String> permissionName = new ArrayList<>();
    PInformationUtil pInformationUtil = new PInformationUtil();
    GroupExample groupExample = new GroupExample();
    logger.info("++++++++++++++++" + groupService);
    logger.info("+++++++++++++++++++" + groupName);
    groupExample.createCriteria().andGroupNameEqualTo(groupName);
    logger.info("++++++++++++++++++++++" + groupExample.toString());
    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 = "findgroup" + ":" + 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) GroupExample(com.ganster.cms.core.pojo.GroupExample) ArrayList(java.util.ArrayList) Permission(com.ganster.cms.core.pojo.Permission) GroupNotFountException(com.ganster.cms.core.exception.GroupNotFountException)

Aggregations

GroupNotFountException (com.ganster.cms.core.exception.GroupNotFountException)5 Group (com.ganster.cms.core.pojo.Group)5 UserNotFoundException (com.ganster.cms.core.exception.UserNotFoundException)3 GroupExample (com.ganster.cms.core.pojo.GroupExample)3 Permission (com.ganster.cms.core.pojo.Permission)3 InformationException (com.ganster.cms.auth.Exception.InformationException)2 PermissionNotFoundException (com.ganster.cms.core.exception.PermissionNotFoundException)2 User (com.ganster.cms.core.pojo.User)2 ArrayList (java.util.ArrayList)2 PInformationUtil (com.ganster.cms.auth.util.PInformationUtil)1 RInformationUtil (com.ganster.cms.auth.util.RInformationUtil)1 Site (com.ganster.cms.core.pojo.Site)1 UserExample (com.ganster.cms.core.pojo.UserExample)1 SimpleAuthorizationInfo (org.apache.shiro.authz.SimpleAuthorizationInfo)1 Subject (org.apache.shiro.subject.Subject)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1