Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpSecurity configuration - permit all still requires basic auhthentication

I'm trying to add an unsecured controller endpoint /foo/bar to my application, but whenever I try calling it, I get 401 Unauthorized.

Here's my WebSecurityConfigurerAdapter:

http
    .authorizeRequests()
        .antMatchers("/foo/**").permitAll()
    .and()
    .formLogin()
        .loginPage("/login").permitAll()
    .and()
    .requestMatchers()
        .antMatchers("/login", "/oauth/authorize", "/oauth/confirm_access")
    .and()
    .authorizeRequests()
        .anyRequest().authenticated();

Would somone kindly point out what am I missing?

like image 238
Ben Avatar asked Mar 27 '16 21:03

Ben


People also ask

How do I bypass Spring Boot security?

First of all, according to Spring Boot dot, we have to add @EnableWebSecurity annotation. Second of all, we have to override configure method WITH @Override annotation AND super. configure(http) at the end of the method.

What is PermitAll ()?

Annotation Type PermitAll. @Documented @Retention(value=RUNTIME) @Target(value={TYPE,METHOD}) public @interface PermitAll. Specifies that all security roles are allowed to invoke the specified method(s) i.e that the specified method(s) are "unchecked". It can be specified on a class or on methods.

What is PermitAll in Spring Security?

Setting up an <intercept-url> element with access=”permitAll” will configure the authorization so that all requests are allowed on that particular path: <intercept-url pattern="/login*" access="permitAll" />

What should I use instead of WebSecurityConfigurerAdapter?

You need to declare SecurityFilterChain and WebSecurityCustomizer beans instead of overriding methods of WebSecurityConfigurerAdapter class.


1 Answers

Concatenate multiple antMatchers in one authorizeRequests section:

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
            .authorizeRequests()
                .antMatchers("/foo/**").permitAll()
                .anyRequest().authenticated()
            .and()
            .formLogin().loginPage("/login").permitAll();
}
like image 151
Ali Dehghani Avatar answered Oct 19 '22 23:10

Ali Dehghani