# Description of Changes * Refactoring of SSO code around OAuth & SAML 2 * Enabling auto-login with SAML 2 via the new `SSOAutoLogin` property * Correcting typos & general cleanup --- ## Checklist ### General - [x] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [x] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [x] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md) (if applicable) - [x] I have performed a self-review of my own code - [x] My changes generate no new warnings ### Documentation - [x] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [x] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [x] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details.
84 lines
2.9 KiB
Java
84 lines
2.9 KiB
Java
package stirling.software.SPDF.config;
|
|
|
|
import java.util.Arrays;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import org.springframework.web.servlet.HandlerInterceptor;
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
|
public class CleanUrlInterceptor implements HandlerInterceptor {
|
|
|
|
private static final List<String> ALLOWED_PARAMS =
|
|
Arrays.asList(
|
|
"lang",
|
|
"endpoint",
|
|
"endpoints",
|
|
"logout",
|
|
"error",
|
|
"errorOAuth",
|
|
"file",
|
|
"messageType",
|
|
"infoMessage");
|
|
|
|
@Override
|
|
public boolean preHandle(
|
|
HttpServletRequest request, HttpServletResponse response, Object handler)
|
|
throws Exception {
|
|
String queryString = request.getQueryString();
|
|
if (queryString != null && !queryString.isEmpty()) {
|
|
String requestURI = request.getRequestURI();
|
|
Map<String, String> allowedParameters = new HashMap<>();
|
|
|
|
// Keep only the allowed parameters
|
|
String[] queryParameters = queryString.split("&");
|
|
for (String param : queryParameters) {
|
|
String[] keyValuePair = param.split("=");
|
|
if (keyValuePair.length != 2) {
|
|
continue;
|
|
}
|
|
if (ALLOWED_PARAMS.contains(keyValuePair[0])) {
|
|
allowedParameters.put(keyValuePair[0], keyValuePair[1]);
|
|
}
|
|
}
|
|
|
|
// If there are any parameters that are not allowed
|
|
if (allowedParameters.size() != queryParameters.length) {
|
|
// Construct new query string
|
|
StringBuilder newQueryString = new StringBuilder();
|
|
for (Map.Entry<String, String> entry : allowedParameters.entrySet()) {
|
|
if (newQueryString.length() > 0) {
|
|
newQueryString.append("&");
|
|
}
|
|
newQueryString.append(entry.getKey()).append("=").append(entry.getValue());
|
|
}
|
|
|
|
// Redirect to the URL with only allowed query parameters
|
|
String redirectUrl = requestURI + "?" + newQueryString;
|
|
|
|
response.sendRedirect(request.getContextPath() + redirectUrl);
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public void postHandle(
|
|
HttpServletRequest request,
|
|
HttpServletResponse response,
|
|
Object handler,
|
|
ModelAndView modelAndView) {}
|
|
|
|
@Override
|
|
public void afterCompletion(
|
|
HttpServletRequest request,
|
|
HttpServletResponse response,
|
|
Object handler,
|
|
Exception ex) {}
|
|
}
|