|
63 | 63 | import it.eng.spagobi.commons.utilities.TOTPService; |
64 | 64 | import it.eng.spagobi.commons.utilities.UserUtilities; |
65 | 65 | import it.eng.spagobi.commons.utilities.messages.MessageBuilder; |
| 66 | +import it.eng.spagobi.utilities.rest.RestUtilities; |
66 | 67 | import it.eng.spagobi.profiling.bean.SbiUser; |
67 | 68 | import it.eng.spagobi.profiling.dao.ISbiUserDAO; |
68 | 69 | import it.eng.spagobi.security.InternalSecurityServiceSupplierImpl; |
@@ -331,12 +332,23 @@ public Response verifyMfaCode(@Context HttpServletRequest req, Map<String, Strin |
331 | 332 | @POST |
332 | 333 | @Path("/oauth2") |
333 | 334 | @PublicService |
334 | | - public Response loginOAuth2(@Context HttpServletRequest req) throws Exception { |
| 335 | + public Response loginOAuth2(@Context HttpServletRequest req, Map<String, String> payload) throws Exception { |
335 | 336 |
|
336 | 337 | IKnowageMonitor monitor = KnowageMonitorFactory.getInstance().start("knowage.login.oauth2.authentication"); |
337 | 338 |
|
338 | 339 | try { |
339 | | - return performOAuth2Login(req, monitor, true); |
| 340 | + |
| 341 | + // Store payload as request attribute if present |
| 342 | + if (payload != null) { |
| 343 | + String jwtLabel = System.getProperty("JWT_LABEL", System.getenv("JWT_LABEL")); |
| 344 | + req.setAttribute(jwtLabel, payload.get(jwtLabel)); |
| 345 | + } |
| 346 | + |
| 347 | + // Check JWT_SESSION_STORAGE variable |
| 348 | + String jwtSessionStorage = System.getProperty("JWT_SESSION_STORAGE", System.getenv("JWT_SESSION_STORAGE")); |
| 349 | + boolean requiresRedirect = StringUtils.isBlank(jwtSessionStorage); |
| 350 | + |
| 351 | + return performOAuth2Login(req, monitor, requiresRedirect); |
340 | 352 | } catch (Exception e) { |
341 | 353 | logger.error("Unexpected error during OAuth2 login", e); |
342 | 354 | monitor.stop(e); |
@@ -863,8 +875,8 @@ private Response completeLogin(HttpServletRequest req, IEngUserProfile profile, |
863 | 875 | } |
864 | 876 |
|
865 | 877 | if (requiresRedirect) { |
866 | | - URI redirectUri = URI |
867 | | - .create(System.getProperty("JWT_KNOWAGE_VUE", System.getenv("JWT_KNOWAGE_VUE")) + "login?authToken=" + profile.getUserUniqueIdentifier()); |
| 878 | + String origin = RestUtilities.getOrigin(req); |
| 879 | + URI redirectUri = URI.create(origin + "/knowage-vue/login?authToken=" + profile.getUserUniqueIdentifier()); |
868 | 880 | return Response.seeOther(redirectUri).build(); |
869 | 881 | } else { |
870 | 882 | Object idToken = req.getAttribute(Oauth2SsoService.ID_TOKEN); |
|
0 commit comments