Jhipster token签名异常——c.f.o.cac.security.jwt.TokenProvider : Invalid JWT signature.
背景,jHipster自动生成的springBoot和angularJs前后台端分离的项目。java后台为了取到当前登录者的信息,所以后台开放了
MicroserviceSecurityConfiguration.java 这个类的注解
//开放前
#@Configuration
#@EnableWebSecurity
#@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
public class MicroserviceSecurityConfiguration extends WebSecurityConfigurerAdapter { private final TokenProvider tokenProvider; public MicroserviceSecurityConfiguration(TokenProvider tokenProvider) {
this.tokenProvider = tokenProvider;
} @Override
public void configure(WebSecurity web) throws Exception {
web.ignoring()
.antMatchers(HttpMethod.OPTIONS, "/**")
.antMatchers("/app/**/*.{js,html}")
.antMatchers("/bower_components/**")
.antMatchers("/i18n/**")
.antMatchers("/content/**")
.antMatchers("/swagger-ui/index.html")
.antMatchers("/test/**")
.antMatchers("/h2-console/**");
} @Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf()
.disable()
.headers()
.frameOptions()
.disable()
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.antMatchers("/api/**").authenticated()
.antMatchers("/management/health").permitAll()
.antMatchers("/management/**").hasAuthority(AuthoritiesConstants.ADMIN)
.antMatchers("/swagger-resources/configuration/ui").permitAll()
.and()
.apply(securityConfigurerAdapter());
} private JWTConfigurer securityConfigurerAdapter() {
return new JWTConfigurer(tokenProvider);
} @Bean
public SecurityEvaluationContextExtension securityEvaluationContextExtension() {
return new SecurityEvaluationContextExtension();
}
}
//开放后
package com.famessoft.oplus.cac.config; import com.famessoft.oplus.cac.security.AuthoritiesConstants;
import com.famessoft.oplus.cac.security.jwt.JWTConfigurer;
import com.famessoft.oplus.cac.security.jwt.TokenProvider; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.data.repository.query.SecurityEvaluationContextExtension; @Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
public class MicroserviceSecurityConfiguration extends WebSecurityConfigurerAdapter { private final TokenProvider tokenProvider; public MicroserviceSecurityConfiguration(TokenProvider tokenProvider) {//开放注解后,这里会报,could not autowire,no beans of 'TokenProvider' type found.不用管这个错,这个错不影响程运行
this.tokenProvider = tokenProvider;
} @Override
public void configure(WebSecurity web) throws Exception {
web.ignoring()
.antMatchers(HttpMethod.OPTIONS, "/**")
.antMatchers("/app/**/*.{js,html}")
.antMatchers("/bower_components/**")
.antMatchers("/i18n/**")
.antMatchers("/content/**")
.antMatchers("/swagger-ui/index.html")
.antMatchers("/test/**")
.antMatchers("/h2-console/**");
} @Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf()
.disable()
.headers()
.frameOptions()
.disable()
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.antMatchers("/api/**").authenticated()
.antMatchers("/management/health").permitAll()
.antMatchers("/management/**").hasAuthority(AuthoritiesConstants.ADMIN)
.antMatchers("/swagger-resources/configuration/ui").permitAll()
.and()
.apply(securityConfigurerAdapter());
} private JWTConfigurer securityConfigurerAdapter() {
return new JWTConfigurer(tokenProvider);
} @Bean
public SecurityEvaluationContextExtension securityEvaluationContextExtension() {
return new SecurityEvaluationContextExtension();
}
}
然后使用
SecurityUtils.getCurrentUserLogin()获取系统当前登录者信息 我在本地测试没问题。但是打包放到生产就报下面这个错,很郁闷,找了一下午才找到原因
c.f.o.cac.security.jwt.TokenProvider : Invalid JWT signature.
原来是我生产的配置文件配的不对
application-dev.yml
jhipster:
http:
version: V_1_1 # To use HTTP/2 you will need SSL support (see above the "server.ssl" configuration)
cache: # Cache configuration
hazelcast: # Hazelcast distributed cache
time-to-live-seconds: 3600
backup-count: 1
# CORS is disabled by default on microservices, as you should access them through a gateway.
# If you want to enable it, please uncomment the configuration below.
cors:
allowed-origins: "*"
allowed-methods: "*"
allowed-headers: "*"
# exposed-headers: "Authorization"
# allow-credentials: true
max-age: 1800
security:
authentication:
jwt:
secret: my-secret-token-to-change-in-production
# Token is valid 24 hours
token-validity-in-seconds: 86400
token-validity-in-seconds-for-remember-me: 2592000
application-prod.yml
jhipster:
http:
version: V_1_1 # To use HTTP/2 you will need SSL support (see above the "server.ssl" configuration)
cache: # Used by the CachingHttpHeadersFilter
timeToLiveInDays: 1461
cache: # Cache configuration
hazelcast: # Hazelcast distributed cache
time-to-live-seconds: 3600
backup-count: 1
# CORS is disabled by default on microservices, as you should access them through a gateway.
# If you want to enable it, please uncomment the configuration below.
cors:
allowed-origins: "*"
allowed-methods: "*"
allowed-headers: "*"
# exposed-headers: "Authorization"
# allow-credentials: true
max-age: 1800
security:
authentication:
jwt:
# secret: e2d66542649f38de03a5443a6bddd1ce18f0fe13 #####这是改之前的代码,后台不认识这串字符串,所以secret的命名前后最后一致(默认就是my-secret-token-to-change-in-production), 这里最后命名为字符常规可读的字符串,不需要加密
secret: my-secret-token-to-change-in-production
# Token is valid 24 hours
token-validity-in-seconds: 86400
token-validity-in-seconds-for-remember-me: 2592000
Jhipster token签名异常——c.f.o.cac.security.jwt.TokenProvider : Invalid JWT signature.的更多相关文章
- Spring Cloud OAuth2.0 微服务中配置 Jwt Token 签名/验证
关于 Jwt Token 的签名与安全性前面已经做了几篇介绍,在 IdentityServer4 中定义了 Jwt Token 与 Reference Token 两种验证方式(https://www ...
- ASP.NET WebApi 基于OAuth2.0实现Token签名认证
一.课程介绍 明人不说暗话,跟着阿笨一起玩WebApi!开发提供数据的WebApi服务,最重要的是数据的安全性.那么对于我们来说,如何确保数据的安全将是我们需要思考的问题.为了保护我们的WebApi数 ...
- ASP.NET WebApi 基于JWT实现Token签名认证
一.前言 明人不说暗话,跟着阿笨一起玩WebApi!开发提供数据的WebApi服务,最重要的是数据的安全性.那么对于我们来说,如何确保数据的安全将会是需要思考的问题.在ASP.NET WebServi ...
- ASP.NET WebApi 基于分布式Session方式实现Token签名认证
一.课程介绍 明人不说暗话,跟着阿笨一起学玩WebApi!开发提供数据的WebApi服务,最重要的是数据的安全性.那么对于我们来说,如何确保数据的安全将会是需要思考的问题.在ASP.NETWebSer ...
- ERROR org.hibernate.hql.internal.ast.ErrorCounter unexpected token: form 异常解决
ERROR org.hibernate.hql.internal.ast.ErrorCounter unexpected token: form 异常解决 根据异常提示:我找了我的MySQL语句:果然 ...
- ASP.NET WebApi 基于分布式Session方式实现Token签名认证(发布版)
一.课程介绍 明人不说暗话,跟着阿笨一起学玩WebApi!开发提供数据的WebApi服务,最重要的是数据的安全性.那么对于我们来说,如何确保数据的安全将会是需要思考的问题.在ASP.NETWebSer ...
- 【转】App开放接口api安全性—Token签名sign的设计与实现
前言 在app开放接口api的设计中,避免不了的就是安全性问题,因为大多数接口涉及到用户的个人信息以及一些敏感的数据,所以对这些接口需要进行身份的认证,那么这就需要用户提供一些信息,比如用户名密码等, ...
- App开放接口api安全性—Token签名sign的设计与实现
前言 在app开放接口api的设计中,避免不了的就是安全性问题,因为大多数接口涉及到用户的个人信息以及一些敏感的数据,所以对这些接口需要进行身份的认证,那么这就需要用户提供一些信息,比如用户名密码等, ...
- App开放接口API安全性 — Token签名sign的设计与实现
在app开放接口API的设计中,避免不了的就是安全性问题. 一.https协议 对于一些敏感的API接口,需要使用https协议. https是在http超文本传输协议加入SSL层,它在网络间通信是加 ...
随机推荐
- 转:RHEL6.3 安装GCC 记录
本文参考:http://blog.163.com/phys_atom/blog/static/1676445532012229814992/ 如果直接使用GUN GCC官方的源码来安装是不成功的,因为 ...
- Python 实int型和list相互转换 现把float型列表转换为int型列表 把列表中的数字由float转换为int型
第一种方法:使用map方法 >>> list = [, ] #带有float型的列表 >>> int_list = map(int,list) #使用map转换 & ...
- 使用while循环和伪列的存储过程
使用while循环和伪列的存储过程如下: USE [JointFrame2] GO /****** Object: StoredProcedure [dbo].[Proc_enterprise_uni ...
- 从pdf 文件中抽取特定的页面
前段时间买了一个kindle 电子书阅读器.我想用它来读的pdf文档.当然最主要是用来读python标准库&mysql的官方文档. 问题就来了.这两个都是大头书.之前用mac看还好.用kind ...
- Memory leak patterns in JavaScript
Handling circular references in JavaScript applications Plugging memory leaks in JavaScript is easy ...
- Linux关机和重启命令总结
一.shutdown 命令 作用:关闭或重启系统 使用权限:超级管理员使用 常用选项 1. -r 关机后立即重启 2. -h关机后不重启 3. -f快速关机,重启时跳过fsck(file system ...
- lua urlencode urldecode URL编码
URL编码其实就是对一些字符转义为%加上该字符对应ASCII码的二位十六进制形式. 如: 字符 特殊字符的含义 URL编码 # 用来标志特定的文档位置 % % 对特殊字符进行编码 % & 分隔 ...
- dubbo接口测试
1.下载所需工具eclipse或intellij idea,下载maven,maven中config/settings.xml中要添加公司(测试人员公司)的maven库,不然被测dubbo服务jar包 ...
- C语言 面试
P1(多选)有如下定义 int a; int *b; 则下列哪些语句是正确的:A: b=&a;B: b=*a;C: b=(int*)a;D: *b=a; 思路如下:b是一个int类型指针,a是 ...
- cpython和lua源码阅读
cpython代码很多,不太容易看出来. lua代码真的短小精悍,不得不佩服.