Skip to content

Commit e52a242

Browse files
committed
Fix #33103: add workaround for links in MS office
1 parent a9974e2 commit e52a242

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* ContainerProxy
3+
*
4+
* Copyright (C) 2016-2024 Open Analytics
5+
*
6+
* ===========================================================================
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the Apache License as published by
10+
* The Apache Software Foundation, either version 2 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* Apache License for more details.
17+
*
18+
* You should have received a copy of the Apache License
19+
* along with this program. If not, see <http://www.apache.org/licenses/>
20+
*/
21+
package eu.openanalytics.containerproxy.security;
22+
23+
import jakarta.servlet.FilterChain;
24+
import jakarta.servlet.ServletException;
25+
import jakarta.servlet.http.HttpServletRequest;
26+
import jakarta.servlet.http.HttpServletResponse;
27+
import org.springframework.http.HttpStatus;
28+
import org.springframework.web.filter.OncePerRequestFilter;
29+
30+
import java.io.IOException;
31+
32+
public class UserAgentFilter extends OncePerRequestFilter {
33+
34+
@Override
35+
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException {
36+
if (request.getHeader("User-Agent").contains("ms-office")) {
37+
// see #33103
38+
// send empty response if request made by MS Office
39+
// otherwise the user will not be able to sign-in (or get logged out)
40+
response.setCharacterEncoding("UTF-8");
41+
response.setContentType("text/html");
42+
response.getWriter().write("");
43+
response.setStatus(HttpStatus.OK.value());
44+
return;
45+
}
46+
chain.doFilter(request, response);
47+
}
48+
}

src/main/java/eu/openanalytics/containerproxy/security/WebSecurityConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
130130

131131
// App Recovery Filter
132132
http.addFilterAfter(appRecoveryFilter, BasicAuthenticationFilter.class);
133+
http.addFilterAfter(new UserAgentFilter(), BasicAuthenticationFilter.class);
133134

134135
// Perform CSRF check on the login form
135136
http.csrf(csrf -> csrf.requireCsrfProtectionMatcher(new AntPathRequestMatcher("/login", "POST")));

0 commit comments

Comments
 (0)