-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
老铁,Swagger2 怎么启用? #1
Comments
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 的依赖
|
搞定了,谢谢大神. |
ContextUtils 这里面获取用户信息 你看看 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() 获取当次请求的用户信息 |
好的,谢谢大神,能不能建个群啊,方便大家交流. |
抬举了,这个项目只是一些积累 |
好的,谢谢大神. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
如题.
@configuration
@EnableSwagger2
启用Swagger2Config 后项目起不来了.
还有就是怎么全局保存用户登录信息呢.
The text was updated successfully, but these errors were encountered: