package org.baeldung.um.spring; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.core.userdetails.UserDetailsService; @Configuration @EnableWebSecurity @EnableGlobalMethodSecurity(securedEnabled = true) @ComponentScan("org.baeldung.um.security") public class UmJavaSecurityConfig extends WebSecurityConfigurerAdapter { @Autowired private UserDetailsService userDetailsService; // @Autowired public void configureGlobal(final AuthenticationManagerBuilder auth) throws Exception { auth.userDetailsService(userDetailsService); } @Override protected void configure(final HttpSecurity http) throws Exception { // @formatter:off http. authorizeRequests(). antMatchers("/api/health").anonymous(). anyRequest().authenticated().and(). httpBasic().and(). sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and(). csrf().disable(); // @formatter:on } }