🎨 Improving structure / format of the code.

This commit is contained in:
冷冷 2024-04-09 12:47:30 +08:00
parent b2c3a6b101
commit 33978af130
13 changed files with 109 additions and 107 deletions

View File

@ -69,7 +69,6 @@ public class AuthorizationServerConfiguration {
private final ValidateCodeFilter validateCodeFilter;
@Bean
@Order(Ordered.HIGHEST_PRECEDENCE)
@ConditionalOnProperty(value = "security.micro", matchIfMissing = true)
@ -90,14 +89,20 @@ public class AuthorizationServerConfiguration {
.authorizationEndpoint(authorizationEndpoint -> authorizationEndpoint// 授权码端点个性化confirm页面
.consentPage(SecurityConstants.CUSTOM_CONSENT_PAGE_URI)), Customizer.withDefaults());
AntPathRequestMatcher[] requestMatchers = new AntPathRequestMatcher[]{AntPathRequestMatcher.antMatcher("/token/**"), AntPathRequestMatcher.antMatcher("/actuator/**"), AntPathRequestMatcher.antMatcher("/code/image"), AntPathRequestMatcher.antMatcher("/css/**"), AntPathRequestMatcher.antMatcher("/error")};
AntPathRequestMatcher[] requestMatchers = new AntPathRequestMatcher[]{
AntPathRequestMatcher.antMatcher("/token/**"), AntPathRequestMatcher.antMatcher("/actuator/**"),
AntPathRequestMatcher.antMatcher("/code/image"), AntPathRequestMatcher.antMatcher("/css/**"),
AntPathRequestMatcher.antMatcher("/error")};
http.authorizeHttpRequests(authorizeRequests -> {
// 自定义接口端点暴露
authorizeRequests.requestMatchers(requestMatchers).permitAll();
authorizeRequests.anyRequest().authenticated();
}).with(authorizationServerConfigurer.authorizationService(authorizationService)// redis存储token的实现
.authorizationServerSettings(AuthorizationServerSettings.builder().issuer(SecurityConstants.PROJECT_LICENSE).build()), Customizer.withDefaults());
})
.with(authorizationServerConfigurer.authorizationService(authorizationService)// redis存储token的实现
.authorizationServerSettings(
AuthorizationServerSettings.builder().issuer(SecurityConstants.PROJECT_LICENSE).build()),
Customizer.withDefaults());
http.with(new FormIdentityLoginConfigurer(), Customizer.withDefaults());
DefaultSecurityFilterChain securityFilterChain = http.build();
@ -128,7 +133,12 @@ public class AuthorizationServerConfiguration {
*/
@Bean
public AuthenticationConverter accessTokenRequestConverter() {
return new DelegatingAuthenticationConverter(Arrays.asList(new OAuth2ResourceOwnerPasswordAuthenticationConverter(), new OAuth2ResourceOwnerSmsAuthenticationConverter(), new OAuth2RefreshTokenAuthenticationConverter(), new OAuth2ClientCredentialsAuthenticationConverter(), new OAuth2AuthorizationCodeAuthenticationConverter(), new OAuth2AuthorizationCodeRequestAuthenticationConverter()));
return new DelegatingAuthenticationConverter(Arrays.asList(
new OAuth2ResourceOwnerPasswordAuthenticationConverter(),
new OAuth2ResourceOwnerSmsAuthenticationConverter(), new OAuth2RefreshTokenAuthenticationConverter(),
new OAuth2ClientCredentialsAuthenticationConverter(),
new OAuth2AuthorizationCodeAuthenticationConverter(),
new OAuth2AuthorizationCodeRequestAuthenticationConverter()));
}
/**
@ -142,9 +152,11 @@ public class AuthorizationServerConfiguration {
AuthenticationManager authenticationManager = http.getSharedObject(AuthenticationManager.class);
OAuth2AuthorizationService authorizationService = http.getSharedObject(OAuth2AuthorizationService.class);
OAuth2ResourceOwnerPasswordAuthenticationProvider resourceOwnerPasswordAuthenticationProvider = new OAuth2ResourceOwnerPasswordAuthenticationProvider(authenticationManager, authorizationService, oAuth2TokenGenerator());
OAuth2ResourceOwnerPasswordAuthenticationProvider resourceOwnerPasswordAuthenticationProvider = new OAuth2ResourceOwnerPasswordAuthenticationProvider(
authenticationManager, authorizationService, oAuth2TokenGenerator());
OAuth2ResourceOwnerSmsAuthenticationProvider resourceOwnerSmsAuthenticationProvider = new OAuth2ResourceOwnerSmsAuthenticationProvider(authenticationManager, authorizationService, oAuth2TokenGenerator());
OAuth2ResourceOwnerSmsAuthenticationProvider resourceOwnerSmsAuthenticationProvider = new OAuth2ResourceOwnerSmsAuthenticationProvider(
authenticationManager, authorizationService, oAuth2TokenGenerator());
// 处理 UsernamePasswordAuthenticationToken
http.authenticationProvider(new PigDaoAuthenticationProvider());

View File

@ -53,14 +53,14 @@ public class PasswordDecoderFilter extends OncePerRequestFilter {
private static final String KEY_ALGORITHM = "AES";
static {
// 关闭hutool 强制关闭Bouncy Castle库的依赖
SecureUtil.disableBouncyCastle();
}
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException {
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
throws ServletException, IOException {
// 不是登录请求直接向下执行
if (!StrUtil.containsAnyIgnoreCase(request.getRequestURI(), SecurityConstants.OAUTH_TOKEN_URL)) {
chain.doFilter(request, response);
@ -76,7 +76,6 @@ public class PasswordDecoderFilter extends OncePerRequestFilter {
new SecretKeySpec(authSecurityConfigProperties.getEncodeKey().getBytes(), KEY_ALGORITHM),
new IvParameterSpec(authSecurityConfigProperties.getEncodeKey().getBytes()));
parameterMap.forEach((k, v) -> {
String[] values = parameterMap.get(k);
if (!PASSWORD.equals(k) || ArrayUtil.isEmpty(values)) {
@ -90,5 +89,4 @@ public class PasswordDecoderFilter extends OncePerRequestFilter {
chain.doFilter(requestWrapper, response);
}
}

View File

@ -7,7 +7,6 @@ package com.pig4cloud.pig.auth.support.filter;
* @date 2024/4/3
*/
import cn.hutool.core.util.StrUtil;
import com.pig4cloud.pig.common.core.constant.CacheConstants;
import com.pig4cloud.pig.common.core.constant.SecurityConstants;
@ -42,9 +41,9 @@ public class ValidateCodeFilter extends OncePerRequestFilter {
private final AuthSecurityConfigProperties authSecurityConfigProperties;
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
String requestUrl = request.getServletPath();
@ -123,4 +122,3 @@ public class ValidateCodeFilter extends OncePerRequestFilter {
}
}

View File

@ -22,8 +22,7 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @author lengleng
* 单体版本启动器只需要运行此模块则整个系统启动
* @author lengleng 单体版本启动器只需要运行此模块则整个系统启动
*/
@EnablePigDoc(value = "admin", isMicro = false)
@EnablePigResourceServer

View File

@ -52,8 +52,7 @@ import org.springframework.security.web.authentication.UsernamePasswordAuthentic
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
/**
* @author lengleng
* 认证授权服务器配置
* @author lengleng 认证授权服务器配置
*/
@Configuration
@RequiredArgsConstructor
@ -77,7 +76,6 @@ public class PigBootSecurityServerConfiguration {
private final PermitAllUrlProperties permitAllUrl;
@Bean
@Order(Ordered.HIGHEST_PRECEDENCE)
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
@ -132,7 +130,6 @@ public class PigBootSecurityServerConfiguration {
return securityFilterChain;
}
/**
* 注入授权模式实现提供方
* <p>

View File

@ -27,7 +27,6 @@ public class OpenAPIMetadataConfiguration implements InitializingBean, Applicati
return;
}
ServiceInstance serviceInstance = applicationContext.getBean(ServiceInstance.class);
serviceInstance.getMetadata().put("spring-doc", path);
}

View File

@ -14,7 +14,6 @@ import org.springframework.context.annotation.Configuration;
@Configuration(proxyBeanMethods = false)
public class GatewayConfiguration {
/**
* 创建PigRequest全局过滤器
* @return PigRequest全局过滤器
@ -24,7 +23,6 @@ public class GatewayConfiguration {
return new PigRequestGlobalFilter();
}
/**
* 创建全局异常处理程序
* @param objectMapper 对象映射器
@ -35,5 +33,4 @@ public class GatewayConfiguration {
return new GlobalExceptionHandler(objectMapper);
}
}

View File

@ -60,4 +60,5 @@ public interface SysLogService extends IService<SysLog> {
* @return List<SysLog>
*/
List<SysLog> getList(SysLogDTO sysLog);
}

View File

@ -93,4 +93,5 @@ public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> impleme
return wrapper;
}
}