From f0e52bdc4a3487dcbfcfc28210ff71f46f5312db Mon Sep 17 00:00:00 2001 From: Luis Majano Date: Wed, 16 Oct 2024 12:35:48 +0200 Subject: [PATCH] BL-327 #resolve Remove CFToken and move to compat module --- changelog.md | 4 ++ .../compat/interceptors/SessionListener.java | 43 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/main/java/ortus/boxlang/modules/compat/interceptors/SessionListener.java diff --git a/changelog.md b/changelog.md index feb3828..b0ca4a4 100644 --- a/changelog.md +++ b/changelog.md @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- `cftoken` migration to comply with CFML engines. + ## [1.9.0] - 2024-10-15 ## [1.8.0] - 2024-10-10 diff --git a/src/main/java/ortus/boxlang/modules/compat/interceptors/SessionListener.java b/src/main/java/ortus/boxlang/modules/compat/interceptors/SessionListener.java new file mode 100644 index 0000000..645368c --- /dev/null +++ b/src/main/java/ortus/boxlang/modules/compat/interceptors/SessionListener.java @@ -0,0 +1,43 @@ +/** + * [BoxLang] + * + * Copyright [2023] [Ortus Solutions, Corp] + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" + * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package ortus.boxlang.modules.compat.interceptors; + +import ortus.boxlang.runtime.application.Session; +import ortus.boxlang.runtime.events.BaseInterceptor; +import ortus.boxlang.runtime.events.InterceptionPoint; +import ortus.boxlang.runtime.scopes.Key; +import ortus.boxlang.runtime.types.IStruct; + +/** + * Listens to when sessions get created to manipulate them for CFML compatibility + */ +public class SessionListener extends BaseInterceptor { + + /** + * Intercept BIF Invocation + * + * @param interceptData The struct containing the context and arguments of the BIF Invocation + */ + @InterceptionPoint + public void onSessionCreated( IStruct interceptData ) { + // Get the session from the interceptData + Session userSession = ( Session ) interceptData.get( Key.session ); + + // This is 0 for compatibility with CFML and for security. + userSession.getSessionScope().put( Key.cftoken, 0 ); + + } + +}