Blog

Gavin Pickin

August 14, 2017

Spread the word


Share your thoughts

I have been working for Ortus Solutions for over two years now, and still, every day I learn something new about one of our modules or tools. In one of my current customer projects, we are taking a ContentBox installation ( our Modular Content Management System built on top of ColdBox ), customizing it, extending it, and it's really fun. One of the big customizations for this projects is extending the permissions structure, outside of what we wanted to do in the ContentBox core.

We have added a lot of great features back into the core ( like we do with most customer projects ), 3.7 was just released, which includes a lot of those pieces, including 2 factor authentication, but I'll save that for another day. We did add permission groups, and several other items into the core, but we needed to do something special with permissions, not difficult to do, difficult to decide how to do it.

Current syntax for checking an author/user's permission in ContentBox

Author.checkPermission( "Pages_Admin" );

The existing permission is on the author object itself, nice neat and tidy. We wanted to name the function "checkPermissionsPlus".

Extend Security Service and add new function

We thought we could extend ContentBox's security service, and add a new function. This would require all our module code reference the new extended service. Since CFML is so dynamic, we could just inject the new method into the existing Security Service.

Inject new function into existing Security Service

This is a solid option, better than extending the security service, but they still have one big drawback. We would need to pass the author into the service, so the service knew which author to work on. The call would look something like this.

securityService.checkPermissionsPlus( "Pages_Admin", author );

Not terrible, but we could do better.

Could we extend / modify the Author object itself?

Yes we could.…but a service in a singleton, with wirebox, you can grab it anywhere, and even have wirebox inject methods for you… but an ORM object, not so easy… until I learned about Hibernate events… and how easy they are to use.

Hibernate Event Hooks

Hibernate has a series of events, it broadcasts when acting on objects… allowing you to hook into them. Including:

  • postNew()
  • preLoad()
  • postLoad()
  • postDelete()
  • preDelete()
  • preUpdate()
  • postUpdate()
  • preInsert()
  • postInsert()

You could try to tap into Hibernate directly, but that doesn't sound like fun, or easy to me… but that is where CBORM comes in. CBORM is our ColdBox ORM module that gives you a variety of tools to make working with ColdFusion ORM easier. One of those things is the ORM to ColdBox Interceptor bridge.

CBORM Interception Points

For each of the above methods, CBORM re-broadcasts a ColdBox interception point. This includes the data from hibernate, in a quick and simple accessible way.


Interception PointIntercept StructureDescription
ORMPostNew{entity}Called via the postNew() event
ORMPreLoad{entity}Called via the preLoad() event
ORMPostLoad{entity}Called via the postLoad() event
ORMPostDelete{entity}Called via the postDelete() event
ORMPreDelete{entity}Called via the preDelete() event
ORMPreUpdate{entity,oldData}Called via the preUpdate() event
ORMPostUpdate{entity}Called via the postUpdate() event
ORMPreInsert{entity}Called via the preInsert() event
ORMPostInsert{entity}Called via the postInsert() event


Now, I can just listen for those interception points, check what entity is being acted upon, if it’s the Author object, I can inject the new function to wrap the old one.

Then I will still be able to use a user friendly syntax

Author.checkPermissionsPlus( "Pages_Admin" );

Internally that function can do its magic, and then call the normal checkPermission() function. The existing function is unchanged, so we don't break existing functionality, and we do not need to edit the ContentBox core.

Here is the link to the ORM to ColdBox Interceptors page https://github.com/coldbox-modules/cbox-cborm/wiki/ORM-To-ColdBox-Interceptions

Would you like to see how to did it? If so, check back for the next post... where I'll share the code.

Add Your Comment

Recent Entries

Adobe CFSummit 2024 Recap | Ortus Solutions

Adobe CFSummit 2024 Recap | Ortus Solutions

A huge thank you to everyone who visited our booth! We had the pleasure of engaging in meaningful conversations about Modern CFML and ColdFusion development, sharing insights, and exploring exciting new ideas. Visitors also got a chance to participate in some fun activities and win fabulous prizes, including our customized t-shirts, which were a huge hit!

Maria Jose Herrera
Maria Jose Herrera
October 02, 2024
BoxLang September Newsletter

BoxLang September Newsletter

Welcome to the September edition of the BoxLang Newsletter! This month has been packed with exciting updates, new features, and enhancements that continue to shape BoxLang into a robust and versatile programming language. In this edition, we highlight the latest beta releases, new integrations, and key features that have been introduced.

Maria Jose Herrera
Maria Jose Herrera
October 01, 2024
Fall Savings: Unlock Exclusive Discounts Until October 31st!

Fall Savings: Unlock Exclusive Discounts Until October 31st!

Get ready for the Ortus October Fall Savings! This is your opportunity to elevate your development experience with fantastic offers designed for everyone—from seasoned developers to tech enthusiasts. Our special promotions are here to help you achieve your goals while saving money!

Don’t Miss Out on These Amazing Offers!

Use the code FALLSAVINGS24 at checkout to enjoy these incredible discounts before they expire on October 31st

Cristobal Escobar
Cristobal Escobar
October 01, 2024