Search in sources :

Example 1 with AuthResource

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

the class ResourceServiceTest method addResource.

@Test
void addResource() {
    AuthResource authResource = AuthResource.builder().name("测试资源").url("baodu.com").description("测试专用资源").createTime(LocalDateTime.now()).categoryId(1L).build();
    boolean b = resourceService.addResource(authResource);
    assertTrue(b, "新增资源失败!");
}
Also used : AuthResource(com.besscroft.aurora.mall.common.entity.AuthResource) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with AuthResource

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

the class ResourceServiceTest method getResourceById.

@Test
void getResourceById() throws JsonProcessingException {
    Long resourceId = 1L;
    AuthResource resource = resourceService.getResourceById(resourceId);
    assertNotNull(resource, "获取资源详情失败!");
    LOGGER.info("资源详情:{}", objectMapper.writeValueAsString(resource));
}
Also used : AuthResource(com.besscroft.aurora.mall.common.entity.AuthResource) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with AuthResource

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

the class ResourceServiceImpl method getAllResourceTree.

@Override
public List<ResourceParam> getAllResourceTree() {
    List<ResourceParam> list = new ArrayList<>();
    List<AuthResourceSort> resourceSorts = authResourceSortMapper.selectList(new QueryWrapper<>());
    resourceSorts.forEach(r -> {
        ResourceParam resourceParam = new ResourceParam();
        QueryWrapper<AuthResource> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("category_id", r.getId());
        List<AuthResource> resources = this.baseMapper.selectList(queryWrapper);
        resourceParam.setName(r.getCategoryName());
        resourceParam.setDisabled(true);
        resourceParam.setChildren(resources);
        list.add(resourceParam);
    });
    return list;
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) AuthResourceSort(com.besscroft.aurora.mall.common.entity.AuthResourceSort) ResourceParam(com.besscroft.aurora.mall.admin.domain.param.ResourceParam) AuthResource(com.besscroft.aurora.mall.common.entity.AuthResource)

Example 4 with AuthResource

use of com.besscroft.aurora.mall.common.entity.AuthResource 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 5 with AuthResource

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

the class ResourceServiceTest method updateResource.

@Test
void updateResource() {
    AuthResource authResource = AuthResource.builder().id(1000L).name("测试资源").url("baodu.com").description("测试专用资源").createTime(LocalDateTime.now()).categoryId(1L).build();
    boolean b = resourceService.updateResource(authResource);
    assertTrue(b, "更新资源失败!");
}
Also used : AuthResource(com.besscroft.aurora.mall.common.entity.AuthResource) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

AuthResource (com.besscroft.aurora.mall.common.entity.AuthResource)5 Test (org.junit.jupiter.api.Test)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)2 ResourceParam (com.besscroft.aurora.mall.admin.domain.param.ResourceParam)2 AuthResourceSort (com.besscroft.aurora.mall.common.entity.AuthResourceSort)2 ServiceImpl (com.baomidou.mybatisplus.extension.service.impl.ServiceImpl)1 AuthResourceMapper (com.besscroft.aurora.mall.admin.mapper.AuthResourceMapper)1 AuthResourceSortMapper (com.besscroft.aurora.mall.admin.mapper.AuthResourceSortMapper)1 AuthRoleMapper (com.besscroft.aurora.mall.admin.mapper.AuthRoleMapper)1 RoleResourceRelationMapper (com.besscroft.aurora.mall.admin.mapper.RoleResourceRelationMapper)1 ResourceService (com.besscroft.aurora.mall.admin.service.ResourceService)1 AuthConstants (com.besscroft.aurora.mall.common.constant.AuthConstants)1 SystemConstants (com.besscroft.aurora.mall.common.constant.SystemConstants)1 AuthRole (com.besscroft.aurora.mall.common.entity.AuthRole)1 NotPermissionException (com.besscroft.aurora.mall.common.exception.NotPermissionException)1 RoleResourceRelation (com.besscroft.aurora.mall.common.model.RoleResourceRelation)1 PageHelper (com.github.pagehelper.PageHelper)1 LocalDateTime (java.time.LocalDateTime)1 java.util (java.util)1