Hibernate always registers JACC event listeners regardless of whether that is enabled or not which causes unecessary exceptions to be thrown.

Description

Hibernate always registers JACC event listeners regardless of whether JACC has been enabled or not (by defining the property hibernate.jacc.enabled in the configurations).

The JACC even listeners cause exceptions to be thrown in several situations when Hibernate is not running as part of a container. The most common exception I've seen so far is the "java.lang.IllegalArgumentException: unknown handler key"

Hibernate should only register the JACC listeners when JACC is enabled.

The fix seems to be in the EventListenerConfigurator class. A simple check for the hibernate.jacc.enabled property should be done before adding any of the JACC event listeners (JACCPreDeleteEventListener, JACCPreLoadEventListener, JACCPreUpdateEventListener, JACCPreInsertEventListener).

I believe a simple check like
if ( properties.containsKey( AvailableSettings.JACC_ENABLED ) ) {
...
}

should be performed before adding them.

In my case these listeners cause exceptions like these to be thrown in a few situations:

java.lang.IllegalArgumentException: unknown handler key
at javax.security.jacc.PolicyContext.getContext(PolicyContext.java:280)
at org.hibernate.secure.JACCPermissions$PolicyContextActions$2.getContextSubject(JACCPermissions.java:111)
at org.hibernate.secure.JACCPermissions.getContextSubject(JACCPermissions.java:120)
at org.hibernate.secure.JACCPermissions.checkPermission(JACCPermissions.java:59)
at org.hibernate.secure.JACCPreLoadEventListener.onPreLoad(JACCPreLoadEventListener.java:53)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:149)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:898)

...so I have to manually remove these listeners.

Environment

None

Activity

Show:
Steve Ebersole
March 24, 2013, 3:00 AM

This is already resolved elsewhere

Brett Meyer
March 7, 2014, 5:30 PM

Bulk closing rejected tickets in "resolved" state.

Assignee

Unassigned

Reporter

Eduardo Born

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure