Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Move login-ui.xml to java config, part 2 #3292

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.cloudfoundry.identity.uaa.login;

import java.io.IOException;

import org.cloudfoundry.identity.uaa.authentication.PasswordChangeUiRequiredFilter;
import org.cloudfoundry.identity.uaa.authentication.ReAuthenticationRequiredFilter;
import org.cloudfoundry.identity.uaa.authentication.UaaAuthenticationDetailsSource;
Expand All @@ -11,7 +9,6 @@
import org.cloudfoundry.identity.uaa.web.FilterChainOrder;
import org.cloudfoundry.identity.uaa.web.UaaFilterChain;
import org.cloudfoundry.identity.uaa.web.UaaSavedRequestCache;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -20,11 +17,18 @@
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.authentication.logout.LogoutFilter;
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
import org.springframework.security.web.context.SecurityContextPersistenceFilter;
import org.springframework.security.web.csrf.CsrfFilter;
import org.springframework.security.web.session.DisableEncodeUrlFilter;

import java.io.IOException;

import static org.cloudfoundry.identity.uaa.web.AuthorizationManagersUtils.anonymousOrFullyAuthenticated;

@Configuration
Expand All @@ -36,6 +40,105 @@
return new ResourcePropertySource("messages.properties");
}

@Bean
@Order(FilterChainOrder.FORGOT_PASSWORD)
UaaFilterChain forgotPassword(HttpSecurity http) throws Exception {
var originalChain = http
.securityMatcher(
"/forgot_password",
"/forgot_password.do"
)
.authorizeHttpRequests(auth -> auth.anyRequest().permitAll())
.csrf(CsrfConfigurer::disable)
Comment on lines +46 to +52

Check failure

Code scanning / CodeQL

Disabled Spring CSRF protection High

CSRF vulnerability due to protection being disabled.
.exceptionHandling(exception -> {
exception.authenticationEntryPoint(new CsrfAwareEntryPointAndDeniedHandler("/invalid_request", "/login?error=invalid_login_request"));
})
.build();
return new UaaFilterChain(originalChain);
}

@Bean
@Order(FilterChainOrder.DELETE_SAVED_ACCOUNT)
UaaFilterChain deleteSavedAccount(
HttpSecurity http,
@Qualifier("clientAuthenticationManager") AuthenticationManager authenticationManager,
@Qualifier("basicAuthenticationEntryPoint") AuthenticationEntryPoint authenticationEntryPoint
) throws Exception {
var originalChain = http
.securityMatcher("/delete_saved_account")
.authorizeHttpRequests(auth -> auth.anyRequest().permitAll())
.authenticationManager(authenticationManager)
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.exceptionHandling(exception -> {
exception.authenticationEntryPoint(authenticationEntryPoint);
})
.build();
return new UaaFilterChain(originalChain);
}

@Bean
@Order(FilterChainOrder.VERIFY_EMAIL)
UaaFilterChain verifyEmail(HttpSecurity http) throws Exception {
var originalChain = http
.securityMatcher("/verify_email")
.authorizeHttpRequests(auth -> auth.anyRequest().permitAll())
.csrf(CsrfConfigurer::disable)
Comment on lines +82 to +85

Check failure

Code scanning / CodeQL

Disabled Spring CSRF protection High

CSRF vulnerability due to protection being disabled.
.exceptionHandling(exception -> {
exception.authenticationEntryPoint(new CsrfAwareEntryPointAndDeniedHandler("/invalid_request", "/login?error=invalid_login_request"));
})
.build();
return new UaaFilterChain(originalChain);
}

@Bean
@Order(FilterChainOrder.VERIFY_USER)
UaaFilterChain verifyUser(HttpSecurity http) throws Exception {
var originalChain = http
.securityMatcher("/verify_user")
.authorizeHttpRequests(auth -> auth.anyRequest().permitAll())
.csrf(CsrfConfigurer::disable)
Comment on lines +96 to +99

Check failure

Code scanning / CodeQL

Disabled Spring CSRF protection High

CSRF vulnerability due to protection being disabled.
.exceptionHandling(exception -> {
exception.authenticationEntryPoint(new CsrfAwareEntryPointAndDeniedHandler("/invalid_request", "/login?error=invalid_login_request"));
})
.build();
return new UaaFilterChain(originalChain);
}

@Bean
@Order(FilterChainOrder.INVITATIONS_ACCEPT)
UaaFilterChain acceptInvitation(HttpSecurity http) throws Exception {
var originalChain = http
.securityMatcher("/invitations/accept")
.authorizeHttpRequests(auth -> auth.anyRequest().permitAll())
.csrf(CsrfConfigurer::disable)
Comment on lines +110 to +113

Check failure

Code scanning / CodeQL

Disabled Spring CSRF protection High

CSRF vulnerability due to protection being disabled.
.exceptionHandling(exception -> {
exception.authenticationEntryPoint(new CsrfAwareEntryPointAndDeniedHandler("/invalid_request", "/login?error=invalid_login_request"));
})
.build();
return new UaaFilterChain(originalChain);
}

/**
* Handle login callbacks from SAML upstream providers.
*/
@Bean
@Order(FilterChainOrder.SAML_IDP_SSO)
UaaFilterChain samlSsoCallback(
HttpSecurity http,
PasswordChangeUiRequiredFilter passwordChangeUiRequiredFilter
) throws Exception {
var originalChain = http
.securityMatcher("/saml/idp/SSO/**")
.authorizeHttpRequests(auth -> auth.anyRequest().fullyAuthenticated())
.addFilterBefore(passwordChangeUiRequiredFilter, BasicAuthenticationFilter.class)
.csrf(CsrfConfigurer::disable)
Comment on lines +130 to +134

Check failure

Code scanning / CodeQL

Disabled Spring CSRF protection High

CSRF vulnerability due to protection being disabled.
.exceptionHandling(exception -> {
exception.authenticationEntryPoint(new CsrfAwareEntryPointAndDeniedHandler("/invalid_request", "/login?error=invalid_login_request"));
})
.build();
return new UaaFilterChain(originalChain);
}

/**
* Handle the UI-related components, such as the login page, the home page, etc.
* <p>
Expand Down
52 changes: 0 additions & 52 deletions server/src/main/resources/spring/login-ui.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,6 @@
<access-denied-handler ref="loginEntryPoint"/>
</http>

<http name="forgotPasswordSecurity"
pattern="/forgot_password**"
disable-url-rewriting="true"
entry-point-ref="loginEntryPoint"
use-expressions="false"
xmlns="http://www.springframework.org/schema/security">
<intercept-url pattern="/**" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
<csrf disabled="true"/>
<access-denied-handler ref="loginEntryPoint"/>
</http>

<bean id="uiAuthorizeRequestMatcher" class="org.springframework.security.web.util.matcher.AntPathRequestMatcher">
<constructor-arg value="/oauth/authorize**"/>
</bean>
Expand All @@ -146,47 +135,6 @@
<property name="requestMatcher" ref="uiAuthorizeRequestMatcher"/>
</bean>

<http name="deleteSavedAccountSecurity" pattern="/delete_saved_account**" create-session="stateless"
entry-point-ref="basicAuthenticationEntryPoint"
authentication-manager-ref="clientAuthenticationManager" use-expressions="false"
xmlns="http://www.springframework.org/schema/security">
<intercept-url pattern="/**" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
</http>

<http name="verifyEmailSecurity" pattern="/verify_email" disable-url-rewriting="true"
xmlns="http://www.springframework.org/schema/security"
entry-point-ref="loginEntryPoint" use-expressions="false">
<intercept-url pattern="/verify_email" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
<anonymous enabled="true"/>
<csrf disabled="true"/>
</http>

<http name="verifyUserSecurity" pattern="/verify_user" disable-url-rewriting="true"
xmlns="http://www.springframework.org/schema/security"
entry-point-ref="loginEntryPoint" use-expressions="false">
<intercept-url pattern="/**" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
<anonymous enabled="true"/>
<csrf disabled="true"/>
</http>

<http name="acceptInvitationSecurity" pattern="/invitations/accept" disable-url-rewriting="true"
xmlns="http://www.springframework.org/schema/security"
entry-point-ref="loginEntryPoint" use-expressions="false">
<intercept-url pattern="/**" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
<anonymous enabled="true"/>
<csrf disabled="true"/>
</http>

<http name="idpSecurity"
use-expressions="true"
pattern="/saml/idp/SSO/**"
entry-point-ref="loginEntryPoint"
xmlns="http://www.springframework.org/schema/security">
<intercept-url pattern="/**" access="isFullyAuthenticated()"/>
<custom-filter ref="passwordChangeUiRequiredFilter" after="BASIC_AUTH_FILTER"/>
<csrf disabled="true"/>
</http>

<bean id="errorMessageAuthenticationFailureHandler"
class="org.springframework.security.web.authentication.ExceptionMappingAuthenticationFailureHandler">
<property name="exceptionMappings">
Expand Down
Loading