Skip to content

Commit 8a2376c

Browse files
authored
Merge pull request #1542 from steve-community/1523-connection-issues-websocket
Fix SOAP/WS connection issues
2 parents 7b1e5a3 + ae47c84 commit 8a2376c

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

src/main/java/de/rwth/idsg/steve/Application.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ public Application() {
4646

4747
switch (sc.getProfile()) {
4848
case DEV:
49+
case TEST:
4950
delegate = new SteveDevStarter();
5051
break;
51-
case TEST:
5252
case PROD:
5353
delegate = new SteveProdStarter();
5454
break;

src/main/java/de/rwth/idsg/steve/SteveAppContext.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,13 @@ private WebAppContext initWebApp() {
110110
ctx.addServlet(web, CONFIG.getSpringMapping());
111111
ctx.addServlet(cxf, CONFIG.getCxfMapping() + "/*");
112112

113-
if (CONFIG.getProfile().isProd()) {
114-
// If PROD, add security filter
115-
ctx.addFilter(
116-
// The bean name is not arbitrary, but is as expected by Spring
117-
new FilterHolder(new DelegatingFilterProxy(AbstractSecurityWebApplicationInitializer.DEFAULT_FILTER_NAME)),
118-
CONFIG.getSpringMapping() + "*",
119-
EnumSet.allOf(DispatcherType.class)
120-
);
121-
}
113+
// add spring security
114+
ctx.addFilter(
115+
// The bean name is not arbitrary, but is as expected by Spring
116+
new FilterHolder(new DelegatingFilterProxy(AbstractSecurityWebApplicationInitializer.DEFAULT_FILTER_NAME)),
117+
CONFIG.getSpringMapping() + "*",
118+
EnumSet.allOf(DispatcherType.class)
119+
);
122120

123121
initJSP(ctx);
124122
return ctx;

src/main/java/de/rwth/idsg/steve/config/SecurityConfiguration.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,9 @@
2020

2121
import com.fasterxml.jackson.databind.ObjectMapper;
2222
import com.google.common.base.Strings;
23-
import de.rwth.idsg.steve.SteveProdCondition;
2423
import de.rwth.idsg.steve.web.api.ApiControllerAdvice;
2524
import lombok.extern.slf4j.Slf4j;
26-
import org.springframework.beans.factory.annotation.Qualifier;
2725
import org.springframework.context.annotation.Bean;
28-
import org.springframework.context.annotation.Conditional;
2926
import org.springframework.context.annotation.Configuration;
3027
import org.springframework.core.annotation.Order;
3128
import org.springframework.http.HttpStatus;
@@ -34,7 +31,6 @@
3431
import org.springframework.security.authentication.DisabledException;
3532
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
3633
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
37-
import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
3834
import org.springframework.security.config.http.SessionCreationPolicy;
3935
import org.springframework.security.core.Authentication;
4036
import org.springframework.security.core.AuthenticationException;
@@ -52,6 +48,7 @@
5248
import jakarta.servlet.ServletException;
5349
import jakarta.servlet.http.HttpServletRequest;
5450
import jakarta.servlet.http.HttpServletResponse;
51+
5552
import java.io.IOException;
5653

5754
import static de.rwth.idsg.steve.SteveConfiguration.CONFIG;
@@ -63,7 +60,6 @@
6360
@Slf4j
6461
@Configuration
6562
@EnableWebSecurity
66-
@Conditional(SteveProdCondition.class)
6763
public class SecurityConfiguration {
6864

6965
/**
@@ -99,10 +95,15 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
9995
.requestMatchers(
10096
"/static/**",
10197
CONFIG.getCxfMapping() + "/**",
98+
WebSocketConfiguration.PATH_INFIX + "**",
10299
"/WEB-INF/views/**" // https://github.com/spring-projects/spring-security/issues/13285#issuecomment-1579097065
103100
).permitAll()
104101
.requestMatchers(prefix + "/**").hasRole("ADMIN")
105102
)
103+
// SOAP stations are making POST calls for communication. even though the following path is permitted for
104+
// all access, there is a global default behaviour from spring security: enable CSRF for all POSTs.
105+
// we need to disable CSRF for SOAP paths explicitly.
106+
.csrf(c -> c.ignoringRequestMatchers(CONFIG.getCxfMapping() + "/**"))
106107
.sessionManagement(
107108
req -> req.invalidSessionUrl(prefix + "/signin")
108109
)

0 commit comments

Comments
 (0)