Comments (6)
aidijing-basic-config
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<!-- 注意这里 -->
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<!-- 注意这里 -->
<scope>provided</scope>
</dependency>
引入 aidijing-basic-config 时,并且需要启用 swagger ,那么源项目需要引入 swagger 的依赖
比如 :
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
from spring-boot-start-current.
搞定了,谢谢大神.
麻烦再请教下全局保存用户登录信息呢.
from spring-boot-start-current.
ContextUtils 这里面获取用户信息
JWT 是无 session 化的,每次请求,请求端都需要携带token,然后解析token,再从redis中得到用户信息.
你看看 JwtAuthenticationTokenFilter.java
@Override
protected void doFilterInternal ( HttpServletRequest request , HttpServletResponse response ,
FilterChain chain ) throws ServletException, IOException {
final String authToken = this.extractAuthTokenFromRequest( request , this.tokenHeader );
final String username = jwtTokenUtil.getUsernameFromToken( authToken );
LogUtils.getLogger().debug( "authToken : {},username : {}" , authToken , username );
if ( username != null && SecurityContextHolder.getContext().getAuthentication() == null ) {
// 对于简单的验证,只需检查令牌的完整性即可。 您不必强制调用数据库。 由你自己决定
// 是否查询数据看情况,目前是查询数据库
UserDetails userDetails = this.userDetailsService.loadUserByUsername( username );
if ( jwtTokenUtil.validateToken( authToken , userDetails ) ) {
UsernamePasswordAuthenticationToken authentication =
new UsernamePasswordAuthenticationToken( userDetails , null , userDetails.getAuthorities() );
ThreadContext.put( USER_ID , String.valueOf( ( ( BasicJwtUser ) userDetails ).getId() ) );
ThreadContext.put( USER_NAME , username );
authentication.setDetails( new WebAuthenticationDetailsSource().buildDetails( request ) );
LogUtils.getLogger().debug( "authToken : {},username : {}" , authToken , username );
LogUtils.getLogger().debug( "该 " + username + "用户已认证, 设置安全上下文" );
// 你看看这里的源码,设置到Security上下文中去了(当前请求有效)
SecurityContextHolder.getContext().setAuthentication( authentication );
}
}
chain.doFilter( request , response );
ThreadContext.clearAll();
}
ContextUtils.java 这个类的注释你也看看,这里就是从 SecurityContextHolder.getContext() 获取当次请求的用户信息
from spring-boot-start-current.
好的,谢谢大神,能不能建个群啊,方便大家交流.
from spring-boot-start-current.
抬举了,这个项目只是一些积累
群就不必了,比较麻烦. 这个项目不算复杂,看看就会了
from spring-boot-start-current.
好的,谢谢大神.
from spring-boot-start-current.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring-boot-start-current.