🎨 链式调用format忽略

This commit is contained in:
b2baccline
2020-07-10 23:05:47 +08:00
parent a457390d89
commit dceb7de5d5
4 changed files with 50 additions and 28 deletions

View File

@@ -45,15 +45,20 @@ public class AdminAccessLogHandler implements AccessLogHandler<AdminAccessLog> {
@Override
public AdminAccessLog prodLog(HttpServletRequest request, HttpServletResponse response, Long time,
Throwable myThrowable) {
AdminAccessLog adminAccessLog = new AdminAccessLog().setTraceId(MDC.get(LogConstant.TRACE_ID))
.setCreateTime(LocalDateTime.now()).setTime(time).setIp(IPUtil.getIpAddr(request))
.setMethod(request.getMethod()).setUserAgent(request.getHeader("user-agent"))
// @formatter:off
AdminAccessLog adminAccessLog = new AdminAccessLog()
.setTraceId(MDC.get(LogConstant.TRACE_ID))
.setCreateTime(LocalDateTime.now())
.setTime(time)
.setIp(IPUtil.getIpAddr(request))
.setMethod(request.getMethod())
.setUserAgent(request.getHeader("user-agent"))
.setUri(URLUtil.getPath(request.getRequestURI()))
.setMatchingPattern(
String.valueOf(request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE)))
.setErrorMsg(Optional.ofNullable(myThrowable).map(Throwable::getMessage).orElse(null))
.setHttpStatus(response.getStatus()).setReqParams(JSONUtil.toJsonStr(request.getParameterMap()));
.setMatchingPattern(String.valueOf(request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE)))
.setErrorMsg(Optional.ofNullable(myThrowable).map(Throwable::getMessage).orElse(""))
.setHttpStatus(response.getStatus())
.setReqParams(JSONUtil.toJsonStr(request.getParameterMap()));
// @formatter:on
// 非文件上传请求记录body
if (!LogUtils.isMultipartContent(request)) {

View File

@@ -57,8 +57,12 @@ public class CustomAuthorizationServerConfigurer implements AuthorizationServerC
*/
@Override
public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
security.tokenKeyAccess("permitAll()").checkTokenAccess("isAuthenticated()")
.authenticationEntryPoint(authenticationEntryPoint).allowFormAuthenticationForClients();
// @formatter:off
security.tokenKeyAccess("permitAll()")
.checkTokenAccess("isAuthenticated()")
.authenticationEntryPoint(authenticationEntryPoint)
.allowFormAuthenticationForClients();
// @formatter:on
}
/**
@@ -79,6 +83,7 @@ public class CustomAuthorizationServerConfigurer implements AuthorizationServerC
*/
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
// @formatter:off
endpoints.tokenStore(tokenStore()).userDetailsService(sysUserDetailsService)
.authenticationManager(authenticationManager)
// 自定义token
@@ -89,11 +94,12 @@ public class CustomAuthorizationServerConfigurer implements AuthorizationServerC
.exceptionTranslator(customWebResponseExceptionTranslator)
// 自定义tokenGranter
.tokenGranter(tokenGranter(endpoints));
// @formatter:on
}
/**
* 定义token的存储方式
* @return
* @return TokenStore token存储
*/
@Bean
public TokenStore tokenStore() {

View File

@@ -40,22 +40,25 @@ public class CustomResourceServerConfigurer extends ResourceServerConfigurerAdap
/**
* 通过重载,配置如何通过拦截器保护请求
* @param http
* @throws Exception
* @param httpSecurity HttpSecurity
* @throws Exception 异常信息
*/
@Override
public void configure(HttpSecurity http) throws Exception {
http
// 拦截 url 配置
.authorizeRequests()
.antMatchers(ArrayUtil.toArray(permitAllUrlProperties.getIgnoreUrls(), String.class)).permitAll()
.anyRequest().authenticated()
public void configure(HttpSecurity httpSecurity) throws Exception {
// @formatter:off
httpSecurity
// 拦截 url 配置
.authorizeRequests()
.antMatchers(ArrayUtil.toArray(permitAllUrlProperties.getIgnoreUrls(), String.class))
.permitAll()
.anyRequest().authenticated()
// 使用token鉴权时 关闭 session 缓存
.and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
// 使用token鉴权时 关闭 session 缓存
.and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
// 关闭 csrf 跨站攻击防护
.and().csrf().disable();
// 关闭 csrf 跨站攻击防护
.and().csrf().disable();
// @formatter:on
}
}

View File

@@ -80,12 +80,20 @@ public class OperationLogAspect {
// 获取 Request
HttpServletRequest request = LogUtils.getHttpServletRequest();
return new OperationLogDTO().setCreateTime(LocalDateTime.now()).setIp(IPUtil.getIpAddr(request))
.setMethod(request.getMethod()).setOperator(Objects.requireNonNull(LogUtils.getUsername()))
.setStatus(LogStatusEnum.SUCCESS.getValue()).setUserAgent(request.getHeader("user-agent"))
.setUri(URLUtil.getPath(request.getRequestURI())).setType(operationLogging.type().getValue())
.setMsg(operationLogging.msg()).setParams(LogUtils.getParams(joinPoint))
// @formatter:off
return new OperationLogDTO()
.setCreateTime(LocalDateTime.now())
.setIp(IPUtil.getIpAddr(request))
.setMethod(request.getMethod())
.setOperator(Objects.requireNonNull(LogUtils.getUsername()))
.setStatus(LogStatusEnum.SUCCESS.getValue())
.setUserAgent(request.getHeader("user-agent"))
.setUri(URLUtil.getPath(request.getRequestURI()))
.setType(operationLogging.type().getValue())
.setMsg(operationLogging.msg())
.setParams(LogUtils.getParams(joinPoint))
.setTraceId(MDC.get(LogConstant.TRACE_ID));
// @formatter:on
}
}