From 7b59ed7aab8dbf58aee56e997f54f2a4d73e9ee7 Mon Sep 17 00:00:00 2001 From: Robert Vokac Date: Thu, 5 Oct 2023 19:56:29 +0200 Subject: [PATCH] Moved AuthenticationFilter to Octagon --- nanodata-web/pom.xml | 7 ++ .../web/filters/AuthenticationFilter.java | 84 ------------------- nanodata-web/src/main/webapp/WEB-INF/web.xml | 19 +++++ pom.xml | 1 + 4 files changed, 27 insertions(+), 84 deletions(-) delete mode 100644 nanodata-web/src/main/java/org/nanoboot/nanodata/web/filters/AuthenticationFilter.java diff --git a/nanodata-web/pom.xml b/nanodata-web/pom.xml index 3af9c05..edda1f2 100644 --- a/nanodata-web/pom.xml +++ b/nanodata-web/pom.xml @@ -162,6 +162,13 @@ + + + org.nanoboot.octagon + octagon-jakarta + ${octagon.version} + + diff --git a/nanodata-web/src/main/java/org/nanoboot/nanodata/web/filters/AuthenticationFilter.java b/nanodata-web/src/main/java/org/nanoboot/nanodata/web/filters/AuthenticationFilter.java deleted file mode 100644 index ba7fb0b..0000000 --- a/nanodata-web/src/main/java/org/nanoboot/nanodata/web/filters/AuthenticationFilter.java +++ /dev/null @@ -1,84 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////////////////////// -// Nanodata. -// Copyright (C) 2023-2023 the original author or authors. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; version 2 -// of the License only. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -/////////////////////////////////////////////////////////////////////////////////////////////// -package org.nanoboot.nanodata.web.filters; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; - -import jakarta.servlet.Filter; -import jakarta.servlet.FilterChain; -import jakarta.servlet.FilterConfig; -import jakarta.servlet.ServletContext; -import jakarta.servlet.ServletException; -import jakarta.servlet.ServletRequest; -import jakarta.servlet.ServletResponse; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import jakarta.servlet.http.HttpSession; - -public class AuthenticationFilter implements Filter { - - private ServletContext context; - - public void init(FilterConfig fConfig) throws ServletException { - this.context = fConfig.getServletContext(); - this.context.log("AuthenticationFilter started"); - } - - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { - - HttpServletRequest req = (HttpServletRequest) request; - HttpServletResponse res = (HttpServletResponse) response; - - HttpSession session = req.getSession(false); - boolean sessionExists = session != null; - - String octConfpath = System.getProperty("nanodata.confpath"); - if (octConfpath == null || octConfpath.isEmpty()) { - String msg = "csa configuration is broken : " + "nanodata.confpath=" + octConfpath; - throw new RuntimeException(msg); - } - File octagonProperties = new File(octConfpath + "/nanodata.properties"); - try ( InputStream input = new FileInputStream(octagonProperties.getAbsolutePath())) { - - Properties properties = new Properties(); - properties.load(input); - - } catch (IOException ex) { - ex.printStackTrace(); - throw new RuntimeException("Loading nanodata.properties failed."); - } - - if (!sessionExists) { - res.sendRedirect(req.getContextPath() + "/login.html"); - this.context.log("Access is not authorized."); - - } else { - this.context.log("Access is authorized."); - chain.doFilter(request, response); - } - } - - public void destroy() { - //close any resources here - } -} diff --git a/nanodata-web/src/main/webapp/WEB-INF/web.xml b/nanodata-web/src/main/webapp/WEB-INF/web.xml index 02865b1..9adf162 100644 --- a/nanodata-web/src/main/webapp/WEB-INF/web.xml +++ b/nanodata-web/src/main/webapp/WEB-INF/web.xml @@ -73,6 +73,16 @@ /* + + AuthenticationFilter + org.nanoboot.octagon.jakarta.filters.AuthenticationFilter + + + + *.jsp @@ -80,4 +90,13 @@ + + octagon.application-code + nanodata + + + + org.nanoboot.octagon.jakarta.listeners.ApplicationCodeListener + + diff --git a/pom.xml b/pom.xml index 2a7fc36..416e15d 100644 --- a/pom.xml +++ b/pom.xml @@ -50,6 +50,7 @@ 2.0.1-SNAPSHOT true 0.1.1-SNAPSHOT + 2.0.0-SNAPSHOT