日志优化
This commit is contained in:
@@ -55,10 +55,10 @@ import jakarta.servlet.ServletException;
|
||||
@SpringBootApplication
|
||||
@EnableDiscoveryClient
|
||||
public class MaxKeyOpenApiApplication extends SpringBootServletInitializer {
|
||||
private static final Logger _logger = LoggerFactory.getLogger(MaxKeyOpenApiApplication.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(MaxKeyOpenApiApplication.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
_logger.info("Start MaxKey OpenApi Application ...");
|
||||
logger.info("Start MaxKey OpenApi Application ...");
|
||||
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
SpringApplication.run(MaxKeyOpenApiApplication.class, args);
|
||||
@@ -67,12 +67,12 @@ public class MaxKeyOpenApiApplication extends SpringBootServletInitializer {
|
||||
try {
|
||||
initWebContext.init(null);
|
||||
} catch (ServletException e) {
|
||||
_logger.error("Exception ",e);
|
||||
logger.error("Exception ",e);
|
||||
}
|
||||
_logger.info("MaxKey OpenApi at {}" , new DateTime());
|
||||
_logger.info("MaxKey OpenApi Server Port {}"
|
||||
logger.info("MaxKey OpenApi at {}" , new DateTime());
|
||||
logger.info("MaxKey OpenApi Server Port {}"
|
||||
,applicationContext.getBean(ApplicationConfig.class).getPort());
|
||||
_logger.info("MaxKey OpenApi started.");
|
||||
logger.info("MaxKey OpenApi started.");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
|
||||
@AutoConfiguration
|
||||
public class MaxKeyOpenApiConfig implements InitializingBean {
|
||||
private static final Logger _logger = LoggerFactory.getLogger(MaxKeyOpenApiConfig.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(MaxKeyOpenApiConfig.class);
|
||||
|
||||
//authenticationRealm for MaxKeyMgtApplication
|
||||
@Bean
|
||||
@@ -54,14 +54,14 @@ public class MaxKeyOpenApiConfig implements InitializingBean {
|
||||
userInfoService,
|
||||
jdbcTemplate);
|
||||
|
||||
_logger.debug("JdbcAuthenticationRealm inited.");
|
||||
logger.debug("JdbcAuthenticationRealm inited.");
|
||||
return authenticationRealm;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AbstractOtpAuthn timeBasedOtpAuthn() {
|
||||
AbstractOtpAuthn tfaOtpAuthn = new TimeBasedOtpAuthn();
|
||||
_logger.debug("TimeBasedOtpAuthn inited.");
|
||||
logger.debug("TimeBasedOtpAuthn inited.");
|
||||
return tfaOtpAuthn;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||
@EnableWebMvc
|
||||
@AutoConfiguration
|
||||
public class MaxKeyOpenApiMvcConfig implements WebMvcConfigurer {
|
||||
private static final Logger _logger = LoggerFactory.getLogger(MaxKeyOpenApiMvcConfig.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(MaxKeyOpenApiMvcConfig.class);
|
||||
|
||||
@Autowired
|
||||
ApplicationConfig applicationConfig;
|
||||
@@ -54,33 +54,33 @@ public class MaxKeyOpenApiMvcConfig implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
_logger.debug("add Resource Handlers");
|
||||
logger.debug("add Resource Handlers");
|
||||
|
||||
_logger.debug("add statics");
|
||||
logger.debug("add statics");
|
||||
registry.addResourceHandler("/static/**")
|
||||
.addResourceLocations("classpath:/static/");
|
||||
_logger.debug("add templates");
|
||||
logger.debug("add templates");
|
||||
registry.addResourceHandler("/templates/**")
|
||||
.addResourceLocations("classpath:/templates/");
|
||||
|
||||
_logger.debug("add swagger");
|
||||
logger.debug("add swagger");
|
||||
registry.addResourceHandler("swagger-ui.html")
|
||||
.addResourceLocations("classpath:/META-INF/resources/");
|
||||
registry.addResourceHandler("/webjars/**")
|
||||
.addResourceLocations("classpath:/META-INF/resources/webjars/");
|
||||
|
||||
_logger.debug("add knife4j");
|
||||
logger.debug("add knife4j");
|
||||
registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
|
||||
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
|
||||
|
||||
_logger.debug("add Resource Handler finished .");
|
||||
logger.debug("add Resource Handler finished .");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
//addPathPatterns 用于添加拦截规则 , 先把所有路径都加入拦截, 再一个个排除
|
||||
//excludePathPatterns 表示改路径不用拦截
|
||||
_logger.debug("add Interceptors");
|
||||
logger.debug("add Interceptors");
|
||||
|
||||
permissionInterceptor.setMgmt(true);
|
||||
|
||||
@@ -114,7 +114,7 @@ public class MaxKeyOpenApiMvcConfig implements WebMvcConfigurer {
|
||||
.addPathPatterns("/logout/**")
|
||||
;
|
||||
|
||||
_logger.debug("add Permission Adapter");
|
||||
logger.debug("add Permission Adapter");
|
||||
|
||||
/*
|
||||
* api
|
||||
@@ -127,7 +127,7 @@ public class MaxKeyOpenApiMvcConfig implements WebMvcConfigurer {
|
||||
.addPathPatterns("/api/idm/scim/**")
|
||||
;
|
||||
|
||||
_logger.debug("add Rest Api Permission Adapter");
|
||||
logger.debug("add Rest Api Permission Adapter");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -44,14 +44,14 @@ import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
*/
|
||||
@AutoConfiguration
|
||||
public class Oauth20ClientAutoConfiguration implements InitializingBean {
|
||||
private static final Logger _logger = LoggerFactory.getLogger(Oauth20ClientAutoConfiguration.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(Oauth20ClientAutoConfiguration.class);
|
||||
|
||||
@Bean
|
||||
public JdbcClientDetailsService oauth20JdbcClientDetailsService(
|
||||
DataSource dataSource,PasswordEncoder passwordReciprocal) {
|
||||
JdbcClientDetailsService clientDetailsService = new JdbcClientDetailsService(dataSource);
|
||||
//clientDetailsService.setPasswordEncoder(passwordReciprocal);
|
||||
_logger.debug("JdbcClientDetailsService inited.");
|
||||
logger.debug("JdbcClientDetailsService inited.");
|
||||
return clientDetailsService;
|
||||
}
|
||||
|
||||
@@ -68,10 +68,10 @@ public class Oauth20ClientAutoConfiguration implements InitializingBean {
|
||||
TokenStore tokenStore = null;
|
||||
if (persistence == 2) {
|
||||
tokenStore = new RedisTokenStore(jedisConnectionFactory);
|
||||
_logger.debug("RedisTokenStore");
|
||||
logger.debug("RedisTokenStore");
|
||||
}else {
|
||||
tokenStore = new InMemoryTokenStore();
|
||||
_logger.debug("InMemoryTokenStore");
|
||||
logger.debug("InMemoryTokenStore");
|
||||
}
|
||||
|
||||
return tokenStore;
|
||||
@@ -109,7 +109,7 @@ public class Oauth20ClientAutoConfiguration implements InitializingBean {
|
||||
daoAuthenticationProvider.setPasswordEncoder(passwordReciprocal);
|
||||
daoAuthenticationProvider.setUserDetailsService(cientDetailsUserDetailsService);
|
||||
ProviderManager authenticationManager = new ProviderManager(daoAuthenticationProvider);
|
||||
_logger.debug("OAuth 2 Client Authentication Manager init.");
|
||||
logger.debug("OAuth 2 Client Authentication Manager init.");
|
||||
return authenticationManager;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ import jakarta.servlet.http.HttpServletResponse;
|
||||
*/
|
||||
@Component
|
||||
public class Oauth20ApiPermissionAdapter implements AsyncHandlerInterceptor {
|
||||
private static final Logger _logger = LoggerFactory.getLogger(Oauth20ApiPermissionAdapter.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(Oauth20ApiPermissionAdapter.class);
|
||||
|
||||
@Autowired
|
||||
protected PasswordReciprocal passwordReciprocal;
|
||||
@@ -57,21 +57,21 @@ public class Oauth20ApiPermissionAdapter implements AsyncHandlerInterceptor {
|
||||
*/
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request,HttpServletResponse response, Object handler) throws Exception {
|
||||
_logger.trace("OAuth20 API Permission Adapter pre handle");
|
||||
logger.trace("OAuth20 API Permission Adapter pre handle");
|
||||
String accessToken = RequestTokenUtils.resolveAccessToken(request);
|
||||
_logger.trace("access_token {} " , accessToken);
|
||||
logger.trace("access_token {} " , accessToken);
|
||||
try {
|
||||
OAuth2Authentication authentication = oauth20TokenServices.loadAuthentication(accessToken);
|
||||
//判断应用的accessToken信息
|
||||
if(authentication != null ){
|
||||
_logger.trace("authentication "+ authentication);
|
||||
logger.trace("authentication {}" , authentication);
|
||||
return true;
|
||||
}
|
||||
}catch(Exception e) {
|
||||
_logger.error("load Authentication Exception ! ",e);
|
||||
logger.error("load Authentication Exception ! ",e);
|
||||
}
|
||||
|
||||
_logger.trace("No Authentication ... forward to /login");
|
||||
logger.trace("No Authentication ... forward to /login");
|
||||
RequestDispatcher dispatcher = request.getRequestDispatcher("/login");
|
||||
dispatcher.forward(request, response);
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ import jakarta.servlet.http.HttpServletResponse;
|
||||
*/
|
||||
@Component
|
||||
public class RestApiPermissionAdapter implements AsyncHandlerInterceptor {
|
||||
private static final Logger _logger = LoggerFactory.getLogger(RestApiPermissionAdapter.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(RestApiPermissionAdapter.class);
|
||||
|
||||
@Autowired
|
||||
DefaultTokenServices oauth20TokenServices;
|
||||
@@ -62,7 +62,7 @@ public class RestApiPermissionAdapter implements AsyncHandlerInterceptor {
|
||||
*/
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request,HttpServletResponse response, Object handler) throws Exception {
|
||||
_logger.trace("Rest API Permission Adapter pre handle");
|
||||
logger.trace("Rest API Permission Adapter pre handle");
|
||||
AuthorizationHeader headerCredential = AuthorizationHeaderUtils.resolve(request);
|
||||
|
||||
//判断应用的AppId和Secret
|
||||
@@ -79,12 +79,12 @@ public class RestApiPermissionAdapter implements AsyncHandlerInterceptor {
|
||||
authenticationToken= (UsernamePasswordAuthenticationToken)oauth20ClientAuthenticationManager.authenticate(authRequest);
|
||||
}
|
||||
}else {
|
||||
_logger.trace("Authentication bearer {}" , headerCredential.getCredential());
|
||||
logger.trace("Authentication bearer {}" , headerCredential.getCredential());
|
||||
OAuth2Authentication oauth2Authentication =
|
||||
oauth20TokenServices.loadAuthentication(headerCredential.getCredential());
|
||||
|
||||
if(oauth2Authentication != null) {
|
||||
_logger.trace("Authentication token {}" , oauth2Authentication.getPrincipal().toString());
|
||||
logger.trace("Authentication token {}" , oauth2Authentication.getPrincipal().toString());
|
||||
authenticationToken= new UsernamePasswordAuthenticationToken(
|
||||
new User(
|
||||
oauth2Authentication.getPrincipal().toString(),
|
||||
@@ -94,7 +94,7 @@ public class RestApiPermissionAdapter implements AsyncHandlerInterceptor {
|
||||
oauth2Authentication.getAuthorities()
|
||||
);
|
||||
}else {
|
||||
_logger.trace("Authentication token is null ");
|
||||
logger.trace("Authentication token is null ");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ public class RestApiPermissionAdapter implements AsyncHandlerInterceptor {
|
||||
}
|
||||
}
|
||||
|
||||
_logger.trace("No Authentication ... forward to /login");
|
||||
logger.trace("No Authentication ... forward to /login");
|
||||
RequestDispatcher dispatcher = request.getRequestDispatcher("/login");
|
||||
dispatcher.forward(request, response);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user