Search in sources :

Example 1 with R

use of com.hccake.ballcat.common.model.result.R in project ballcat by ballcat-projects.

the class SysMenuController method getUserPermission.

/**
 * 返回当前用户的路由集合
 * @return 当前用户的路由
 */
@GetMapping("/router")
@Operation(summary = "动态路由", description = "动态路由")
public R<List<SysMenuRouterVO>> getUserPermission() {
    // 获取角色Code
    User user = SecurityUtils.getUser();
    Map<String, Object> attributes = user.getAttributes();
    Object rolesObject = attributes.get(UserAttributeNameConstants.ROLE_CODES);
    if (!(rolesObject instanceof Collection)) {
        return R.ok(new ArrayList<>());
    }
    @SuppressWarnings("unchecked") Collection<String> roleCodes = (Collection<String>) rolesObject;
    if (CollectionUtil.isEmpty(roleCodes)) {
        return R.ok(new ArrayList<>());
    }
    // 获取符合条件的权限
    Set<SysMenu> all = new HashSet<>();
    roleCodes.forEach(roleCode -> all.addAll(sysMenuService.listByRoleCode(roleCode)));
    // 筛选出菜单
    List<SysMenuRouterVO> menuVOList = all.stream().filter(menuVo -> SysMenuType.BUTTON.getValue() != menuVo.getType()).sorted(Comparator.comparingInt(SysMenu::getSort)).map(SysMenuConverter.INSTANCE::poToRouterVo).collect(Collectors.toList());
    return R.ok(menuVOList);
}
Also used : SysMenuUpdateDTO(com.hccake.ballcat.system.model.dto.SysMenuUpdateDTO) PathVariable(org.springframework.web.bind.annotation.PathVariable) SysMenuConverter(com.hccake.ballcat.system.converter.SysMenuConverter) SysMenuRouterVO(com.hccake.ballcat.system.model.vo.SysMenuRouterVO) SysMenuService(com.hccake.ballcat.system.service.SysMenuService) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequiredArgsConstructor(lombok.RequiredArgsConstructor) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ArrayList(java.util.ArrayList) RequestBody(org.springframework.web.bind.annotation.RequestBody) Valid(javax.validation.Valid) HashSet(java.util.HashSet) R(com.hccake.ballcat.common.model.result.R) UserAttributeNameConstants(com.hccake.ballcat.common.security.constant.UserAttributeNameConstants) Operation(io.swagger.v3.oas.annotations.Operation) PutMapping(org.springframework.web.bind.annotation.PutMapping) Map(java.util.Map) UpdateOperationLogging(com.hccake.ballcat.common.log.operation.annotation.UpdateOperationLogging) GetMapping(org.springframework.web.bind.annotation.GetMapping) SysMenuQO(com.hccake.ballcat.system.model.qo.SysMenuQO) SysMenu(com.hccake.ballcat.system.model.entity.SysMenu) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) PostMapping(org.springframework.web.bind.annotation.PostMapping) SecurityUtils(com.hccake.ballcat.common.security.util.SecurityUtils) SysMenuType(com.hccake.ballcat.system.enums.SysMenuType) CollectionUtil(cn.hutool.core.collection.CollectionUtil) BaseResultCode(com.hccake.ballcat.common.model.result.BaseResultCode) Collection(java.util.Collection) Set(java.util.Set) RestController(org.springframework.web.bind.annotation.RestController) Collectors(java.util.stream.Collectors) User(com.hccake.ballcat.common.security.userdetails.User) CreateOperationLogging(com.hccake.ballcat.common.log.operation.annotation.CreateOperationLogging) List(java.util.List) SysMenuPageVO(com.hccake.ballcat.system.model.vo.SysMenuPageVO) SysMenuCreateDTO(com.hccake.ballcat.system.model.dto.SysMenuCreateDTO) Tag(io.swagger.v3.oas.annotations.tags.Tag) SysMenuGrantVO(com.hccake.ballcat.system.model.vo.SysMenuGrantVO) Comparator(java.util.Comparator) DeleteOperationLogging(com.hccake.ballcat.common.log.operation.annotation.DeleteOperationLogging) User(com.hccake.ballcat.common.security.userdetails.User) SysMenuConverter(com.hccake.ballcat.system.converter.SysMenuConverter) SysMenuRouterVO(com.hccake.ballcat.system.model.vo.SysMenuRouterVO) SysMenu(com.hccake.ballcat.system.model.entity.SysMenu) Collection(java.util.Collection) HashSet(java.util.HashSet) GetMapping(org.springframework.web.bind.annotation.GetMapping) Operation(io.swagger.v3.oas.annotations.Operation)

Example 2 with R

use of com.hccake.ballcat.common.model.result.R in project ballcat by ballcat-projects.

the class LoginPasswordDecoderFilter method doFilterInternal.

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
    // 未配置密码密钥时,直接跳过
    if (passwordSecretKey == null) {
        log.warn("passwordSecretKey not configured, skip password decoder");
        filterChain.doFilter(request, response);
        return;
    }
    // 测试客户端 跳过密码解密(swagger 或 postman测试时使用)
    if (SecurityUtils.isTestClient()) {
        filterChain.doFilter(request, response);
        return;
    }
    // 解密前台加密后的密码
    Map<String, String[]> parameterMap = new HashMap<>(request.getParameterMap());
    String passwordAes = request.getParameter(PASSWORD);
    try {
        if (request.getParameter(GRANT_TYPE).equals(PASSWORD)) {
            String password = PasswordUtils.decodeAES(passwordAes, passwordSecretKey);
            parameterMap.put(PASSWORD, new String[] { password });
        }
    } catch (Exception e) {
        log.error("[doFilterInternal] password decode aes error,passwordAes: {},passwordSecretKey: {}", passwordAes, passwordSecretKey, e);
        response.setHeader("Content-Type", MediaType.APPLICATION_JSON.toString());
        response.setHeader("Accept-Charset", StandardCharsets.UTF_8.toString());
        response.setStatus(HttpStatus.BAD_REQUEST.value());
        R<String> r = R.failed(SystemResultCode.UNAUTHORIZED, "用户名或密码错误!");
        response.getWriter().write(JsonUtils.toJson(r));
        return;
    }
    // SpringSecurity 默认从ParameterMap中获取密码参数
    // 由于原生的request中对parameter加锁了,无法修改,所以使用包装类
    filterChain.doFilter(new ModifyParamMapRequestWrapper(request, parameterMap), response);
}
Also used : R(com.hccake.ballcat.common.model.result.R) HashMap(java.util.HashMap) ModifyParamMapRequestWrapper(com.hccake.ballcat.common.core.request.wrapper.ModifyParamMapRequestWrapper) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Aggregations

R (com.hccake.ballcat.common.model.result.R)2 CollectionUtil (cn.hutool.core.collection.CollectionUtil)1 ModifyParamMapRequestWrapper (com.hccake.ballcat.common.core.request.wrapper.ModifyParamMapRequestWrapper)1 CreateOperationLogging (com.hccake.ballcat.common.log.operation.annotation.CreateOperationLogging)1 DeleteOperationLogging (com.hccake.ballcat.common.log.operation.annotation.DeleteOperationLogging)1 UpdateOperationLogging (com.hccake.ballcat.common.log.operation.annotation.UpdateOperationLogging)1 BaseResultCode (com.hccake.ballcat.common.model.result.BaseResultCode)1 UserAttributeNameConstants (com.hccake.ballcat.common.security.constant.UserAttributeNameConstants)1 User (com.hccake.ballcat.common.security.userdetails.User)1 SecurityUtils (com.hccake.ballcat.common.security.util.SecurityUtils)1 SysMenuConverter (com.hccake.ballcat.system.converter.SysMenuConverter)1 SysMenuType (com.hccake.ballcat.system.enums.SysMenuType)1 SysMenuCreateDTO (com.hccake.ballcat.system.model.dto.SysMenuCreateDTO)1 SysMenuUpdateDTO (com.hccake.ballcat.system.model.dto.SysMenuUpdateDTO)1 SysMenu (com.hccake.ballcat.system.model.entity.SysMenu)1 SysMenuQO (com.hccake.ballcat.system.model.qo.SysMenuQO)1 SysMenuGrantVO (com.hccake.ballcat.system.model.vo.SysMenuGrantVO)1 SysMenuPageVO (com.hccake.ballcat.system.model.vo.SysMenuPageVO)1 SysMenuRouterVO (com.hccake.ballcat.system.model.vo.SysMenuRouterVO)1 SysMenuService (com.hccake.ballcat.system.service.SysMenuService)1