🎨 链式调用format忽略
This commit is contained in:
@@ -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)) {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user