Skip to content

Commit 1d4e5cb

Browse files
author
Dave Syer
committed
Add /error to unprotected resource patterns
1 parent 6a4e399 commit 1d4e5cb

File tree

6 files changed

+10
-6
lines changed

6 files changed

+10
-6
lines changed

click/README.adoc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public class SocialApplication extends WebSecurityConfigurerAdapter {
103103
http
104104
.antMatcher("/**")
105105
.authorizeRequests()
106-
.antMatchers("/", "/login**", "/webjars/**")
106+
.antMatchers("/", "/login**", "/webjars/**", "/error**")
107107
.permitAll()
108108
.anyRequest()
109109
.authenticated();
@@ -121,6 +121,10 @@ the static resources it contains (we also include access to the login
121121
endpoints which handle the authentication). All other requests
122122
(e.g. to the `/user` endpoint) require authentication.
123123

124+
NOTE: `/error**` is an unprotected path because we want Spring Boot
125+
to bew able to render errors if there is a problem in the app, even
126+
if the user is unauthenticated.
127+
124128
With that change in place the application is complete, and if you run
125129
it and visit the home page you should see a nicely styled HTML link to
126130
"login with Facebook". The link takes you not directly to Facebook,

click/src/main/java/com/example/SocialApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public Principal user(Principal principal) {
3737

3838
@Override
3939
protected void configure(HttpSecurity http) throws Exception {
40-
http.antMatcher("/**").authorizeRequests().antMatchers("/", "/login**", "/webjars/**").permitAll().anyRequest()
40+
http.antMatcher("/**").authorizeRequests().antMatchers("/", "/login**", "/webjars/**", "/error**").permitAll().anyRequest()
4141
.authenticated();
4242
}
4343

custom-error/src/main/java/com/example/SocialApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public String unauthenticated() {
7979
@Override
8080
protected void configure(HttpSecurity http) throws Exception {
8181
// @formatter:off
82-
http.antMatcher("/**").authorizeRequests().antMatchers("/", "/login**", "/webjars/**").permitAll().anyRequest()
82+
http.antMatcher("/**").authorizeRequests().antMatchers("/", "/login**", "/webjars/**", "/error**").permitAll().anyRequest()
8383
.authenticated().and().logout().logoutSuccessUrl("/").permitAll().and().csrf()
8484
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());
8585
// @formatter:on

github/src/main/java/com/example/SocialApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public Map<String, String> user(Principal principal) {
7272
@Override
7373
protected void configure(HttpSecurity http) throws Exception {
7474
// @formatter:off
75-
http.antMatcher("/**").authorizeRequests().antMatchers("/", "/login**", "/webjars/**").permitAll().anyRequest()
75+
http.antMatcher("/**").authorizeRequests().antMatchers("/", "/login**", "/webjars/**", "/error**").permitAll().anyRequest()
7676
.authenticated().and().exceptionHandling()
7777
.authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/")).and().logout()
7878
.logoutSuccessUrl("/").permitAll().and().csrf()

logout/src/main/java/com/example/SocialApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public Principal user(Principal principal) {
3939
@Override
4040
protected void configure(HttpSecurity http) throws Exception {
4141
// @formatter:off
42-
http.antMatcher("/**").authorizeRequests().antMatchers("/", "/login**", "/webjars/**").permitAll().anyRequest()
42+
http.antMatcher("/**").authorizeRequests().antMatchers("/", "/login**", "/webjars/**", "/error**").permitAll().anyRequest()
4343
.authenticated().and().logout().logoutSuccessUrl("/").permitAll().and().csrf()
4444
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());
4545
// @formatter:on

manual/src/main/java/com/example/SocialApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public Principal user(Principal principal) {
5757
@Override
5858
protected void configure(HttpSecurity http) throws Exception {
5959
// @formatter:off
60-
http.antMatcher("/**").authorizeRequests().antMatchers("/", "/login**", "/webjars/**").permitAll().anyRequest()
60+
http.antMatcher("/**").authorizeRequests().antMatchers("/", "/login**", "/webjars/**", "/error**").permitAll().anyRequest()
6161
.authenticated().and().exceptionHandling()
6262
.authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/")).and().logout()
6363
.logoutSuccessUrl("/").permitAll().and().csrf()

0 commit comments

Comments
 (0)