From bad299d97404461c2a36c01ef4552e5fcfb1aecf Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Sun, 30 Aug 2020 12:37:32 +0200 Subject: [PATCH] Integreted Apache Wicket Former-commit-id: a6b20a34bf371b8500f7545b5d5a0c086162f63c --- ccm-bundle-devel-wildfly/pom.xml | 7 +- ccm-core/pom.xml | 6 ++ .../java/org/libreccm/ui/CcmAdminFilter.java | 99 +++++++++++++++++++ .../java/org/libreccm/ui/admin/AdminPage.java | 31 ++++++ .../java/org/libreccm/ui/admin/CcmAdmin.java | 41 ++++++++ .../org/libreccm/ui/admin/DashboardPage.java | 35 +++++++ .../org/libreccm/ui/admin/DashboardPanel.java | 38 +++++++ .../org/libreccm/ui/admin/AdminPage.html | 13 +++ .../org/libreccm/ui/admin/DashboardPanel.html | 13 +++ .../libreccm/ui/admin/OffDashboardPage.html | 14 +++ pom.xml | 15 ++- 11 files changed, 308 insertions(+), 4 deletions(-) create mode 100644 ccm-core/src/main/java/org/libreccm/ui/CcmAdminFilter.java create mode 100644 ccm-core/src/main/java/org/libreccm/ui/admin/AdminPage.java create mode 100644 ccm-core/src/main/java/org/libreccm/ui/admin/CcmAdmin.java create mode 100644 ccm-core/src/main/java/org/libreccm/ui/admin/DashboardPage.java create mode 100644 ccm-core/src/main/java/org/libreccm/ui/admin/DashboardPanel.java create mode 100644 ccm-core/src/main/resources/org/libreccm/ui/admin/AdminPage.html create mode 100644 ccm-core/src/main/resources/org/libreccm/ui/admin/DashboardPanel.html create mode 100644 ccm-core/src/main/resources/org/libreccm/ui/admin/OffDashboardPage.html diff --git a/ccm-bundle-devel-wildfly/pom.xml b/ccm-bundle-devel-wildfly/pom.xml index 3b5274fa5..aeea4098c 100644 --- a/ccm-bundle-devel-wildfly/pom.xml +++ b/ccm-bundle-devel-wildfly/pom.xml @@ -84,8 +84,8 @@ org.apache.maven.plugins maven-compiler-plugin - 1.8 - 1.8 + 11 + 11 true true ${project.build.sourceEncoding} @@ -244,6 +244,9 @@ false ${project.basedir}/wildfly.properties + + development + diff --git a/ccm-core/pom.xml b/ccm-core/pom.xml index 0080ece81..82ae07062 100644 --- a/ccm-core/pom.xml +++ b/ccm-core/pom.xml @@ -250,6 +250,12 @@ Saxon-HE + + org.apache.wicket + wicket-core + 9.0.0 + + diff --git a/ccm-core/src/main/java/org/libreccm/ui/CcmAdminFilter.java b/ccm-core/src/main/java/org/libreccm/ui/CcmAdminFilter.java new file mode 100644 index 000000000..fc8587b12 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/ui/CcmAdminFilter.java @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2020 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.ui; + +import org.apache.wicket.protocol.http.WicketFilter; +import org.libreccm.core.CoreConstants; +import org.libreccm.security.PermissionChecker; +import org.libreccm.security.Shiro; + +import java.io.IOException; +import java.net.URL; +import java.net.http.HttpRequest; + +import javax.inject.Inject; +import javax.servlet.FilterChain; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.annotation.WebFilter; +import javax.servlet.annotation.WebInitParam; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * + * @author Jens Pelzetter + */ +@WebFilter( + value = "/@admin/", + initParams = { + @WebInitParam( + name = "applicationClassName", + value = "org.libreccm.ui.admin.CcmAdmin" + ), + @WebInitParam(name = "filterMappingUrlPattern", value = "/@admin/*") + } +) +public class CcmAdminFilter extends WicketFilter { + + @Inject + private Shiro shiro; + + @Inject + private PermissionChecker permissionChecker; + + @Inject + private ServletContext servletContext; + + @Override + public void doFilter( + final ServletRequest request, + final ServletResponse response, + final FilterChain chain + ) throws IOException, ServletException { + if (permissionChecker.isPermitted(CoreConstants.PRIVILEGE_ADMIN)) { + super.doFilter(request, response, chain); + } else if (shiro.getSubject().isAuthenticated()) { + final HttpServletResponse httpResponse + = (HttpServletResponse) response; + httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED); + } else { + final HttpServletRequest httpRequest = (HttpServletRequest) request; + final HttpServletResponse httpResponse + = (HttpServletResponse) response; + + final String returnUrl = String.format( + "%s%s", + httpRequest.getContextPath(), + httpRequest.getServletPath() + ); + + httpResponse.sendRedirect( + String.format( + "%s/ccm/register?return_url=%s", + servletContext.getContextPath(), + returnUrl + ) + ); + } + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/AdminPage.java b/ccm-core/src/main/java/org/libreccm/ui/admin/AdminPage.java new file mode 100644 index 000000000..f2f6b2846 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/AdminPage.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2020 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.ui.admin; + +import org.apache.wicket.markup.html.WebPage; + +/** + * + * @author Jens Pelzetter + */ +public class AdminPage extends WebPage { + + private static final long serialVersionUID = 1L; + +} diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/CcmAdmin.java b/ccm-core/src/main/java/org/libreccm/ui/admin/CcmAdmin.java new file mode 100644 index 000000000..b5b64ff74 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/CcmAdmin.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2020 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.ui.admin; + +import org.apache.wicket.markup.html.WebPage; +import org.apache.wicket.protocol.http.WebApplication; + +/** + * + * @author Jens Pelzetter + */ +public class CcmAdmin extends WebApplication { + + @Override + public Class getHomePage() { + return DashboardPage.class; + } + + @Override + public void init() { + super.init(); +// setConfigurationType(RuntimeConfigurationType.DEPLOYMENT); + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/DashboardPage.java b/ccm-core/src/main/java/org/libreccm/ui/admin/DashboardPage.java new file mode 100644 index 000000000..0da217545 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/DashboardPage.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2020 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.ui.admin; + +/** + * + * @author Jens Pelzetter + */ +public class DashboardPage extends AdminPage { + + private static final long serialVersionUID = 1L; + + @SuppressWarnings("OverridableMethodCallInConstructor") + public DashboardPage() { +// add(new Label("dashboardLabel", "CCM Admin Dashboard")); + add(new DashboardPanel("adminPanel")); + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/DashboardPanel.java b/ccm-core/src/main/java/org/libreccm/ui/admin/DashboardPanel.java new file mode 100644 index 000000000..8b412b851 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/DashboardPanel.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2020 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.ui.admin; + +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.panel.Panel; + +/** + * + * @author Jens Pelzetter + */ +public class DashboardPanel extends Panel { + + private static final long serialVersionUID = 1L; + + @SuppressWarnings("OverridableMethodCallInConstructor") + public DashboardPanel(String id) { + super(id); + add(new Label("dashboardLabel", "CCM Admin Dashboard")); + } + +} diff --git a/ccm-core/src/main/resources/org/libreccm/ui/admin/AdminPage.html b/ccm-core/src/main/resources/org/libreccm/ui/admin/AdminPage.html new file mode 100644 index 000000000..f8358e4b4 --- /dev/null +++ b/ccm-core/src/main/resources/org/libreccm/ui/admin/AdminPage.html @@ -0,0 +1,13 @@ + + + + + LibreCCM Admin + + +
[admin panel]
+ + + + + diff --git a/ccm-core/src/main/resources/org/libreccm/ui/admin/DashboardPanel.html b/ccm-core/src/main/resources/org/libreccm/ui/admin/DashboardPanel.html new file mode 100644 index 000000000..b34949bba --- /dev/null +++ b/ccm-core/src/main/resources/org/libreccm/ui/admin/DashboardPanel.html @@ -0,0 +1,13 @@ + + + + + + + +
+ [Label's message goes here] +
+
+ + diff --git a/ccm-core/src/main/resources/org/libreccm/ui/admin/OffDashboardPage.html b/ccm-core/src/main/resources/org/libreccm/ui/admin/OffDashboardPage.html new file mode 100644 index 000000000..0d62e1175 --- /dev/null +++ b/ccm-core/src/main/resources/org/libreccm/ui/admin/OffDashboardPage.html @@ -0,0 +1,14 @@ + + + + + Dashboard - LibreCCM Admin + + +
+ [Label's message goes here] +
+ + + + diff --git a/pom.xml b/pom.xml index 6d7793cd9..49d84ed65 100644 --- a/pom.xml +++ b/pom.xml @@ -164,8 +164,8 @@ maven-compiler-plugin 3.8.1 - 1.8 - 1.8 + 11 + 11 true true ${project.build.sourceEncoding} @@ -556,6 +556,17 @@ 0.11.2
+ + org.apache.wicket + wicket-core + 9.0.0 + + + org.apache.wicket + wicket-cdi + 9.0.0 + +