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;
}
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;
}
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);
}
}
}
}
}
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());
}
}
Aggregations