Search in sources :

Example 1 with AuthRole

use of com.besscroft.aurora.mall.common.entity.AuthRole in project aurora-mall by besscroft.

the class RoleServiceTest method addRole.

@Test
void addRole() {
    AuthRole role = AuthRole.builder().name("单元测试角色").description("单元测试专用").createTime(LocalDateTime.now()).status(0).sort(10L).del(1).build();
    boolean b = roleService.addRole(role);
    assertTrue(b, "新增角色失败!");
}
Also used : AuthRole(com.besscroft.aurora.mall.common.entity.AuthRole) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with AuthRole

use of com.besscroft.aurora.mall.common.entity.AuthRole in project aurora-mall by besscroft.

the class RoleServiceTest method getRoleById.

@Test
void getRoleById() throws JsonProcessingException {
    Long roleId = 1L;
    AuthRole role = roleService.getRoleById(roleId);
    assertNotNull(role, "获取角色详情失败!");
    LOGGER.info("角色详情:{}", objectMapper.writeValueAsString(role));
}
Also used : AuthRole(com.besscroft.aurora.mall.common.entity.AuthRole) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with AuthRole

use of com.besscroft.aurora.mall.common.entity.AuthRole in project aurora-mall by besscroft.

the class ResourceServiceImpl method initRoleResourceMap.

@Override
public Map<String, List<String>> initRoleResourceMap() {
    Map<String, List<String>> RoleResourceMap = new TreeMap<>();
    List<AuthResource> authResourceList = this.baseMapper.selectAll();
    List<AuthRole> authRoleList = authRoleMapper.selectAll();
    List<RoleResourceRelation> roleResourceRelationList = roleResourceRelationMapper.selectAll();
    for (AuthResource resource : authResourceList) {
        Set<Long> roleIds = roleResourceRelationList.stream().filter(item -> item.getResourceId().equals(resource.getId())).map(RoleResourceRelation::getRoleId).collect(Collectors.toSet());
        List<String> roleNames = authRoleList.stream().filter(item -> roleIds.contains(item.getId())).map(item -> AuthConstants.AUTHORITY_PREFIX + item.getId() + "_" + item.getName()).collect(Collectors.toList());
        // key为访问路径/资源路径,value为角色
        RoleResourceMap.put("/" + applicationName + resource.getUrl(), roleNames);
    }
    redisTemplate.delete(AuthConstants.PERMISSION_RULES_KEY);
    redisTemplate.opsForHash().putAll(AuthConstants.PERMISSION_RULES_KEY, RoleResourceMap);
    return RoleResourceMap;
}
Also used : java.util(java.util) ResourceParam(com.besscroft.aurora.mall.admin.domain.param.ResourceParam) NotPermissionException(com.besscroft.aurora.mall.common.exception.NotPermissionException) RequiredArgsConstructor(lombok.RequiredArgsConstructor) LocalDateTime(java.time.LocalDateTime) RoleResourceRelationMapper(com.besscroft.aurora.mall.admin.mapper.RoleResourceRelationMapper) ResourceService(com.besscroft.aurora.mall.admin.service.ResourceService) Value(org.springframework.beans.factory.annotation.Value) RoleResourceRelation(com.besscroft.aurora.mall.common.model.RoleResourceRelation) Service(org.springframework.stereotype.Service) RedisTemplate(org.springframework.data.redis.core.RedisTemplate) AuthResourceSortMapper(com.besscroft.aurora.mall.admin.mapper.AuthResourceSortMapper) SystemConstants(com.besscroft.aurora.mall.common.constant.SystemConstants) AuthResourceSort(com.besscroft.aurora.mall.common.entity.AuthResourceSort) AuthRole(com.besscroft.aurora.mall.common.entity.AuthRole) ServiceImpl(com.baomidou.mybatisplus.extension.service.impl.ServiceImpl) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) AuthConstants(com.besscroft.aurora.mall.common.constant.AuthConstants) PageHelper(com.github.pagehelper.PageHelper) Collectors(java.util.stream.Collectors) AuthResource(com.besscroft.aurora.mall.common.entity.AuthResource) Slf4j(lombok.extern.slf4j.Slf4j) AuthRoleMapper(com.besscroft.aurora.mall.admin.mapper.AuthRoleMapper) AuthResourceMapper(com.besscroft.aurora.mall.admin.mapper.AuthResourceMapper) Transactional(org.springframework.transaction.annotation.Transactional) AuthRole(com.besscroft.aurora.mall.common.entity.AuthRole) AuthResource(com.besscroft.aurora.mall.common.entity.AuthResource) RoleResourceRelation(com.besscroft.aurora.mall.common.model.RoleResourceRelation)

Example 4 with AuthRole

use of com.besscroft.aurora.mall.common.entity.AuthRole in project aurora-mall by besscroft.

the class UserServiceImpl method loadUserByUsername.

@Override
public UserDto loadUserByUsername(String username) {
    AuthUser authUser = this.baseMapper.selectAuthUserByUsername(username);
    if (authUser != null) {
        List<AuthRole> authRoles = authRoleMapper.selectAuthRoleListByAdminId(authUser.getId());
        UserDto userDto = new UserDto();
        BeanUtils.copyProperties(authUser, userDto);
        if (CollUtil.isNotEmpty(authRoles)) {
            List<String> roleStrList = authRoles.stream().map(item -> item.getId() + "_" + item.getName()).collect(Collectors.toList());
            userDto.setRoles(roleStrList);
        }
        return userDto;
    }
    return null;
}
Also used : BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) AuthUserExcelDto(com.besscroft.aurora.mall.common.domain.AuthUserExcelDto) UserDto(com.besscroft.aurora.mall.common.domain.UserDto) AuthFeignClient(com.besscroft.aurora.mall.admin.api.AuthFeignClient) RequiredArgsConstructor(lombok.RequiredArgsConstructor) LocalDateTime(java.time.LocalDateTime) HashMap(java.util.HashMap) EasyExcel(com.alibaba.excel.EasyExcel) AdminParam(com.besscroft.aurora.mall.admin.domain.param.AdminParam) JSONUtil(cn.hutool.json.JSONUtil) HttpServletRequest(javax.servlet.http.HttpServletRequest) UserService(com.besscroft.aurora.mall.admin.service.UserService) Service(org.springframework.stereotype.Service) RedisTemplate(org.springframework.data.redis.core.RedisTemplate) Map(java.util.Map) AuthRole(com.besscroft.aurora.mall.common.entity.AuthRole) ServiceImpl(com.baomidou.mybatisplus.extension.service.impl.ServiceImpl) MenuService(com.besscroft.aurora.mall.admin.service.MenuService) AuthConstants(com.besscroft.aurora.mall.common.constant.AuthConstants) HttpServletResponse(javax.servlet.http.HttpServletResponse) UserConverterMapper(com.besscroft.aurora.mall.admin.converter.UserConverterMapper) PageHelper(com.github.pagehelper.PageHelper) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) CollUtil(cn.hutool.core.collection.CollUtil) StrUtil(cn.hutool.core.util.StrUtil) AjaxResult(com.besscroft.aurora.mall.common.result.AjaxResult) Slf4j(lombok.extern.slf4j.Slf4j) URLEncoder(java.net.URLEncoder) List(java.util.List) AuthRoleMapper(com.besscroft.aurora.mall.admin.mapper.AuthRoleMapper) AuthUser(com.besscroft.aurora.mall.common.entity.AuthUser) AuthUserMapper(com.besscroft.aurora.mall.admin.mapper.AuthUserMapper) BeanUtils(org.springframework.beans.BeanUtils) Transactional(org.springframework.transaction.annotation.Transactional) AuthRole(com.besscroft.aurora.mall.common.entity.AuthRole) UserDto(com.besscroft.aurora.mall.common.domain.UserDto) AuthUser(com.besscroft.aurora.mall.common.entity.AuthUser)

Example 5 with AuthRole

use of com.besscroft.aurora.mall.common.entity.AuthRole in project aurora-mall by besscroft.

the class UserServiceImpl method getUserInfo.

@Override
@Transactional(rollbackFor = Exception.class)
public Map<String, Object> getUserInfo() {
    AuthUser currentAdmin = getCurrentAdmin();
    Map<String, Object> data = menuService.getTreeListById(currentAdmin.getId());
    data.put("username", currentAdmin.getNickName());
    data.put("icon", currentAdmin.getIcon());
    List<AuthRole> roleList = getRoleList(currentAdmin.getId());
    if (CollUtil.isNotEmpty(roleList)) {
        List<String> roles = roleList.stream().map(AuthRole::getName).collect(Collectors.toList());
        data.put("roles", roles);
    }
    // 设置登录时间
    setLoginTime(LocalDateTime.now(), currentAdmin.getId());
    return data;
}
Also used : AuthRole(com.besscroft.aurora.mall.common.entity.AuthRole) AuthUser(com.besscroft.aurora.mall.common.entity.AuthUser) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

AuthRole (com.besscroft.aurora.mall.common.entity.AuthRole)6 Test (org.junit.jupiter.api.Test)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 Transactional (org.springframework.transaction.annotation.Transactional)3 ServiceImpl (com.baomidou.mybatisplus.extension.service.impl.ServiceImpl)2 AuthRoleMapper (com.besscroft.aurora.mall.admin.mapper.AuthRoleMapper)2 AuthConstants (com.besscroft.aurora.mall.common.constant.AuthConstants)2 AuthUser (com.besscroft.aurora.mall.common.entity.AuthUser)2 PageHelper (com.github.pagehelper.PageHelper)2 LocalDateTime (java.time.LocalDateTime)2 Collectors (java.util.stream.Collectors)2 RequiredArgsConstructor (lombok.RequiredArgsConstructor)2 Slf4j (lombok.extern.slf4j.Slf4j)2 RedisTemplate (org.springframework.data.redis.core.RedisTemplate)2 Service (org.springframework.stereotype.Service)2 CollUtil (cn.hutool.core.collection.CollUtil)1 StrUtil (cn.hutool.core.util.StrUtil)1 JSONUtil (cn.hutool.json.JSONUtil)1 EasyExcel (com.alibaba.excel.EasyExcel)1 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)1