-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/1.0.0' into develop
- Loading branch information
Showing
13 changed files
with
247 additions
and
267 deletions.
There are no files selected for viewing
File renamed without changes.
102 changes: 102 additions & 0 deletions
102
...ity-starter/src/main/java/com/fuhouyu/framework/security/AuthenticationConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Copyright 2024-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.fuhouyu.framework.security; | ||
|
||
import com.fuhouyu.framework.security.core.passwordencoder.PasswordEncoderFactory; | ||
import com.fuhouyu.framework.security.core.provider.oidc.OidcAuthenticationProvider; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Primary; | ||
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.core.userdetails.UserDetailsService; | ||
import org.springframework.security.crypto.password.PasswordEncoder; | ||
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository; | ||
import org.springframework.security.oauth2.client.userinfo.DefaultOAuth2UserService; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* <p> | ||
* oidc配置 | ||
* </p> | ||
* | ||
* @author fuhouyu | ||
* @since 2024/11/4 22:06 | ||
*/ | ||
@Configuration | ||
public class AuthenticationConfiguration { | ||
|
||
/** | ||
* dao层实现 | ||
* | ||
* @param passwordEncoder 密码管理器 | ||
* @param userDetailsService 用户详情接口 | ||
* @return dao默认实现 | ||
*/ | ||
@Bean | ||
public AuthenticationProvider daoAuthenticationProvider(UserDetailsService userDetailsService, | ||
PasswordEncoder passwordEncoder) { | ||
DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider(passwordEncoder); | ||
daoAuthenticationProvider.setUserDetailsService(userDetailsService); | ||
return daoAuthenticationProvider; | ||
} | ||
|
||
/** | ||
* oidc provider | ||
* | ||
* @param userDetailsService 用户详情service | ||
* @param clientRegistrationRepository 客户端仓库信息 | ||
* @return oidcProvider | ||
*/ | ||
@Bean | ||
@ConditionalOnBean({UserDetailsService.class, ClientRegistrationRepository.class}) | ||
public AuthenticationProvider oidcAuthenticationProvider(UserDetailsService userDetailsService, | ||
ClientRegistrationRepository clientRegistrationRepository) { | ||
return new OidcAuthenticationProvider(new DefaultOAuth2UserService(), userDetailsService, clientRegistrationRepository); | ||
} | ||
|
||
|
||
/** | ||
* 认证管理器配置这里可以进行除其他登录模式的扩展,需要实现{@link AuthenticationProvider} | ||
* | ||
* @param authenticationProviders 认证提供者集合 | ||
* @return 认证管理器 | ||
*/ | ||
@Bean | ||
@Primary | ||
@ConditionalOnBean({AuthenticationProvider.class}) | ||
public AuthenticationManager authenticationManager(List<AuthenticationProvider> authenticationProviders) { | ||
return new ProviderManager(authenticationProviders); | ||
} | ||
|
||
/** | ||
* 返回sm3 密码编码器的bean,当passwordEncoder不存在时,则会创建。 | ||
* | ||
* @return sm3 密码编码器bean | ||
*/ | ||
@Bean | ||
@ConditionalOnMissingBean(PasswordEncoder.class) | ||
public PasswordEncoder passwordEncoder() { | ||
return PasswordEncoderFactory.createDelegatingPasswordEncoder("sm3"); | ||
} | ||
|
||
|
||
} |
65 changes: 0 additions & 65 deletions
65
...ter/src/main/java/com/fuhouyu/framework/security/AuthenticationProviderConfiguration.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.