From 88bbbb75c2ce0804008e1c8275b76338c8e80de1 Mon Sep 17 00:00:00 2001 From: Yanick Minder Date: Fri, 23 Aug 2024 07:59:51 +0200 Subject: [PATCH] restore unused files --- .../java/ch/puzzle/okr/ForwardFilter.java | 18 +++----- .../okr/SanitizeParametersRequestWrapper.java | 43 ------------------- frontend/src/app/app.module.ts | 2 +- frontend/src/app/shared/customRouter.ts | 8 +--- frontend/src/app/shared/guards/auth.guard.ts | 6 +-- frontend/src/environments/environment.prod.ts | 2 +- frontend/src/environments/environment.ts | 1 - 7 files changed, 10 insertions(+), 70 deletions(-) delete mode 100644 backend/src/main/java/ch/puzzle/okr/SanitizeParametersRequestWrapper.java diff --git a/backend/src/main/java/ch/puzzle/okr/ForwardFilter.java b/backend/src/main/java/ch/puzzle/okr/ForwardFilter.java index b362e2227f..bb76f5444c 100644 --- a/backend/src/main/java/ch/puzzle/okr/ForwardFilter.java +++ b/backend/src/main/java/ch/puzzle/okr/ForwardFilter.java @@ -7,6 +7,7 @@ import jakarta.servlet.http.HttpServletRequest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; import org.springframework.web.filter.GenericFilterBean; import java.io.IOException; @@ -15,30 +16,21 @@ public class ForwardFilter extends GenericFilterBean { private static final Logger logger = LoggerFactory.getLogger(ForwardFilter.class); - private final String[] allowedRoutes = { "/keyresult", "/objective", "/dashboard" }; + private final String[] allowedRoutes = { "/keyresult", "/objective", "/?state" }; @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { - SanitizeParametersRequestWrapper request = new SanitizeParametersRequestWrapper( - (HttpServletRequest) servletRequest); + HttpServletRequest request = (HttpServletRequest) servletRequest; String path = request.getRequestURI(); - // logger.debug(String.format("This is the URI '%s'", path)); - // if (path.startsWith("/?state")) { - // logger.debug("change path to /dashboard"); - // - // request.getRequestDispatcher("/dashboard"); - // } - logger.info("This is the URI: " + path); if (Arrays.stream(this.allowedRoutes).anyMatch(path::startsWith)) { logger.info(String.format("Keycloak state parameter detected ====> make a forward from '%s' to '%s'", request.getRequestURI(), "/")); - request.getRequestDispatcher("/").forward(request, servletResponse); + servletRequest.getRequestDispatcher("/").forward(servletRequest, servletResponse); return; } - logger.debug(String.format("====> pass through the filter '%s'", request.getRequestURI())); - filterChain.doFilter(request, servletResponse); + filterChain.doFilter(servletRequest, servletResponse); } } diff --git a/backend/src/main/java/ch/puzzle/okr/SanitizeParametersRequestWrapper.java b/backend/src/main/java/ch/puzzle/okr/SanitizeParametersRequestWrapper.java deleted file mode 100644 index 35d1008ace..0000000000 --- a/backend/src/main/java/ch/puzzle/okr/SanitizeParametersRequestWrapper.java +++ /dev/null @@ -1,43 +0,0 @@ -package ch.puzzle.okr; - -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletRequestWrapper; -import org.apache.commons.lang3.StringEscapeUtils; - -import java.util.*; -import java.util.stream.Collectors; - -public class SanitizeParametersRequestWrapper extends HttpServletRequestWrapper { - - private final Map sanitizedMap; - - public SanitizeParametersRequestWrapper(HttpServletRequest request) { - super(request); - sanitizedMap = Collections.unmodifiableMap(request.getParameterMap().entrySet().stream() - .collect(Collectors.toMap(Map.Entry::getKey, entry -> Arrays.stream(entry.getValue()) - .map(StringEscapeUtils::escapeHtml4).toArray(String[]::new)))); - } - - @Override - public Map getParameterMap() { - return new HashMap<>(); - } - - @Override - public String[] getParameterValues(String name) { - return new String[0]; - } - - @Override - public String getParameter(String name) { - if (name.equals("state")) - return null; - - return Optional.ofNullable(getParameterValues(name)).map(values -> values[0]).orElse(null); - } - - @Override - public Enumeration getParameterNames() { - return null; - } -} \ No newline at end of file diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.ts index 2565574b9e..59dab8cddb 100644 --- a/frontend/src/app/app.module.ts +++ b/frontend/src/app/app.module.ts @@ -34,7 +34,7 @@ import { ApplicationTopBarComponent } from './application-top-bar/application-to import { TeamComponent } from './team/team.component'; import { OverviewComponent } from './overview/overview.component'; import { ObjectiveComponent } from './objective/objective.component'; -import { CommonModule, LocationStrategy, NgOptimizedImage } from '@angular/common'; +import { CommonModule, NgOptimizedImage } from '@angular/common'; import { KeyresultComponent } from './keyresult/keyresult.component'; import { KeyresultDetailComponent } from './keyresult-detail/keyresult-detail.component'; import { ObjectiveDetailComponent } from './objective-detail/objective-detail.component'; diff --git a/frontend/src/app/shared/customRouter.ts b/frontend/src/app/shared/customRouter.ts index 6ef50fb0fa..1851a01b52 100644 --- a/frontend/src/app/shared/customRouter.ts +++ b/frontend/src/app/shared/customRouter.ts @@ -1,5 +1,5 @@ import { Injectable } from '@angular/core'; -import { ActivatedRoute, NavigationExtras, Router } from '@angular/router'; +import { NavigationExtras, Router } from '@angular/router'; @Injectable() export class CustomRouter extends Router { @@ -8,12 +8,6 @@ export class CustomRouter extends Router { } override navigate(commands: any[], extras?: NavigationExtras | undefined): Promise { - // const noMergeParams = ['iss', 'state', 'session_state']; - // const newQueryParam = new URLSearchParams(window.location.search); - // if (noMergeParams.every((e) => newQueryParam.has(e))) { - // return super.navigate(commands, extras); - // } - const customExtras = { ...extras, queryParamsHandling: 'merge' } as NavigationExtras; return super.navigate(commands, customExtras); } diff --git a/frontend/src/app/shared/guards/auth.guard.ts b/frontend/src/app/shared/guards/auth.guard.ts index e373990e37..137380edbe 100644 --- a/frontend/src/app/shared/guards/auth.guard.ts +++ b/frontend/src/app/shared/guards/auth.guard.ts @@ -1,12 +1,9 @@ -import { CanActivateFn, Router } from '@angular/router'; +import { CanActivateFn } from '@angular/router'; import { inject } from '@angular/core'; import { OAuthService } from 'angular-oauth2-oidc'; export const authGuard: CanActivateFn = (route, state) => { const oauthService = inject(OAuthService); - const router = inject(Router); - - console.log('test123'); return oauthService.loadDiscoveryDocumentAndTryLogin().then(async () => { // if the login failed initialize code flow let validToken = oauthService.hasValidIdToken(); @@ -15,6 +12,7 @@ export const authGuard: CanActivateFn = (route, state) => { return false; } oauthService.setupAutomaticSilentRefresh(); + location.hash = ''; return true; }); }; diff --git a/frontend/src/environments/environment.prod.ts b/frontend/src/environments/environment.prod.ts index e40aea3652..14c9e556e5 100644 --- a/frontend/src/environments/environment.prod.ts +++ b/frontend/src/environments/environment.prod.ts @@ -11,7 +11,7 @@ export const environment = { customQueryParams: { response_modes_supported: ['query'] }, // redirectUri: 'http://localhost:8080/auth/keycloakopenid/callback', // redirectUri: `${window.location.protocol}//${window.location.hostname}:${window.location.port}/auth/keycloakopenid/callback${window.location.search}`, - redirectUri: window.location.origin + '/dashboard', + redirectUri: window.location.origin, scope: 'profile openid', clientId: 'pitc_okr_prod', responseType: 'code', diff --git a/frontend/src/environments/environment.ts b/frontend/src/environments/environment.ts index 41d272f22c..6b65b98b9b 100644 --- a/frontend/src/environments/environment.ts +++ b/frontend/src/environments/environment.ts @@ -11,7 +11,6 @@ export const environment = { decreaseExpirationBySec: 30, clearHashAfterLogin: true, issuer: '', - customQueryParams: { response_mode: 'query' }, strictDiscoveryDocumentValidation: false, redirectUri: 'http://localhost:4200', scope: 'openid profile',