Search in sources :

Example 1 with Role

use of com.zyd.blog.business.entity.Role in project OneBlog by zhangyd-c.

the class SysRoleServiceImpl method insertList.

@Override
public void insertList(List<Role> entities) {
    Assert.notNull(entities, "entities不可为空!");
    List<SysRole> sysRole = new ArrayList<>();
    for (Role role : entities) {
        role.setUpdateTime(new Date());
        role.setCreateTime(new Date());
        sysRole.add(role.getSysRole());
    }
    roleMapper.insertList(sysRole);
}
Also used : SysRole(com.zyd.blog.persistence.beans.SysRole) Role(com.zyd.blog.business.entity.Role) SysRole(com.zyd.blog.persistence.beans.SysRole)

Example 2 with Role

use of com.zyd.blog.business.entity.Role in project OneBlog by zhangyd-c.

the class ShiroRealm method doGetAuthorizationInfo.

/**
 * 权限认证,为当前登录的Subject授予角色和权限(角色的权限信息集合)
 */
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
    // 权限信息对象info,用来存放查出的用户的所有的角色(role)及权限(permission)
    SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
    Long userId = (Long) SecurityUtils.getSubject().getPrincipal();
    // 赋予角色
    List<Role> roleList = roleService.listRolesByUserId(userId);
    if (null != roleList) {
        for (Role role : roleList) {
            info.addRole(role.getName());
        }
    }
    // 赋予权限
    List<Resources> resourcesList = null;
    User user = userService.getByPrimaryKey(userId);
    if (null == user) {
        return info;
    }
    // ROOT用户默认拥有所有权限
    if (UserTypeEnum.ROOT.toString().equalsIgnoreCase(user.getUserType())) {
        resourcesList = resourcesService.listAll();
    } else {
        resourcesList = resourcesService.listByUserId(userId);
    }
    if (!CollectionUtils.isEmpty(resourcesList)) {
        Set<String> permissionSet = new HashSet<>();
        for (Resources resources : resourcesList) {
            String permission = null;
            if (!StringUtils.isEmpty(permission = resources.getPermission())) {
                permissionSet.addAll(Arrays.asList(permission.trim().split(",")));
            }
        }
        info.setStringPermissions(permissionSet);
    }
    return info;
}
Also used : Role(com.zyd.blog.business.entity.Role) SimpleAuthorizationInfo(org.apache.shiro.authz.SimpleAuthorizationInfo) User(com.zyd.blog.business.entity.User) Resources(com.zyd.blog.business.entity.Resources) HashSet(java.util.HashSet)

Example 3 with Role

use of com.zyd.blog.business.entity.Role in project OneBlog by zhangyd-c.

the class SysRoleServiceImpl method getByPrimaryKey.

@Override
public Role getByPrimaryKey(Long primaryKey) {
    Assert.notNull(primaryKey, "PrimaryKey不可为空!");
    SysRole sysRole = roleMapper.selectByPrimaryKey(primaryKey);
    return null == sysRole ? null : new Role(sysRole);
}
Also used : SysRole(com.zyd.blog.persistence.beans.SysRole) Role(com.zyd.blog.business.entity.Role) SysRole(com.zyd.blog.persistence.beans.SysRole)

Example 4 with Role

use of com.zyd.blog.business.entity.Role in project OneBlog by zhangyd-c.

the class SysRoleServiceImpl method findPageBreakByCondition.

@Override
public PageInfo<Role> findPageBreakByCondition(RoleConditionVO vo) {
    PageHelper.startPage(vo.getPageNumber(), vo.getPageSize());
    List<SysRole> sysRoles = roleMapper.findPageBreakByCondition(vo);
    if (CollectionUtils.isEmpty(sysRoles)) {
        return null;
    }
    List<Role> roles = this.getRole(sysRoles);
    PageInfo bean = new PageInfo<SysRole>(sysRoles);
    bean.setList(roles);
    return bean;
}
Also used : SysRole(com.zyd.blog.persistence.beans.SysRole) Role(com.zyd.blog.business.entity.Role) PageInfo(com.github.pagehelper.PageInfo) SysRole(com.zyd.blog.persistence.beans.SysRole)

Aggregations

Role (com.zyd.blog.business.entity.Role)4 SysRole (com.zyd.blog.persistence.beans.SysRole)3 PageInfo (com.github.pagehelper.PageInfo)1 Resources (com.zyd.blog.business.entity.Resources)1 User (com.zyd.blog.business.entity.User)1 HashSet (java.util.HashSet)1 SimpleAuthorizationInfo (org.apache.shiro.authz.SimpleAuthorizationInfo)1