Search in sources :

Example 1 with JaccPermissionDeclarations

use of org.hibernate.secure.spi.JaccPermissionDeclarations in project hibernate-orm by hibernate.

the class LoadedConfig method consume.

/**
	 * Consumes the JAXB representation of a {@code cfg.xml} file and builds the
	 * LoadedConfig representation.
	 *
	 * @param jaxbCfg The JAXB representation of a {@code cfg.xml} file
	 *
	 * @return The parsed representation
	 */
public static LoadedConfig consume(JaxbCfgHibernateConfiguration jaxbCfg) {
    final LoadedConfig cfg = new LoadedConfig(jaxbCfg.getSessionFactory().getName());
    for (JaxbCfgConfigPropertyType jaxbProperty : jaxbCfg.getSessionFactory().getProperty()) {
        cfg.addConfigurationValue(jaxbProperty.getName(), jaxbProperty.getValue());
    }
    for (JaxbCfgMappingReferenceType jaxbMapping : jaxbCfg.getSessionFactory().getMapping()) {
        cfg.addMappingReference(MappingReference.consume(jaxbMapping));
    }
    for (Object cacheDeclaration : jaxbCfg.getSessionFactory().getClassCacheOrCollectionCache()) {
        cfg.addCacheRegionDefinition(parseCacheRegionDefinition(cacheDeclaration));
    }
    if (jaxbCfg.getSecurity() != null) {
        for (JaxbCfgHibernateConfiguration.JaxbCfgSecurity.JaxbCfgGrant grant : jaxbCfg.getSecurity().getGrant()) {
            final JaccPermissionDeclarations jaccPermissions = cfg.getOrCreateJaccPermissions(jaxbCfg.getSecurity().getContext());
            jaccPermissions.addPermissionDeclaration(new GrantedPermission(grant.getRole(), grant.getEntityName(), grant.getActions()));
        }
    }
    if (!jaxbCfg.getSessionFactory().getListener().isEmpty()) {
        for (JaxbCfgEventListenerType listener : jaxbCfg.getSessionFactory().getListener()) {
            final EventType eventType = EventType.resolveEventTypeByName(listener.getType().value());
            cfg.addEventListener(eventType, listener.getClazz());
        }
    }
    if (!jaxbCfg.getSessionFactory().getEvent().isEmpty()) {
        for (JaxbCfgEventListenerGroupType listenerGroup : jaxbCfg.getSessionFactory().getEvent()) {
            if (listenerGroup.getListener().isEmpty()) {
                continue;
            }
            final String eventTypeName = listenerGroup.getType().value();
            final EventType eventType = EventType.resolveEventTypeByName(eventTypeName);
            for (JaxbCfgEventListenerType listener : listenerGroup.getListener()) {
                if (listener.getType() != null) {
                    log.debugf("Listener [%s] defined as part of a group also defined event type", listener.getClazz());
                }
                cfg.addEventListener(eventType, listener.getClazz());
            }
        }
    }
    return cfg;
}
Also used : JaxbCfgEventListenerType(org.hibernate.boot.jaxb.cfg.spi.JaxbCfgEventListenerType) JaccPermissionDeclarations(org.hibernate.secure.spi.JaccPermissionDeclarations) EventType(org.hibernate.event.spi.EventType) JaxbCfgConfigPropertyType(org.hibernate.boot.jaxb.cfg.spi.JaxbCfgConfigPropertyType) GrantedPermission(org.hibernate.secure.spi.GrantedPermission) JaxbCfgMappingReferenceType(org.hibernate.boot.jaxb.cfg.spi.JaxbCfgMappingReferenceType) JaxbCfgEventListenerGroupType(org.hibernate.boot.jaxb.cfg.spi.JaxbCfgEventListenerGroupType)

Example 2 with JaccPermissionDeclarations

use of org.hibernate.secure.spi.JaccPermissionDeclarations in project hibernate-orm by hibernate.

the class LoadedConfig method getOrCreateJaccPermissions.

public JaccPermissionDeclarations getOrCreateJaccPermissions(String contextId) {
    if (jaccPermissionsByContextId == null) {
        jaccPermissionsByContextId = new HashMap<String, JaccPermissionDeclarations>();
    }
    JaccPermissionDeclarations jaccPermission = jaccPermissionsByContextId.get(contextId);
    if (jaccPermission == null) {
        jaccPermission = new JaccPermissionDeclarations(contextId);
    }
    jaccPermissionsByContextId.put(contextId, jaccPermission);
    return jaccPermission;
}
Also used : JaccPermissionDeclarations(org.hibernate.secure.spi.JaccPermissionDeclarations)

Example 3 with JaccPermissionDeclarations

use of org.hibernate.secure.spi.JaccPermissionDeclarations in project hibernate-orm by hibernate.

the class SessionFactoryImpl method applyCfgXmlValues.

private void applyCfgXmlValues(LoadedConfig aggregatedConfig, SessionFactoryServiceRegistry serviceRegistry) {
    final JaccService jaccService = serviceRegistry.getService(JaccService.class);
    if (jaccService.getContextId() != null) {
        final JaccPermissionDeclarations permissions = aggregatedConfig.getJaccPermissions(jaccService.getContextId());
        if (permissions != null) {
            for (GrantedPermission grantedPermission : permissions.getPermissionDeclarations()) {
                jaccService.addPermission(grantedPermission);
            }
        }
    }
    if (aggregatedConfig.getEventListenerMap() != null) {
        final ClassLoaderService cls = serviceRegistry.getService(ClassLoaderService.class);
        final EventListenerRegistry eventListenerRegistry = serviceRegistry.getService(EventListenerRegistry.class);
        for (Map.Entry<EventType, Set<String>> entry : aggregatedConfig.getEventListenerMap().entrySet()) {
            final EventListenerGroup group = eventListenerRegistry.getEventListenerGroup(entry.getKey());
            for (String listenerClassName : entry.getValue()) {
                try {
                    group.appendListener(cls.classForName(listenerClassName).newInstance());
                } catch (Exception e) {
                    throw new ConfigurationException("Unable to instantiate event listener class : " + listenerClassName, e);
                }
            }
        }
    }
}
Also used : Set(java.util.Set) EventListenerGroup(org.hibernate.event.service.spi.EventListenerGroup) EventType(org.hibernate.event.spi.EventType) JaccService(org.hibernate.secure.spi.JaccService) GrantedPermission(org.hibernate.secure.spi.GrantedPermission) InvalidObjectException(java.io.InvalidObjectException) HibernateException(org.hibernate.HibernateException) SQLException(java.sql.SQLException) ConfigurationException(org.hibernate.internal.util.config.ConfigurationException) IOException(java.io.IOException) PersistenceException(javax.persistence.PersistenceException) MappingException(org.hibernate.MappingException) EventListenerRegistry(org.hibernate.event.service.spi.EventListenerRegistry) JaccPermissionDeclarations(org.hibernate.secure.spi.JaccPermissionDeclarations) ConfigurationException(org.hibernate.internal.util.config.ConfigurationException) Map(java.util.Map) HashMap(java.util.HashMap) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService)

Example 4 with JaccPermissionDeclarations

use of org.hibernate.secure.spi.JaccPermissionDeclarations in project hibernate-orm by hibernate.

the class LoadedConfig method addJaccPermissions.

private void addJaccPermissions(Map<String, JaccPermissionDeclarations> jaccPermissionsByContextId) {
    if (jaccPermissionsByContextId == null) {
        return;
    }
    if (this.jaccPermissionsByContextId == null) {
        this.jaccPermissionsByContextId = new HashMap<String, JaccPermissionDeclarations>();
    }
    for (Map.Entry<String, JaccPermissionDeclarations> incomingEntry : jaccPermissionsByContextId.entrySet()) {
        JaccPermissionDeclarations permissions = jaccPermissionsByContextId.get(incomingEntry.getKey());
        if (permissions == null) {
            permissions = new JaccPermissionDeclarations(incomingEntry.getKey());
            this.jaccPermissionsByContextId.put(incomingEntry.getKey(), permissions);
        }
        permissions.addPermissionDeclarations(incomingEntry.getValue().getPermissionDeclarations());
    }
}
Also used : JaccPermissionDeclarations(org.hibernate.secure.spi.JaccPermissionDeclarations) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

JaccPermissionDeclarations (org.hibernate.secure.spi.JaccPermissionDeclarations)4 HashMap (java.util.HashMap)2 Map (java.util.Map)2 EventType (org.hibernate.event.spi.EventType)2 GrantedPermission (org.hibernate.secure.spi.GrantedPermission)2 IOException (java.io.IOException)1 InvalidObjectException (java.io.InvalidObjectException)1 SQLException (java.sql.SQLException)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 PersistenceException (javax.persistence.PersistenceException)1 HibernateException (org.hibernate.HibernateException)1 MappingException (org.hibernate.MappingException)1 JaxbCfgConfigPropertyType (org.hibernate.boot.jaxb.cfg.spi.JaxbCfgConfigPropertyType)1 JaxbCfgEventListenerGroupType (org.hibernate.boot.jaxb.cfg.spi.JaxbCfgEventListenerGroupType)1 JaxbCfgEventListenerType (org.hibernate.boot.jaxb.cfg.spi.JaxbCfgEventListenerType)1 JaxbCfgMappingReferenceType (org.hibernate.boot.jaxb.cfg.spi.JaxbCfgMappingReferenceType)1 ClassLoaderService (org.hibernate.boot.registry.classloading.spi.ClassLoaderService)1 EventListenerGroup (org.hibernate.event.service.spi.EventListenerGroup)1 EventListenerRegistry (org.hibernate.event.service.spi.EventListenerRegistry)1