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

TestBox Latest Updates and News!

TestBox Latest Updates and News!

We’re thrilled to have launched the new TestBox website and TestBox 6.0! If you haven’t had a chance to explore yet, visit TestBox to discover updated documentation, powerful resources, and features that make testing more efficient than ever.

Maria Jose Herrera
Maria Jose Herrera
November 21, 2024
Is Your ColdFusion Application Ready for the Future?

Is Your ColdFusion Application Ready for the Future?

In a rapidly evolving digital world, maintaining performance, security, and scalability for ColdFusion applications is more challenging than ever. Whether you're using Lucee or Adobe ColdFusion, legacy systems can become a bottleneck for growth, innovation, and user satisfaction. The need to future-proof your ColdFusion applications has never been more critical.

But where do you start?


The Hidden Costs of an Outdated ColdFusion Application

As you...

Cristobal Escobar
Cristobal Escobar
November 21, 2024
The Hidden Costs of In-House Database Management

The Hidden Costs of In-House Database Management

The Hidden Costs of In-House Database Management


Opting for in-house database management involves more than just a salary. Here are some often-overlooked costs associated with maintaining your own DBA team.



1. High Salaries and Benefits


Hiring skilled DBAs is expensive. According to industry reports, the average salary of a DBA in the U.S. can range from $85,000 to over $130,000 per year, depending on experience and expertise. When you add ...

Cristobal Escobar
Cristobal Escobar
November 20, 2024