Summary
When using a Form Login, a single OAuth2 provider and the auto-generated login page, the auto-configured AuthenticationEntryPoint will redirect to the provider immediately, bypassing the login page and effectively preventing form login.
Actual Behavior
When trying to access a protected resource, spring security will immediately redirect to the OAuth2 provider's authentication page instead of the local login page.
Expected Behavior
When Form Login is configured, the login page should never be skipped.
Configuration
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().authenticated()
.and()
.oauth2Login()
.and()
.oauth2Client()
.and()
.formLogin().permitAll();
}
spring.security.oauth2.client.registration.facebook.client-id=some-id
spring.security.oauth2.client.registration.facebook.client-secret=some-secret
Version
5.1.4-RELEASE, not sure as of which version this happens.
Sample
I don't have a sample, but I found the exact location of the bug:
|
if (loginUrlToClientName.size() == 1) { |
|
// Setup auto-redirect to provider login page |
|
// when only 1 client is configured |
|
this.updateAuthenticationDefaults(); |
|
this.updateAccessDefaults(http); |
|
String providerLoginPage = loginUrlToClientName.keySet().iterator().next(); |
|
this.registerAuthenticationEntryPoint(http, this.getLoginEntryPoint(http, providerLoginPage)); |
|
} else { |
|
super.init(http); |
|
} |
The condition should check whether Form Login is enabled and don't apply the shortcut if it is.
Summary
When using a Form Login, a single OAuth2 provider and the auto-generated login page, the auto-configured
AuthenticationEntryPointwill redirect to the provider immediately, bypassing the login page and effectively preventing form login.Actual Behavior
When trying to access a protected resource, spring security will immediately redirect to the OAuth2 provider's authentication page instead of the local login page.
Expected Behavior
When Form Login is configured, the login page should never be skipped.
Configuration
Version
5.1.4-RELEASE, not sure as of which version this happens.
Sample
I don't have a sample, but I found the exact location of the bug:
spring-security/config/src/main/java/org/springframework/security/config/annotation/web/configurers/oauth2/client/OAuth2LoginConfigurer.java
Lines 444 to 453 in 2c136f7
The condition should check whether Form Login is enabled and don't apply the shortcut if it is.