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;
}
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("信息错误");
}
}
}
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);
}
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;
}
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;
}
Aggregations