Skip to content

Commit

Permalink
🎨 Improving structure / format of the code. 代码格式化
Browse files Browse the repository at this point in the history
  • Loading branch information
lltx committed Apr 17, 2024
1 parent 4ef0bb4 commit af10316
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,28 +81,28 @@ public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity h
http.addFilterBefore(passwordDecoderFilter, UsernamePasswordAuthenticationFilter.class);

http.with(authorizationServerConfigurer.tokenEndpoint((tokenEndpoint) -> {// 个性化认证授权端点
tokenEndpoint.accessTokenRequestConverter(accessTokenRequestConverter()) // 注入自定义的授权认证Converter
.accessTokenResponseHandler(new PigAuthenticationSuccessEventHandler()) // 登录成功处理器
.errorResponseHandler(new PigAuthenticationFailureEventHandler());// 登录失败处理器
}).clientAuthentication(oAuth2ClientAuthenticationConfigurer -> // 个性化客户端认证
oAuth2ClientAuthenticationConfigurer.errorResponseHandler(new PigAuthenticationFailureEventHandler()))// 处理客户端认证异常
.authorizationEndpoint(authorizationEndpoint -> authorizationEndpoint// 授权码端点个性化confirm页面
.consentPage(SecurityConstants.CUSTOM_CONSENT_PAGE_URI)), Customizer.withDefaults());

AntPathRequestMatcher[] requestMatchers = new AntPathRequestMatcher[]{
tokenEndpoint.accessTokenRequestConverter(accessTokenRequestConverter()) // 注入自定义的授权认证Converter
.accessTokenResponseHandler(new PigAuthenticationSuccessEventHandler()) // 登录成功处理器
.errorResponseHandler(new PigAuthenticationFailureEventHandler());// 登录失败处理器
}).clientAuthentication(oAuth2ClientAuthenticationConfigurer -> // 个性化客户端认证
oAuth2ClientAuthenticationConfigurer.errorResponseHandler(new PigAuthenticationFailureEventHandler()))// 处理客户端认证异常
.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.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());
// 自定义接口、端点暴露
authorizeRequests.requestMatchers(requestMatchers).permitAll();
authorizeRequests.anyRequest().authenticated();
})
.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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void image(String randomStr, HttpServletResponse response) {

String result = captcha.text();
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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@ public class PigTokenEndpoint {

/**
* 认证页面
*
* @param modelAndView
* @param error 表单登录失败处理回调的错误信息
* @param error 表单登录失败处理回调的错误信息
* @return ModelAndView
*/
@GetMapping("/login")
Expand All @@ -106,13 +105,13 @@ public ModelAndView require(ModelAndView modelAndView, @RequestParam(required =

@GetMapping("/confirm_access")
public ModelAndView confirm(Principal principal, ModelAndView modelAndView,
@RequestParam(OAuth2ParameterNames.CLIENT_ID) String clientId,
@RequestParam(OAuth2ParameterNames.SCOPE) String scope,
@RequestParam(OAuth2ParameterNames.STATE) String state) {
@RequestParam(OAuth2ParameterNames.CLIENT_ID) String clientId,
@RequestParam(OAuth2ParameterNames.SCOPE) String scope,
@RequestParam(OAuth2ParameterNames.STATE) String state) {
SysOauthClientDetails clientDetails = RetOps
.of(clientDetailsService.getClientDetailsById(clientId, SecurityConstants.FROM_IN))
.getData()
.orElseThrow(() -> new OAuthClientException("clientId 不合法"));
.of(clientDetailsService.getClientDetailsById(clientId, SecurityConstants.FROM_IN))
.getData()
.orElseThrow(() -> new OAuthClientException("clientId 不合法"));

Set<String> authorizedScopes = StringUtils.commaDelimitedListToSet(clientDetails.getScope());
modelAndView.addObject("clientId", clientId);
Expand All @@ -125,7 +124,6 @@ public ModelAndView confirm(Principal principal, ModelAndView modelAndView,

/**
* 退出并删除token
*
* @param authHeader Authorization
*/
@DeleteMapping("/logout")
Expand All @@ -140,7 +138,6 @@ public R<Boolean> logout(@RequestHeader(value = HttpHeaders.AUTHORIZATION, requi

/**
* 校验token
*
* @param token 令牌
*/
@SneakyThrows
Expand Down Expand Up @@ -171,7 +168,6 @@ public void checkToken(String token, HttpServletResponse response, HttpServletRe

/**
* 令牌管理调用
*
* @param token token
*/
@Inner
Expand All @@ -198,7 +194,6 @@ public R<Boolean> removeToken(@PathVariable("token") String token) {

/**
* 查询token
*
* @param params 分页参数
* @return
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse

// 解密密码
String decryptPassword = aes.decryptStr(values[0]);
parameterMap.put(k, new String[]{decryptPassword});
parameterMap.put(k, new String[] { decryptPassword });
});
chain.doFilter(requestWrapper, response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
try {
checkCode();
filterChain.doFilter(request, response);
} catch (ValidateCodeException validateCodeException) {
}
catch (ValidateCodeException validateCodeException) {
throw new OAuth2AuthenticationException(validateCodeException.getMessage());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,39 +88,39 @@ public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity h

// 认证服务器配置
http.with(authorizationServerConfigurer.tokenEndpoint((tokenEndpoint) -> {// 个性化认证授权端点
tokenEndpoint.accessTokenRequestConverter(accessTokenRequestConverter) // 注入自定义的授权认证Converter
.accessTokenResponseHandler(new PigAuthenticationSuccessEventHandler()) // 登录成功处理器
.errorResponseHandler(new PigAuthenticationFailureEventHandler());// 登录失败处理器
}).clientAuthentication(oAuth2ClientAuthenticationConfigurer -> // 个性化客户端认证
oAuth2ClientAuthenticationConfigurer.errorResponseHandler(new PigAuthenticationFailureEventHandler()))// 处理客户端认证异常
, Customizer.withDefaults())
.with(authorizationServerConfigurer.authorizationService(authorizationService)// redis存储token的实现
.authorizationServerSettings(
AuthorizationServerSettings.builder().issuer(SecurityConstants.PROJECT_LICENSE).build()),
Customizer.withDefaults());
tokenEndpoint.accessTokenRequestConverter(accessTokenRequestConverter) // 注入自定义的授权认证Converter
.accessTokenResponseHandler(new PigAuthenticationSuccessEventHandler()) // 登录成功处理器
.errorResponseHandler(new PigAuthenticationFailureEventHandler());// 登录失败处理器
}).clientAuthentication(oAuth2ClientAuthenticationConfigurer -> // 个性化客户端认证
oAuth2ClientAuthenticationConfigurer.errorResponseHandler(new PigAuthenticationFailureEventHandler()))// 处理客户端认证异常
, Customizer.withDefaults())
.with(authorizationServerConfigurer.authorizationService(authorizationService)// redis存储token的实现
.authorizationServerSettings(
AuthorizationServerSettings.builder().issuer(SecurityConstants.PROJECT_LICENSE).build()),
Customizer.withDefaults());

// 资源服务器配置
AntPathRequestMatcher[] requestMatchers = permitAllUrl.getUrls()
.stream()
.map(AntPathRequestMatcher::new)
.toList()
.toArray(new AntPathRequestMatcher[]{});
.stream()
.map(AntPathRequestMatcher::new)
.toList()
.toArray(new AntPathRequestMatcher[] {});

http.authorizeHttpRequests(authorizeRequests -> authorizeRequests.requestMatchers(requestMatchers)
.permitAll()
.anyRequest()
.authenticated())
.oauth2ResourceServer(
oauth2 -> oauth2.opaqueToken(token -> token.introspector(customOpaqueTokenIntrospector))
.authenticationEntryPoint(resourceAuthExceptionEntryPoint)
.bearerTokenResolver(pigBearerTokenExtractor))
.exceptionHandling(configurer -> configurer.authenticationEntryPoint(resourceAuthExceptionEntryPoint))
.headers(headers -> headers.frameOptions(HeadersConfigurer.FrameOptionsConfig::disable))
.csrf(AbstractHttpConfigurer::disable);
.permitAll()
.anyRequest()
.authenticated())
.oauth2ResourceServer(
oauth2 -> oauth2.opaqueToken(token -> token.introspector(customOpaqueTokenIntrospector))
.authenticationEntryPoint(resourceAuthExceptionEntryPoint)
.bearerTokenResolver(pigBearerTokenExtractor))
.exceptionHandling(configurer -> configurer.authenticationEntryPoint(resourceAuthExceptionEntryPoint))
.headers(headers -> headers.frameOptions(HeadersConfigurer.FrameOptionsConfig::disable))
.csrf(AbstractHttpConfigurer::disable);

http.with(authorizationServerConfigurer.authorizationService(authorizationService)// redis存储token的实现
.authorizationServerSettings(
AuthorizationServerSettings.builder().issuer(SecurityConstants.PROJECT_LICENSE).build()),
.authorizationServerSettings(
AuthorizationServerSettings.builder().issuer(SecurityConstants.PROJECT_LICENSE).build()),
Customizer.withDefaults());

DefaultSecurityFilterChain securityFilterChain = http.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ private static byte[] getByteBody(HttpServletRequest request) {
byte[] body = new byte[0];
try {
body = StreamUtils.copyToByteArray(request.getInputStream());
} catch (IOException e) {
}
catch (IOException e) {
log.error("解析流中数据异常", e);
}
return body;
}

/**
* 重写 getParameterMap() 方法 解决 undertow 中流被读取后,会进行标记,从而导致无法正确获取 body 中的表单数据的问题
*
* @return Map<String, String [ ]> parameterMap
*/
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private void registerFeignClients(BeanDefinitionRegistry registry) {

validate(attributes);
BeanDefinitionBuilder definition = BeanDefinitionBuilder
.genericBeanDefinition(FeignClientFactoryBean.class);
.genericBeanDefinition(FeignClientFactoryBean.class);
definition.addPropertyValue("url", getUrl(registry, attributes));
definition.addPropertyValue("path", getPath(attributes));
String name = getName(attributes);
Expand All @@ -110,7 +110,8 @@ private void registerFeignClients(BeanDefinitionRegistry registry) {
String contextId = getContextId(attributes);
aliasBuilder.append(contextId);
definition.addPropertyValue("contextId", contextId);
} else {
}
else {
aliasBuilder.append(name);
}

Expand Down Expand Up @@ -141,10 +142,11 @@ private void registerFeignClients(BeanDefinitionRegistry registry) {
}

BeanDefinitionHolder holder = new BeanDefinitionHolder(beanDefinition, className,
new String[]{alias});
new String[] { alias });
BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry);

} catch (ClassNotFoundException e) {
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
Expand All @@ -153,7 +155,6 @@ private void registerFeignClients(BeanDefinitionRegistry registry) {
/**
* Return the class used by {@link SpringFactoriesLoader} to load configuration
* candidates.
*
* @return the factory class
*/
private Class<?> getSpringFactoriesLoaderFactoryClass() {
Expand Down Expand Up @@ -259,7 +260,7 @@ private void registerClientConfiguration(BeanDefinitionRegistry registry, Object
}

private void registerClientConfiguration(BeanDefinitionRegistry registry, Object name, Object className,
Object configuration) {
Object configuration) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(FeignClientSpecification.class);
builder.addConstructorArgValue(name);
builder.addConstructorArgValue(className);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ public class SysLogController {

/**
* 简单分页查询
*
* @param page 分页对象
* @param page 分页对象
* @param sysLog 系统日志
* @return
*/
Expand All @@ -69,7 +68,6 @@ public R getLogPage(@ParameterObject Page page, @ParameterObject SysLogDTO sysLo

/**
* 批量删除日志
*
* @param ids ID
* @return success/false
*/
Expand All @@ -81,7 +79,6 @@ public R removeByIds(@RequestBody Long[] ids) {

/**
* 插入日志
*
* @param sysLog 日志实体
* @return success/false
*/
Expand All @@ -93,7 +90,6 @@ public R save(@Valid @RequestBody SysLog sysLog) {

/**
* 导出excel 表格
*
* @param sysLog 查询条件
* @return
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public interface SysLogService extends IService<SysLog> {

/**
* 分页查询日志
*
* @param page
* @param sysLog
* @return
Expand All @@ -47,7 +46,6 @@ public interface SysLogService extends IService<SysLog> {

/**
* 插入日志
*
* @param sysLog 日志对象
* @return true/false
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public Page getLogByPage(Page page, SysLogDTO sysLog) {

/**
* 插入日志
*
* @param sysLog 日志对象
* @return true/false
*/
Expand All @@ -65,7 +64,6 @@ public Boolean saveLog(SysLog sysLog) {

/**
* 查询日志列表
*
* @param sysLog 查询条件
* @return List<SysLog>
*/
Expand All @@ -76,7 +74,6 @@ public List<SysLog> getList(SysLogDTO sysLog) {

/**
* 构建查询条件
*
* @param sysLog 前端条件
* @return LambdaQueryWrapper
*/
Expand All @@ -88,7 +85,7 @@ private LambdaQueryWrapper buildQuery(SysLogDTO sysLog) {

if (ArrayUtil.isNotEmpty(sysLog.getCreateTime())) {
wrapper.ge(SysLog::getCreateTime, sysLog.getCreateTime()[0])
.le(SysLog::getCreateTime, sysLog.getCreateTime()[1]);
.le(SysLog::getCreateTime, sysLog.getCreateTime()[1]);
}

return wrapper;
Expand Down

0 comments on commit af10316

Please sign in to comment.