I want to log username and password for a given authenticated web service.
I have my WebSecurityConfigurerAdapter
configured as following:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/webservice/path").fullyAuthenticated().and().
httpBasic().and().
csrf().disable();
}
what I want is to get http request and log the user name and password like in this example
so what I want is how do I get the http request for my web service in spring boot and log the credentials regardless if user and pass are correct or not.
Consider adding a LoggingFilter in your application.
@Bean
public FilterRegistrationBean loggingFilterRegistration() {
FilterRegistrationBean loggingBean = new FilterRegistrationBean();
loggingBean.setFilter(loggingFilter());
loggingBean.addUrlPatterns("/login");
loggingBean.setName("loggingFilter");
return registration;
}
@Bean
public Filter loggingFilter() {
return new GenericFilterBean {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) {
if("POST".equalsIgnoreCase(request.getMethod())){
// Implement Logging logic here
}
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.