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
{
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.UUID;
import com.kingsrook.qqq.backend.core.exceptions.QAuthenticationException;
import com.kingsrook.qqq.backend.core.logging.QLogger;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.session.QSession;
@ -45,8 +46,13 @@ public class MockAuthenticationModule implements QAuthenticationModuleInterface
**
*******************************************************************************/
@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.setIdReference("User:" + (System.currentTimeMillis() % USER_ID_MODULO));
qUser.setFullName("John Smith");
@ -80,4 +86,16 @@ public class MockAuthenticationModule implements QAuthenticationModuleInterface
return (true);
}
/***************************************************************************
**
***************************************************************************/
@Override
public String getLoginRedirectUrl(String originalUrl)
{
return originalUrl + "?createMockSession=true";
}
}