syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject [13/15] syncope git commit: [SYNCOPE-652] Still several things to refine, but it starts taking shape
Date Sun, 02 Aug 2015 05:45:27 GMT
http://git-wip-us.apache.org/repos/asf/syncope/blob/34a1c214/core/misc/src/main/java/org/apache/syncope/core/misc/policy/PolicyEnforcer.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/policy/PolicyEnforcer.java b/core/misc/src/main/java/org/apache/syncope/core/misc/policy/PolicyEnforcer.java
index c8274a4..86e6583 100644
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/policy/PolicyEnforcer.java
+++ b/core/misc/src/main/java/org/apache/syncope/core/misc/policy/PolicyEnforcer.java
@@ -23,5 +23,13 @@ import org.apache.syncope.common.lib.types.PolicyType;
 
 public interface PolicyEnforcer<T extends PolicySpec, E> {
 
-    void enforce(final T policy, final PolicyType type, final E object);
+    /**
+     * Check the given entity to see if it conforms with the indicated policy.
+     *
+     * @param policy
+     * @param type
+     * @param entity
+     * @return whether user is to be suspended
+     */
+    boolean enforce(final T policy, final PolicyType type, final E entity);
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/34a1c214/core/misc/src/main/java/org/apache/syncope/core/misc/policy/PolicyEvaluator.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/policy/PolicyEvaluator.java b/core/misc/src/main/java/org/apache/syncope/core/misc/policy/PolicyEvaluator.java
index 52fa0d8..fd6abd2 100644
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/policy/PolicyEvaluator.java
+++ b/core/misc/src/main/java/org/apache/syncope/core/misc/policy/PolicyEvaluator.java
@@ -34,9 +34,6 @@ import org.springframework.stereotype.Component;
 @Component
 public class PolicyEvaluator {
 
-    /**
-     * Logger.
-     */
     private static final Logger LOG = LoggerFactory.getLogger(PolicyEvaluator.class);
 
     @SuppressWarnings("unchecked")
@@ -54,7 +51,7 @@ public class PolicyEvaluator {
                 BeanUtils.copyProperties(ppSpec, evaluatedPPSpec, new String[] { "schemasNotPermitted" });
 
                 for (String schema : ppSpec.getSchemasNotPermitted()) {
-                    PlainAttr attr = any.getPlainAttr(schema);
+                    PlainAttr<?> attr = any.getPlainAttr(schema);
                     if (attr != null) {
                         List<String> values = attr.getValuesAsStrings();
                         if (values != null && !values.isEmpty()) {

http://git-wip-us.apache.org/repos/asf/syncope/blob/34a1c214/core/misc/src/main/java/org/apache/syncope/core/misc/security/AuthContextUtils.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/security/AuthContextUtils.java b/core/misc/src/main/java/org/apache/syncope/core/misc/security/AuthContextUtils.java
index 932627d..38240d9 100644
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/security/AuthContextUtils.java
+++ b/core/misc/src/main/java/org/apache/syncope/core/misc/security/AuthContextUtils.java
@@ -18,12 +18,18 @@
  */
 package org.apache.syncope.core.misc.security;
 
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.collections4.MapUtils;
+import org.apache.commons.collections4.Transformer;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.syncope.common.lib.SyncopeConstants;
+import org.apache.syncope.common.lib.types.Entitlement;
+import org.apache.syncope.core.misc.spring.ApplicationContextProvider;
 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
 import org.springframework.security.core.Authentication;
 import org.springframework.security.core.GrantedAuthority;
@@ -79,6 +85,27 @@ public final class AuthContextUtils {
         return domainKey;
     }
 
+    public static void setFakeAuth(final String domain) {
+        List<GrantedAuthority> authorities = CollectionUtils.collect(Entitlement.values(),
+                new Transformer<String, GrantedAuthority>() {
+
+                    @Override
+                    public GrantedAuthority transform(final String entitlement) {
+                        return new SyncopeGrantedAuthority(entitlement, SyncopeConstants.ROOT_REALM);
+                    }
+                }, new ArrayList<GrantedAuthority>());
+
+        UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(
+                new User(ApplicationContextProvider.getBeanFactory().getBean("adminUser", String.class),
+                        "FAKE_PASSWORD", authorities), "FAKE_PASSWORD", authorities);
+        auth.setDetails(new SyncopeAuthenticationDetails(domain));
+        SecurityContextHolder.getContext().setAuthentication(auth);
+    }
+
+    public static void clearFakeAuth() {
+        SecurityContextHolder.clearContext();
+    }
+
     /**
      * Private default constructor, for static-only classes.
      */

http://git-wip-us.apache.org/repos/asf/syncope/blob/34a1c214/core/misc/src/main/java/org/apache/syncope/core/misc/security/PasswordGenerator.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/security/PasswordGenerator.java b/core/misc/src/main/java/org/apache/syncope/core/misc/security/PasswordGenerator.java
index eab59bb..44635be 100644
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/security/PasswordGenerator.java
+++ b/core/misc/src/main/java/org/apache/syncope/core/misc/security/PasswordGenerator.java
@@ -215,7 +215,7 @@ public class PasswordGenerator {
         String[] generatedPassword = new String[policySpec.getMinLength()];
 
         for (int i = 0; i < generatedPassword.length; i++) {
-            generatedPassword[i] = "";
+            generatedPassword[i] = StringUtils.EMPTY;
         }
 
         checkStartChar(generatedPassword, policySpec);
@@ -224,7 +224,6 @@ public class PasswordGenerator {
 
         checkRequired(generatedPassword, policySpec);
 
-        //filled empty chars
         for (int firstEmptyChar = firstEmptyChar(generatedPassword);
                 firstEmptyChar < generatedPassword.length - 1; firstEmptyChar++) {
 
@@ -252,6 +251,10 @@ public class PasswordGenerator {
         if (policySpec.isMustntStartWithNonAlpha()) {
             generatedPassword[0] = SecureRandomUtils.generateRandomLetter();
         }
+
+        if (StringUtils.EMPTY.equals(generatedPassword[0])) {
+            generatedPassword[0] = SecureRandomUtils.generateRandomLetter();
+        }
     }
 
     private void checkEndChar(final String[] generatedPassword, final PasswordPolicySpec policySpec) {
@@ -271,6 +274,10 @@ public class PasswordGenerator {
         if (policySpec.isMustntEndWithNonAlpha()) {
             generatedPassword[policySpec.getMinLength() - 1] = SecureRandomUtils.generateRandomLetter();
         }
+
+        if (StringUtils.EMPTY.equals(generatedPassword[policySpec.getMinLength() - 1])) {
+            generatedPassword[policySpec.getMinLength() - 1] = SecureRandomUtils.generateRandomLetter();
+        }
     }
 
     private int firstEmptyChar(final String[] generatedPStrings) {

http://git-wip-us.apache.org/repos/asf/syncope/blob/34a1c214/core/misc/src/main/java/org/apache/syncope/core/misc/security/SyncopeAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/security/SyncopeAuthenticationProvider.java b/core/misc/src/main/java/org/apache/syncope/core/misc/security/SyncopeAuthenticationProvider.java
index 01abb93..f452128 100644
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/security/SyncopeAuthenticationProvider.java
+++ b/core/misc/src/main/java/org/apache/syncope/core/misc/security/SyncopeAuthenticationProvider.java
@@ -191,23 +191,23 @@ public class SyncopeAuthenticationProvider implements AuthenticationProvider {
 
             auditManager.audit(
                     AuditElements.EventCategoryType.REST,
-                    "AuthenticationController",
+                    AuditElements.AUTHENTICATION_CATEGORY,
                     null,
-                    "login",
+                    AuditElements.LOGIN_EVENT,
                     Result.SUCCESS,
                     null,
                     authenticated,
                     authentication,
-                    "Successfully authenticated, with groups: " + token.getAuthorities());
+                    "Successfully authenticated, with entitlements: " + token.getAuthorities());
 
             LOG.debug("User {} successfully authenticated, with groups {}",
                     authentication.getPrincipal(), token.getAuthorities());
         } else {
             auditManager.audit(
                     AuditElements.EventCategoryType.REST,
-                    "AuthenticationController",
+                    AuditElements.AUTHENTICATION_CATEGORY,
                     null,
-                    "login",
+                    AuditElements.LOGIN_EVENT,
                     Result.FAILURE,
                     null,
                     authenticated,

http://git-wip-us.apache.org/repos/asf/syncope/blob/34a1c214/core/misc/src/main/java/org/apache/syncope/core/misc/security/SyncopeGrantedAuthority.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/security/SyncopeGrantedAuthority.java b/core/misc/src/main/java/org/apache/syncope/core/misc/security/SyncopeGrantedAuthority.java
index f8f974b..100de17 100644
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/security/SyncopeGrantedAuthority.java
+++ b/core/misc/src/main/java/org/apache/syncope/core/misc/security/SyncopeGrantedAuthority.java
@@ -27,6 +27,8 @@ import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.collections4.SetUtils;
 import org.apache.commons.lang3.builder.EqualsBuilder;
 import org.apache.commons.lang3.builder.HashCodeBuilder;
+import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
 import org.apache.syncope.core.misc.RealmUtils;
 import org.springframework.security.core.GrantedAuthority;
 
@@ -80,4 +82,9 @@ public class SyncopeGrantedAuthority implements GrantedAuthority {
         return HashCodeBuilder.reflectionHashCode(this);
     }
 
+    @Override
+    public String toString() {
+        return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/34a1c214/core/misc/src/main/java/org/apache/syncope/core/misc/spring/ApplicationContextProvider.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/spring/ApplicationContextProvider.java b/core/misc/src/main/java/org/apache/syncope/core/misc/spring/ApplicationContextProvider.java
index 1aa4367..e67dcd6 100644
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/spring/ApplicationContextProvider.java
+++ b/core/misc/src/main/java/org/apache/syncope/core/misc/spring/ApplicationContextProvider.java
@@ -27,12 +27,22 @@ public class ApplicationContextProvider implements ApplicationContextAware {
 
     private static ConfigurableApplicationContext CTX;
 
+    private static DefaultListableBeanFactory BEAN_FACTORY;
+
     public static ConfigurableApplicationContext getApplicationContext() {
         return CTX;
     }
 
     public static DefaultListableBeanFactory getBeanFactory() {
-        return (DefaultListableBeanFactory) CTX.getBeanFactory();
+        return BEAN_FACTORY == null
+                ? CTX == null
+                        ? null
+                        : (DefaultListableBeanFactory) CTX.getBeanFactory()
+                : BEAN_FACTORY;
+    }
+
+    public static void setBeanFactory(final DefaultListableBeanFactory beanFactory) {
+        BEAN_FACTORY = beanFactory;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/syncope/blob/34a1c214/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/DomainsHolder.java
----------------------------------------------------------------------
diff --git a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/DomainsHolder.java b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/DomainsHolder.java
new file mode 100644
index 0000000..1d8e27c
--- /dev/null
+++ b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/DomainsHolder.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.persistence.api;
+
+import java.util.Map;
+import javax.sql.DataSource;
+
+public interface DomainsHolder {
+
+    Map<String, DataSource> getDomains();
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/34a1c214/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/content/ContentExporter.java
----------------------------------------------------------------------
diff --git a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/content/ContentExporter.java b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/content/ContentExporter.java
index 67508f7..5ed50df 100644
--- a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/content/ContentExporter.java
+++ b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/content/ContentExporter.java
@@ -24,6 +24,6 @@ import org.xml.sax.SAXException;
 
 public interface ContentExporter {
 
-    void export(OutputStream output, String uwfPrefix, String rwfPrefix) 
+    void export(String domain, OutputStream output, String uwfPrefix, String rwfPrefix) 
             throws SAXException, TransformerConfigurationException;
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/34a1c214/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/DAO.java
----------------------------------------------------------------------
diff --git a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/DAO.java b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/DAO.java
index eb00a0d..4452890 100644
--- a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/DAO.java
+++ b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/DAO.java
@@ -22,8 +22,6 @@ import org.apache.syncope.core.persistence.api.entity.Entity;
 
 public interface DAO<E extends Entity<KEY>, KEY> {
 
-    String getDomain(E entity);
-
     void refresh(E entity);
 
     void detach(E entity);

http://git-wip-us.apache.org/repos/asf/syncope/blob/34a1c214/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/task/SchedTask.java
----------------------------------------------------------------------
diff --git a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/task/SchedTask.java b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/task/SchedTask.java
index 734194b..0913ee1 100644
--- a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/task/SchedTask.java
+++ b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/task/SchedTask.java
@@ -24,7 +24,7 @@ public interface SchedTask extends Task {
 
     String getDescription();
 
-    String getJobClassName();
+    String getJobDelegateClassName();
 
     String getName();
 
@@ -32,7 +32,7 @@ public interface SchedTask extends Task {
 
     void setDescription(String description);
 
-    void setJobClassName(String jobClassName);
+    void setJobDelegateClassName(String jobDelegateClassName);
 
     void setName(String name);
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/34a1c214/core/persistence-jpa/pom.xml
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/pom.xml b/core/persistence-jpa/pom.xml
index f60f3da..7f1ff38 100644
--- a/core/persistence-jpa/pom.xml
+++ b/core/persistence-jpa/pom.xml
@@ -80,6 +80,11 @@ under the License.
     </dependency>
       
     <dependency>
+      <groupId>org.aspectj</groupId>
+      <artifactId>aspectjweaver</artifactId>
+    </dependency>
+    
+    <dependency>
       <groupId>commons-io</groupId>
       <artifactId>commons-io</artifactId>
     </dependency>

http://git-wip-us.apache.org/repos/asf/syncope/blob/34a1c214/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/content/AbstractContentDealer.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/content/AbstractContentDealer.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/content/AbstractContentDealer.java
index 3bec6b1..9e44efe 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/content/AbstractContentDealer.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/content/AbstractContentDealer.java
@@ -18,17 +18,10 @@
  */
 package org.apache.syncope.core.persistence.jpa.content;
 
-import java.io.IOException;
-import java.util.Properties;
-import javax.annotation.Resource;
-import javax.sql.DataSource;
-import org.apache.syncope.core.misc.spring.ResourceWithFallbackLoader;
+import org.apache.syncope.core.persistence.api.DomainsHolder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.core.io.support.PropertiesLoaderUtils;
-import org.springframework.dao.DataAccessException;
-import org.springframework.jdbc.core.JdbcTemplate;
 
 public abstract class AbstractContentDealer {
 
@@ -36,53 +29,7 @@ public abstract class AbstractContentDealer {
 
     protected static final String ROOT_ELEMENT = "dataset";
 
-    @Resource(name = "database.schema")
-    protected String dbSchema;
-
-    @Resource(name = "indexesXML")
-    private ResourceWithFallbackLoader indexesXML;
-
-    @Resource(name = "viewsXML")
-    private ResourceWithFallbackLoader viewsXML;
-
     @Autowired
-    protected DataSource dataSource;
-
-    protected void createIndexes() throws IOException {
-        LOG.debug("Creating indexes");
-
-        JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
-
-        Properties indexes = PropertiesLoaderUtils.loadProperties(indexesXML.getResource());
-        for (String idx : indexes.stringPropertyNames()) {
-            LOG.debug("Creating index {}", indexes.get(idx).toString());
-
-            try {
-                jdbcTemplate.execute(indexes.get(idx).toString());
-            } catch (DataAccessException e) {
-                LOG.error("Could not create index ", e);
-            }
-        }
-
-        LOG.debug("Indexes created");
-    }
-
-    protected void createViews() throws IOException {
-        LOG.debug("Creating views");
-
-        JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
-
-        Properties views = PropertiesLoaderUtils.loadProperties(viewsXML.getResource());
-        for (String idx : views.stringPropertyNames()) {
-            LOG.debug("Creating view {}", views.get(idx).toString());
-
-            try {
-                jdbcTemplate.execute(views.get(idx).toString().replaceAll("\\n", " "));
-            } catch (DataAccessException e) {
-                LOG.error("Could not create view ", e);
-            }
-        }
+    protected DomainsHolder domainsHolder;
 
-        LOG.debug("Views created");
-    }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/34a1c214/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/content/XMLContentExporter.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/content/XMLContentExporter.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/content/XMLContentExporter.java
index ea13072..17f4bce 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/content/XMLContentExporter.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/content/XMLContentExporter.java
@@ -40,6 +40,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.TreeMap;
 import java.util.TreeSet;
+import javax.sql.DataSource;
 import javax.xml.transform.OutputKeys;
 import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerConfigurationException;
@@ -50,6 +51,7 @@ import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.syncope.common.lib.SyncopeConstants;
 import org.apache.syncope.core.misc.DataFormat;
+import org.apache.syncope.core.misc.spring.ApplicationContextProvider;
 import org.apache.syncope.core.persistence.api.content.ContentExporter;
 import org.apache.syncope.core.persistence.jpa.entity.JPAReportExec;
 import org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAADerAttr;
@@ -91,30 +93,13 @@ public class XMLContentExporter extends AbstractContentDealer implements Content
                 JPAARelationship.TABLE, JPAAMembership.TABLE, JPAURelationship.TABLE, JPAUMembership.TABLE
             }));
 
-    protected static final Set<String> TABLE_SUFFIXES_TO_BE_INCLUDED =
-            new HashSet<>(Arrays.asList(new String[] { "TEMPLATE" }));
-
     protected static final Map<String, String> TABLES_TO_BE_FILTERED =
             Collections.singletonMap("TASK", "DTYPE <> 'PropagationTask'");
 
     protected static final Map<String, Set<String>> COLUMNS_TO_BE_NULLIFIED =
             Collections.singletonMap("SYNCOPEGROUP", Collections.singleton("USEROWNER_ID"));
 
-    private boolean isTableAllowed(final String tableName) {
-        boolean allowed = true;
-        for (String prefix : TABLE_PREFIXES_TO_BE_EXCLUDED) {
-            if (tableName.toUpperCase().startsWith(prefix)) {
-                for (String suffix : TABLE_SUFFIXES_TO_BE_INCLUDED) {
-                    if (!tableName.toUpperCase().endsWith(suffix)) {
-                        allowed = false;
-                    }
-                }
-            }
-        }
-        return allowed;
-    }
-
-    private List<String> sortByForeignKeys(final Connection conn, final Set<String> tableNames)
+    private List<String> sortByForeignKeys(final String dbSchema, final Connection conn, final Set<String> tableNames)
             throws SQLException {
 
         Set<MultiParentNode<String>> roots = new HashSet<>();
@@ -325,7 +310,7 @@ public class XMLContentExporter extends AbstractContentDealer implements Content
     }
 
     @Override
-    public void export(final OutputStream os, final String uwfPrefix, final String rwfPrefix)
+    public void export(final String domain, final OutputStream os, final String uwfPrefix, final String rwfPrefix)
             throws SAXException, TransformerConfigurationException {
 
         if (StringUtils.isNotBlank(uwfPrefix)) {
@@ -346,6 +331,13 @@ public class XMLContentExporter extends AbstractContentDealer implements Content
         handler.startDocument();
         handler.startElement("", "", ROOT_ELEMENT, new AttributesImpl());
 
+        DataSource dataSource = domainsHolder.getDomains().get(domain);
+        if (dataSource == null) {
+            throw new IllegalArgumentException("Could not find DataSource for domain " + domain);
+        }
+
+        String dbSchema = ApplicationContextProvider.getBeanFactory().getBean(domain + "DatabaseSchema", String.class);
+
         Connection conn = null;
         ResultSet rs = null;
         try {
@@ -359,15 +351,13 @@ public class XMLContentExporter extends AbstractContentDealer implements Content
             while (rs.next()) {
                 String tableName = rs.getString("TABLE_NAME");
                 LOG.debug("Found table {}", tableName);
-                if (isTableAllowed(tableName)) {
-                    tableNames.add(tableName);
-                }
+                tableNames.add(tableName);
             }
 
             LOG.debug("Tables to be exported {}", tableNames);
 
             // then sort tables based on foreign keys and dump
-            for (String tableName : sortByForeignKeys(conn, tableNames)) {
+            for (String tableName : sortByForeignKeys(dbSchema, conn, tableNames)) {
                 try {
                     doExportTable(handler, conn, tableName, TABLES_TO_BE_FILTERED.get(tableName.toUpperCase()));
                 } catch (Exception e) {

http://git-wip-us.apache.org/repos/asf/syncope/blob/34a1c214/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/content/XMLContentLoader.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/content/XMLContentLoader.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/content/XMLContentLoader.java
index 086adfd..5d8cfc5 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/content/XMLContentLoader.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/content/XMLContentLoader.java
@@ -20,17 +20,22 @@ package org.apache.syncope.core.persistence.jpa.content;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.Map;
+import java.util.Properties;
 import javax.annotation.Resource;
+import javax.sql.DataSource;
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
 import org.apache.commons.io.IOUtils;
+import org.apache.syncope.core.misc.spring.ApplicationContextProvider;
+import org.apache.syncope.core.misc.spring.ResourceWithFallbackLoader;
 import org.apache.syncope.core.persistence.api.content.ContentLoader;
 import org.apache.syncope.core.persistence.jpa.entity.conf.JPAConf;
-import org.apache.syncope.core.misc.spring.ResourceWithFallbackLoader;
+import org.springframework.core.io.support.PropertiesLoaderUtils;
 import org.springframework.dao.DataAccessException;
 import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.orm.jpa.EntityManagerFactoryUtils;
 import org.springframework.stereotype.Component;
-import org.springframework.transaction.annotation.Transactional;
 
 /**
  * Initialize Database with default content if no data is present already.
@@ -38,47 +43,59 @@ import org.springframework.transaction.annotation.Transactional;
 @Component
 public class XMLContentLoader extends AbstractContentDealer implements ContentLoader {
 
-    @Resource(name = "contentXML")
-    private ResourceWithFallbackLoader contentXML;
+    @Resource(name = "indexesXML")
+    private ResourceWithFallbackLoader indexesXML;
+
+    @Resource(name = "viewsXML")
+    private ResourceWithFallbackLoader viewsXML;
 
     @Override
     public Integer getPriority() {
         return 0;
     }
 
-    @Transactional
     @Override
     public void load() {
-        JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
-
-        boolean existingData;
-        try {
-            existingData = jdbcTemplate.queryForObject("SELECT COUNT(0) FROM " + JPAConf.TABLE, Integer.class) > 0;
-        } catch (DataAccessException e) {
-            LOG.error("Could not access to table " + JPAConf.TABLE, e);
-            existingData = true;
-        }
-
-        if (existingData) {
-            LOG.info("Data found in the database, leaving untouched");
-        } else {
-            LOG.info("Empty database found, loading default content");
+        for (Map.Entry<String, DataSource> entry : domainsHolder.getDomains().entrySet()) {
+            // create EntityManager so OpenJPA will build the SQL schema
+            EntityManagerFactoryUtils.findEntityManagerFactory(
+                    ApplicationContextProvider.getBeanFactory(), entry.getKey()).createEntityManager();
 
+            JdbcTemplate jdbcTemplate = new JdbcTemplate(entry.getValue());
+            boolean existingData;
             try {
-                loadDefaultContent();
-            } catch (Exception e) {
-                LOG.error("While loading default content", e);
+                existingData = jdbcTemplate.queryForObject("SELECT COUNT(0) FROM " + JPAConf.TABLE, Integer.class) > 0;
+            } catch (DataAccessException e) {
+                LOG.error("[{}] Could not access to table " + JPAConf.TABLE, entry.getKey(), e);
+                existingData = true;
             }
-            try {
-                createIndexes();
-                createViews();
-            } catch (IOException e) {
-                LOG.error("While creating indexes and views", e);
+
+            if (existingData) {
+                LOG.info("[{}] Data found in the database, leaving untouched", entry.getKey());
+            } else {
+                LOG.info("[{}] Empty database found, loading default content", entry.getKey());
+
+                try {
+                    ResourceWithFallbackLoader contentXML = ApplicationContextProvider.getBeanFactory().
+                            getBean(entry.getKey() + "ContentXML", ResourceWithFallbackLoader.class);
+                    loadDefaultContent(entry.getKey(), contentXML, entry.getValue());
+                } catch (Exception e) {
+                    LOG.error("[{}] While loading default content", entry.getKey(), e);
+                }
+                try {
+                    createIndexes(entry.getKey(), entry.getValue());
+                    createViews(entry.getKey(), entry.getValue());
+                } catch (IOException e) {
+                    LOG.error("[{}] While creating indexes and views", entry.getKey(), e);
+                }
             }
         }
     }
 
-    private void loadDefaultContent() throws Exception {
+    private void loadDefaultContent(
+            final String domain, final ResourceWithFallbackLoader contentXML, final DataSource dataSource)
+            throws Exception {
+
         SAXParserFactory factory = SAXParserFactory.newInstance();
         InputStream in = null;
         try {
@@ -86,9 +103,47 @@ public class XMLContentLoader extends AbstractContentDealer implements ContentLo
 
             SAXParser parser = factory.newSAXParser();
             parser.parse(in, new ContentLoaderHandler(dataSource, ROOT_ELEMENT));
-            LOG.debug("Default content successfully loaded");
+            LOG.debug("[{}] Default content successfully loaded", domain);
         } finally {
             IOUtils.closeQuietly(in);
         }
     }
+
+    private void createIndexes(final String domain, final DataSource dataSource) throws IOException {
+        LOG.debug("[{}] Creating indexes", domain);
+
+        JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
+
+        Properties indexes = PropertiesLoaderUtils.loadProperties(indexesXML.getResource());
+        for (String idx : indexes.stringPropertyNames()) {
+            LOG.debug("[{}] Creating index {}", domain, indexes.get(idx).toString());
+
+            try {
+                jdbcTemplate.execute(indexes.get(idx).toString());
+            } catch (DataAccessException e) {
+                LOG.error("[{}] Could not create index", domain, e);
+            }
+        }
+
+        LOG.debug("Indexes created");
+    }
+
+    private void createViews(final String domain, final DataSource dataSource) throws IOException {
+        LOG.debug("[{}] Creating views", domain);
+
+        JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
+
+        Properties views = PropertiesLoaderUtils.loadProperties(viewsXML.getResource());
+        for (String idx : views.stringPropertyNames()) {
+            LOG.debug("[{}] Creating view {}", domain, views.get(idx).toString());
+
+            try {
+                jdbcTemplate.execute(views.get(idx).toString().replaceAll("\\n", " "));
+            } catch (DataAccessException e) {
+                LOG.error("[{}] Could not create view", domain, e);
+            }
+        }
+
+        LOG.debug("Views created");
+    }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/34a1c214/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/AbstractAnyDAO.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/AbstractAnyDAO.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/AbstractAnyDAO.java
index ef2161e..95f5b4e 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/AbstractAnyDAO.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/AbstractAnyDAO.java
@@ -18,8 +18,6 @@
  */
 package org.apache.syncope.core.persistence.jpa.dao;
 
-import static org.apache.syncope.core.persistence.jpa.dao.AbstractDAO.LOG;
-
 import java.io.StringReader;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -54,6 +52,7 @@ import org.apache.syncope.core.persistence.api.entity.resource.ExternalResource;
 import org.apache.syncope.core.persistence.api.entity.user.User;
 import org.apache.syncope.core.persistence.jpa.entity.AbstractPlainAttrValue;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
 
 public abstract class AbstractAnyDAO<A extends Any<?, ?, ?>> extends AbstractDAO<A, Long> implements AnyDAO<A> {
 
@@ -81,6 +80,7 @@ public abstract class AbstractAnyDAO<A extends Any<?, ?, ?>> extends AbstractDAO
 
     protected abstract void securityChecks(A any);
 
+    @Transactional(readOnly = true)
     @Override
     public A authFind(final Long key) {
         if (key == null) {
@@ -98,16 +98,17 @@ public abstract class AbstractAnyDAO<A extends Any<?, ?, ?>> extends AbstractDAO
         return any;
     }
 
+    @Transactional(readOnly = true)
     @Override
     @SuppressWarnings("unchecked")
     public A find(final Long key) {
-        return (A) entityManager.find(getAnyUtils().anyClass(), key);
+        return (A) entityManager().find(getAnyUtils().anyClass(), key);
     }
 
     @SuppressWarnings("unchecked")
     @Override
     public A findByWorkflowId(final String workflowId) {
-        Query query = entityManager.createQuery("SELECT e FROM " + getAnyUtils().anyClass().getSimpleName()
+        Query query = entityManager().createQuery("SELECT e FROM " + getAnyUtils().anyClass().getSimpleName()
                 + " e WHERE e.workflowId = :workflowId", User.class);
         query.setParameter("workflowId", workflowId);
 
@@ -122,7 +123,7 @@ public abstract class AbstractAnyDAO<A extends Any<?, ?, ?>> extends AbstractDAO
     }
 
     private Query findByAttrValueQuery(final String entityName) {
-        return entityManager.createQuery("SELECT e FROM " + entityName + " e"
+        return entityManager().createQuery("SELECT e FROM " + entityName + " e"
                 + " WHERE e.attribute.schema.name = :schemaName AND (e.stringValue IS NOT NULL"
                 + " AND e.stringValue = :stringValue)"
                 + " OR (e.booleanValue IS NOT NULL AND e.booleanValue = :booleanValue)"
@@ -362,7 +363,7 @@ public abstract class AbstractAnyDAO<A extends Any<?, ?, ?>> extends AbstractDAO
             }
         }
 
-        Query query = entityManager.createNativeQuery(querystring.toString());
+        Query query = entityManager().createNativeQuery(querystring.toString());
 
         List<A> result = new ArrayList<>();
         for (Object anyKey : query.getResultList()) {
@@ -378,7 +379,7 @@ public abstract class AbstractAnyDAO<A extends Any<?, ?, ?>> extends AbstractDAO
     @SuppressWarnings("unchecked")
     @Override
     public List<A> findByResource(final ExternalResource resource) {
-        Query query = entityManager.createQuery(
+        Query query = entityManager().createQuery(
                 "SELECT e FROM " + getAnyUtils().anyClass().getSimpleName() + " e "
                 + "WHERE :resource MEMBER OF e.resources");
         query.setParameter("resource", resource);
@@ -414,7 +415,7 @@ public abstract class AbstractAnyDAO<A extends Any<?, ?, ?>> extends AbstractDAO
 
     @Override
     public A save(final A any) {
-        A merged = entityManager.merge(any);
+        A merged = entityManager().merge(any);
         for (VirAttr<?> virAttr : merged.getVirAttrs()) {
             virAttr.getValues().clear();
             virAttr.getValues().addAll(any.getVirAttr(virAttr.getSchema().getKey()).getValues());

http://git-wip-us.apache.org/repos/asf/syncope/blob/34a1c214/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/AbstractDAO.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/AbstractDAO.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/AbstractDAO.java
index f4916c7..e5c1d66 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/AbstractDAO.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/AbstractDAO.java
@@ -20,17 +20,16 @@ package org.apache.syncope.core.persistence.jpa.dao;
 
 import java.util.List;
 import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-import javax.persistence.PersistenceContextType;
 import org.apache.commons.lang3.StringUtils;
-import org.apache.syncope.common.lib.SyncopeConstants;
+import org.apache.syncope.core.misc.security.AuthContextUtils;
+import org.apache.syncope.core.misc.spring.ApplicationContextProvider;
 import org.apache.syncope.core.persistence.api.dao.DAO;
 import org.apache.syncope.core.persistence.api.dao.search.OrderByClause;
 import org.apache.syncope.core.persistence.api.entity.Entity;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Configurable;
-import org.springframework.beans.factory.annotation.Value;
+import org.springframework.orm.jpa.EntityManagerFactoryUtils;
 import org.springframework.util.ReflectionUtils;
 
 @Configurable
@@ -38,9 +37,16 @@ public abstract class AbstractDAO<E extends Entity<KEY>, KEY> implements DAO<E,
 
     protected static final Logger LOG = LoggerFactory.getLogger(DAO.class);
 
-    @Value("#{entityManager}")
-    @PersistenceContext(type = PersistenceContextType.TRANSACTION)
-    protected EntityManager entityManager;
+    protected EntityManager entityManager() {
+        EntityManager entityManager = EntityManagerFactoryUtils.getTransactionalEntityManager(
+                EntityManagerFactoryUtils.findEntityManagerFactory(
+                        ApplicationContextProvider.getBeanFactory(), AuthContextUtils.getDomain()));
+        if (entityManager == null) {
+            throw new IllegalStateException("Could not find EntityManager for domain " + AuthContextUtils.getDomain());
+        }
+
+        return entityManager;
+    }
 
     protected String toOrderByStatement(final Class<? extends Entity<KEY>> beanClass, final String prefix,
             final List<OrderByClause> orderByClauses) {
@@ -64,27 +70,22 @@ public abstract class AbstractDAO<E extends Entity<KEY>, KEY> implements DAO<E,
     }
 
     @Override
-    public String getDomain(final E entity) {
-        return SyncopeConstants.MASTER_DOMAIN;
-    }
-
-    @Override
     public void refresh(final E entity) {
-        entityManager.refresh(entity);
+        entityManager().refresh(entity);
     }
 
     @Override
     public void detach(final E entity) {
-        entityManager.detach(entity);
+        entityManager().detach(entity);
     }
 
     @Override
     public void flush() {
-        entityManager.flush();
+        entityManager().flush();
     }
 
     @Override
     public void clear() {
-        entityManager.clear();
+        entityManager().clear();
     }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/34a1c214/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnyObjectDAO.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnyObjectDAO.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnyObjectDAO.java
index 968f990..75b903d 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnyObjectDAO.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnyObjectDAO.java
@@ -99,7 +99,7 @@ public class JPAAnyObjectDAO extends AbstractAnyDAO<AnyObject> implements AnyObj
 
     @Override
     public List<ARelationship> findARelationships(final AnyObject anyObject) {
-        TypedQuery<ARelationship> query = entityManager.createQuery(
+        TypedQuery<ARelationship> query = entityManager().createQuery(
                 "SELECT e FROM " + JPAARelationship.class.getSimpleName()
                 + " e WHERE e.rightEnd=:anyObject", ARelationship.class);
         query.setParameter("anyObject", anyObject);
@@ -109,7 +109,7 @@ public class JPAAnyObjectDAO extends AbstractAnyDAO<AnyObject> implements AnyObj
 
     @Override
     public List<URelationship> findURelationships(final AnyObject anyObject) {
-        TypedQuery<URelationship> query = entityManager.createQuery(
+        TypedQuery<URelationship> query = entityManager().createQuery(
                 "SELECT e FROM " + JPAURelationship.class.getSimpleName()
                 + " e WHERE e.rightEnd=:anyObject", URelationship.class);
         query.setParameter("anyObject", anyObject);
@@ -132,13 +132,13 @@ public class JPAAnyObjectDAO extends AbstractAnyDAO<AnyObject> implements AnyObj
             group.getADynMembership().remove(any);
         }
 
-        entityManager.remove(any);
+        entityManager().remove(any);
     }
 
     @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true)
     @Override
     public List<Group> findDynGroupMemberships(final AnyObject anyObject) {
-        TypedQuery<Group> query = entityManager.createQuery(
+        TypedQuery<Group> query = entityManager().createQuery(
                 "SELECT e.group FROM " + JPAADynGroupMembership.class.getSimpleName()
                 + " e WHERE :anyObject MEMBER OF e.anyObjects", Group.class);
         query.setParameter("anyObject", anyObject);

http://git-wip-us.apache.org/repos/asf/syncope/blob/34a1c214/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnySearchDAO.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnySearchDAO.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnySearchDAO.java
index e0eae6a..2b422eb 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnySearchDAO.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnySearchDAO.java
@@ -143,7 +143,7 @@ public class JPAAnySearchDAO extends AbstractDAO<Any<?, ?, ?>, Long> implements
         queryString.insert(0, "SELECT COUNT(any_id) FROM (");
         queryString.append(") count_any_id");
 
-        Query countQuery = entityManager.createNativeQuery(queryString.toString());
+        Query countQuery = entityManager().createNativeQuery(queryString.toString());
         fillWithParameters(countQuery, parameters);
 
         return ((Number) countQuery.getSingleResult()).intValue();
@@ -208,7 +208,7 @@ public class JPAAnySearchDAO extends AbstractDAO<Any<?, ?, ?>, Long> implements
             queryString.append(") u WHERE any_id=?").append(setParameter(parameters, any.getKey()));
 
             // 3. prepare the search query
-            Query query = entityManager.createNativeQuery(queryString.toString());
+            Query query = entityManager().createNativeQuery(queryString.toString());
 
             // 4. populate the search query with parameter values
             fillWithParameters(query, parameters);
@@ -371,7 +371,7 @@ public class JPAAnySearchDAO extends AbstractDAO<Any<?, ?, ?>, Long> implements
                 append(buildOrderBy(orderBySupport));
 
         // 3. prepare the search query
-        Query query = entityManager.createNativeQuery(queryString.toString());
+        Query query = entityManager().createNativeQuery(queryString.toString());
 
         // 4. page starts from 1, while setFirtResult() starts from 0
         query.setFirstResult(itemsPerPage * (page <= 0 ? 0 : page - 1));

http://git-wip-us.apache.org/repos/asf/syncope/blob/34a1c214/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnyTypeClassDAO.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnyTypeClassDAO.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnyTypeClassDAO.java
index 58b547d..9a01442 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnyTypeClassDAO.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnyTypeClassDAO.java
@@ -51,19 +51,19 @@ public class JPAAnyTypeClassDAO extends AbstractDAO<AnyTypeClass, String> implem
 
     @Override
     public AnyTypeClass find(final String key) {
-        return entityManager.find(JPAAnyTypeClass.class, key);
+        return entityManager().find(JPAAnyTypeClass.class, key);
     }
 
     @Override
     public List<AnyTypeClass> findAll() {
-        TypedQuery<AnyTypeClass> query = entityManager.createQuery(
+        TypedQuery<AnyTypeClass> query = entityManager().createQuery(
                 "SELECT e FROM " + JPAAnyTypeClass.class.getSimpleName() + " e ", AnyTypeClass.class);
         return query.getResultList();
     }
 
     @Override
     public AnyTypeClass save(final AnyTypeClass anyTypeClass) {
-        AnyTypeClass merge = entityManager.merge(anyTypeClass);
+        AnyTypeClass merge = entityManager().merge(anyTypeClass);
 
         for (PlainSchema schema : merge.getPlainSchemas()) {
             schema.setAnyTypeClass(merge);
@@ -99,7 +99,7 @@ public class JPAAnyTypeClassDAO extends AbstractDAO<AnyTypeClass, String> implem
             type.remove(anyTypeClass);
         }
 
-        entityManager.remove(anyTypeClass);
+        entityManager().remove(anyTypeClass);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/34a1c214/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnyTypeDAO.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnyTypeDAO.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnyTypeDAO.java
index 4342811..cf87a3b 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnyTypeDAO.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnyTypeDAO.java
@@ -32,7 +32,7 @@ public class JPAAnyTypeDAO extends AbstractDAO<AnyType, String> implements AnyTy
 
     @Override
     public AnyType find(final String key) {
-        return entityManager.find(JPAAnyType.class, key);
+        return entityManager().find(JPAAnyType.class, key);
     }
 
     @Override
@@ -50,7 +50,7 @@ public class JPAAnyTypeDAO extends AbstractDAO<AnyType, String> implements AnyTy
                 append(JPAAnyType.class.getSimpleName()).
                 append(" e WHERE :anyTypeClass MEMBER OF e.classes");
 
-        TypedQuery<AnyType> query = entityManager.createQuery(queryString.toString(), AnyType.class);
+        TypedQuery<AnyType> query = entityManager().createQuery(queryString.toString(), AnyType.class);
         query.setParameter("anyTypeClass", anyTypeClass);
 
         return query.getResultList();
@@ -58,14 +58,14 @@ public class JPAAnyTypeDAO extends AbstractDAO<AnyType, String> implements AnyTy
 
     @Override
     public List<AnyType> findAll() {
-        TypedQuery<AnyType> query = entityManager.createQuery(
+        TypedQuery<AnyType> query = entityManager().createQuery(
                 "SELECT e FROM " + JPAAnyType.class.getSimpleName() + " e ", AnyType.class);
         return query.getResultList();
     }
 
     @Override
     public AnyType save(final AnyType anyType) {
-        return entityManager.merge(anyType);
+        return entityManager().merge(anyType);
     }
 
     @Override
@@ -79,7 +79,7 @@ public class JPAAnyTypeDAO extends AbstractDAO<AnyType, String> implements AnyTy
             throw new IllegalArgumentException(key + " cannot be deleted");
         }
 
-        entityManager.remove(anyType);
+        entityManager().remove(anyType);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/34a1c214/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAConfDAO.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAConfDAO.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAConfDAO.java
index 7045a1a..4afe78e 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAConfDAO.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAConfDAO.java
@@ -42,12 +42,12 @@ public class JPAConfDAO extends AbstractDAO<Conf, Long> implements ConfDAO {
 
     @Override
     public Conf get() {
-        Conf instance = entityManager.find(JPAConf.class, 1L);
+        Conf instance = entityManager().find(JPAConf.class, 1L);
         if (instance == null) {
             instance = new JPAConf();
             instance.setKey(1L);
 
-            instance = entityManager.merge(instance);
+            instance = entityManager().merge(instance);
         }
 
         return instance;
@@ -97,7 +97,7 @@ public class JPAConfDAO extends AbstractDAO<Conf, Long> implements ConfDAO {
         instance.add(attr);
         attr.setOwner(instance);
 
-        return entityManager.merge(instance);
+        return entityManager().merge(instance);
     }
 
     @Override
@@ -106,7 +106,7 @@ public class JPAConfDAO extends AbstractDAO<Conf, Long> implements ConfDAO {
         CPlainAttr attr = instance.getPlainAttr(key);
         if (attr != null) {
             instance.remove(attr);
-            instance = entityManager.merge(instance);
+            instance = entityManager().merge(instance);
         }
 
         return instance;

http://git-wip-us.apache.org/repos/asf/syncope/blob/34a1c214/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAConnInstanceDAO.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAConnInstanceDAO.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAConnInstanceDAO.java
index 453c363..eb027e9 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAConnInstanceDAO.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAConnInstanceDAO.java
@@ -44,19 +44,19 @@ public class JPAConnInstanceDAO extends AbstractDAO<ConnInstance, Long> implemen
 
     @Override
     public ConnInstance find(final Long key) {
-        return entityManager.find(JPAConnInstance.class, key);
+        return entityManager().find(JPAConnInstance.class, key);
     }
 
     @Override
     public List<ConnInstance> findAll() {
-        TypedQuery<ConnInstance> query = entityManager.createQuery(
+        TypedQuery<ConnInstance> query = entityManager().createQuery(
                 "SELECT e FROM " + JPAConnInstance.class.getSimpleName() + " e", ConnInstance.class);
         return query.getResultList();
     }
 
     @Override
     public ConnInstance save(final ConnInstance connector) {
-        final ConnInstance merged = entityManager.merge(connector);
+        final ConnInstance merged = entityManager().merge(connector);
 
         for (ExternalResource resource : merged.getResources()) {
             try {
@@ -86,7 +86,7 @@ public class JPAConnInstanceDAO extends AbstractDAO<ConnInstance, Long> implemen
 
                 });
 
-        entityManager.remove(connInstance);
+        entityManager().remove(connInstance);
 
         connRegistry.unregisterConnector(key.toString());
     }

http://git-wip-us.apache.org/repos/asf/syncope/blob/34a1c214/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPADerAttrDAO.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPADerAttrDAO.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPADerAttrDAO.java
index 2162898..8dff203 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPADerAttrDAO.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPADerAttrDAO.java
@@ -49,19 +49,19 @@ public class JPADerAttrDAO extends AbstractDAO<DerAttr<?>, Long> implements DerA
 
     @Override
     public <T extends DerAttr<?>> T find(final Long key, final Class<T> reference) {
-        return reference.cast(entityManager.find(getJPAEntityReference(reference), key));
+        return reference.cast(entityManager().find(getJPAEntityReference(reference), key));
     }
 
     @Override
     public <T extends DerAttr<?>> List<T> findAll(final Class<T> reference) {
-        TypedQuery<T> query = entityManager.createQuery(
+        TypedQuery<T> query = entityManager().createQuery(
                 "SELECT e FROM " + getJPAEntityReference(reference).getSimpleName() + " e", reference);
         return query.getResultList();
     }
 
     @Override
     public <T extends DerAttr<?>> T save(final T derAttr) {
-        return entityManager.merge(derAttr);
+        return entityManager().merge(derAttr);
     }
 
     @Override
@@ -81,6 +81,6 @@ public class JPADerAttrDAO extends AbstractDAO<DerAttr<?>, Long> implements DerA
             ((Any<?, T, ?>) derAttr.getOwner()).remove(derAttr);
         }
 
-        entityManager.remove(derAttr);
+        entityManager().remove(derAttr);
     }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/34a1c214/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPADerSchemaDAO.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPADerSchemaDAO.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPADerSchemaDAO.java
index 18b6636..4ed17ca 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPADerSchemaDAO.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPADerSchemaDAO.java
@@ -45,7 +45,7 @@ public class JPADerSchemaDAO extends AbstractDAO<DerSchema, String> implements D
 
     @Override
     public DerSchema find(final String key) {
-        return entityManager.find(JPADerSchema.class, key);
+        return entityManager().find(JPADerSchema.class, key);
     }
 
     @Override
@@ -54,7 +54,7 @@ public class JPADerSchemaDAO extends AbstractDAO<DerSchema, String> implements D
                 append(JPADerSchema.class.getSimpleName()).
                 append(" e WHERE e.anyTypeClass=:anyTypeClass");
 
-        TypedQuery<DerSchema> query = entityManager.createQuery(queryString.toString(), DerSchema.class);
+        TypedQuery<DerSchema> query = entityManager().createQuery(queryString.toString(), DerSchema.class);
         query.setParameter("anyTypeClass", anyTypeClass);
 
         return query.getResultList();
@@ -62,7 +62,7 @@ public class JPADerSchemaDAO extends AbstractDAO<DerSchema, String> implements D
 
     @Override
     public List<DerSchema> findAll() {
-        TypedQuery<DerSchema> query = entityManager.createQuery(
+        TypedQuery<DerSchema> query = entityManager().createQuery(
                 "SELECT e FROM " + JPADerSchema.class.getSimpleName() + " e", DerSchema.class);
         return query.getResultList();
     }
@@ -73,7 +73,7 @@ public class JPADerSchemaDAO extends AbstractDAO<DerSchema, String> implements D
                 append(((JPADerAttrDAO) derAttrDAO).getJPAEntityReference(reference).getSimpleName()).
                 append(" e WHERE e.schema=:schema");
 
-        TypedQuery<T> query = entityManager.createQuery(queryString.toString(), reference);
+        TypedQuery<T> query = entityManager().createQuery(queryString.toString(), reference);
         query.setParameter("schema", schema);
 
         return query.getResultList();
@@ -81,7 +81,7 @@ public class JPADerSchemaDAO extends AbstractDAO<DerSchema, String> implements D
 
     @Override
     public DerSchema save(final DerSchema derSchema) {
-        return entityManager.merge(derSchema);
+        return entityManager().merge(derSchema);
     }
 
     @Override
@@ -106,6 +106,6 @@ public class JPADerSchemaDAO extends AbstractDAO<DerSchema, String> implements D
             schema.getAnyTypeClass().remove(schema);
         }
 
-        entityManager.remove(schema);
+        entityManager().remove(schema);
     }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/34a1c214/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPADomainDAO.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPADomainDAO.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPADomainDAO.java
index 37a4cd2..b3bb188 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPADomainDAO.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPADomainDAO.java
@@ -30,19 +30,19 @@ public class JPADomainDAO extends AbstractDAO<Domain, String> implements DomainD
 
     @Override
     public Domain find(final String key) {
-        return entityManager.find(JPADomain.class, key);
+        return entityManager().find(JPADomain.class, key);
     }
 
     @Override
     public List<Domain> findAll() {
-        TypedQuery<Domain> query = entityManager.createQuery(
+        TypedQuery<Domain> query = entityManager().createQuery(
                 "SELECT e FROM " + JPADomain.class.getSimpleName() + " e ", Domain.class);
         return query.getResultList();
     }
 
     @Override
     public Domain save(final Domain anyTypeClass) {
-        return entityManager.merge(anyTypeClass);
+        return entityManager().merge(anyTypeClass);
     }
 
     @Override
@@ -52,6 +52,6 @@ public class JPADomainDAO extends AbstractDAO<Domain, String> implements DomainD
             return;
         }
 
-        entityManager.remove(domain);
+        entityManager().remove(domain);
     }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/34a1c214/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAExternalResourceDAO.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAExternalResourceDAO.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAExternalResourceDAO.java
index 17553a2..4a8a759 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAExternalResourceDAO.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAExternalResourceDAO.java
@@ -71,7 +71,7 @@ public class JPAExternalResourceDAO extends AbstractDAO<ExternalResource, String
 
     @Override
     public ExternalResource find(final String name) {
-        return entityManager.find(JPAExternalResource.class, name);
+        return entityManager().find(JPAExternalResource.class, name);
     }
 
     private StringBuilder getByPolicyQuery(final PolicyType type) {
@@ -99,7 +99,7 @@ public class JPAExternalResourceDAO extends AbstractDAO<ExternalResource, String
 
     @Override
     public List<ExternalResource> findByPolicy(final Policy policy) {
-        TypedQuery<ExternalResource> query = entityManager.createQuery(
+        TypedQuery<ExternalResource> query = entityManager().createQuery(
                 getByPolicyQuery(policy.getType()).append(" = :policy").toString(), ExternalResource.class);
         query.setParameter("policy", policy);
         return query.getResultList();
@@ -107,21 +107,21 @@ public class JPAExternalResourceDAO extends AbstractDAO<ExternalResource, String
 
     @Override
     public List<ExternalResource> findWithoutPolicy(final PolicyType type) {
-        TypedQuery<ExternalResource> query = entityManager.createQuery(
+        TypedQuery<ExternalResource> query = entityManager().createQuery(
                 getByPolicyQuery(type).append(" IS NULL").toString(), ExternalResource.class);
         return query.getResultList();
     }
 
     @Override
     public List<ExternalResource> findAll() {
-        TypedQuery<ExternalResource> query = entityManager.createQuery(
+        TypedQuery<ExternalResource> query = entityManager().createQuery(
                 "SELECT e FROM  " + JPAExternalResource.class.getSimpleName() + " e", ExternalResource.class);
         return query.getResultList();
     }
 
     @Override
     public List<ExternalResource> findAllByPriority() {
-        TypedQuery<ExternalResource> query = entityManager.createQuery(
+        TypedQuery<ExternalResource> query = entityManager().createQuery(
                 "SELECT e FROM  " + JPAExternalResource.class.getSimpleName() + " e ORDER BY e.propagationPriority",
                 ExternalResource.class);
         return query.getResultList();
@@ -138,7 +138,7 @@ public class JPAExternalResourceDAO extends AbstractDAO<ExternalResource, String
     @Override
     @Transactional(rollbackFor = { Throwable.class })
     public ExternalResource save(final ExternalResource resource) {
-        ExternalResource merged = entityManager.merge(resource);
+        ExternalResource merged = entityManager().merge(resource);
         try {
             connRegistry.registerConnector(merged);
         } catch (NotFoundException e) {
@@ -154,7 +154,7 @@ public class JPAExternalResourceDAO extends AbstractDAO<ExternalResource, String
             return;
         }
 
-        TypedQuery<MappingItem> query = entityManager.createQuery(
+        TypedQuery<MappingItem> query = entityManager().createQuery(
                 "SELECT m FROM " + JPAMappingItem.class.getSimpleName()
                 + " m WHERE m.intAttrName=:intAttrName AND m.intMappingType=:intMappingType", MappingItem.class);
         query.setParameter("intAttrName", intAttrName);
@@ -165,18 +165,18 @@ public class JPAExternalResourceDAO extends AbstractDAO<ExternalResource, String
             itemKeys.add(item.getKey());
         }
         for (Long itemKey : itemKeys) {
-            MappingItem item = entityManager.find(JPAMappingItem.class, itemKey);
+            MappingItem item = entityManager().find(JPAMappingItem.class, itemKey);
             if (item != null) {
                 item.getMapping().remove(item);
                 item.setMapping(null);
 
-                entityManager.remove(item);
+                entityManager().remove(item);
             }
         }
 
         // Make empty query cache for *MappingItem and related *Mapping
-        entityManager.getEntityManagerFactory().getCache().evict(JPAMappingItem.class);
-        entityManager.getEntityManagerFactory().getCache().evict(JPAMapping.class);
+        entityManager().getEntityManagerFactory().getCache().evict(JPAMappingItem.class);
+        entityManager().getEntityManagerFactory().getCache().evict(JPAMapping.class);
     }
 
     @Override
@@ -219,6 +219,6 @@ public class JPAExternalResourceDAO extends AbstractDAO<ExternalResource, String
             provision.setResource(null);
         }
 
-        entityManager.remove(resource);
+        entityManager().remove(resource);
     }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/34a1c214/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAGroupDAO.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAGroupDAO.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAGroupDAO.java
index 22ce79e..368ea07 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAGroupDAO.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAGroupDAO.java
@@ -88,7 +88,7 @@ public class JPAGroupDAO extends AbstractAnyDAO<Group> implements GroupDAO {
 
     @Override
     public Group find(final String name) {
-        TypedQuery<Group> query = entityManager.createQuery(
+        TypedQuery<Group> query = entityManager().createQuery(
                 "SELECT e FROM " + JPAGroup.class.getSimpleName() + " e WHERE e.name = :name", Group.class);
         query.setParameter("name", name);
 
@@ -116,7 +116,7 @@ public class JPAGroupDAO extends AbstractAnyDAO<Group> implements GroupDAO {
             queryString.append("OR e.groupOwner.id=").append(groupKey).append(' ');
         }
 
-        TypedQuery<Group> query = entityManager.createQuery(queryString.toString(), Group.class);
+        TypedQuery<Group> query = entityManager().createQuery(queryString.toString(), Group.class);
         query.setParameter("owner", owner);
 
         return query.getResultList();
@@ -133,7 +133,7 @@ public class JPAGroupDAO extends AbstractAnyDAO<Group> implements GroupDAO {
         StringBuilder queryString = new StringBuilder("SELECT e FROM ").append(JPAGroup.class.getSimpleName()).
                 append(" e WHERE e.groupOwner=:owner ");
 
-        TypedQuery<Group> query = entityManager.createQuery(queryString.toString(), Group.class);
+        TypedQuery<Group> query = entityManager().createQuery(queryString.toString(), Group.class);
         query.setParameter("owner", owner);
 
         return query.getResultList();
@@ -141,7 +141,7 @@ public class JPAGroupDAO extends AbstractAnyDAO<Group> implements GroupDAO {
 
     @Override
     public List<AMembership> findAMemberships(final Group group) {
-        TypedQuery<AMembership> query = entityManager.createQuery(
+        TypedQuery<AMembership> query = entityManager().createQuery(
                 "SELECT e FROM " + JPAAMembership.class.getSimpleName()
                 + " e WHERE e.rightEnd=:group", AMembership.class);
         query.setParameter("group", group);
@@ -151,7 +151,7 @@ public class JPAGroupDAO extends AbstractAnyDAO<Group> implements GroupDAO {
 
     @Override
     public List<UMembership> findUMemberships(final Group group) {
-        TypedQuery<UMembership> query = entityManager.createQuery(
+        TypedQuery<UMembership> query = entityManager().createQuery(
                 "SELECT e FROM " + JPAUMembership.class.getSimpleName()
                 + " e WHERE e.rightEnd=:group", UMembership.class);
         query.setParameter("group", group);
@@ -190,16 +190,16 @@ public class JPAGroupDAO extends AbstractAnyDAO<Group> implements GroupDAO {
             membership.getLeftEnd().remove(membership);
             anyObjectDAO.save(membership.getLeftEnd());
 
-            entityManager.remove(membership);
+            entityManager().remove(membership);
         }
         for (UMembership membership : findUMemberships(group)) {
             membership.getLeftEnd().remove(membership);
             userDAO.save(membership.getLeftEnd());
 
-            entityManager.remove(membership);
+            entityManager().remove(membership);
         }
 
-        entityManager.remove(group);
+        entityManager().remove(group);
     }
 
     private void populateTransitiveResources(

http://git-wip-us.apache.org/repos/asf/syncope/blob/34a1c214/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPALoggerDAO.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPALoggerDAO.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPALoggerDAO.java
index 327149f..9189e2a 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPALoggerDAO.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPALoggerDAO.java
@@ -32,12 +32,12 @@ public class JPALoggerDAO extends AbstractDAO<Logger, String> implements LoggerD
 
     @Override
     public Logger find(final String key) {
-        return entityManager.find(JPALogger.class, key);
+        return entityManager().find(JPALogger.class, key);
     }
 
     @Override
     public List<Logger> findAll(final LoggerType type) {
-        TypedQuery<Logger> query = entityManager.createQuery(
+        TypedQuery<Logger> query = entityManager().createQuery(
                 "SELECT e FROM " + JPALogger.class.getSimpleName() + " e WHERE e.type=:type", Logger.class);
         query.setParameter("type", type);
         return query.getResultList();
@@ -49,12 +49,12 @@ public class JPALoggerDAO extends AbstractDAO<Logger, String> implements LoggerD
         if (LoggerType.AUDIT == logger.getType() && LoggerLevel.OFF != logger.getLevel()) {
             logger.setLevel(LoggerLevel.DEBUG);
         }
-        return entityManager.merge(logger);
+        return entityManager().merge(logger);
     }
 
     @Override
     public void delete(final Logger logger) {
-        entityManager.remove(logger);
+        entityManager().remove(logger);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/syncope/blob/34a1c214/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPANotificationDAO.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPANotificationDAO.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPANotificationDAO.java
index b3b4b01..a43cf22 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPANotificationDAO.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPANotificationDAO.java
@@ -30,23 +30,23 @@ public class JPANotificationDAO extends AbstractDAO<Notification, Long> implemen
 
     @Override
     public Notification find(final Long key) {
-        return entityManager.find(JPANotification.class, key);
+        return entityManager().find(JPANotification.class, key);
     }
 
     @Override
     public List<Notification> findAll() {
-        TypedQuery<Notification> query = entityManager.createQuery(
+        TypedQuery<Notification> query = entityManager().createQuery(
                 "SELECT e FROM " + JPANotification.class.getSimpleName() + " e", Notification.class);
         return query.getResultList();
     }
 
     @Override
     public Notification save(final Notification notification) {
-        return entityManager.merge(notification);
+        return entityManager().merge(notification);
     }
 
     @Override
     public void delete(final Long key) {
-        entityManager.remove(find(key));
+        entityManager().remove(find(key));
     }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/34a1c214/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAPlainAttrDAO.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAPlainAttrDAO.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAPlainAttrDAO.java
index 5e232fd..d21d1f3 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAPlainAttrDAO.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAPlainAttrDAO.java
@@ -51,7 +51,7 @@ public class JPAPlainAttrDAO extends AbstractDAO<PlainAttr<?>, Long> implements
 
     @Override
     public <T extends PlainAttr<?>> T find(final Long key, final Class<T> reference) {
-        return reference.cast(entityManager.find(getJPAEntityReference(reference), key));
+        return reference.cast(entityManager().find(getJPAEntityReference(reference), key));
     }
 
     @Override
@@ -71,6 +71,6 @@ public class JPAPlainAttrDAO extends AbstractDAO<PlainAttr<?>, Long> implements
             ((Any<T, ?, ?>) plainAttr.getOwner()).remove(plainAttr);
         }
 
-        entityManager.remove(plainAttr);
+        entityManager().remove(plainAttr);
     }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/34a1c214/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAPlainAttrValueDAO.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAPlainAttrValueDAO.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAPlainAttrValueDAO.java
index 655decd..be2965c 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAPlainAttrValueDAO.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAPlainAttrValueDAO.java
@@ -68,19 +68,19 @@ public class JPAPlainAttrValueDAO extends AbstractDAO<PlainAttrValue, Long> impl
 
     @Override
     public <T extends PlainAttrValue> T find(final Long key, final Class<T> reference) {
-        return reference.cast(entityManager.find(getJPAEntityReference(reference), key));
+        return reference.cast(entityManager().find(getJPAEntityReference(reference), key));
     }
 
     @Override
     public <T extends PlainAttrValue> List<T> findAll(final Class<T> reference) {
-        TypedQuery<T> query = entityManager.createQuery(
+        TypedQuery<T> query = entityManager().createQuery(
                 "SELECT e FROM " + getJPAEntityReference(reference).getSimpleName() + " e", reference);
         return query.getResultList();
     }
 
     @Override
     public <T extends PlainAttrValue> T save(final T attributeValue) {
-        return entityManager.merge(attributeValue);
+        return entityManager().merge(attributeValue);
     }
 
     @Override
@@ -99,6 +99,6 @@ public class JPAPlainAttrValueDAO extends AbstractDAO<PlainAttrValue, Long> impl
             attrValue.getAttr().remove(attrValue);
         }
 
-        entityManager.remove(attrValue);
+        entityManager().remove(attrValue);
     }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/34a1c214/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAPlainSchemaDAO.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAPlainSchemaDAO.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAPlainSchemaDAO.java
index c3c94ce..47e8fe3 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAPlainSchemaDAO.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAPlainSchemaDAO.java
@@ -45,7 +45,7 @@ public class JPAPlainSchemaDAO extends AbstractDAO<PlainSchema, String> implemen
 
     @Override
     public PlainSchema find(final String key) {
-        return entityManager.find(JPAPlainSchema.class, key);
+        return entityManager().find(JPAPlainSchema.class, key);
     }
 
     @Override
@@ -54,7 +54,7 @@ public class JPAPlainSchemaDAO extends AbstractDAO<PlainSchema, String> implemen
                 append(JPAPlainSchema.class.getSimpleName()).
                 append(" e WHERE e.anyTypeClass=:anyTypeClass");
 
-        TypedQuery<PlainSchema> query = entityManager.createQuery(queryString.toString(), PlainSchema.class);
+        TypedQuery<PlainSchema> query = entityManager().createQuery(queryString.toString(), PlainSchema.class);
         query.setParameter("anyTypeClass", anyTypeClass);
 
         return query.getResultList();
@@ -62,7 +62,7 @@ public class JPAPlainSchemaDAO extends AbstractDAO<PlainSchema, String> implemen
 
     @Override
     public List<PlainSchema> findAll() {
-        TypedQuery<PlainSchema> query = entityManager.createQuery(
+        TypedQuery<PlainSchema> query = entityManager().createQuery(
                 "SELECT e FROM " + JPAPlainSchema.class.getSimpleName() + " e", PlainSchema.class);
         return query.getResultList();
     }
@@ -73,7 +73,7 @@ public class JPAPlainSchemaDAO extends AbstractDAO<PlainSchema, String> implemen
                 append(((JPAPlainAttrDAO) plainAttrDAO).getJPAEntityReference(reference).getSimpleName()).
                 append(" e WHERE e.schema=:schema");
 
-        TypedQuery<T> query = entityManager.createQuery(queryString.toString(), reference);
+        TypedQuery<T> query = entityManager().createQuery(queryString.toString(), reference);
         query.setParameter("schema", schema);
 
         return query.getResultList();
@@ -81,7 +81,7 @@ public class JPAPlainSchemaDAO extends AbstractDAO<PlainSchema, String> implemen
 
     @Override
     public PlainSchema save(final PlainSchema schema) {
-        return entityManager.merge(schema);
+        return entityManager().merge(schema);
     }
 
     @Override
@@ -106,6 +106,6 @@ public class JPAPlainSchemaDAO extends AbstractDAO<PlainSchema, String> implemen
             schema.getAnyTypeClass().remove(schema);
         }
 
-        entityManager.remove(schema);
+        entityManager().remove(schema);
     }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/34a1c214/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAPolicyDAO.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAPolicyDAO.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAPolicyDAO.java
index 176cfbd..ab0a8c5 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAPolicyDAO.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAPolicyDAO.java
@@ -43,7 +43,7 @@ public class JPAPolicyDAO extends AbstractDAO<Policy, Long> implements PolicyDAO
     @Override
     @SuppressWarnings("unchecked")
     public <T extends Policy> T find(final Long key) {
-        final Query query = entityManager.createQuery(
+        final Query query = entityManager().createQuery(
                 "SELECT e FROM " + JPAPolicy.class.getSimpleName() + " e WHERE e.id=:id");
         query.setParameter("id", key);
 
@@ -56,7 +56,7 @@ public class JPAPolicyDAO extends AbstractDAO<Policy, Long> implements PolicyDAO
     @Override
     @SuppressWarnings("unchecked")
     public <T extends Policy> List<T> find(final PolicyType type) {
-        final Query query = entityManager.createQuery(
+        final Query query = entityManager().createQuery(
                 "SELECT e FROM " + JPAPolicy.class.getSimpleName() + " e WHERE e.type=:type");
         query.setParameter("type", type);
 
@@ -65,7 +65,7 @@ public class JPAPolicyDAO extends AbstractDAO<Policy, Long> implements PolicyDAO
 
     @Override
     public List<AccountPolicy> findByResource(final ExternalResource resource) {
-        TypedQuery<AccountPolicy> query = entityManager.createQuery(
+        TypedQuery<AccountPolicy> query = entityManager().createQuery(
                 "SELECT e FROM " + JPAAccountPolicy.class.getSimpleName() + " e "
                 + "WHERE :resource MEMBER OF e.resources", AccountPolicy.class);
         query.setParameter("resource", resource);
@@ -75,14 +75,14 @@ public class JPAPolicyDAO extends AbstractDAO<Policy, Long> implements PolicyDAO
 
     @Override
     public List<Policy> findAll() {
-        TypedQuery<Policy> query = entityManager.createQuery(
+        TypedQuery<Policy> query = entityManager().createQuery(
                 "SELECT e FROM " + JPAPolicy.class.getSimpleName() + " e", Policy.class);
         return query.getResultList();
     }
 
     @Override
     public <T extends Policy> T save(final T policy) {
-        return entityManager.merge(policy);
+        return entityManager().merge(policy);
     }
 
     @Override
@@ -95,6 +95,6 @@ public class JPAPolicyDAO extends AbstractDAO<Policy, Long> implements PolicyDAO
             }
         }
 
-        entityManager.remove(policy);
+        entityManager().remove(policy);
     }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/34a1c214/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPARealmDAO.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPARealmDAO.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPARealmDAO.java
index f5625ee..36ce550 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPARealmDAO.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPARealmDAO.java
@@ -50,7 +50,7 @@ public class JPARealmDAO extends AbstractDAO<Realm, Long> implements RealmDAO {
 
     @Override
     public Realm getRoot() {
-        TypedQuery<Realm> query = entityManager.createQuery(
+        TypedQuery<Realm> query = entityManager().createQuery(
                 "SELECT e FROM " + JPARealm.class.getSimpleName() + " e WHERE e.parent IS NULL", Realm.class);
 
         Realm result = null;
@@ -65,7 +65,7 @@ public class JPARealmDAO extends AbstractDAO<Realm, Long> implements RealmDAO {
 
     @Override
     public Realm find(final Long key) {
-        return entityManager.find(JPARealm.class, key);
+        return entityManager().find(JPARealm.class, key);
     }
 
     @Override
@@ -126,7 +126,7 @@ public class JPARealmDAO extends AbstractDAO<Realm, Long> implements RealmDAO {
                 append(JPARealm.class.getSimpleName()).append(" e WHERE e.").
                 append(policy instanceof AccountPolicy ? "accountPolicy" : "passwordPolicy").append("=:policy");
 
-        TypedQuery<Realm> query = entityManager.createQuery(queryString.toString(), Realm.class);
+        TypedQuery<Realm> query = entityManager().createQuery(queryString.toString(), Realm.class);
         query.setParameter("policy", policy);
 
         List<Realm> result = new ArrayList<>();
@@ -154,7 +154,7 @@ public class JPARealmDAO extends AbstractDAO<Realm, Long> implements RealmDAO {
 
     @Override
     public List<Realm> findChildren(final Realm realm) {
-        TypedQuery<Realm> query = entityManager.createQuery(
+        TypedQuery<Realm> query = entityManager().createQuery(
                 "SELECT e FROM " + JPARealm.class.getSimpleName() + " e WHERE e.parent=:realm", Realm.class);
         query.setParameter("realm", realm);
 
@@ -180,14 +180,14 @@ public class JPARealmDAO extends AbstractDAO<Realm, Long> implements RealmDAO {
 
     @Override
     public List<Realm> findAll() {
-        TypedQuery<Realm> query = entityManager.createQuery(
+        TypedQuery<Realm> query = entityManager().createQuery(
                 "SELECT e FROM " + JPARealm.class.getSimpleName() + " e ", Realm.class);
         return query.getResultList();
     }
 
     @Override
     public Realm save(final Realm realm) {
-        return entityManager.merge(realm);
+        return entityManager().merge(realm);
     }
 
     @Override
@@ -199,7 +199,7 @@ public class JPARealmDAO extends AbstractDAO<Realm, Long> implements RealmDAO {
 
             toBeDeleted.setParent(null);
 
-            entityManager.remove(toBeDeleted);
+            entityManager().remove(toBeDeleted);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/syncope/blob/34a1c214/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPARelationshipTypeDAO.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPARelationshipTypeDAO.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPARelationshipTypeDAO.java
index 37ce107..5eb3951 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPARelationshipTypeDAO.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPARelationshipTypeDAO.java
@@ -39,27 +39,27 @@ public class JPARelationshipTypeDAO extends AbstractDAO<RelationshipType, String
 
     @Override
     public RelationshipType find(final String key) {
-        return entityManager.find(JPARelationshipType.class, key);
+        return entityManager().find(JPARelationshipType.class, key);
     }
 
     @Override
     public List<RelationshipType> findAll() {
-        TypedQuery<RelationshipType> query = entityManager.createQuery(
+        TypedQuery<RelationshipType> query = entityManager().createQuery(
                 "SELECT e FROM " + JPARelationshipType.class.getSimpleName() + " e ", RelationshipType.class);
         return query.getResultList();
     }
 
     @Override
     public RelationshipType save(final RelationshipType anyType) {
-        return entityManager.merge(anyType);
+        return entityManager().merge(anyType);
     }
 
     private Collection<? extends Relationship<?, ?>> findRelationshipsByType(final RelationshipType type) {
-        TypedQuery<ARelationship> aquery = entityManager.createQuery(
+        TypedQuery<ARelationship> aquery = entityManager().createQuery(
                 "SELECT e FROM " + JPAARelationship.class.getSimpleName() + " e WHERE e.type=:type",
                 ARelationship.class);
         aquery.setParameter("type", type);
-        TypedQuery<URelationship> uquery = entityManager.createQuery(
+        TypedQuery<URelationship> uquery = entityManager().createQuery(
                 "SELECT e FROM " + JPAURelationship.class.getSimpleName() + " e WHERE e.type=:type",
                 URelationship.class);
         uquery.setParameter("type", type);
@@ -86,10 +86,10 @@ public class JPARelationshipTypeDAO extends AbstractDAO<RelationshipType, String
             }
 
             relationship.setLeftEnd(null);
-            entityManager.remove(relationship);
+            entityManager().remove(relationship);
         }
 
-        entityManager.remove(type);
+        entityManager().remove(type);
     }
 
 }


Mime
View raw message