Skip to content

Commit f792026

Browse files
committed
Fix Redirection when not logged in
1 parent fb3b491 commit f792026

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

source/src/main/java/org/cerberus/core/config/cerberus/WebAppInitializer.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import jakarta.servlet.*;
2424
import jakarta.servlet.http.HttpSessionEvent;
2525
import jakarta.servlet.http.HttpSessionListener;
26+
import org.apache.logging.log4j.LogManager;
27+
import org.apache.logging.log4j.Logger;
2628
import org.cerberus.core.config.webmvc.WebMvcConfiguration;
2729
import org.springframework.web.WebApplicationInitializer;
2830
import org.springframework.web.context.ContextLoaderListener;
@@ -38,9 +40,15 @@
3840
*/
3941
public class WebAppInitializer implements WebApplicationInitializer {
4042

43+
private static final Logger LOG = LogManager.getLogger(WebAppInitializer.class);
44+
4145
@Override
4246
public void onStartup(ServletContext servletContext) throws ServletException {
4347

48+
LOG.info("========================================");
49+
LOG.info(">>> WebAppInitializer.onStartup() called");
50+
LOG.info("========================================");
51+
4452
// Single shared Spring context for both root beans and MVC beans.
4553
// Avoids the classic root/servlet context split that causes issues with Spring Security.
4654
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();

source/src/main/webapp/Homepage.jsp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@
2323
<%@page import="org.springframework.context.ApplicationContext" %>
2424
<%@page import="org.cerberus.core.database.IDatabaseVersioningService" %>
2525

26+
<%-- Forcer l'authentification : si non connecté, rediriger vers Homepage.jsp pour passer par Spring Security --%>
27+
<%
28+
if (request.getUserPrincipal() == null) {
29+
response.sendRedirect(request.getContextPath() + "/Homepage.jsp");
30+
return;
31+
}
32+
%>
33+
2634
<%@page contentType="text/html" pageEncoding="UTF-8" %>
2735
<!DOCTYPE html>
2836
<html class="h-full">

0 commit comments

Comments
 (0)