use of com.ganster.cms.core.pojo.Group 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.Group in project Ganster-CMS by Gangster-trio.
the class AllotGroupController method updateGroup.
@RequestMapping("/update")
public int updateGroup(@RequestParam(value = "Group") Group group) {
this.index();
List<String> permissionName = this.getPermissionName("group", "updategroup");
Subject subject = SecurityUtils.getSubject();
for (String i : permissionName) {
if (subject.isPermitted(i)) {
PInformationUtil pInformationUtil = new PInformationUtil();
try {
pInformationUtil.dealInfromation(i);
Group needUpdateGroup = groupService.selectByPrimaryKey(Integer.parseInt(pInformationUtil.getId()));
if (needUpdateGroup.getGroupId().equals(group.getGroupId())) {
return groupService.updateByPrimaryKey(group);
} else
continue;
} catch (InformationException e) {
logger.info("权限信息异常");
}
}
}
return 0;
}
use of com.ganster.cms.core.pojo.Group 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.Group 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("信息错误");
}
}
}
use of com.ganster.cms.core.pojo.Group 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);
}
Aggregations