Search in sources :

Example 1 with JACCPreLoadEventListener

use of org.hibernate.secure.internal.JACCPreLoadEventListener in project hibernate-orm by hibernate.

the class JaccIntegrator method doIntegration.

private void doIntegration(Map properties, JaccPermissionDeclarations permissionDeclarations, SessionFactoryServiceRegistry serviceRegistry) {
    boolean isSecurityEnabled = properties.containsKey(AvailableSettings.JACC_ENABLED);
    if (!isSecurityEnabled) {
        log.debug("Skipping JACC integration as it was not enabled");
        return;
    }
    final String contextId = (String) properties.get(AvailableSettings.JACC_CONTEXT_ID);
    if (contextId == null) {
        throw new IntegrationException("JACC context id must be specified");
    }
    final JaccService jaccService = serviceRegistry.getService(JaccService.class);
    if (jaccService == null) {
        throw new IntegrationException("JaccService was not set up");
    }
    if (permissionDeclarations != null) {
        for (GrantedPermission declaration : permissionDeclarations.getPermissionDeclarations()) {
            jaccService.addPermission(declaration);
        }
    }
    final EventListenerRegistry eventListenerRegistry = serviceRegistry.getService(EventListenerRegistry.class);
    eventListenerRegistry.addDuplicationStrategy(DUPLICATION_STRATEGY);
    eventListenerRegistry.prependListeners(EventType.PRE_DELETE, new JaccPreDeleteEventListener());
    eventListenerRegistry.prependListeners(EventType.PRE_INSERT, new JaccPreInsertEventListener());
    eventListenerRegistry.prependListeners(EventType.PRE_UPDATE, new JaccPreUpdateEventListener());
    eventListenerRegistry.prependListeners(EventType.PRE_LOAD, new JaccPreLoadEventListener());
}
Also used : JaccPreDeleteEventListener(org.hibernate.secure.internal.JaccPreDeleteEventListener) JaccPreUpdateEventListener(org.hibernate.secure.internal.JaccPreUpdateEventListener) JaccPreLoadEventListener(org.hibernate.secure.internal.JaccPreLoadEventListener) JaccPreInsertEventListener(org.hibernate.secure.internal.JaccPreInsertEventListener) EventListenerRegistry(org.hibernate.event.service.spi.EventListenerRegistry)

Example 2 with JACCPreLoadEventListener

use of org.hibernate.secure.internal.JACCPreLoadEventListener in project hibernate-orm by hibernate.

the class JaccEventListenerIntegrator method integrate.

@Override
@SuppressWarnings({ "unchecked" })
public void integrate(Configuration configuration, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
    boolean isSecurityEnabled = configuration.getProperties().containsKey(AvailableSettings.JACC_ENABLED);
    if (!isSecurityEnabled) {
        return;
    }
    final EventListenerRegistry eventListenerRegistry = serviceRegistry.getService(EventListenerRegistry.class);
    eventListenerRegistry.addDuplicationStrategy(JACC_DUPLICATION_STRATEGY);
    final String jaccContextId = configuration.getProperty(Environment.JACC_CONTEXTID);
    eventListenerRegistry.prependListeners(EventType.PRE_DELETE, new JACCPreDeleteEventListener(jaccContextId));
    eventListenerRegistry.prependListeners(EventType.PRE_INSERT, new JACCPreInsertEventListener(jaccContextId));
    eventListenerRegistry.prependListeners(EventType.PRE_UPDATE, new JACCPreUpdateEventListener(jaccContextId));
    eventListenerRegistry.prependListeners(EventType.PRE_LOAD, new JACCPreLoadEventListener(jaccContextId));
}
Also used : JACCPreLoadEventListener(org.hibernate.secure.internal.JACCPreLoadEventListener) JACCPreDeleteEventListener(org.hibernate.secure.internal.JACCPreDeleteEventListener) JACCPreUpdateEventListener(org.hibernate.secure.internal.JACCPreUpdateEventListener) JACCPreInsertEventListener(org.hibernate.secure.internal.JACCPreInsertEventListener) EventListenerRegistry(org.hibernate.event.service.spi.EventListenerRegistry)

Aggregations

EventListenerRegistry (org.hibernate.event.service.spi.EventListenerRegistry)2 JACCPreDeleteEventListener (org.hibernate.secure.internal.JACCPreDeleteEventListener)1 JACCPreInsertEventListener (org.hibernate.secure.internal.JACCPreInsertEventListener)1 JACCPreLoadEventListener (org.hibernate.secure.internal.JACCPreLoadEventListener)1 JACCPreUpdateEventListener (org.hibernate.secure.internal.JACCPreUpdateEventListener)1 JaccPreDeleteEventListener (org.hibernate.secure.internal.JaccPreDeleteEventListener)1 JaccPreInsertEventListener (org.hibernate.secure.internal.JaccPreInsertEventListener)1 JaccPreLoadEventListener (org.hibernate.secure.internal.JaccPreLoadEventListener)1 JaccPreUpdateEventListener (org.hibernate.secure.internal.JaccPreUpdateEventListener)1