From 62d1a761ccb20a5fd4d008767fb4951e46ef43f5 Mon Sep 17 00:00:00 2001 From: weihongyang <1075331873@qq.com> Date: Tue, 21 Jun 2022 17:00:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9sercurity=E7=9A=84conf?= =?UTF-8?q?ig=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/cnbm/admin/config/SecurityConfig.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/ym-admin/src/main/java/com/cnbm/admin/config/SecurityConfig.java b/ym-admin/src/main/java/com/cnbm/admin/config/SecurityConfig.java index 8a6b5c8..d6fb33b 100644 --- a/ym-admin/src/main/java/com/cnbm/admin/config/SecurityConfig.java +++ b/ym-admin/src/main/java/com/cnbm/admin/config/SecurityConfig.java @@ -1,10 +1,14 @@ package com.cnbm.admin.config; import com.cnbm.admin.filter.JwtAuthenticationTokenFilter; +import com.cnbm.admin.service.impl.UserDetailsServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.authentication.AuthenticationProvider; +import org.springframework.security.authentication.dao.DaoAuthenticationProvider; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 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.configuration.WebSecurityConfigurerAdapter; @@ -38,6 +42,10 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { @Autowired private AccessDeniedHandler accessDeniedHandler; + @Autowired + private UserDetailsServiceImpl userDetailsService; + + @Override protected void configure(HttpSecurity http) throws Exception { http @@ -75,4 +83,22 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { public AuthenticationManager authenticationManagerBean() throws Exception { return super.authenticationManagerBean(); } + + + @Bean + public AuthenticationProvider daoAuthenticationProvider() { + DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider(); + daoAuthenticationProvider.setUserDetailsService(userDetailsService); + daoAuthenticationProvider.setPasswordEncoder(passwordEncoder()); + daoAuthenticationProvider.setHideUserNotFoundExceptions(false); + return daoAuthenticationProvider; + } + @Override + protected void configure(AuthenticationManagerBuilder auth) throws Exception { + // 加入自定义认证, 无需配置userDetailsService,否则会执行默认的provider + // auth.authenticationProvider(myAuthenticationProvider()); + /* auth.userDetailsService(userService) + .passwordEncoder(passwordEncoder());*/ + auth.authenticationProvider(daoAuthenticationProvider()); + } }