Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fucodo Conditional Redirect

This Neos Flow package provides a PSR-15 middleware to conditionally redirect requests based on Eel expressions. It is designed to intercept requests after routing and security entry points, but before dispatching to a controller.

Features

  • Eel-based conditions: Use powerful Eel expressions to decide when a redirect should happen.
  • Role-based checks: Includes a securityContext Eel helper for role membership and authentication checks.
  • Global Whitelist: Prevent redirection for specific routes (e.g., login, logout, authentication) using a configurable whitelist.
  • Redirect Loop Protection: Limits the number of consecutive redirects to prevent infinite loops, with configurable maximum redirects.
  • Original Request Storage: Automatically stores the original request URI in the session, allowing targets to redirect the user back after handling the condition (e.g., after successful onboarding).
  • Custom Status Codes: Support for different HTTP redirect status codes (default is 303).

Installation

Add the package via composer:

{
    "require": {
        "fucodo/conditional-redirect": "*"
    }
}

Configuration

The package is configured via Settings.yaml.

Example Configuration

fucodo:
  conditional:
    redirect:
      enabled: true
      
      # Rules are checked in order. The first matching rule wins.
      rules:
        onboardingRedirect:
          condition: "${securityContext.isAuthenticated() && !securityContext.hasRole('Some.Package:AlreadyOnboarded')}"
          target:
            package: 'Some.Package'
            controller: 'Onboarding'
            action: 'index'
            arguments: {}
            statusCode: 303

      # Whitelist targets that should NEVER be redirected
      whitelist:
        login:
          enabled: true
          package: 'Neos.Neos'
          controller: 'Login'
          action: 'index'
        logout:
          enabled: true
          package: 'Neos.Neos'
          controller: 'Login'
          action: 'logout'

      # Redirect loop protection
      redirectLoop:
        maxRedirects: 5
        counterSessionKey: 'fucodo_conditional_redirect_Counter'
        originalRequestSessionKey: 'fucodo_conditional_redirect_OriginalRequest'

      # Whether to store the original request URI in the session
      storeOriginalRequest: true

Eel Context

The following variables are available in the Eel expressions:

  • request: The current ServerRequestInterface.
  • actionRequest: The resolved ActionRequest.
  • controllerObjectName: The name of the target controller class.
  • controllerName: The short name of the target controller.
  • actionName: The name of the target action.
  • packageKey: The package key of the target.
  • arguments: The arguments for the action.
  • account: The currently authenticated account (if any).
  • securityContext: An instance of fucodo\conditional\redirect\Eel\SecurityHelper.

SecurityHelper Methods

  • securityContext.hasRole(roleIdentifier): Returns true if the current account has the specified role.
  • securityContext.isAuthenticated(): Returns true if an account is authenticated.
  • securityContext.getAccountIdentifier(): Returns the identifier of the current account or null.

Middleware Position

The middleware is automatically registered in Settings.Neos.Flow.http.yaml and positioned after securityEntryPoint to ensure authentication data is available for the Eel expressions.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages