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层,它在网络间通信是加 ...
随机推荐
- Servlet/Jsp实现购物车
(1)用servlet实现简单的购物车系统,项目结构例如以下:(新建web Project项目 仅仅须要AddItemServlet , ListItemServlet.exam403.jsp三个文 ...
- C#:将数据网格内的数据导出到Excel
public void ExportDataToExecel(DataGridView dataGridView1) { SaveFileDialog kk = new SaveFileDialog( ...
- SectionIndexer中的getSectionForPosition()与getPositionForSection()解惑
大家在做字母索引的时候常常会用到SectionIndexer这个类,里面有2个重要的方法 1. getSectionForPosition()通过该项的位置,获得所在分类组的索引号 2. ge ...
- 容器适配器(stack、 queue 、priority_queue)源码浅析与使用示例
一.容器适配器 stack queue priority_queue stack.queue.priority_queue 都不支持任一种迭代器,它们都是容器适配器类型,stack是用vector/d ...
- android:hint属性对TextView的影响
近期看到同事写的一段代码,非常easy吧就是: <LinearLayout android:layout_width="wrap_content" android:layou ...
- CTC loss 理解
参考文献 CTC学习笔记(一) 简介:https://blog.csdn.net/xmdxcsj/article/details/51763868 CTC学习笔记(二) 训练和公式推导 很详细的公示推 ...
- 关闭危害的端口DOS命令(转载)
rem ipseccmd -w REG -p "HFUT_SECU" -r "Block UDP/137" -f *+0:137:UDP -n BLOCK -x ...
- struts2 的国际化
一.使用步骤 1)写资源文件,资源文件名命名规范和之前的讲的一致,有疑问请参考java开发中国际化 2)配置,在 struts.xml 中使用常量进行加载 struts.custom.i18n.res ...
- HTTP长连接?短连接?长轮询?短轮询?
错觉与突然的察觉 大多数人都知道HTTP1.0不支持长连接,知道HTTP1.1支持长连接. 这是业界的一个常识. 然而这样的描述导致了一些不做网络底层开发的开发者都下意识的认为HTTP1.1是一个可以 ...
- IIS6 伪静态 IIS文件类型映射配置方法 【图解】
1.右键点击 要设置网站的网站 2.属性 -->主目录 -->配置--> 3.如右侧窗口,找到 .aspx 扩展名-->编辑-->复制 可执行文件的路径-->关闭 ...