update mock auth module to fail if an accessToken of 'Deny' is given; add method getLoginRedirectUrl t auth module interface

This commit is contained in:
2025-03-12 19:55:59 -05:00
parent f92ab85c8c
commit 0c72210e8e
3 changed files with 32 additions and 3 deletions

View File

@ -87,7 +87,17 @@ public interface QAuthenticationModuleInterface
*******************************************************************************/ *******************************************************************************/
default String createAccessToken(QAuthenticationMetaData metaData, String clientId, String clientSecret) throws AccessTokenException default String createAccessToken(QAuthenticationMetaData metaData, String clientId, String clientSecret) throws AccessTokenException
{ {
throw (new NotImplementedException("The method createAccessToken() is not implemented in the class: " + this.getClass().getSimpleName())); throw (new NotImplementedException("The method createAccessToken() is not implemented in the authentication module: " + this.getClass().getSimpleName()));
}
/***************************************************************************
**
***************************************************************************/
default String getLoginRedirectUrl(String originalUrl)
{
throw (new NotImplementedException("The method getLoginRedirectUrl() is not implemented in the authentication module: " + this.getClass().getSimpleName()));
} }
} }

View File

@ -24,6 +24,7 @@ package com.kingsrook.qqq.backend.core.modules.authentication.implementations;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import com.kingsrook.qqq.backend.core.exceptions.QAuthenticationException;
import com.kingsrook.qqq.backend.core.logging.QLogger; import com.kingsrook.qqq.backend.core.logging.QLogger;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance; import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.session.QSession; import com.kingsrook.qqq.backend.core.model.session.QSession;
@ -45,8 +46,13 @@ public class MockAuthenticationModule implements QAuthenticationModuleInterface
** **
*******************************************************************************/ *******************************************************************************/
@Override @Override
public QSession createSession(QInstance qInstance, Map<String, String> context) public QSession createSession(QInstance qInstance, Map<String, String> context) throws QAuthenticationException
{ {
if("Deny".equalsIgnoreCase(context.get("accessToken")))
{
throw (new QAuthenticationException("Access denied (per accessToken requesting as such)"));
}
QUser qUser = new QUser(); QUser qUser = new QUser();
qUser.setIdReference("User:" + (System.currentTimeMillis() % USER_ID_MODULO)); qUser.setIdReference("User:" + (System.currentTimeMillis() % USER_ID_MODULO));
qUser.setFullName("John Smith"); qUser.setFullName("John Smith");
@ -80,4 +86,16 @@ public class MockAuthenticationModule implements QAuthenticationModuleInterface
return (true); return (true);
} }
/***************************************************************************
**
***************************************************************************/
@Override
public String getLoginRedirectUrl(String originalUrl)
{
return originalUrl + "?createMockSession=true";
}
} }

View File

@ -40,6 +40,7 @@ import com.kingsrook.qqq.backend.core.actions.tables.QueryAction;
import com.kingsrook.qqq.backend.core.actions.tables.UpdateAction; import com.kingsrook.qqq.backend.core.actions.tables.UpdateAction;
import com.kingsrook.qqq.backend.core.actions.values.QCustomPossibleValueProvider; import com.kingsrook.qqq.backend.core.actions.values.QCustomPossibleValueProvider;
import com.kingsrook.qqq.backend.core.context.QContext; import com.kingsrook.qqq.backend.core.context.QContext;
import com.kingsrook.qqq.backend.core.exceptions.QAuthenticationException;
import com.kingsrook.qqq.backend.core.exceptions.QException; import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.instances.QMetaDataVariableInterpreter; import com.kingsrook.qqq.backend.core.instances.QMetaDataVariableInterpreter;
import com.kingsrook.qqq.backend.core.logging.QLogger; import com.kingsrook.qqq.backend.core.logging.QLogger;
@ -1289,7 +1290,7 @@ public class TestUtils
/******************************************************************************* /*******************************************************************************
** **
*******************************************************************************/ *******************************************************************************/
public static QSession getMockSession() public static QSession getMockSession() throws QAuthenticationException
{ {
MockAuthenticationModule mockAuthenticationModule = new MockAuthenticationModule(); MockAuthenticationModule mockAuthenticationModule = new MockAuthenticationModule();
return (mockAuthenticationModule.createSession(null, null)); return (mockAuthenticationModule.createSession(null, null));