Skip to content

Commit 01ccb27

Browse files
authored
Limit wellknown servlet to serve single file
1 parent cf5c78a commit 01ccb27

File tree

1 file changed

+30
-20
lines changed

1 file changed

+30
-20
lines changed

Diff for: src/main/java/com/mxgraph/online/WellKnownServlet.java

+30-20
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import javax.servlet.http.HttpServletResponse;
1515

1616
/**
17-
* Servlet to fake a .well-known directory
17+
* Servlet to fake a .well-known directory, GAE does not directly support . prefixed directories
1818
*/
1919
@SuppressWarnings("serial")
2020
public class WellKnownServlet extends HttpServlet
@@ -38,31 +38,41 @@ protected void doGet(HttpServletRequest request,
3838
{
3939
// GAE can't serve dot prefixed folders
4040
String uri = request.getRequestURI().replace("/.", "/");
41-
42-
if (uri.toLowerCase().contains(".json"))
43-
{
44-
response.setContentType("application/json");
45-
}
46-
47-
// Serve whatever was requested from .well-known
48-
try (InputStream in = getServletContext().getResourceAsStream(uri))
41+
42+
// Currently, there is only one file that this servlet serves. This is only
43+
// needed if you want OneDrive integration.
44+
if (uri != null && uri.equals("/well-known/microsoft-identity-association.json"))
4945
{
50-
if (in == null)
46+
if (uri.toLowerCase().contains(".json"))
5147
{
52-
response.sendError(404);
53-
return;
48+
response.setContentType("application/json");
5449
}
55-
56-
byte[] buffer = new byte[8192];
57-
int count;
5850

59-
while ((count = in.read(buffer)) > 0)
51+
// Serve whatever was requested from .well-known
52+
try (InputStream in = getServletContext().getResourceAsStream(uri))
6053
{
61-
response.getOutputStream().write(buffer, 0, count);
54+
if (in == null)
55+
{
56+
response.sendError(404);
57+
return;
58+
}
59+
60+
byte[] buffer = new byte[8192];
61+
int count;
62+
63+
while ((count = in.read(buffer)) > 0)
64+
{
65+
response.getOutputStream().write(buffer, 0, count);
66+
}
67+
68+
response.getOutputStream().flush();
69+
response.getOutputStream().close();
6270
}
63-
64-
response.getOutputStream().flush();
65-
response.getOutputStream().close();
71+
}
72+
else
73+
{
74+
response.sendError(404);
75+
return;
6676
}
6777
}
6878
}

0 commit comments

Comments
 (0)