博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
基于jwt的用户鉴权:配置拦截器并测试
阅读量:2161 次
发布时间:2019-05-01

本文共 3307 字,大约阅读时间需要 11 分钟。

package com.learn.system;import com.learn.common.interceptor.JwtInterceptor;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.context.annotation.Configuration;import org.springframework.web.servlet.config.annotation.InterceptorRegistry;import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;@Configurationpublic class SystemConfig extends WebMvcConfigurationSupport {    @Autowired    private JwtInterceptor jwtInterceptor;    /**     * 添加拦截器的配置     */    @Override    protected void addInterceptors(InterceptorRegistry registry) {        //1.添加自定义拦截器        registry.addInterceptor(jwtInterceptor).                addPathPatterns("/**").//2.指定拦截器的url地址                excludePathPatterns("/sys/login","/frame/register/**");//3.指定不拦截的url地址    }}
package com.learn.system;import com.learn.common.utils.IdWorker;import com.learn.common.utils.JwtUtils;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.boot.autoconfigure.domain.EntityScan;import org.springframework.context.annotation.Bean;import org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter;//1.配置springboot的包扫描@SpringBootApplication(scanBasePackages = "com.learn")//2.配置jpa注解的扫描@EntityScan(value="com.learn.domain.system")public class SystemApplication {    /**     * 启动方法     */    public static void main(String[] args) {        SpringApplication.run(SystemApplication.class,args);    }    @Bean    public IdWorker idWorker() {        return new IdWorker();    }    @Bean    public JwtUtils jwtUtils() {        return new JwtUtils();    }    //解决no session    @Bean    public OpenEntityManagerInViewFilter openEntityManagerInViewFilter() {        return new OpenEntityManagerInViewFilter();    }}
localhost:9002/sys/login{	"mobile":"18975979967",	"password":"123456"}localhost:9002/sys/profileBearer Authorizationlocalhost:9002/sys/login{	"mobile":"18975979967",	"password":"123456"}{    "success": true,    "code": 10000,    "message": "操作成功!",    "data": "eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiIxMjEwOTc5MTQ5MDMxNDQwMzg0Iiwic3ViIjoibGVvbiIsImlhdCI6MTU3Nzg0NjAxOCwiY29tcGFueUlkIjoiMSIsImFwaXMiOiIiLCJjb21wYW55TmFtZSI6IuS4reWbveWlveWjsOmfsyIsImV4cCI6MTU3Nzg0OTYxOH0.dQaKqwtyiCidHIMApUXeSltFNdrIO_HYhI_s1PJKS7s"}localhost:9002/sys/profileAuthorizationBearer eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiIxMjEwOTc5MTQ5MDMxNDQwMzg0Iiwic3ViIjoibGVvbiIsImlhdCI6MTU3Nzg0NjAxOCwiY29tcGFueUlkIjoiMSIsImFwaXMiOiIiLCJjb21wYW55TmFtZSI6IuS4reWbveWlveWjsOmfsyIsImV4cCI6MTU3Nzg0OTYxOH0.dQaKqwtyiCidHIMApUXeSltFNdrIO_HYhI_s1PJKS7s{    "success": true,    "code": 10000,    "message": "操作成功!",    "data": {        "mobile": "18975979967",        "username": "leon",        "company": "中国好声音",        "roles": {            "apis": [                "API-USER-DELETE"            ],            "menus": [                "啊啊啊",                "settings",                "12",                "test",                "permissions",                "departments",                "saas-clients",                "employees"            ],            "points": [                "point-dept",                "POINT-USER-ADD",                "point-user-delete",                "POINT-USER-UPDATE"            ]        }    }}

 

转载地址:http://elkzb.baihongyu.com/

你可能感兴趣的文章
Android Studio color和font设置
查看>>
Python 格式化打印json数据(展开状态)
查看>>
Centos7 安装curl(openssl)和libxml2
查看>>
Centos7 离线安装RabbitMQ,并配置集群
查看>>
Centos7 or Other Linux RPM包查询下载
查看>>
运行springboot项目出现:Type javax.xml.bind.JAXBContext not present
查看>>
Java中多线程向mysql插入同一条数据冲突问题
查看>>
Idea Maven项目使用jar包,添加到本地库使用
查看>>
FastDFS集群架构配置搭建(转载)
查看>>
HTM+CSS实现立方体图片旋转展示效果
查看>>
FFmpeg 命令操作音视频
查看>>
问题:Opencv(3.1.0/3.4)找不到 /opencv2/gpu/gpu.hpp 问题
查看>>
目的:使用CUDA环境变量CUDA_VISIBLE_DEVICES来限定CUDA程序所能使用的GPU设备
查看>>
问题:Mysql中字段类型为text的值, java使用selectByExample查询为null
查看>>
程序员--学习之路--技巧
查看>>
解决问题之 MySQL慢查询日志设置
查看>>
contOS6 部署 lnmp、FTP、composer、ThinkPHP5、docker详细步骤
查看>>
TP5.1模板布局中遇到的坑,配置完不生效解决办法
查看>>
PHPstudy中遇到的坑No input file specified,以及传到linux环境下遇到的坑,模板文件不存在
查看>>
TP5.1事务操作和TP5事务回滚操作多表
查看>>