How to make spring boot never issue session cookie?

Have you tried using SessionCreationPolicy.STATELESS. There is a subtle difference between STATELESS and NEVER in the spring docs: STATELESS: Spring Security will never create an HttpSession and it will never use it to obtain the SecurityContext. NEVER: Spring Security will never create an HttpSession, but will use the HttpSession if it already exists. So I … Read more

Spring Boot project shows the Login page

If you don’t want login page (from Spring-Security) remove the following dependency from your pom.xml and do maven update to refresh the dependencies on the class path. <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> Or if you want to use the Spring-Security then on console it will display the default password like below : Using default security password: … Read more

Spring Boot 2.0 disable default security

According to the new updates in Spring 2.0, if Spring Security is on the classpath, Spring Boot will add @EnableWebSecurity.So adding entries to the application.properties ain’t gonna work (i.e it is no longer customizable that way). For more information visit the official website Security changes in Spring Boot 2.0 Albeit not sure about your requirement … Read more

Spring Security and @Async (Authenticated Users mixed up)

I guess MODE_INHERITABLETHREADLOCAL doesn’t work correctly with thread pool. As a possible solution you can try to subclass ThreadPoolTaskExecutor and override its methods to propagate SecurityContext manually, and then declare that executor instead of <task:executor>, something like this: public void execute(final Runnable r) { final Authentication a = SecurityContextHolder.getContext().getAuthentication(); super.execute(new Runnable() { public void run() … Read more

What is the reason to disable csrf in spring boot web application?

What is the real-life reason to disable it? The Spring documentation suggests: Our recommendation is to use CSRF protection for any request that could be processed by a browser by normal users. If you are only creating a service that is used by non-browser clients, you will likely want to disable CSRF protection. Does it … Read more

Spring Security exclude url patterns in security annotation configurartion

Found the solution in Spring security examples posted in Github. WebSecurityConfigurerAdapter has a overloaded configure message that takes WebSecurity as argument which accepts ant matchers on requests to be ignored. @Override public void configure(WebSecurity web) throws Exception { web.ignoring().antMatchers(“/authFailure”); } See Spring Security Samples for more details

Spring Security 5 Replacement for OAuth2RestTemplate

OAuth 2.0 Client features of Spring Security 5.2.x do not support RestTemplate, but only WebClient. See Spring Security Reference: HTTP Client support WebClient integration for Servlet Environments (for requesting protected resources) In addition, RestTemplate will be deprecated in a future version. See RestTemplate javadoc: NOTE: As of 5.0, the non-blocking, reactive org.springframework.web.reactive.client.WebClient offers a modern … Read more

Spring security CORS Filter

Since Spring Security 4.1, this is the proper way to make Spring Security support CORS (also needed in Spring Boot 1.4/1.5): @Configuration public class WebConfig extends WebMvcConfigurerAdapter { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping(“/**”) .allowedMethods(“HEAD”, “GET”, “PUT”, “POST”, “DELETE”, “PATCH”); } } and: @Configuration public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity … Read more