From 9d80a93fd5a34b565719672f14afb2bf97dd3e6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=87=95=E9=B9=8F?= Date: Mon, 30 Nov 2020 09:35:29 +0800 Subject: [PATCH] =?UTF-8?q?jwt=E6=9D=83=E9=99=90=E8=B5=B0=E9=80=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/aiprose/scauth/conf/WebSecurityConfig.java | 8 ++------ src/main/java/com/aiprose/scauth/entity/Menu.java | 2 +- src/main/java/com/aiprose/scauth/entity/User.java | 4 ++++ 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/aiprose/scauth/conf/WebSecurityConfig.java b/src/main/java/com/aiprose/scauth/conf/WebSecurityConfig.java index ed23b83..aaa7c00 100644 --- a/src/main/java/com/aiprose/scauth/conf/WebSecurityConfig.java +++ b/src/main/java/com/aiprose/scauth/conf/WebSecurityConfig.java @@ -40,7 +40,7 @@ import java.util.List; * @since 1.0 */ @Configuration -//@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true, jsr250Enabled = true) +@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true, jsr250Enabled = true) public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Autowired private IUserService userService; @@ -50,8 +50,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Override public void configure(WebSecurity web) throws Exception { -// super.configure(web); - web.ignoring().antMatchers("login", "/v2/api-docs/**", "/swagger-resources/**", "/swagger-ui.html"); + web.ignoring().antMatchers("/v3/api-docs/**", "/swagger-resources/**", "/swagger-ui/**","/swagger-ui/index.html"); } @Override @@ -60,7 +59,6 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { // 授权配置 http.authorizeRequests().anyRequest().authenticated(); - // 配置登录 http.formLogin().usernameParameter("username").passwordParameter("password").loginProcessingUrl("/login"); @@ -76,9 +74,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { // 登出授权 // http.logout().permitAll(); - http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS); - /* 配置token验证过滤器 */ http.addFilterBefore(new JWTAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class); } diff --git a/src/main/java/com/aiprose/scauth/entity/Menu.java b/src/main/java/com/aiprose/scauth/entity/Menu.java index ad2b397..8e90927 100644 --- a/src/main/java/com/aiprose/scauth/entity/Menu.java +++ b/src/main/java/com/aiprose/scauth/entity/Menu.java @@ -13,7 +13,7 @@ import javax.persistence.Table; * @date 2020/11/27 17:04 * @since 1.0 */ - @Data +@Data @Entity @Table(name = "sys_menu") public class Menu extends IDEntity { diff --git a/src/main/java/com/aiprose/scauth/entity/User.java b/src/main/java/com/aiprose/scauth/entity/User.java index aa21488..cad3043 100644 --- a/src/main/java/com/aiprose/scauth/entity/User.java +++ b/src/main/java/com/aiprose/scauth/entity/User.java @@ -1,5 +1,7 @@ package com.aiprose.scauth.entity; +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.Data; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; @@ -42,6 +44,8 @@ public class User extends IDEntity implements UserDetails { @Transient private List roles; + @JsonIgnore + @JSONField(serialize = false) @Override public Collection getAuthorities() { return roles;