Answers for "configure basic auth spring boot"

0

configure basic auth spring boot

@EnableWebSecurity
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Value("${app.basicAuthUserName}")
    private String basicAuthUserName;

    @Value("${app.basicAuthPassword}")
    private String basicAuthPassword;
   // add endpoint you want to protect to this list
    private String[] basicAuthEndpoints = {"/mytendpoint/path"};

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable();
        http.authorizeRequests().antMatchers(basicAuthEndpoints).fullyAuthenticated()
                .and().httpBasic().and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);

    }

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication().withUser(basicAuthUserName)
                .password("{noop}" + basicAuthPassword).roles("USER");
    }

}
Posted by: Guest on March-22-2021

Code answers related to "configure basic auth spring boot"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language