🎨 Improving structure / format of the code. 代码格式化

This commit is contained in:
冷冷 2024-04-17 13:40:38 +08:00
parent 4ef0bb4dbe
commit af10316ce0
11 changed files with 65 additions and 77 deletions

View File

@ -81,28 +81,28 @@ public class AuthorizationServerConfiguration {
http.addFilterBefore(passwordDecoderFilter, UsernamePasswordAuthenticationFilter.class); http.addFilterBefore(passwordDecoderFilter, UsernamePasswordAuthenticationFilter.class);
http.with(authorizationServerConfigurer.tokenEndpoint((tokenEndpoint) -> {// 个性化认证授权端点 http.with(authorizationServerConfigurer.tokenEndpoint((tokenEndpoint) -> {// 个性化认证授权端点
tokenEndpoint.accessTokenRequestConverter(accessTokenRequestConverter()) // 注入自定义的授权认证Converter tokenEndpoint.accessTokenRequestConverter(accessTokenRequestConverter()) // 注入自定义的授权认证Converter
.accessTokenResponseHandler(new PigAuthenticationSuccessEventHandler()) // 登录成功处理器 .accessTokenResponseHandler(new PigAuthenticationSuccessEventHandler()) // 登录成功处理器
.errorResponseHandler(new PigAuthenticationFailureEventHandler());// 登录失败处理器 .errorResponseHandler(new PigAuthenticationFailureEventHandler());// 登录失败处理器
}).clientAuthentication(oAuth2ClientAuthenticationConfigurer -> // 个性化客户端认证 }).clientAuthentication(oAuth2ClientAuthenticationConfigurer -> // 个性化客户端认证
oAuth2ClientAuthenticationConfigurer.errorResponseHandler(new PigAuthenticationFailureEventHandler()))// 处理客户端认证异常 oAuth2ClientAuthenticationConfigurer.errorResponseHandler(new PigAuthenticationFailureEventHandler()))// 处理客户端认证异常
.authorizationEndpoint(authorizationEndpoint -> authorizationEndpoint// 授权码端点个性化confirm页面 .authorizationEndpoint(authorizationEndpoint -> authorizationEndpoint// 授权码端点个性化confirm页面
.consentPage(SecurityConstants.CUSTOM_CONSENT_PAGE_URI)), Customizer.withDefaults()); .consentPage(SecurityConstants.CUSTOM_CONSENT_PAGE_URI)), Customizer.withDefaults());
AntPathRequestMatcher[] requestMatchers = new AntPathRequestMatcher[]{ AntPathRequestMatcher[] requestMatchers = new AntPathRequestMatcher[] {
AntPathRequestMatcher.antMatcher("/token/**"), AntPathRequestMatcher.antMatcher("/actuator/**"), AntPathRequestMatcher.antMatcher("/token/**"), AntPathRequestMatcher.antMatcher("/actuator/**"),
AntPathRequestMatcher.antMatcher("/code/image"), AntPathRequestMatcher.antMatcher("/css/**"), AntPathRequestMatcher.antMatcher("/code/image"), AntPathRequestMatcher.antMatcher("/css/**"),
AntPathRequestMatcher.antMatcher("/error")}; AntPathRequestMatcher.antMatcher("/error") };
http.authorizeHttpRequests(authorizeRequests -> { http.authorizeHttpRequests(authorizeRequests -> {
// 自定义接口端点暴露 // 自定义接口端点暴露
authorizeRequests.requestMatchers(requestMatchers).permitAll(); authorizeRequests.requestMatchers(requestMatchers).permitAll();
authorizeRequests.anyRequest().authenticated(); authorizeRequests.anyRequest().authenticated();
}) })
.with(authorizationServerConfigurer.authorizationService(authorizationService)// redis存储token的实现 .with(authorizationServerConfigurer.authorizationService(authorizationService)// redis存储token的实现
.authorizationServerSettings( .authorizationServerSettings(
AuthorizationServerSettings.builder().issuer(SecurityConstants.PROJECT_LICENSE).build()), AuthorizationServerSettings.builder().issuer(SecurityConstants.PROJECT_LICENSE).build()),
Customizer.withDefaults()); Customizer.withDefaults());
http.with(new FormIdentityLoginConfigurer(), Customizer.withDefaults()); http.with(new FormIdentityLoginConfigurer(), Customizer.withDefaults());
DefaultSecurityFilterChain securityFilterChain = http.build(); DefaultSecurityFilterChain securityFilterChain = http.build();

View File

@ -40,7 +40,7 @@ public class ImageCodeEndpoint {
String result = captcha.text(); String result = captcha.text();
redisTemplate.opsForValue() redisTemplate.opsForValue()
.set(CacheConstants.DEFAULT_CODE_KEY + randomStr, result, SecurityConstants.CODE_TIME, TimeUnit.SECONDS); .set(CacheConstants.DEFAULT_CODE_KEY + randomStr, result, SecurityConstants.CODE_TIME, TimeUnit.SECONDS);
// 转换流信息写出 // 转换流信息写出
captcha.out(response.getOutputStream()); captcha.out(response.getOutputStream());
} }

View File

@ -92,9 +92,8 @@ public class PigTokenEndpoint {
/** /**
* 认证页面 * 认证页面
*
* @param modelAndView * @param modelAndView
* @param error 表单登录失败处理回调的错误信息 * @param error 表单登录失败处理回调的错误信息
* @return ModelAndView * @return ModelAndView
*/ */
@GetMapping("/login") @GetMapping("/login")
@ -106,13 +105,13 @@ public class PigTokenEndpoint {
@GetMapping("/confirm_access") @GetMapping("/confirm_access")
public ModelAndView confirm(Principal principal, ModelAndView modelAndView, public ModelAndView confirm(Principal principal, ModelAndView modelAndView,
@RequestParam(OAuth2ParameterNames.CLIENT_ID) String clientId, @RequestParam(OAuth2ParameterNames.CLIENT_ID) String clientId,
@RequestParam(OAuth2ParameterNames.SCOPE) String scope, @RequestParam(OAuth2ParameterNames.SCOPE) String scope,
@RequestParam(OAuth2ParameterNames.STATE) String state) { @RequestParam(OAuth2ParameterNames.STATE) String state) {
SysOauthClientDetails clientDetails = RetOps SysOauthClientDetails clientDetails = RetOps
.of(clientDetailsService.getClientDetailsById(clientId, SecurityConstants.FROM_IN)) .of(clientDetailsService.getClientDetailsById(clientId, SecurityConstants.FROM_IN))
.getData() .getData()
.orElseThrow(() -> new OAuthClientException("clientId 不合法")); .orElseThrow(() -> new OAuthClientException("clientId 不合法"));
Set<String> authorizedScopes = StringUtils.commaDelimitedListToSet(clientDetails.getScope()); Set<String> authorizedScopes = StringUtils.commaDelimitedListToSet(clientDetails.getScope());
modelAndView.addObject("clientId", clientId); modelAndView.addObject("clientId", clientId);
@ -125,7 +124,6 @@ public class PigTokenEndpoint {
/** /**
* 退出并删除token * 退出并删除token
*
* @param authHeader Authorization * @param authHeader Authorization
*/ */
@DeleteMapping("/logout") @DeleteMapping("/logout")
@ -140,7 +138,6 @@ public class PigTokenEndpoint {
/** /**
* 校验token * 校验token
*
* @param token 令牌 * @param token 令牌
*/ */
@SneakyThrows @SneakyThrows
@ -171,7 +168,6 @@ public class PigTokenEndpoint {
/** /**
* 令牌管理调用 * 令牌管理调用
*
* @param token token * @param token token
*/ */
@Inner @Inner
@ -198,7 +194,6 @@ public class PigTokenEndpoint {
/** /**
* 查询token * 查询token
*
* @param params 分页参数 * @param params 分页参数
* @return * @return
*/ */

View File

@ -84,7 +84,7 @@ public class PasswordDecoderFilter extends OncePerRequestFilter {
// 解密密码 // 解密密码
String decryptPassword = aes.decryptStr(values[0]); String decryptPassword = aes.decryptStr(values[0]);
parameterMap.put(k, new String[]{decryptPassword}); parameterMap.put(k, new String[] { decryptPassword });
}); });
chain.doFilter(requestWrapper, response); chain.doFilter(requestWrapper, response);
} }

View File

@ -71,7 +71,8 @@ public class ValidateCodeFilter extends OncePerRequestFilter {
try { try {
checkCode(); checkCode();
filterChain.doFilter(request, response); filterChain.doFilter(request, response);
} catch (ValidateCodeException validateCodeException) { }
catch (ValidateCodeException validateCodeException) {
throw new OAuth2AuthenticationException(validateCodeException.getMessage()); throw new OAuth2AuthenticationException(validateCodeException.getMessage());
} }
} }

View File

@ -88,39 +88,39 @@ public class PigBootSecurityServerConfiguration {
// 认证服务器配置 // 认证服务器配置
http.with(authorizationServerConfigurer.tokenEndpoint((tokenEndpoint) -> {// 个性化认证授权端点 http.with(authorizationServerConfigurer.tokenEndpoint((tokenEndpoint) -> {// 个性化认证授权端点
tokenEndpoint.accessTokenRequestConverter(accessTokenRequestConverter) // 注入自定义的授权认证Converter tokenEndpoint.accessTokenRequestConverter(accessTokenRequestConverter) // 注入自定义的授权认证Converter
.accessTokenResponseHandler(new PigAuthenticationSuccessEventHandler()) // 登录成功处理器 .accessTokenResponseHandler(new PigAuthenticationSuccessEventHandler()) // 登录成功处理器
.errorResponseHandler(new PigAuthenticationFailureEventHandler());// 登录失败处理器 .errorResponseHandler(new PigAuthenticationFailureEventHandler());// 登录失败处理器
}).clientAuthentication(oAuth2ClientAuthenticationConfigurer -> // 个性化客户端认证 }).clientAuthentication(oAuth2ClientAuthenticationConfigurer -> // 个性化客户端认证
oAuth2ClientAuthenticationConfigurer.errorResponseHandler(new PigAuthenticationFailureEventHandler()))// 处理客户端认证异常 oAuth2ClientAuthenticationConfigurer.errorResponseHandler(new PigAuthenticationFailureEventHandler()))// 处理客户端认证异常
, Customizer.withDefaults()) , Customizer.withDefaults())
.with(authorizationServerConfigurer.authorizationService(authorizationService)// redis存储token的实现 .with(authorizationServerConfigurer.authorizationService(authorizationService)// redis存储token的实现
.authorizationServerSettings( .authorizationServerSettings(
AuthorizationServerSettings.builder().issuer(SecurityConstants.PROJECT_LICENSE).build()), AuthorizationServerSettings.builder().issuer(SecurityConstants.PROJECT_LICENSE).build()),
Customizer.withDefaults()); Customizer.withDefaults());
// 资源服务器配置 // 资源服务器配置
AntPathRequestMatcher[] requestMatchers = permitAllUrl.getUrls() AntPathRequestMatcher[] requestMatchers = permitAllUrl.getUrls()
.stream() .stream()
.map(AntPathRequestMatcher::new) .map(AntPathRequestMatcher::new)
.toList() .toList()
.toArray(new AntPathRequestMatcher[]{}); .toArray(new AntPathRequestMatcher[] {});
http.authorizeHttpRequests(authorizeRequests -> authorizeRequests.requestMatchers(requestMatchers) http.authorizeHttpRequests(authorizeRequests -> authorizeRequests.requestMatchers(requestMatchers)
.permitAll() .permitAll()
.anyRequest() .anyRequest()
.authenticated()) .authenticated())
.oauth2ResourceServer( .oauth2ResourceServer(
oauth2 -> oauth2.opaqueToken(token -> token.introspector(customOpaqueTokenIntrospector)) oauth2 -> oauth2.opaqueToken(token -> token.introspector(customOpaqueTokenIntrospector))
.authenticationEntryPoint(resourceAuthExceptionEntryPoint) .authenticationEntryPoint(resourceAuthExceptionEntryPoint)
.bearerTokenResolver(pigBearerTokenExtractor)) .bearerTokenResolver(pigBearerTokenExtractor))
.exceptionHandling(configurer -> configurer.authenticationEntryPoint(resourceAuthExceptionEntryPoint)) .exceptionHandling(configurer -> configurer.authenticationEntryPoint(resourceAuthExceptionEntryPoint))
.headers(headers -> headers.frameOptions(HeadersConfigurer.FrameOptionsConfig::disable)) .headers(headers -> headers.frameOptions(HeadersConfigurer.FrameOptionsConfig::disable))
.csrf(AbstractHttpConfigurer::disable); .csrf(AbstractHttpConfigurer::disable);
http.with(authorizationServerConfigurer.authorizationService(authorizationService)// redis存储token的实现 http.with(authorizationServerConfigurer.authorizationService(authorizationService)// redis存储token的实现
.authorizationServerSettings( .authorizationServerSettings(
AuthorizationServerSettings.builder().issuer(SecurityConstants.PROJECT_LICENSE).build()), AuthorizationServerSettings.builder().issuer(SecurityConstants.PROJECT_LICENSE).build()),
Customizer.withDefaults()); Customizer.withDefaults());
DefaultSecurityFilterChain securityFilterChain = http.build(); DefaultSecurityFilterChain securityFilterChain = http.build();

View File

@ -84,7 +84,8 @@ public class RepeatBodyRequestWrapper extends HttpServletRequestWrapper {
byte[] body = new byte[0]; byte[] body = new byte[0];
try { try {
body = StreamUtils.copyToByteArray(request.getInputStream()); body = StreamUtils.copyToByteArray(request.getInputStream());
} catch (IOException e) { }
catch (IOException e) {
log.error("解析流中数据异常", e); log.error("解析流中数据异常", e);
} }
return body; return body;
@ -92,7 +93,6 @@ public class RepeatBodyRequestWrapper extends HttpServletRequestWrapper {
/** /**
* 重写 getParameterMap() 方法 解决 undertow 中流被读取后会进行标记从而导致无法正确获取 body 中的表单数据的问题 * 重写 getParameterMap() 方法 解决 undertow 中流被读取后会进行标记从而导致无法正确获取 body 中的表单数据的问题
*
* @return Map<String, String [ ]> parameterMap * @return Map<String, String [ ]> parameterMap
*/ */
@Override @Override

View File

@ -98,7 +98,7 @@ public class PigFeignClientsRegistrar implements ImportBeanDefinitionRegistrar,
validate(attributes); validate(attributes);
BeanDefinitionBuilder definition = BeanDefinitionBuilder BeanDefinitionBuilder definition = BeanDefinitionBuilder
.genericBeanDefinition(FeignClientFactoryBean.class); .genericBeanDefinition(FeignClientFactoryBean.class);
definition.addPropertyValue("url", getUrl(registry, attributes)); definition.addPropertyValue("url", getUrl(registry, attributes));
definition.addPropertyValue("path", getPath(attributes)); definition.addPropertyValue("path", getPath(attributes));
String name = getName(attributes); String name = getName(attributes);
@ -110,7 +110,8 @@ public class PigFeignClientsRegistrar implements ImportBeanDefinitionRegistrar,
String contextId = getContextId(attributes); String contextId = getContextId(attributes);
aliasBuilder.append(contextId); aliasBuilder.append(contextId);
definition.addPropertyValue("contextId", contextId); definition.addPropertyValue("contextId", contextId);
} else { }
else {
aliasBuilder.append(name); aliasBuilder.append(name);
} }
@ -141,10 +142,11 @@ public class PigFeignClientsRegistrar implements ImportBeanDefinitionRegistrar,
} }
BeanDefinitionHolder holder = new BeanDefinitionHolder(beanDefinition, className, BeanDefinitionHolder holder = new BeanDefinitionHolder(beanDefinition, className,
new String[]{alias}); new String[] { alias });
BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry); BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry);
} catch (ClassNotFoundException e) { }
catch (ClassNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -153,7 +155,6 @@ public class PigFeignClientsRegistrar implements ImportBeanDefinitionRegistrar,
/** /**
* Return the class used by {@link SpringFactoriesLoader} to load configuration * Return the class used by {@link SpringFactoriesLoader} to load configuration
* candidates. * candidates.
*
* @return the factory class * @return the factory class
*/ */
private Class<?> getSpringFactoriesLoaderFactoryClass() { private Class<?> getSpringFactoriesLoaderFactoryClass() {
@ -259,7 +260,7 @@ public class PigFeignClientsRegistrar implements ImportBeanDefinitionRegistrar,
} }
private void registerClientConfiguration(BeanDefinitionRegistry registry, Object name, Object className, private void registerClientConfiguration(BeanDefinitionRegistry registry, Object name, Object className,
Object configuration) { Object configuration) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(FeignClientSpecification.class); BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(FeignClientSpecification.class);
builder.addConstructorArgValue(name); builder.addConstructorArgValue(name);
builder.addConstructorArgValue(className); builder.addConstructorArgValue(className);

View File

@ -57,8 +57,7 @@ public class SysLogController {
/** /**
* 简单分页查询 * 简单分页查询
* * @param page 分页对象
* @param page 分页对象
* @param sysLog 系统日志 * @param sysLog 系统日志
* @return * @return
*/ */
@ -69,7 +68,6 @@ public class SysLogController {
/** /**
* 批量删除日志 * 批量删除日志
*
* @param ids ID * @param ids ID
* @return success/false * @return success/false
*/ */
@ -81,7 +79,6 @@ public class SysLogController {
/** /**
* 插入日志 * 插入日志
*
* @param sysLog 日志实体 * @param sysLog 日志实体
* @return success/false * @return success/false
*/ */
@ -93,7 +90,6 @@ public class SysLogController {
/** /**
* 导出excel 表格 * 导出excel 表格
*
* @param sysLog 查询条件 * @param sysLog 查询条件
* @return * @return
*/ */

View File

@ -38,7 +38,6 @@ public interface SysLogService extends IService<SysLog> {
/** /**
* 分页查询日志 * 分页查询日志
*
* @param page * @param page
* @param sysLog * @param sysLog
* @return * @return
@ -47,7 +46,6 @@ public interface SysLogService extends IService<SysLog> {
/** /**
* 插入日志 * 插入日志
*
* @param sysLog 日志对象 * @param sysLog 日志对象
* @return true/false * @return true/false
*/ */

View File

@ -52,7 +52,6 @@ public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> impleme
/** /**
* 插入日志 * 插入日志
*
* @param sysLog 日志对象 * @param sysLog 日志对象
* @return true/false * @return true/false
*/ */
@ -65,7 +64,6 @@ public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> impleme
/** /**
* 查询日志列表 * 查询日志列表
*
* @param sysLog 查询条件 * @param sysLog 查询条件
* @return List<SysLog> * @return List<SysLog>
*/ */
@ -76,7 +74,6 @@ public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> impleme
/** /**
* 构建查询条件 * 构建查询条件
*
* @param sysLog 前端条件 * @param sysLog 前端条件
* @return LambdaQueryWrapper * @return LambdaQueryWrapper
*/ */
@ -88,7 +85,7 @@ public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> impleme
if (ArrayUtil.isNotEmpty(sysLog.getCreateTime())) { if (ArrayUtil.isNotEmpty(sysLog.getCreateTime())) {
wrapper.ge(SysLog::getCreateTime, sysLog.getCreateTime()[0]) wrapper.ge(SysLog::getCreateTime, sysLog.getCreateTime()[0])
.le(SysLog::getCreateTime, sysLog.getCreateTime()[1]); .le(SysLog::getCreateTime, sysLog.getCreateTime()[1]);
} }
return wrapper; return wrapper;