Search in sources :

Example 1 with PmphPermission

use of com.bc.pmpheep.back.po.PmphPermission in project pmph by BCSquad.

the class PmphUserController method resources.

/**
 * <pre>
 * 功能描述:根据用户 id 跳转到用户权限的列表页面
 * 使用示范:
 *
 * @param userId
 * @param model
 * @return
 * </pre>
 */
@ResponseBody
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "查询指定用户 id 所拥有的权限")
@RequestMapping(value = "/resources/{id}", method = RequestMethod.GET)
public ResponseBean resources(@PathVariable("id") Long userId) {
    Map<String, Object> result = new HashMap<String, Object>();
    List<PmphPermission> resourceList = userService.getListAllResource(userId);
    PmphUser user = userService.get(userId);
    result.put("resources", resourceList);
    result.put("user", user);
    return new ResponseBean(result);
}
Also used : HashMap(java.util.HashMap) PmphPermission(com.bc.pmpheep.back.po.PmphPermission) PmphUser(com.bc.pmpheep.back.po.PmphUser) ResponseBean(com.bc.pmpheep.controller.bean.ResponseBean) LogDetail(com.bc.pmpheep.annotation.LogDetail) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with PmphPermission

use of com.bc.pmpheep.back.po.PmphPermission in project pmph by BCSquad.

the class PmphUserRealm method doGetAuthorizationInfo.

/**
 * 授权
 *
 * @param principalCollection
 * @return
 */
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
    logger.info("--- MyRealm doGetAuthorizationInfo ---");
    // 获得经过认证的主体信息
    PmphUser user = (PmphUser) principalCollection.getPrimaryPrincipal();
    Long userId = user.getId();
    // UserService userService = (UserService)InitServlet.getBean("userService");
    List<PmphPermission> resourceList = null;
    List<String> roleSnList = null;
    SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
    try {
        resourceList = userService.getListAllResource(userId);
        roleSnList = userService.getListRoleSnByUser(userId);
        List<String> resStrList = new ArrayList<>();
        for (PmphPermission resource : resourceList) {
            resStrList.add(resource.getUrl());
        }
        info.setRoles(new HashSet<>(roleSnList));
        info.setStringPermissions(new HashSet<>(resStrList));
        // 以上完成了动态地对用户授权
        logger.info("role => " + roleSnList);
        logger.info("permission => " + resStrList);
    } catch (Exception e) {
        logger.info("message => " + e);
    }
    return info;
}
Also used : SimpleAuthorizationInfo(org.apache.shiro.authz.SimpleAuthorizationInfo) PmphUser(com.bc.pmpheep.back.po.PmphUser) PmphPermission(com.bc.pmpheep.back.po.PmphPermission) ArrayList(java.util.ArrayList) AuthenticationException(org.apache.shiro.authc.AuthenticationException)

Example 3 with PmphPermission

use of com.bc.pmpheep.back.po.PmphPermission in project pmph by BCSquad.

the class PmphPermissionServiceTest method testDeletePmphPermissionById.

@Test
@Rollback(Const.ISROLLBACK)
public void testDeletePmphPermissionById() {
    pmphPermissionService.addPmphPermission(pmphPermission);
    Integer bInteger = pmphPermissionService.deletePmphPermissionById(new PmphPermission((pmphPermission.getId())));
    Assert.assertTrue("删除失败", bInteger > 0);
}
Also used : PmphPermission(com.bc.pmpheep.back.po.PmphPermission) Test(org.junit.Test) BaseTest(com.bc.pmpheep.test.BaseTest) Rollback(org.springframework.test.annotation.Rollback)

Example 4 with PmphPermission

use of com.bc.pmpheep.back.po.PmphPermission in project pmph by BCSquad.

the class PmphPermissionServiceTest method testGetPmphPermissionById.

@Test
@Rollback(Const.ISROLLBACK)
public void testGetPmphPermissionById() {
    pmphPermissionService.addPmphPermission(pmphPermission);
    PmphPermission pp = pmphPermissionService.getPmphPermissionById(new PmphPermission((pmphPermission.getId())));
    Assert.assertNotNull("获取数据", pp);
}
Also used : PmphPermission(com.bc.pmpheep.back.po.PmphPermission) Test(org.junit.Test) BaseTest(com.bc.pmpheep.test.BaseTest) Rollback(org.springframework.test.annotation.Rollback)

Example 5 with PmphPermission

use of com.bc.pmpheep.back.po.PmphPermission in project pmph by BCSquad.

the class PmphPermissionServiceImpl method getListAllParentMenu.

@Override
public List<PmphPermission> getListAllParentMenu() {
    List<PmphPermission> permissions = pmphPermissionDao.getListAllParentMenu();
    for (PmphPermission permission : permissions) {
        List<PmphPermission> subList = this.getListChildMenuByParentId(permission.getId());
        permission.setChildren(subList);
    }
    return permissions;
}
Also used : PmphPermission(com.bc.pmpheep.back.po.PmphPermission)

Aggregations

PmphPermission (com.bc.pmpheep.back.po.PmphPermission)6 BaseTest (com.bc.pmpheep.test.BaseTest)3 Test (org.junit.Test)3 Rollback (org.springframework.test.annotation.Rollback)3 PmphUser (com.bc.pmpheep.back.po.PmphUser)2 LogDetail (com.bc.pmpheep.annotation.LogDetail)1 ResponseBean (com.bc.pmpheep.controller.bean.ResponseBean)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 AuthenticationException (org.apache.shiro.authc.AuthenticationException)1 SimpleAuthorizationInfo (org.apache.shiro.authz.SimpleAuthorizationInfo)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1