zoukankan      html  css  js  c++  java
  • 授权和微服务的相互认证

    一授权

    1课程服务是一个资源服务

    在其某个controller中加preauthorize注解,

    2同时配置文件中开启

    3.jwt令牌中包含对应权限信息才可以操作

    XcUserExt userext = userClient.findUserInfo(username);


    /*
    //获取当前用户的权限信息
    List<XcMenu> menuList = xcMenuMapper.findMenuList(xcUser.getId());
    xcUserExt.setPermissions(menuList);*/

    select * from xc_menu where id in (select menu_id from xc_permission where role_id in(select role_id from xc_user_role where user_id ='49') )

     存到jwt令牌中

    权限五张表阿帕奇的shrio和springsecurity都是基于

    权限,权限角色roleid,resourceID,角色,用户角色userid roleid,用户,

    查询主表为权限,根据用户id查roleid 查中间表

    4.权限不足友好提示

     1 import com.google.common.collect.ImmutableMap;
     2 import com.xuecheng.filesystem.framework.model.response.CommonCode;
     3 import com.xuecheng.filesystem.framework.model.response.ResponseResult;
     4 import com.xuecheng.filesystem.framework.model.response.ResultCode;
     5 import lombok.extern.slf4j.Slf4j;
     6 import org.springframework.http.converter.HttpMessageNotReadableException;
     7 import org.springframework.web.bind.annotation.ControllerAdvice;
     8 import org.springframework.web.bind.annotation.ExceptionHandler;
     9 import org.springframework.web.bind.annotation.ResponseBody;
    10 
    11 //全局异常抓取类
    12 @ControllerAdvice //增强controller
    13 @Slf4j
    14 public class ExceptionCatch {
    15 
    16     //ImmutableMap 线程安全,声明之后内容不可变
    17     private static ImmutableMap<Class<? extends Throwable>,ResultCode> EXCEPTIONS;
    18 
    19     protected static ImmutableMap.Builder<Class<? extends Throwable>,ResultCode> builder = ImmutableMap.builder();
    20 
    21     //抓取自定义异常(可预知异常)
    22     @ExceptionHandler(CustomerException.class)
    23     @ResponseBody
    24     public ResponseResult customerException(CustomerException customerException){
    25         //给用户返回友好信息
    26         ResultCode resultCode = customerException.getResultCode();
    27 
    28         ResponseResult responseResult = new ResponseResult(resultCode);
    29         return responseResult;
    30     }
    31 
    32     //抓取不可预知异常
    33     @ExceptionHandler(Exception.class)
    34     @ResponseBody
    35     public ResponseResult exception(Exception exception){
    36 
    37         log.error(exception.getMessage());
    38 
    39         if (EXCEPTIONS == null){
    40             EXCEPTIONS = builder.build();
    41         }
    42         ResultCode resultCode = EXCEPTIONS.get(exception.getClass());
    43         if (resultCode == null){
    44             return new ResponseResult(CommonCode.SERVER_ERROR);
    45         }else{
    46             return new ResponseResult(resultCode);
    47         }
    48 
    49     }
    50 
    51     static {
    52         builder.put(HttpMessageNotReadableException.class, CommonCode.INVALIDATE_PARAMS);
    53     }
    54 }

    权限不足,无权操作。

    点击“”管理课程“”没信息回显,发出查询课程基础信息请求,被拦截,

    当一个男人不再对你啰嗦,不再缠着你,不再没事找你,对你说话也客气了,也不再气你了。那么恭喜你,你已经成功的失去了他。别嫌弃男人幼稚,那是他喜欢你,爱你。女人说男人像小孩子一样不成熟,可又有谁知道,男人在自己喜欢的女人面前才像小孩子,如果不喜欢你了,不爱你了,他比你爸还成熟。
  • 相关阅读:
    Python——GUI编程 控件及常用信号
    Python——PYQT:控件基本使用
    Android 自己定义圆圈进度并显示百分比例控件(纯代码实现)
    Parallel and Perpendicular
    策略模式(Strategy Pattern)
    Linux Framebuffer驱动剖析之中的一个—软件需求
    Java知识总结---整合SpringMVC+Mybatis+Spring(二)
    wav音频文件头解析
    【EasyUi DataGrid】批量删除
    Spark SQL Catalyst源代码分析之UDF
  • 原文地址:https://www.cnblogs.com/fengtangjiang/p/11148130.html
Copyright © 2011-2022 走看看