[ BAEL-5337 ] - Enable Logging for Spring Security (#11803)

* feat: logging application

* fix: apply formatter
This commit is contained in:
lucaCambi77 2022-02-25 02:17:58 +01:00 committed by GitHub
parent 1d80576a7c
commit cb65018f66
4 changed files with 60 additions and 0 deletions

View File

@ -0,0 +1,16 @@
package com.baeldung.logging;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class LoggingController {
@GetMapping("/logging")
public ResponseEntity<String> logging() {
return new ResponseEntity<>("logging/baeldung", HttpStatus.OK);
}
}

View File

@ -0,0 +1,26 @@
package com.baeldung.logging;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Value("${spring.websecurity.debug:false}")
boolean webSecurityDebug;
@Override
public void configure(WebSecurity web) {
web.debug(webSecurityDebug);
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/**")
.permitAll();
}
}

View File

@ -0,0 +1,14 @@
package com.baeldung.logging;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SecurityLoggingApplication {
public static void main(String... args) {
SpringApplication application = new SpringApplication(SecurityLoggingApplication.class);
application.setAdditionalProfiles("logging");
application.run(args);
}
}

View File

@ -0,0 +1,4 @@
logging.level.org.springframework.security=DEBUG
spring.websecurity.debug=true