Knowledge Base

Access Control Installation Guide

Last Modified:
10 Apr 2024
User Level:
Administrator +

This step by step guide will help you get up and running with the Access Control Module.

You can download the Access Control Module here (authentication required).

Server Requirements

Access Control requires PHP 5.6+ to be installed on the web server that will host the site, and on the staging server (if this is a separate server). In addition, the following extensions should be enabled:

The Tomcat user should be able to generate .htaccess files in the publish directory in order to ensure that media access control works correctly.

Users should not be able to view or download the PHAR file via the browser. To prevent this, add the following lines to the httpd.conf file or wherever your server configuration is handled. 

<Files ~ "\.phar$">
Order allow,deny
Deny from all
</Files>

Files required for installation

The following source files are required to install PHP Access Control on a Terminalfour instance correctly. They can be found in the latest php-access-control.zip file.

  • php-access-control.phar - the Access Control module
  • media-restriction.php - the code to check Media Category / Section restrictions
  • config.json - the configuration file for the PHP Access Control
  • various Content Layout descriptions - for the creation of Content Layouts
  • code.php - the code for the before and after fields of the Terminalfour Access Control (at {context-url}/SiteManger?ctfn=access-control)

Required Assets

You must enable the following in your installation. Further details on each asset are provided if required.

File Extensions

This file extension must be allowed on the Channel you’re using Access Control with.

Extension  Description Required for
PHP Required to include the Access Control scripts. Access Control Media Restriction File Element Restriction

Media Types

PHP and PHAR Media Types must be created if they do not already exist and must be set to always publish on the Channel you’re using Access Control with.

Type Description Required for
PHP Required for PHP file  Access Control Media Restriction File Element Restriction
PHAR File Required for Access Control Module PHAR file Access Control Media Restriction File Element Restriction
JavaScript Required for Access Control Config Access Control Media Restriction File Element Restriction

Media Files

The required files can be downloaded from the Terminalfour Community Site which requires authentication through the product.

Type Description Required for
PHP Access Control PHAR PHP Access Control Library Access Control  Media Restriction  File Element Restriction
 PHP Access Control Configuration PHP Access Control Configuration File Access Control Media Restriction  File Element Restriction
Media Restriction PHP File Media Restriction PHP File   Media Restriction  
Section htaccess

Contents of .htaccess files that are generated in protected sections. Only required if using .htaccess based SAML section protection - see Section protection

Contents of the file should be:

AuthType shibboleth
ShibRequestSetting requireSession 1
Require valid-user

Access Control    

Navigation Objects 

Name Description Required for
Generate .htaccess for File Section A Generate File Navigation Object used to generate the .htaccess file used to protect media brought in by File Elements within a section     File Element Restriction
Get All Media Restriction rules A Related Content Navigation Object used to get Media Restriction rules for media Access Control   Media Restriction  File Element Restriction 
Get path to Logout Section A Section Details Navigation Object used to get the path to the media restriction Section

Access Control (optional)

Media Restriction
(optional)
File Element Restriction
(optional)
Get path to Login Section A Section Details Navigation Object used to get the path to the login Section for logging into Access Control

Access Control
(for Terminalfour type)

Media Restriction

(for Terminalfour type)

File Element Restriction
(for Terminalfour type)
Get path to Current Section Section Details Navigation Object used to get the path to the current Section   Media Restriction File Element Restriction
Get Path to Access Denied Section A Section Details Navigation Object used to get the path to the access denied Section Access Control Media Restriction File Element Restriction
Generate .htaccess for section protection A Generate File Navigation Object used to generate the .htaccess file used to protect sections. Only required if using .htaccess based SAML section protection - see Section protection Access Control    

Content Types

Name Description Required for
Access Control Allows the use of restricted Sections in your Site Structure Access Controla Media Restriction  File Element Restriction 
Restrict Media Category Add a new Media Category restriction rule for files in a section   Media Restriction  
Restrict File Section Add a new Media Category restriction rule     File Element Restriction

Sections and Media Categories

Name Description Required for
Media Restriction The Section to hold Media Restriction Content and Restrict Media Content   Media Restriction File Element Restriction 
Access Denied Section The Section that users are redirected to if their Group is denied access Access Control Media Restriction  File Element Restriction 
Protected Media Category The Category to hold Media Items under media protection   Media Restriction File Element Restriction
PHP Access Control Config Category The Category to hold PHP Access Control config files Access Control Media Restriction File Element Restriction
Login Terminalfour authentication only. The page with the login form. Access Control Media Restriction File Element Restriction

Page Layout

Type Description Required for
Blank Layout Blank page layout used for media access control code   Media Restriction  File Element Restriction

Create Required Assets

File Extensions: PHP

If you haven't already, set up PHP as a file extension and enable the extension on your Channel.

Name PHP
Description This is a PHP file extension
Extension php

 

Remember to enable the Channel to Publish this file extension and rebuild the cache.

Media Layouts

Path Content Layout

Go to Assets > Content Types and search for the Media System Content Type. If it does not already exist, add a Content Layout named "path/*". In the Content Layout code input field add the following:

<t4 type="content" name="Media" output="file" />

Screenshot of the Content Layout Code for Media System Content Type

JavaScript Content Layout

If it does not already exist, add another Content Layout to the Media System Content Type named "javascript/*". In the Content Layout code input field add the following:

<script type="text/javascript" src="<t4 type="content" name="Media" output="file" />"></script>

Media Types

When the Content Layout has been created, go to System Administration > System Settings > Media Library and, in the Media Types tab, add the following Media Types:

PHP File

Create a PHP Media Type and associate the "path/*" Content Layout with it:

Screenshot of the PHP Media File with associated Content Layout

Name PHP File
Permitted file extensions php
Maximum file size 0
Media type options Parse for T4 tags
Media Content Layout path/* (default)

PHAR File

Create a PHAR Media Type and associate the "path/*" Content Layout with it:

Screenshot of a PHAR Media File with an associated Content Layout

Name PHAR File
Permitted file extensions phar
Maximum file size 0
Media type options Binary file
Media Content Layout path/* (default)

JavaScript

If it does not already exist, create a JavaScript Media Type and associate the "javascript/*" Content Layout with it:

Name JavaScript
Permitted file extensions js
Maximum file size 0
Media type options Parse for T4 tags
Media Content Layout javascript/* (default)

Configure the Media Publish on the Channel

Ensure that Media Type extensions will publish in the Channel by going to System administration > Setup sites & channels > Channels,  edit the Channel settings and go to Publish Options: 

Screenshot of Enable Publish Outputs in Channels setings

Navigation Objects

Generate htaccess for File Section

This is a Generate File Navigation Object.
Set it up using the options in the table below. Unlisted options should be left at their default values. (" should be omitted, they are used to denote literal text values)

Name Generate htaccess for File Section
Description Generate the htaccess file used to protect media brought in by File Elements within a Section
File name Leave blank
File extension htaccess
Output Directory Use the current directory
Content Layout text/htaccess

Get All Media Restriction rules

This is a Related Content Navigation Object.
Set it up using the options in the table below. Unlisted options should be left at their default values. (" should be omitted, they are used to denote literal text values) 

Name Get All Media Restriction rules
Description Get Media Restriction rules for media access control
Fetch method Use section
Section Section containing the Restrict Media Category content items
Content layouts Use alternate content layout
Alternate Content Layout text/restrict-media

Get path to Media Restriction

This is a Section Details Navigation Object.
Set it up using the options in the table below. Unlisted options should be left at their default values. (" should be omitted, they are used to denote literal text values)

Name Get Path to media restriction
Description Get the path to the media restriction section
Detail method Choose "Use section" -> select the media restriction Section
Output detail Section path

Get path to Logout Section

This is a Section Details Navigation Object.
Set it up using the options in the table below. Unlisted options should be left at their default values. (" should be omitted, they are used to denote literal text values)

Name Get path to logout section
Description Gets the path to the logout section for logging out of access control
Detail method Choose "Use section" -> select the logout Section
Output detail Section path

Get path to Login Section

This is a Section Details Navigation Object
Set it up using the options in the table below. Unlisted options should be left at their default values. (" should be omitted, they are used to denote literal text values)

Name Get path to logout section
Description Gets the path to the logout section for logging out of access control
Detail method Choose "Use section" -> select the logout section
Output detail Section path

Get path to Current Section

This is a Section Details Navigation Object. 
Set it up using the options in the table below. Unlisted options should be left at their default values. (" should be omitted, they are used to denote literal text values)

Name Get path to Current Section
Description Gets the path to the current Section
Detail method Current section
Output detail Section path

Get path to Access Denied Section

This is a Section Details Navigation Object. 
Set it up using the options in the table below. Unlisted options should be left at their default values. (" should be omitted, they are used to denote literal text values)

Name Get path to Access Denied Section
Description Gets the path to the Access Denied section
Detail method Choose "Use section" -> select No Access Section
Output detail Section path 

Generate htaccess for section protection

This is a Generate File Navigation Object.
Set it up using the options in the table below. Unlisted options should be left at their default values. (" should be omitted, they are used to denote literal text values). Only required if using .htaccess based SAML section protection - see Section protection

Name Generate htaccess for section protection
Description Generate the htaccess file used to protect sections
File name Leave blank
File extension htaccess
Output Directory Use the current directory
Media file section-htaccess


Content Types

The following Content Types should be created. Associated Content Layouts are also listed.

Access Control

Create an "Access Control" Content Type using the following General options (anything not mentioned may be left at default):

Name: Access Control

Description: Allows the use of Restricted Sections in your Site Structure

Name Description Type Max Size Required

Name

The Name element

Plain Text

80 Yes

Groups

Select a Group or Groups

Group Select

N/A  

The content type should be converted to a system content type, please submit a Client Support ticket to have that done.

Restrict Media Category

Create a "Restrict Media Category" Content Type using the following General options (anything not mentioned may be left at default):

Name: Restrict Media Category

Description: Add a new media category restriction rule

Name Description Type Max Size Required

Name

The Name Element

Plain Text

80 Yes

Media Category

Media Item from category to restrict

Media

N/A Yes

Groups

Select a Group or Groups

Group Select

N/A Yes

Content Layouts

text/restrict-media

Check if the channel where the files are used has a Base HREF set. Go to Administration > Set up Sites & Channels > Channels and open the channel or microsite. Check the 'Base HREF' field in the 'Output information' section. If it's set the layout should be:

try {
    importClass(com.terminalfour.publish.utils.BrokerUtils);
  
    function processTags(tag) {
          return String(BrokerUtils.processT4Tags(dbStatement, publishCache, section, content, language, isPreview, tag,''));
      }
  
    var mediaPath = processTags('<t4 type="content" name="Media Category" output="normal" formatter="path/*" />');
    var groups = processTags('<t4 type="content" name="Groups" output="normal" />'); 
    var path = mediaPath.replace("<!-- REPLACE WITH BASE HREF -->", "");

  
    document.write(path);
    document.write("=");
    document.write(groups);
    document.write("|");
  
} catch (err) {
    document.write(err);
}

Otherwise it should be:

try {
    importClass(com.terminalfour.publish.utils.BrokerUtils);
  
    function processTags(tag) {
          return String(BrokerUtils.processT4Tags(dbStatement, publishCache, section, content, language, isPreview, tag,''));
      }
  
    var mediaPath = processTags('<t4 type="content" name="Media Category" output="normal" formatter="path/*" />');
    var groups = processTags('<t4 type="content" name="Groups" output="normal" />'); 

  
    document.write(mediaPath);
    document.write("=");
    document.write(groups);
    document.write("|");
  
} catch (err) {
    document.write(err);
}

Restrict File Section

Create a "Restrict Media Category" Content Type using the following General options (anything not mentioned may be left at default):

Name: Restrict File Section

Description: Add a new media Section restriction rule for files

Name Description Type Max Size Required

Name

The Name Element

Plain Text

80 Yes

Groups

Select a Group or Groups

Group Select

N/A Yes

Content Layouts

Navigation tags

Navigation tags should be replaced with correct tags from Terminalfour

text/html
<t4 type="navigation" name="Generate File Section Access Control htaccess" id="xxx" />
text/restrict-media
try {
importClass(com.terminalfour.publish.utils.BrokerUtils);

function processTags(tag) {
return String(BrokerUtils.processT4Tags(dbStatement, publishCache, section, content, language, isPreview, tag,''));
}

var sectionPath = processTags('<t4 type="navigation" name="Path to current section" id="xxx" />');
var groups = processTags('<t4 type="content" name="Groups" output="normal" />');

document.write(sectionPath);
document.write("=");
document.write(groups);
document.write("|");

} catch (err) {
document.write(err);
}

Sections and Media Categories

The following Sections / Categories need to be created in Terminalfour.

Media Restriction Section

Name Media Restriction
Type Section
Display Hide from Navigation

Content Types

No Access Section

Name Access Denied
Type Section
Display
Hide from Navigation

Content Types

Any

Login Section

Terminalfour type only. Should contain a form with inputs for username and password, with name attributes being 'uname' and 'pwd' unless specified otherwise in the config JSON.

Name Login
Type Section
Display
Hide from Navigation

Content Types

Any

Protected Media Category

Create a Media Category to store the Media files that need to be protected:

Name Protected
Type Media Category

Upload the .htaccess file to the Protected section. Replace the t4 tag in the RewriteRule directive with the t4 tag outputting the path to the media-restriction.php file:

<t4 type="media" formatter="path/*" id="FILE ID" />

PHP Access Control Config Category

Create a Media Category to store the Access Control media files:

Name PHP Access Control
Type Media Category

Upload the following files to this media category:

  • php-access-control.phar - the PHP Access Control Library
  • config.json - The PHP Access Control Configuration File
  • media-restriction.php - File handling access to protected files in the Media Library

Page Layout

The following page layout needs to be created in Terminalfour:

Blank Layout

Name Blank Layout
Header Code Leave blank
Footer Code Leave blank 

Installation Steps

Section Protection

Create an access control profile. Go to Sites & Channels > Personalisation & Access Control. Under "Existing Access Control Profiles" click "Create New" and then "Basic PHP Access Control". Fill in "Name" (e.g. "SAML Access Control"). Copy the contents of beforeCode.php in the module files to "Code Before Section" and of afterCode.php to "Code After Section". In "Code Before Section" replace the placeholders in

$t4_config['config']    = '<t4 type="media" formatter="path/*" id="<!-- INSERT ID -->" />';

and

$t4_config['phar']      = '<t4 type="media" formatter="path/*" id="<!-- INSERT ID -->" />';

with the IDs of media library files config.json and access-control.phar, respectively.

Go to Administration > Set up Sites & Channels > Access Control and set 'Access control content type' to the Access Control system content type.

Go to the channel page (Administration > Set up Sites & Channels > Channels and choose the channel that contains the protected sections from the list) and in section 'Access control and personalisation' check 'Enable access control' and set 'Configuration' to the access control profile you created.

SAML only: Protected sections need to be set up prior to access control being enabled on them. In case of CAS and T4 access control, this step can be omitted. There are two ways to do it. You can submit a Client Support ticket to have the sections set up in the server settings. Or you can generate .htaccess files in the protected sections. To do the latter, add a Generate htaccess for section protection t4 tag at the top of the header in the access control profile.

Terminalfour only: Create an admin user to be used by the module to verify users' credentials in the API. Put the credentials in an .ini file and place it on the server (if Terminalfour is hosting, submit a Client Support ticket to have it done). Set "t4AuthenticationFilePath" in the config JSON to the absolute server path to the file. Also, since the users will be logging in with their Terminalfour credentials, create users in the system for each user that needs to access the protected pages.

Go to Administration > User Rights & Roles > Group Management and create groups that should have access to protected pages. Protected sections are set up to be restricted to specified groups. In case of CAS and SAML authentication, those groups should match the group names that will be received from the SSO.

Go to the More > Access tab in the sections that you want protected and choose the groups that should have access to the section.

Update the entries in the config JSON relevant to your authentication type. See Access Control Configuration.

Media Category Protection

Create subcategories of the Protected media category. Each category will be restricted to one or more groups.

In the Media Restriction section create an instance of the Restrict Media Category content type for each protected category. In each content item, select a file from the category to be protected and the groups that should have access to it. The whole category will be protected, not just the selected file.

Set "mediaList" in the config JSON to the Get All Media Restriction Rules navigation object t4 tag.

When a request is made for files in the Protected media category, the htaccess file at the root will redirect it to the media-restriction.php file which will determine if the logged in user has access to the file or not and then serve it or block it.

Back to top