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

ColdBox 7.2.0 Released

ColdBox 7.2.0 Released

ColdBox, a widely used development platform for ColdFusion (CFML), has unveiled version 7.2. Packed with compelling new features, bug fixes, and enhancements, this release is designed to empower developers by boosting productivity, refining scheduled task capabilities, and enhancing the overall reliability and efficiency of application development. This article will delve into the key highlights of ColdBox 7.2 and elucidate how these advancements can positively impact developers in their daily coding endeavors.

Luis Majano
Luis Majano
November 20, 2023
Into the Box 2023 Series on CFCast

Into the Box 2023 Series on CFCast

Excitement is in the air as we unleash the highly anticipated ITB 2023 series exclusively for our valued CFCast subscribers – and the best part? It's FREE for CFCast members! Now is the perfect time if you haven't joined the CFCast community yet. Plus, we've got an incredible End-of-Year deal that's too good to miss

Maria Jose Herrera
Maria Jose Herrera
November 20, 2023
Ortus Deals are Finally Here!

Ortus Deals are Finally Here!

The much-anticipated Ortus End-of-the-Year Sale has arrived, and it's time to elevate your development experience! Whether you're a seasoned developer, a tech enthusiast, or someone on the lookout for top-notch projects, Ortus has something special in store for you. Brace yourself for incredible discounts across a wide array of products and services, including Ortus annual events, books, cutting-edge services, and more.

Maria Jose Herrera
Maria Jose Herrera
November 15, 2023