Checkpoint on cleaning up, preparing for completion of auth + routing

This commit is contained in:
2025-03-18 09:46:57 -05:00
parent 5a5d98a3ff
commit 2c32c5a9fc
7 changed files with 147 additions and 13 deletions

View File

@ -22,6 +22,7 @@
package com.kingsrook.qqq.backend.javalin; package com.kingsrook.qqq.backend.javalin;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.function.Function; import java.util.function.Function;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance; import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
@ -312,4 +313,20 @@ public class QJavalinMetaData implements QSupplementalInstanceMetaData
return (this); return (this);
} }
/*******************************************************************************
** Fluent setter to add 1 routeProvider
*******************************************************************************/
public QJavalinMetaData withRouteProvider(JavalinRouteProviderMetaData routeProvider)
{
if(this.routeProviders == null)
{
this.routeProviders = new ArrayList<>();
}
this.routeProviders.add(routeProvider);
return (this);
}
} }

View File

@ -32,12 +32,13 @@ import com.kingsrook.qqq.backend.core.modules.authentication.QAuthenticationModu
import com.kingsrook.qqq.backend.core.modules.authentication.QAuthenticationModuleInterface; import com.kingsrook.qqq.backend.core.modules.authentication.QAuthenticationModuleInterface;
import com.kingsrook.qqq.backend.javalin.QJavalinImplementation; import com.kingsrook.qqq.backend.javalin.QJavalinImplementation;
import io.javalin.http.Context; import io.javalin.http.Context;
import static com.kingsrook.qqq.backend.core.logging.LogUtils.logPair;
/******************************************************************************* /*******************************************************************************
** simple implementation of a route authenticator. Assumes that unauthenticated ** simple implementation of a route authenticator. Assumes that unauthenticated
** requests should redirect to a login page. Note though, maybe that should be ** requests should redirect to a login page. Note though, maybe that should be
** more intelligent, like, only redirect requets for a .html file, but not ** more intelligent, like, only redirect requests for a .html file, but not
** requests for include files like images or .js/.css? ** requests for include files like images or .js/.css?
*******************************************************************************/ *******************************************************************************/
public class SimpleRouteAuthenticator implements RouteAuthenticatorInterface public class SimpleRouteAuthenticator implements RouteAuthenticatorInterface
@ -53,7 +54,7 @@ public class SimpleRouteAuthenticator implements RouteAuthenticatorInterface
try try
{ {
QSession qSession = QJavalinImplementation.setupSession(context, null); QSession qSession = QJavalinImplementation.setupSession(context, null);
LOG.debug("Session has been activated", "uuid=" + qSession.getUuid()); LOG.debug("Session has been activated", logPair("uuid", qSession.getUuid()));
return (true); return (true);
} }
catch(QAuthenticationException e) catch(QAuthenticationException e)

View File

@ -23,11 +23,7 @@ package com.kingsrook.sampleapp;
import com.kingsrook.qqq.backend.core.logging.QLogger; import com.kingsrook.qqq.backend.core.logging.QLogger;
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeReference;
import com.kingsrook.qqq.middleware.javalin.QApplicationJavalinServer; import com.kingsrook.qqq.middleware.javalin.QApplicationJavalinServer;
import com.kingsrook.qqq.middleware.javalin.routeproviders.ProcessBasedRouter;
import com.kingsrook.qqq.middleware.javalin.routeproviders.SimpleFileSystemDirectoryRouter;
import com.kingsrook.qqq.middleware.javalin.routeproviders.authentication.SimpleRouteAuthenticator;
import com.kingsrook.sampleapp.metadata.SampleMetaDataProvider; import com.kingsrook.sampleapp.metadata.SampleMetaDataProvider;
@ -59,12 +55,6 @@ public class SampleJavalinServer
{ {
QApplicationJavalinServer javalinServer = new QApplicationJavalinServer(new SampleMetaDataProvider()); QApplicationJavalinServer javalinServer = new QApplicationJavalinServer(new SampleMetaDataProvider());
javalinServer.withAdditionalRouteProvider(new SimpleFileSystemDirectoryRouter("/static-site", "static-site/")
.withRouteAuthenticator(new QCodeReference(SimpleRouteAuthenticator.class)));
javalinServer.withAdditionalRouteProvider(new ProcessBasedRouter("dynamic-site/<pagePath>", "DynamicSiteProcess")
.withRouteAuthenticator(new QCodeReference(SimpleRouteAuthenticator.class)));
javalinServer.start(); javalinServer.start();
} }
catch(Exception e) catch(Exception e)

View File

@ -0,0 +1,66 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2025. Kingsrook, LLC
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
* contact@kingsrook.com
* https://github.com/Kingsrook/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.kingsrook.sampleapp.metadata;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.metadata.MetaDataProducer;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeReference;
import com.kingsrook.qqq.backend.javalin.QJavalinMetaData;
import com.kingsrook.qqq.middleware.javalin.metadata.JavalinRouteProviderMetaData;
import com.kingsrook.qqq.middleware.javalin.routeproviders.authentication.SimpleRouteAuthenticator;
/*******************************************************************************
** Meta Data Producer for SampleJavalin
*******************************************************************************/
public class SampleJavalinMetaDataProducer extends MetaDataProducer<QJavalinMetaData>
{
/*******************************************************************************
** todo wip - test sub-directories of each other
** todo wip - another redirect to get rid of the code & state from url
** todo wip - allow mat-dash to be served at a different path
** todo wip - get mat-dash committed
*******************************************************************************/
@Override
public QJavalinMetaData produce(QInstance qInstance) throws QException
{
return (new QJavalinMetaData()
.withRouteProvider(new JavalinRouteProviderMetaData()
.withHostedPath("/public")
.withFileSystemPath("site/public"))
.withRouteProvider(new JavalinRouteProviderMetaData()
.withRouteAuthenticator(new QCodeReference(SimpleRouteAuthenticator.class))
.withHostedPath("/private")
.withFileSystemPath("site/private"))
.withRouteProvider(new JavalinRouteProviderMetaData()
.withRouteAuthenticator(new QCodeReference(SimpleRouteAuthenticator.class))
.withHostedPath("/dynamic-site/<pagePath>")
.withProcessName(DynamicSiteProcessMetaDataProducer.NAME))
);
}
}

View File

@ -43,7 +43,7 @@ public class DynamicSiteProcessStep implements BackendStep
ProcessBasedRouterPayload processPayload = runBackendStepInput.getProcessPayload(ProcessBasedRouterPayload.class); ProcessBasedRouterPayload processPayload = runBackendStepInput.getProcessPayload(ProcessBasedRouterPayload.class);
String path = processPayload.getPath(); String path = processPayload.getPath();
processPayload.setResponseString("You requested: " + path); processPayload.setResponseString("You requested: " + path + "(at path-param: " + processPayload.getPathParams().get("pagePath") + ")");
runBackendStepOutput.setProcessPayload(processPayload); runBackendStepOutput.setProcessPayload(processPayload);
} }

View File

@ -0,0 +1,30 @@
<!--
~ QQQ - Low-code Application Framework for Engineers.
~ Copyright (C) 2021-2025. Kingsrook, LLC
~ 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
~ contact@kingsrook.com
~ https://github.com/Kingsrook/
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU Affero General Public License as
~ published by the Free Software Foundation, either version 3 of the
~ License, or (at your option) any later version.
~
~ 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 Affero General Public License for more details.
~
~ You should have received a copy of the GNU Affero General Public License
~ along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<html lang="en">
<body>
<h1>Welcome to the private site</h1>
<ul>
<li><a href="/public/">Return to the public site.</a></li>
</ul>
</body>
</html>

View File

@ -0,0 +1,30 @@
<!--
~ QQQ - Low-code Application Framework for Engineers.
~ Copyright (C) 2021-2025. Kingsrook, LLC
~ 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
~ contact@kingsrook.com
~ https://github.com/Kingsrook/
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU Affero General Public License as
~ published by the Free Software Foundation, either version 3 of the
~ License, or (at your option) any later version.
~
~ 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 Affero General Public License for more details.
~
~ You should have received a copy of the GNU Affero General Public License
~ along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<html lang="en">
<body>
<h1>Welcome to the public site</h1>
<ul>
<li><a href="/private/">Try to access the private site.</a></li>
</ul>
</body>
</html>