user3452075 February 2016

Spring - Http Basic Auth - Mark endpoint as public

I am using spring for providing basic http authentication. For this I am simply setting user and password in the application.properies:

enter image description here

However, I would like to expose an endpoint/or a static file as public (no authentication required for this). Is there a simple way to do this?

I find the spring documentation quite hard to search so any tips would be appreciated.

Answers


nobeh February 2016

You can use a method to configure the endpoints on your application:

protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests()
            .antMatchers("/", "/public/**").permitAll()
            .antMatchers("/users/**").hasAuthority("ADMIN")
            .anyRequest().fullyAuthenticated()
            .and()
            .formLogin()
            .loginPage("/login")
            .failureUrl("/login?error")
            .usernameParameter("email")
            .permitAll()
            .and()
            .logout()
            .logoutUrl("/logout")
            .deleteCookies("remember-me")
            .logoutSuccessUrl("/")
            .permitAll()
            .and()
            .rememberMe();
}

The complete example can be found here: https://github.com/bkielczewski/example-spring-boot-security

Post Status

Asked in February 2016
Viewed 2,652 times
Voted 14
Answered 1 times

Search




Leave an answer