Skip to content

Commit

Permalink
Merge branch 'feature/1.0.0' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
fuhouyu committed Nov 4, 2024
2 parents e29ca66 + f797ca5 commit 49f407e
Show file tree
Hide file tree
Showing 15 changed files with 549 additions and 394 deletions.
4 changes: 4 additions & 0 deletions base-framework-security-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,9 @@
<artifactId>spring-boot-starter-data-redis</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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 org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
* <p>
* oidc配置
* </p>
*
* @author fuhouyu
* @since 2024/11/4 22:06
*/
@Configuration(proxyBeanMethods = false)
public class AuthenticationProviderConfiguration {

/**
* 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
// public AuthenticationProvider oidcAuthenticationProvider(UserDetailsService userDetailsService,
// ClientRegistrationRepository clientRegistrationRepository) {
// return new OidcAuthenticationProvider(new DefaultOAuth2UserService(), userDetailsService, clientRegistrationRepository);
// }


}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@
import com.fuhouyu.framework.security.token.TokenStoreCache;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.security.oauth2.client.servlet.OAuth2ClientAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
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 java.util.List;
Expand All @@ -44,9 +43,12 @@
* @author fuhouyu
* @since 2024/8/15 16:22
*/
@Configuration
@Import({OpenPlatformConfiguration.class})
@AutoConfigureAfter(CacheAutoConfiguration.class)
@Configuration(proxyBeanMethods = false)
@AutoConfigureAfter({
CacheAutoConfiguration.class,
OAuth2ClientAutoConfiguration.class
})
@Import({AuthenticationProviderConfiguration.class})
public class SecurityAutoConfiguration {

/**
Expand All @@ -66,17 +68,11 @@ public TokenStore tokenStore(CacheService<String, Object> cacheService) {
* 认证管理器配置这里可以进行除其他登录模式的扩展,需要实现{@link AuthenticationProvider}
*
* @param authenticationProviders 认证提供者集合
* @param userDetailsService 用户接口详情
* @param passwordEncoder 密码认证管理器
* @return 认证管理器
*/
@Bean("authenticationManager")
@Bean
@Primary
public AuthenticationManager authenticationManager(
List<AuthenticationProvider> authenticationProviders,
UserDetailsService userDetailsService,
PasswordEncoder passwordEncoder) {
authenticationProviders.add(daoAuthenticationProvider(userDetailsService, passwordEncoder));
public AuthenticationManager authenticationManager(List<AuthenticationProvider> authenticationProviders) {
return new ProviderManager(authenticationProviders);
}

Expand All @@ -91,19 +87,5 @@ public PasswordEncoder passwordEncoder() {
return PasswordEncoderFactory.createDelegatingPasswordEncoder("sm3");
}

/**
* dao层实现
*
* @param passwordEncoder 密码管理器
* @param userDetailsService 用户详情接口
* @return dao默认实现
*/
private AuthenticationProvider daoAuthenticationProvider(UserDetailsService userDetailsService,
PasswordEncoder passwordEncoder) {
DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider(passwordEncoder);
daoAuthenticationProvider.setUserDetailsService(userDetailsService);
return daoAuthenticationProvider;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
package com.fuhouyu.framework.security.core;

import com.fuhouyu.framework.common.utils.JacksonUtil;
import com.fuhouyu.framework.security.core.authentication.refreshtoken.RefreshAuthenticationProvider;
import com.fuhouyu.framework.security.core.authentication.wechat.WechatAppletsPlatformProvider;
import com.fuhouyu.framework.security.core.provider.refreshtoken.RefreshAuthenticationProvider;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.security.authentication.AbstractAuthenticationToken;
Expand Down Expand Up @@ -62,16 +61,7 @@ public <T extends AbstractAuthenticationToken> Class<T> getAuthenticationTokenCl
return (Class<T>) RefreshAuthenticationProvider.RefreshAuthenticationToken.class;
}
},

/**
* 微信小程序
*/
WECHAT_APPLETS("WECHAT_APPLETS") {
@Override
public <T extends AbstractAuthenticationToken> Class<T> getAuthenticationTokenClass() {
return (Class<T>) WechatAppletsPlatformProvider.WechatAppletsAuthenticationToken.class;
}
};
;

private final String grantType;

Expand Down

This file was deleted.

Loading

0 comments on commit 49f407e

Please sign in to comment.