-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Run reverse proxy security test automatically
Uses a modified Jetty proxy servlet to deal with path rewriting
- Loading branch information
1 parent
3bf1753
commit 32247f3
Showing
5 changed files
with
61 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...t-spring-helpers/src/main/java/com/vaadin/flow/spring/test/PathRewritingProxyServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.vaadin.flow.spring.test; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.util.Locale; | ||
|
||
import javax.servlet.ServletConfig; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.http.Cookie; | ||
import javax.servlet.http.HttpServletRequest; | ||
|
||
import org.eclipse.jetty.client.api.Response; | ||
import org.eclipse.jetty.proxy.ProxyServlet.Transparent; | ||
|
||
public class PathRewritingProxyServlet extends Transparent { | ||
|
||
private String prefix; | ||
private String proxyTo; | ||
|
||
@Override | ||
public void init(ServletConfig config) throws ServletException { | ||
proxyTo = config.getInitParameter("proxyTo"); | ||
prefix = config.getInitParameter("prefix"); | ||
super.init(config); | ||
} | ||
|
||
@Override | ||
protected String filterServerResponseHeader( | ||
HttpServletRequest clientRequest, Response serverResponse, | ||
String headerName, String headerValue) { | ||
if (headerName.toLowerCase(Locale.ENGLISH).equals("set-cookie")) { | ||
// Set-Cookie: JSESSIONID=07E35F87D336463E597B5B0D32744660; Path=/; | ||
// HttpOnly | ||
return headerValue.replace("Path=/", "Path=" + prefix); | ||
} else if (headerName.equals("Location")) { | ||
// Location: http://localhost:8888/my/login/page | ||
URL publicURL; | ||
try { | ||
publicURL = new java.net.URL( | ||
clientRequest.getRequestURL().toString()); | ||
} catch (MalformedURLException e) { | ||
e.printStackTrace(); | ||
return headerValue; | ||
} | ||
String hostAndBasePath = publicURL.getProtocol() + "://" | ||
+ publicURL.getHost() + ":" + publicURL.getPort() + prefix | ||
+ "/"; | ||
|
||
return headerValue.replace(proxyTo, hostAndBasePath); | ||
} | ||
return super.filterServerResponseHeader(clientRequest, serverResponse, | ||
headerName, headerValue); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters