Created
June 27, 2018 15:08
-
-
Save george-hawkins/a977ac49507105322a2c6779f2348aa9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.springframework.context.annotation.Configuration | |
import org.springframework.core.annotation.Order | |
import org.springframework.security.config.annotation.web.builders.HttpSecurity | |
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter | |
@Order(2) | |
@Configuration | |
class WebSecurityPublicConfiguration : WebSecurityConfigurerAdapter() { | |
// ResourceServerConfiguration invokes OAuth2ResourceServerConfiguration.ResourceSecurityConfigurer.configure | |
// which turns on authorization for all paths. | |
// So to e.g. permit-all for a given path this configuration must be run first, i.e. it must have an @Order | |
// value that's lower than ResourceServerConfiguration.order. | |
override fun configure(http: HttpSecurity) { | |
http.anonymous().and().authorizeRequests().antMatchers("/api/public/**").permitAll() | |
http.csrf().disable() | |
super.configure(http) | |
// Trying to do permit-all like this results in our previously working OAuth protected methods returning: | |
// "status":401,"error":"Unauthorized" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment