From 234b0ac195934b34c06045b2d2ef0f10e239dd8e Mon Sep 17 00:00:00 2001 From: zhuo <2089219845@qq.com> Date: 星期三, 23 四月 2025 00:06:54 +0800 Subject: [PATCH] 系统合并 --- ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java | 35 +++++++++++++++++++++++++++++------ 1 files changed, 29 insertions(+), 6 deletions(-) diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java index 511842b..13b3568 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java @@ -1,10 +1,13 @@ package com.ruoyi.framework.config; +import com.ruoyi.framework.web.ssoAuth.SsoCodeAuthenticationProvider; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpMethod; import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.authentication.AuthenticationProvider; import org.springframework.security.authentication.ProviderManager; import org.springframework.security.authentication.dao.DaoAuthenticationProvider; import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; @@ -21,9 +24,12 @@ import com.ruoyi.framework.security.handle.AuthenticationEntryPointImpl; import com.ruoyi.framework.security.handle.LogoutSuccessHandlerImpl; +import java.util.ArrayList; +import java.util.List; + /** * spring security閰嶇疆 - * + * * @author ruoyi */ @EnableMethodSecurity(prePostEnabled = true, securedEnabled = true) @@ -34,8 +40,16 @@ * 鑷畾涔夌敤鎴疯璇侀�昏緫 */ @Autowired + @Qualifier("UserDetailsServiceImpl") private UserDetailsService userDetailsService; - + + /** + * sso鑷畾涔夋牎楠� + */ + @Autowired + @Qualifier("UserDetailsByOpenIdServiceImpl") + private UserDetailsService userDetailsServiceBySSO; + /** * 璁よ瘉澶辫触澶勭悊绫� */ @@ -53,7 +67,7 @@ */ @Autowired private JwtAuthenticationTokenFilter authenticationTokenFilter; - + /** * 璺ㄥ煙杩囨护鍣� */ @@ -75,7 +89,16 @@ DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider(); daoAuthenticationProvider.setUserDetailsService(userDetailsService); daoAuthenticationProvider.setPasswordEncoder(bCryptPasswordEncoder()); - return new ProviderManager(daoAuthenticationProvider); + + // sso鐧婚檰閴存潈 Provider + SsoCodeAuthenticationProvider ssoCodeAuthenticationProvider = new SsoCodeAuthenticationProvider(); + ssoCodeAuthenticationProvider.setUserDetailsService(userDetailsServiceBySSO); + List<AuthenticationProvider> providers = new ArrayList<>(); + + providers.add(ssoCodeAuthenticationProvider); + providers.add(daoAuthenticationProvider); + + return new ProviderManager(providers); } /** @@ -111,9 +134,9 @@ .authorizeHttpRequests((requests) -> { permitAllUrl.getUrls().forEach(url -> requests.antMatchers(url).permitAll()); // 瀵逛簬鐧诲綍login 娉ㄥ唽register 楠岃瘉鐮乧aptchaImage 鍏佽鍖垮悕璁块棶 - requests.antMatchers("/login", "/register", "/captchaImage").permitAll() + requests.antMatchers("/login", "/register", "/captchaImage", "/getSsoAuthUrl", "/loginBySSO").permitAll() // 闈欐�佽祫婧愶紝鍙尶鍚嶈闂� - .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll() + .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**", "/img/**", "/word/**").permitAll() .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll() // 闄や笂闈㈠鐨勬墍鏈夎姹傚叏閮ㄩ渶瑕侀壌鏉冭璇� .anyRequest().authenticated(); -- Gitblit v1.9.3