syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdisabat...@apache.org
Subject [26/31] syncope git commit: [SYNCOPE-652] Adjusting log management
Date Fri, 14 Aug 2015 08:30:55 GMT
[SYNCOPE-652] Adjusting log management


Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/feba6991
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/feba6991
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/feba6991

Branch: refs/heads/SYNCOPE-156
Commit: feba6991edfa551d02bec421b2ec576e083755ec
Parents: bcb9a0d
Author: Francesco Chicchiriccò <ilgrosso@apache.org>
Authored: Tue Aug 11 16:19:14 2015 +0200
Committer: Francesco Chicchiriccò <ilgrosso@apache.org>
Committed: Thu Aug 13 17:16:51 2015 +0200

----------------------------------------------------------------------
 .../client/cli/commands/LoggerCommand.java      |   6 +-
 .../client/console/rest/LoggerRestClient.java   |  11 +-
 .../apache/syncope/common/lib/to/LoggerTO.java  |   2 +
 .../common/rest/api/service/LoggerService.java  |   6 +-
 core/logic/pom.xml                              |   7 +
 .../syncope/core/logic/init/LoggerAccessor.java |  95 +++++++++++++
 .../syncope/core/logic/init/LoggerLoader.java   |  65 ++-------
 .../apache/syncope/core/logic/AbstractTest.java |   1 -
 .../apache/syncope/core/logic/MappingTest.java  |  69 ----------
 core/logic/src/test/resources/logicTest.xml     |  19 ++-
 .../core/misc/security/AuthContextUtils.java    |  16 +++
 .../core/misc/security/AuthDataAccessor.java    |   6 +
 .../security/SyncopeAuthenticationProvider.java |  99 ++++++--------
 .../core/provisioning/java/MappingTest.java     |  69 ++++++++++
 .../java/ResourceDataBinderTest.java            | 130 ++++++++++++++++++
 .../java/data/ResourceDataBinderTest.java       | 132 -------------------
 .../rest/cxf/service/LoggerServiceImpl.java     |  10 +-
 .../src/main/resources/log4j2.xml               |   6 +
 .../fit/core/reference/LoggerITCase.java        |   7 +-
 19 files changed, 419 insertions(+), 337 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/feba6991/client/cli/src/main/java/org/apache/syncope/client/cli/commands/LoggerCommand.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/LoggerCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/LoggerCommand.java
index bbb826a..469e68a 100644
--- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/LoggerCommand.java
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/LoggerCommand.java
@@ -105,7 +105,7 @@ public class LoggerCommand extends AbstractCommand {
                 final LoggerTO loggerTO = loggerService.read(LoggerType.LOG, log.getKey());
                 try {
                     loggerTO.setLevel(LoggerLevel.valueOf(log.getValue()));
-                    loggerService.update(LoggerType.LOG, loggerTO.getKey(), loggerTO);
+                    loggerService.update(LoggerType.LOG, loggerTO);
                     System.out.println(" - Logger " + loggerTO.getKey() + " new level -> " + loggerTO.getLevel());
                 } catch (final SyncopeClientException ex) {
                     System.out.println(" - Error: " + ex.getMessage());
@@ -121,7 +121,7 @@ public class LoggerCommand extends AbstractCommand {
             for (final LoggerTO loggerTO : loggerService.list(LoggerType.LOG)) {
                 try {
                     loggerTO.setLevel(LoggerLevel.valueOf(logLevel));
-                    loggerService.update(LoggerType.LOG, loggerTO.getKey(), loggerTO);
+                    loggerService.update(LoggerType.LOG, loggerTO);
                     System.out.println(" - Logger " + loggerTO.getKey() + " new level -> " + loggerTO.getLevel());
                 } catch (final SyncopeClientException ex) {
                     System.out.println(" - Error: " + ex.getMessage());
@@ -140,7 +140,7 @@ public class LoggerCommand extends AbstractCommand {
                 try {
                     loggerTO.setKey(entrySet.getKey());
                     loggerTO.setLevel(LoggerLevel.valueOf(entrySet.getValue()));
-                    loggerService.update(LoggerType.LOG, loggerTO.getKey(), loggerTO);
+                    loggerService.update(LoggerType.LOG, loggerTO);
                     System.out.println(" - Logger " + loggerTO.getKey() + " created with level -> " + loggerTO.
                             getLevel());
                 } catch (final SyncopeClientException ex) {

http://git-wip-us.apache.org/repos/asf/syncope/blob/feba6991/client/console/src/main/java/org/apache/syncope/client/console/rest/LoggerRestClient.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/rest/LoggerRestClient.java b/client/console/src/main/java/org/apache/syncope/client/console/rest/LoggerRestClient.java
index 318edcb..627e828 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/rest/LoggerRestClient.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/rest/LoggerRestClient.java
@@ -59,19 +59,18 @@ public class LoggerRestClient extends BaseRestClient {
         return result;
     }
 
-    public void setLogLevel(final String name, final LoggerLevel level) {
+    public void setLogLevel(final String key, final LoggerLevel level) {
         LoggerTO loggerTO = new LoggerTO();
-        loggerTO.setKey(name);
+        loggerTO.setKey(key);
         loggerTO.setLevel(level);
-        getService(LoggerService.class).update(LoggerType.LOG, name, loggerTO);
+        getService(LoggerService.class).update(LoggerType.LOG, loggerTO);
     }
 
     public void enableAudit(final AuditLoggerName auditLoggerName) {
-        String name = auditLoggerName.toLoggerName();
         LoggerTO loggerTO = new LoggerTO();
-        loggerTO.setKey(name);
+        loggerTO.setKey(auditLoggerName.toLoggerName());
         loggerTO.setLevel(LoggerLevel.DEBUG);
-        getService(LoggerService.class).update(LoggerType.AUDIT, name, loggerTO);
+        getService(LoggerService.class).update(LoggerType.AUDIT, loggerTO);
     }
 
     public void deleteLog(final String name) {

http://git-wip-us.apache.org/repos/asf/syncope/blob/feba6991/common/lib/src/main/java/org/apache/syncope/common/lib/to/LoggerTO.java
----------------------------------------------------------------------
diff --git a/common/lib/src/main/java/org/apache/syncope/common/lib/to/LoggerTO.java b/common/lib/src/main/java/org/apache/syncope/common/lib/to/LoggerTO.java
index 810a143..6e1ce1d 100644
--- a/common/lib/src/main/java/org/apache/syncope/common/lib/to/LoggerTO.java
+++ b/common/lib/src/main/java/org/apache/syncope/common/lib/to/LoggerTO.java
@@ -18,6 +18,7 @@
  */
 package org.apache.syncope.common.lib.to;
 
+import javax.ws.rs.PathParam;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlType;
 import org.apache.syncope.common.lib.AbstractBaseBean;
@@ -41,6 +42,7 @@ public class LoggerTO extends AbstractBaseBean {
         this.level = level;
     }
 
+    @PathParam("key")
     public String getKey() {
         return key;
     }

http://git-wip-us.apache.org/repos/asf/syncope/blob/feba6991/common/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/LoggerService.java
----------------------------------------------------------------------
diff --git a/common/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/LoggerService.java b/common/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/LoggerService.java
index 6ab40e7..3b89b7c 100644
--- a/common/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/LoggerService.java
+++ b/common/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/LoggerService.java
@@ -76,14 +76,12 @@ public interface LoggerService extends JAXRSService {
      * Creates or updates (if existing) the logger with matching name.
      *
      * @param type LoggerType to be selected
-     * @param name Logger name to be updated
      * @param logger Logger to be created or updated
      */
     @PUT
-    @Path("{type}/{name}")
+    @Path("{type}/{key}")
     @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
-    void update(@NotNull @PathParam("type") LoggerType type, @NotNull @PathParam("name") String name,
-            @NotNull LoggerTO logger);
+    void update(@NotNull @PathParam("type") LoggerType type, @NotNull LoggerTO logger);
 
     /**
      * Deletes the logger with matching name.

http://git-wip-us.apache.org/repos/asf/syncope/blob/feba6991/core/logic/pom.xml
----------------------------------------------------------------------
diff --git a/core/logic/pom.xml b/core/logic/pom.xml
index 7ce109f..d652f3e 100644
--- a/core/logic/pom.xml
+++ b/core/logic/pom.xml
@@ -163,6 +163,13 @@ under the License.
         <directory>${basedir}/../persistence-jpa/src/test/resources</directory>
         <filtering>true</filtering>
       </testResource>
+      <testResource>
+        <directory>${basedir}/../provisioning-java/src/main/resources</directory>
+        <includes>
+          <include>connid.properties</include>
+        </includes>
+        <filtering>true</filtering>
+      </testResource>
     </testResources>
     
     <plugins>

http://git-wip-us.apache.org/repos/asf/syncope/blob/feba6991/core/logic/src/main/java/org/apache/syncope/core/logic/init/LoggerAccessor.java
----------------------------------------------------------------------
diff --git a/core/logic/src/main/java/org/apache/syncope/core/logic/init/LoggerAccessor.java b/core/logic/src/main/java/org/apache/syncope/core/logic/init/LoggerAccessor.java
new file mode 100644
index 0000000..e83a768
--- /dev/null
+++ b/core/logic/src/main/java/org/apache/syncope/core/logic/init/LoggerAccessor.java
@@ -0,0 +1,95 @@
+/*
+ * 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.logic.init;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.LoggerConfig;
+import org.apache.syncope.common.lib.SyncopeConstants;
+import org.apache.syncope.common.lib.types.LoggerLevel;
+import org.apache.syncope.common.lib.types.LoggerType;
+import org.apache.syncope.core.misc.security.AuthContextUtils;
+import org.apache.syncope.core.persistence.api.dao.LoggerDAO;
+import org.apache.syncope.core.persistence.api.entity.EntityFactory;
+import org.apache.syncope.core.persistence.api.entity.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * Domain-sensible (via {@code @Transactional} access to logger / audit data.
+ *
+ * @see LoggerLoader
+ */
+@Component
+public class LoggerAccessor {
+
+    @Autowired
+    private LoggerDAO loggerDAO;
+
+    @Autowired
+    private EntityFactory entityFactory;
+
+    @Transactional
+    public void synchronizeLog4J(final LoggerContext ctx) {
+        Map<String, Logger> syncopeLoggers = new HashMap<>();
+        if (SyncopeConstants.MASTER_DOMAIN.equals(AuthContextUtils.getDomain())) {
+            for (Logger syncopeLogger : loggerDAO.findAll(LoggerType.LOG)) {
+                syncopeLoggers.put(syncopeLogger.getKey(), syncopeLogger);
+            }
+        }
+        for (Logger syncopeLogger : loggerDAO.findAll(LoggerType.AUDIT)) {
+            syncopeLoggers.put(syncopeLogger.getKey(), syncopeLogger);
+        }
+
+        /*
+         * Traverse all defined log4j loggers: if there is a matching SyncopeLogger, set log4j level accordingly,
+         * otherwise create a SyncopeLogger instance with given name and level.
+         */
+        for (LoggerConfig logConf : ctx.getConfiguration().getLoggers().values()) {
+            if (!LogManager.ROOT_LOGGER_NAME.equals(logConf.getName()) && logConf.getLevel() != null) {
+                String loggerName = logConf.getName();
+                if (syncopeLoggers.containsKey(loggerName)) {
+                    logConf.setLevel(syncopeLoggers.get(loggerName).getLevel().getLevel());
+                    syncopeLoggers.remove(loggerName);
+                } else if (!loggerName.equals(LoggerType.AUDIT.getPrefix())) {
+                    Logger syncopeLogger = entityFactory.newEntity(Logger.class);
+                    syncopeLogger.setKey(loggerName);
+                    syncopeLogger.setLevel(LoggerLevel.fromLevel(logConf.getLevel()));
+                    syncopeLogger.setType(loggerName.startsWith(LoggerType.AUDIT.getPrefix())
+                            ? LoggerType.AUDIT
+                            : LoggerType.LOG);
+                    loggerDAO.save(syncopeLogger);
+                }
+            }
+        }
+
+        /*
+         * Foreach SyncopeLogger not found in log4j create a new log4j logger with given name and level.
+         */
+        for (Logger syncopeLogger : syncopeLoggers.values()) {
+            LoggerConfig logConf = ctx.getConfiguration().getLoggerConfig(syncopeLogger.getKey());
+            if (!LogManager.ROOT_LOGGER_NAME.equals(logConf.getName()) && logConf.getLevel() != null) {
+                logConf.setLevel(syncopeLogger.getLevel().getLevel());
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/feba6991/core/logic/src/main/java/org/apache/syncope/core/logic/init/LoggerLoader.java
----------------------------------------------------------------------
diff --git a/core/logic/src/main/java/org/apache/syncope/core/logic/init/LoggerLoader.java b/core/logic/src/main/java/org/apache/syncope/core/logic/init/LoggerLoader.java
index e86b46a..6187959 100644
--- a/core/logic/src/main/java/org/apache/syncope/core/logic/init/LoggerLoader.java
+++ b/core/logic/src/main/java/org/apache/syncope/core/logic/init/LoggerLoader.java
@@ -20,7 +20,6 @@ package org.apache.syncope.core.logic.init;
 
 import java.sql.Connection;
 import java.sql.SQLException;
-import java.util.HashMap;
 import java.util.Map;
 import javax.sql.DataSource;
 import org.apache.logging.log4j.Level;
@@ -31,15 +30,10 @@ import org.apache.logging.log4j.core.appender.db.jdbc.ColumnConfig;
 import org.apache.logging.log4j.core.appender.db.jdbc.ConnectionSource;
 import org.apache.logging.log4j.core.appender.db.jdbc.JdbcAppender;
 import org.apache.logging.log4j.core.config.LoggerConfig;
-import org.apache.syncope.common.lib.SyncopeConstants;
-import org.apache.syncope.common.lib.types.LoggerLevel;
-import org.apache.syncope.common.lib.types.LoggerType;
 import org.apache.syncope.core.misc.AuditManager;
+import org.apache.syncope.core.misc.security.AuthContextUtils;
 import org.apache.syncope.core.persistence.api.DomainsHolder;
 import org.apache.syncope.core.persistence.api.SyncopeLoader;
-import org.apache.syncope.core.persistence.api.dao.LoggerDAO;
-import org.apache.syncope.core.persistence.api.entity.EntityFactory;
-import org.apache.syncope.core.persistence.api.entity.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.jdbc.datasource.DataSourceUtils;
 import org.springframework.stereotype.Component;
@@ -52,10 +46,7 @@ public class LoggerLoader implements SyncopeLoader {
     private DomainsHolder domainsHolder;
 
     @Autowired
-    private LoggerDAO loggerDAO;
-
-    @Autowired
-    private EntityFactory entityFactory;
+    private LoggerAccessor loggerAccessor;
 
     @Override
     public Integer getPriority() {
@@ -65,9 +56,9 @@ public class LoggerLoader implements SyncopeLoader {
     @Transactional
     @Override
     public void load() {
-        LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
+        final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
 
-        // 1. Audit table and DataSource for each configured domain
+        // Audit table and DataSource for each configured domain
         ColumnConfig[] columns = {
             ColumnConfig.createColumnConfig(ctx.getConfiguration(), "EVENT_DATE", null, null, "true", null, null),
             ColumnConfig.createColumnConfig(ctx.getConfiguration(), "LOGGER_LEVEL", "%level", null, null, null, null),
@@ -90,52 +81,18 @@ public class LoggerLoader implements SyncopeLoader {
                 ctx.getConfiguration().addAppender(appender);
             }
 
-            LoggerConfig logConf = new LoggerConfig(
-                    AuditManager.getDomainAuditLoggerName(entry.getKey()), null, false);
+            LoggerConfig logConf = new LoggerConfig(AuditManager.getDomainAuditLoggerName(entry.getKey()), null, false);
             logConf.addAppender(appender, Level.DEBUG, null);
             ctx.getConfiguration().addLogger(AuditManager.getDomainAuditLoggerName(entry.getKey()), logConf);
-        }
-        ctx.updateLoggers();
-
-        // 2. Aligning log4j conf with database content
-        Map<String, Logger> syncopeLoggers = new HashMap<>();
-        for (Logger syncopeLogger : loggerDAO.findAll(LoggerType.LOG)) {
-            syncopeLoggers.put(syncopeLogger.getKey(), syncopeLogger);
-        }
 
-        for (Logger syncopeLogger : loggerDAO.findAll(LoggerType.AUDIT)) {
-            syncopeLoggers.put(syncopeLogger.getKey(), syncopeLogger);
-        }
+            AuthContextUtils.execWithAuthContext(entry.getKey(), new AuthContextUtils.Executable<Void>() {
 
-        /*
-         * Traverse all defined log4j loggers: if there is a matching SyncopeLogger, set log4j level accordingly,
-         * otherwise create a SyncopeLogger instance with given name and level.
-         */
-        for (LoggerConfig logConf : ctx.getConfiguration().getLoggers().values()) {
-            final String loggerName = LogManager.ROOT_LOGGER_NAME.equals(logConf.getName())
-                    ? SyncopeConstants.ROOT_LOGGER : logConf.getName();
-            if (logConf.getLevel() != null) {
-                if (syncopeLoggers.containsKey(loggerName)) {
-                    logConf.setLevel(syncopeLoggers.get(loggerName).getLevel().getLevel());
-                    syncopeLoggers.remove(loggerName);
-                } else if (!loggerName.equals(LoggerType.AUDIT.getPrefix())) {
-                    Logger syncopeLogger = entityFactory.newEntity(Logger.class);
-                    syncopeLogger.setKey(loggerName);
-                    syncopeLogger.setLevel(LoggerLevel.fromLevel(logConf.getLevel()));
-                    syncopeLogger.setType(loggerName.startsWith(LoggerType.AUDIT.getPrefix())
-                            ? LoggerType.AUDIT
-                            : LoggerType.LOG);
-                    loggerDAO.save(syncopeLogger);
+                @Override
+                public Void exec() {
+                    loggerAccessor.synchronizeLog4J(ctx);
+                    return null;
                 }
-            }
-        }
-
-        /*
-         * Foreach SyncopeLogger not found in log4j create a new log4j logger with given name and level.
-         */
-        for (Logger syncopeLogger : syncopeLoggers.values()) {
-            LoggerConfig logConf = ctx.getConfiguration().getLoggerConfig(syncopeLogger.getKey());
-            logConf.setLevel(syncopeLogger.getLevel().getLevel());
+            });
         }
 
         ctx.updateLoggers();

http://git-wip-us.apache.org/repos/asf/syncope/blob/feba6991/core/logic/src/test/java/org/apache/syncope/core/logic/AbstractTest.java
----------------------------------------------------------------------
diff --git a/core/logic/src/test/java/org/apache/syncope/core/logic/AbstractTest.java b/core/logic/src/test/java/org/apache/syncope/core/logic/AbstractTest.java
index d4b0fa4..32ae367 100644
--- a/core/logic/src/test/java/org/apache/syncope/core/logic/AbstractTest.java
+++ b/core/logic/src/test/java/org/apache/syncope/core/logic/AbstractTest.java
@@ -30,7 +30,6 @@ import org.springframework.test.context.transaction.TransactionConfiguration;
     "classpath:provisioningContext.xml",
     "classpath:logicContext.xml",
     "classpath:workflowContext.xml",
-    "classpath:persistenceTest.xml",
     "classpath:logicTest.xml"
 })
 @TransactionConfiguration(transactionManager = "MasterTransactionManager")

http://git-wip-us.apache.org/repos/asf/syncope/blob/feba6991/core/logic/src/test/java/org/apache/syncope/core/logic/MappingTest.java
----------------------------------------------------------------------
diff --git a/core/logic/src/test/java/org/apache/syncope/core/logic/MappingTest.java b/core/logic/src/test/java/org/apache/syncope/core/logic/MappingTest.java
deleted file mode 100644
index 770bac9..0000000
--- a/core/logic/src/test/java/org/apache/syncope/core/logic/MappingTest.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * 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.logic;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import org.apache.syncope.core.misc.MappingUtils;
-import org.apache.syncope.core.persistence.api.dao.AnyTypeDAO;
-import org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO;
-import org.apache.syncope.core.persistence.api.dao.UserDAO;
-import org.apache.syncope.core.persistence.api.entity.resource.ExternalResource;
-import org.apache.syncope.core.persistence.api.entity.resource.Provision;
-import org.apache.syncope.core.persistence.api.entity.user.User;
-import org.identityconnectors.framework.common.objects.Name;
-import org.junit.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.transaction.annotation.Transactional;
-
-@Transactional
-public class MappingTest extends AbstractTest {
-
-    @Autowired
-    private ExternalResourceDAO resourceDAO;
-
-    @Autowired
-    private AnyTypeDAO anyTypeDAO;
-
-    @Autowired
-    private UserDAO userDAO;
-
-    @Test
-    public void connObjectLink() {
-        ExternalResource ldap = resourceDAO.find("resource-ldap");
-        assertNotNull(ldap);
-
-        Provision provision = ldap.getProvision(anyTypeDAO.findUser());
-        assertNotNull(provision);
-        assertNotNull(provision.getMapping());
-        assertNotNull(provision.getMapping().getConnObjectLink());
-
-        User user = userDAO.find("rossini");
-        assertNotNull(user);
-
-        Name name = MappingUtils.evaluateNAME(user, provision, user.getUsername());
-        assertEquals("uid=rossini,ou=people,o=isp", name.getNameValue());
-
-        provision.getMapping().setConnObjectLink("'uid=' + username + ',o=' + realm + ',ou=people,o=isp'");
-
-        name = MappingUtils.evaluateNAME(user, provision, user.getUsername());
-        assertEquals("uid=rossini,o=even,ou=people,o=isp", name.getNameValue());
-    }
-}

http://git-wip-us.apache.org/repos/asf/syncope/blob/feba6991/core/logic/src/test/resources/logicTest.xml
----------------------------------------------------------------------
diff --git a/core/logic/src/test/resources/logicTest.xml b/core/logic/src/test/resources/logicTest.xml
index 2dca918..fd6edd6 100644
--- a/core/logic/src/test/resources/logicTest.xml
+++ b/core/logic/src/test/resources/logicTest.xml
@@ -19,8 +19,11 @@ under the License.
 -->
 <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
-                           http://www.springframework.org/schema/beans/spring-beans.xsd">
+                           http://www.springframework.org/schema/beans/spring-beans.xsd
+                           http://www.springframework.org/schema/context
+                           http://www.springframework.org/schema/context/spring-context.xsd">
     
   <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
     <property name="locations">
@@ -39,4 +42,18 @@ under the License.
     <property name="ignoreUnresolvablePlaceholders" value="true"/>
   </bean>
 
+  <bean class="org.apache.syncope.core.misc.spring.ApplicationContextProvider"/>
+
+  <bean id="adminUser" class="java.lang.String">
+    <constructor-arg value="${adminUser}"/>
+  </bean>
+  <bean id="anonymousUser" class="java.lang.String">
+    <constructor-arg value="${anonymousUser}"/>
+  </bean>
+  
+  <context:component-scan base-package="org.apache.syncope.core.misc.policy"/>
+  <context:component-scan base-package="org.apache.syncope.core.misc.security"/>
+
+  <import resource="persistenceContext.xml"/>
+  
 </beans>

http://git-wip-us.apache.org/repos/asf/syncope/blob/feba6991/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 38240d9..4586ee3 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
@@ -39,6 +39,11 @@ import org.springframework.security.core.userdetails.User;
 
 public final class AuthContextUtils {
 
+    public interface Executable<T> {
+
+        T exec();
+    }
+
     public static String getUsername() {
         Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
         return authentication == null ? SyncopeConstants.UNAUTHENTICATED : authentication.getName();
@@ -106,6 +111,17 @@ public final class AuthContextUtils {
         SecurityContextHolder.clearContext();
     }
 
+    public static <T> T execWithAuthContext(final String domainKey, final Executable<T> executable) {
+        SecurityContext ctx = SecurityContextHolder.getContext();
+        setFakeAuth(domainKey);
+        try {
+            return executable.exec();
+        } finally {
+            clearFakeAuth();
+            SecurityContextHolder.setContext(ctx);
+        }
+    }
+
     /**
      * Private default constructor, for static-only classes.
      */

http://git-wip-us.apache.org/repos/asf/syncope/blob/feba6991/core/misc/src/main/java/org/apache/syncope/core/misc/security/AuthDataAccessor.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/security/AuthDataAccessor.java b/core/misc/src/main/java/org/apache/syncope/core/misc/security/AuthDataAccessor.java
index 7643f9d..052cc30 100644
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/security/AuthDataAccessor.java
+++ b/core/misc/src/main/java/org/apache/syncope/core/misc/security/AuthDataAccessor.java
@@ -64,6 +64,12 @@ import org.springframework.security.core.Authentication;
 import org.springframework.security.core.userdetails.UsernameNotFoundException;
 import org.springframework.transaction.annotation.Transactional;
 
+/**
+ * Domain-sensible (via {@code @Transactional} access to authentication / authorization data.
+ *
+ * @see SyncopeAuthenticationProvider
+ * @see SyncopeAuthenticationDetails
+ */
 public class AuthDataAccessor {
 
     protected static final Logger LOG = LoggerFactory.getLogger(AuthDataAccessor.class);

http://git-wip-us.apache.org/repos/asf/syncope/blob/feba6991/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 c8fa53d..ff7e453 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
@@ -25,6 +25,7 @@ import org.apache.syncope.common.lib.SyncopeConstants;
 import org.apache.syncope.common.lib.types.AuditElements;
 import org.apache.syncope.common.lib.types.AuditElements.Result;
 import org.apache.syncope.common.lib.types.CipherAlgorithm;
+import org.apache.syncope.core.misc.security.AuthContextUtils.Executable;
 import org.apache.syncope.core.persistence.api.entity.Domain;
 import org.apache.syncope.core.provisioning.api.UserProvisioningManager;
 import org.slf4j.Logger;
@@ -35,8 +36,6 @@ import org.springframework.security.authentication.AuthenticationProvider;
 import org.springframework.security.authentication.BadCredentialsException;
 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
 import org.springframework.security.core.Authentication;
-import org.springframework.security.core.context.SecurityContext;
-import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.security.core.userdetails.UserDetailsService;
 
 @Configurable
@@ -91,17 +90,6 @@ public class SyncopeAuthenticationProvider implements AuthenticationProvider {
         this.userDetailsService = syncopeUserDetailsService;
     }
 
-    protected <T> T execWithAuthContext(final String domainKey, final Executable<T> executable) {
-        SecurityContext ctx = SecurityContextHolder.getContext();
-        AuthContextUtils.setFakeAuth(domainKey);
-        try {
-            return executable.exec();
-        } finally {
-            AuthContextUtils.clearFakeAuth();
-            SecurityContextHolder.setContext(ctx);
-        }
-    }
-
     @Override
     public Authentication authenticate(final Authentication authentication) {
         String domainKey = SyncopeAuthenticationDetails.class.cast(authentication.getDetails()).getDomain();
@@ -121,22 +109,23 @@ public class SyncopeAuthenticationProvider implements AuthenticationProvider {
                         adminPassword);
             } else {
                 final String domainToFind = domainKey;
-                authenticated = execWithAuthContext(SyncopeConstants.MASTER_DOMAIN, new Executable<Boolean>() {
-
-                    @Override
-                    public Boolean exec() {
-                        Domain domain = dataAccessor.findDomain(domainToFind);
-
-                        return encryptor.verify(
-                                authentication.getCredentials().toString(),
-                                domain.getAdminCipherAlgorithm(),
-                                domain.getAdminPwd());
-                    }
-                });
+                authenticated = AuthContextUtils.execWithAuthContext(
+                        SyncopeConstants.MASTER_DOMAIN, new Executable<Boolean>() {
+
+                            @Override
+                            public Boolean exec() {
+                                Domain domain = dataAccessor.findDomain(domainToFind);
+
+                                return encryptor.verify(
+                                        authentication.getCredentials().toString(),
+                                        domain.getAdminCipherAlgorithm(),
+                                        domain.getAdminPwd());
+                            }
+                        });
             }
         } else {
             final Pair<Long, Boolean> authResult =
-                    execWithAuthContext(domainKey, new Executable<Pair<Long, Boolean>>() {
+                    AuthContextUtils.execWithAuthContext(domainKey, new Executable<Pair<Long, Boolean>>() {
 
                         @Override
                         public Pair<Long, Boolean> exec() {
@@ -145,7 +134,7 @@ public class SyncopeAuthenticationProvider implements AuthenticationProvider {
                     });
             authenticated = authResult.getValue();
             if (!authenticated) {
-                execWithAuthContext(domainKey, new Executable<Void>() {
+                AuthContextUtils.execWithAuthContext(domainKey, new Executable<Void>() {
 
                     @Override
                     public Void exec() {
@@ -159,35 +148,36 @@ public class SyncopeAuthenticationProvider implements AuthenticationProvider {
         final boolean isAuthenticated = authenticated;
         UsernamePasswordAuthenticationToken token;
         if (isAuthenticated) {
-            token = execWithAuthContext(domainKey, new Executable<UsernamePasswordAuthenticationToken>() {
-
-                @Override
-                public UsernamePasswordAuthenticationToken exec() {
-                    UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(
-                            authentication.getPrincipal(),
-                            null,
-                            userDetailsService.loadUserByUsername(authentication.getPrincipal().toString()).
-                            getAuthorities());
-                    token.setDetails(authentication.getDetails());
+            token = AuthContextUtils.execWithAuthContext(
+                    domainKey, new Executable<UsernamePasswordAuthenticationToken>() {
 
-                    dataAccessor.audit(
-                            AuditElements.EventCategoryType.REST,
-                            AuditElements.AUTHENTICATION_CATEGORY,
-                            null,
-                            AuditElements.LOGIN_EVENT,
-                            Result.SUCCESS,
-                            null,
-                            isAuthenticated,
-                            authentication,
-                            "Successfully authenticated, with entitlements: " + token.getAuthorities());
-                    return token;
-                }
-            });
+                        @Override
+                        public UsernamePasswordAuthenticationToken exec() {
+                            UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(
+                                    authentication.getPrincipal(),
+                                    null,
+                                    userDetailsService.loadUserByUsername(authentication.getPrincipal().toString()).
+                                    getAuthorities());
+                            token.setDetails(authentication.getDetails());
+
+                            dataAccessor.audit(
+                                    AuditElements.EventCategoryType.REST,
+                                    AuditElements.AUTHENTICATION_CATEGORY,
+                                    null,
+                                    AuditElements.LOGIN_EVENT,
+                                    Result.SUCCESS,
+                                    null,
+                                    isAuthenticated,
+                                    authentication,
+                                    "Successfully authenticated, with entitlements: " + token.getAuthorities());
+                            return token;
+                        }
+                    });
 
-            LOG.debug("User {} successfully authenticated, with groups {}",
+            LOG.debug("User {} successfully authenticated, with entitlements {}",
                     authentication.getPrincipal(), token.getAuthorities());
         } else {
-            execWithAuthContext(domainKey, new Executable<Void>() {
+            AuthContextUtils.execWithAuthContext(domainKey, new Executable<Void>() {
 
                 @Override
                 public Void exec() {
@@ -217,9 +207,4 @@ public class SyncopeAuthenticationProvider implements AuthenticationProvider {
     public boolean supports(final Class<? extends Object> type) {
         return type.equals(UsernamePasswordAuthenticationToken.class);
     }
-
-    protected interface Executable<T> {
-
-        T exec();
-    }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/feba6991/core/provisioning-java/src/test/java/org/apache/syncope/core/provisioning/java/MappingTest.java
----------------------------------------------------------------------
diff --git a/core/provisioning-java/src/test/java/org/apache/syncope/core/provisioning/java/MappingTest.java b/core/provisioning-java/src/test/java/org/apache/syncope/core/provisioning/java/MappingTest.java
new file mode 100644
index 0000000..eb100f3
--- /dev/null
+++ b/core/provisioning-java/src/test/java/org/apache/syncope/core/provisioning/java/MappingTest.java
@@ -0,0 +1,69 @@
+/*
+ * 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.provisioning.java;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.apache.syncope.core.misc.MappingUtils;
+import org.apache.syncope.core.persistence.api.dao.AnyTypeDAO;
+import org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO;
+import org.apache.syncope.core.persistence.api.dao.UserDAO;
+import org.apache.syncope.core.persistence.api.entity.resource.ExternalResource;
+import org.apache.syncope.core.persistence.api.entity.resource.Provision;
+import org.apache.syncope.core.persistence.api.entity.user.User;
+import org.identityconnectors.framework.common.objects.Name;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+@Transactional
+public class MappingTest extends AbstractTest {
+
+    @Autowired
+    private ExternalResourceDAO resourceDAO;
+
+    @Autowired
+    private AnyTypeDAO anyTypeDAO;
+
+    @Autowired
+    private UserDAO userDAO;
+
+    @Test
+    public void connObjectLink() {
+        ExternalResource ldap = resourceDAO.find("resource-ldap");
+        assertNotNull(ldap);
+
+        Provision provision = ldap.getProvision(anyTypeDAO.findUser());
+        assertNotNull(provision);
+        assertNotNull(provision.getMapping());
+        assertNotNull(provision.getMapping().getConnObjectLink());
+
+        User user = userDAO.find("rossini");
+        assertNotNull(user);
+
+        Name name = MappingUtils.evaluateNAME(user, provision, user.getUsername());
+        assertEquals("uid=rossini,ou=people,o=isp", name.getNameValue());
+
+        provision.getMapping().setConnObjectLink("'uid=' + username + ',o=' + realm + ',ou=people,o=isp'");
+
+        name = MappingUtils.evaluateNAME(user, provision, user.getUsername());
+        assertEquals("uid=rossini,o=even,ou=people,o=isp", name.getNameValue());
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/feba6991/core/provisioning-java/src/test/java/org/apache/syncope/core/provisioning/java/ResourceDataBinderTest.java
----------------------------------------------------------------------
diff --git a/core/provisioning-java/src/test/java/org/apache/syncope/core/provisioning/java/ResourceDataBinderTest.java b/core/provisioning-java/src/test/java/org/apache/syncope/core/provisioning/java/ResourceDataBinderTest.java
new file mode 100644
index 0000000..f0a706c
--- /dev/null
+++ b/core/provisioning-java/src/test/java/org/apache/syncope/core/provisioning/java/ResourceDataBinderTest.java
@@ -0,0 +1,130 @@
+/*
+ * 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.provisioning.java;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.HashSet;
+import java.util.Set;
+import org.apache.syncope.common.lib.to.MappingItemTO;
+import org.apache.syncope.common.lib.to.MappingTO;
+import org.apache.syncope.common.lib.to.ProvisionTO;
+import org.apache.syncope.common.lib.to.ResourceTO;
+import org.apache.syncope.common.lib.types.AnyTypeKind;
+import org.apache.syncope.common.lib.types.IntMappingType;
+import org.apache.syncope.common.lib.types.MappingPurpose;
+import org.apache.syncope.common.lib.types.PropagationMode;
+import org.apache.syncope.core.persistence.api.dao.AnyTypeDAO;
+import org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO;
+import org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO;
+import org.apache.syncope.core.persistence.api.entity.PlainSchema;
+import org.apache.syncope.core.persistence.api.entity.resource.ExternalResource;
+import org.apache.syncope.core.persistence.api.entity.resource.MappingItem;
+import org.apache.syncope.core.provisioning.api.data.ResourceDataBinder;
+import org.identityconnectors.framework.common.objects.ObjectClass;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+@Transactional
+public class ResourceDataBinderTest extends AbstractTest {
+
+    @Autowired
+    private AnyTypeDAO anyTypeDAO;
+
+    @Autowired
+    private ExternalResourceDAO resourceDAO;
+
+    @Autowired
+    private ResourceDataBinder resourceDataBinder;
+
+    @Autowired
+    private PlainSchemaDAO plainSchemaDAO;
+
+    @Test
+    public void issue42() {
+        PlainSchema userId = plainSchemaDAO.find("userId");
+
+        Set<MappingItem> beforeUserIdMappings = new HashSet<>();
+        for (ExternalResource res : resourceDAO.findAll()) {
+            if (res.getProvision(anyTypeDAO.findUser()) != null
+                    && res.getProvision(anyTypeDAO.findUser()).getMapping() != null) {
+
+                for (MappingItem mapItem : res.getProvision(anyTypeDAO.findUser()).getMapping().getItems()) {
+                    if (userId.getKey().equals(mapItem.getIntAttrName())) {
+                        beforeUserIdMappings.add(mapItem);
+                    }
+                }
+            }
+        }
+
+        ResourceTO resourceTO = new ResourceTO();
+        resourceTO.setKey("resource-issue42");
+        resourceTO.setConnector(100L);
+        resourceTO.setPropagationMode(PropagationMode.ONE_PHASE);
+        resourceTO.setEnforceMandatoryCondition(true);
+
+        ProvisionTO provisionTO = new ProvisionTO();
+        provisionTO.setAnyType(AnyTypeKind.USER.name());
+        provisionTO.setObjectClass(ObjectClass.ACCOUNT_NAME);
+        resourceTO.getProvisions().add(provisionTO);
+
+        MappingTO mapping = new MappingTO();
+        provisionTO.setMapping(mapping);
+
+        MappingItemTO item = new MappingItemTO();
+        item.setIntAttrName("userId");
+        item.setIntMappingType(IntMappingType.UserPlainSchema);
+        item.setExtAttrName("campo1");
+        item.setConnObjectKey(true);
+        item.setMandatoryCondition("false");
+        item.setPurpose(MappingPurpose.BOTH);
+        mapping.setConnObjectKeyItem(item);
+
+        ExternalResource resource = resourceDataBinder.create(resourceTO);
+        resource = resourceDAO.save(resource);
+        assertNotNull(resource);
+        assertNotNull(resource.getProvision(anyTypeDAO.findUser()).getMapping());
+        assertEquals(1, resource.getProvision(anyTypeDAO.findUser()).getMapping().getItems().size());
+
+        resourceDAO.flush();
+
+        ExternalResource actual = resourceDAO.find("resource-issue42");
+        assertNotNull(actual);
+        assertEquals(resource, actual);
+
+        userId = plainSchemaDAO.find("userId");
+
+        Set<MappingItem> afterUserIdMappings = new HashSet<>();
+        for (ExternalResource res : resourceDAO.findAll()) {
+            if (res.getProvision(anyTypeDAO.findUser()) != null
+                    && res.getProvision(anyTypeDAO.findUser()).getMapping() != null) {
+
+                for (MappingItem mapItem : res.getProvision(anyTypeDAO.findUser()).getMapping().getItems()) {
+                    if (userId.getKey().equals(mapItem.getIntAttrName())) {
+                        afterUserIdMappings.add(mapItem);
+                    }
+                }
+            }
+        }
+
+        assertEquals(beforeUserIdMappings.size(), afterUserIdMappings.size() - 1);
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/feba6991/core/provisioning-java/src/test/java/org/apache/syncope/core/provisioning/java/data/ResourceDataBinderTest.java
----------------------------------------------------------------------
diff --git a/core/provisioning-java/src/test/java/org/apache/syncope/core/provisioning/java/data/ResourceDataBinderTest.java b/core/provisioning-java/src/test/java/org/apache/syncope/core/provisioning/java/data/ResourceDataBinderTest.java
deleted file mode 100644
index f2eb839..0000000
--- a/core/provisioning-java/src/test/java/org/apache/syncope/core/provisioning/java/data/ResourceDataBinderTest.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * 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.provisioning.java.data;
-
-import org.apache.syncope.core.provisioning.java.AbstractTest;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.util.HashSet;
-import java.util.Set;
-import org.apache.syncope.common.lib.to.MappingItemTO;
-import org.apache.syncope.common.lib.to.MappingTO;
-import org.apache.syncope.common.lib.to.ProvisionTO;
-import org.apache.syncope.common.lib.to.ResourceTO;
-import org.apache.syncope.common.lib.types.AnyTypeKind;
-import org.apache.syncope.common.lib.types.IntMappingType;
-import org.apache.syncope.common.lib.types.MappingPurpose;
-import org.apache.syncope.common.lib.types.PropagationMode;
-import org.apache.syncope.core.persistence.api.dao.AnyTypeDAO;
-import org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO;
-import org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO;
-import org.apache.syncope.core.persistence.api.entity.PlainSchema;
-import org.apache.syncope.core.persistence.api.entity.resource.ExternalResource;
-import org.apache.syncope.core.persistence.api.entity.resource.MappingItem;
-import org.apache.syncope.core.provisioning.api.data.ResourceDataBinder;
-import org.identityconnectors.framework.common.objects.ObjectClass;
-import org.junit.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.transaction.annotation.Transactional;
-
-@Transactional
-public class ResourceDataBinderTest extends AbstractTest {
-
-    @Autowired
-    private AnyTypeDAO anyTypeDAO;
-
-    @Autowired
-    private ExternalResourceDAO resourceDAO;
-
-    @Autowired
-    private ResourceDataBinder resourceDataBinder;
-
-    @Autowired
-    private PlainSchemaDAO plainSchemaDAO;
-
-    @Test
-    public void issue42() {
-        PlainSchema userId = plainSchemaDAO.find("userId");
-
-        Set<MappingItem> beforeUserIdMappings = new HashSet<>();
-        for (ExternalResource res : resourceDAO.findAll()) {
-            if (res.getProvision(anyTypeDAO.findUser()) != null
-                    && res.getProvision(anyTypeDAO.findUser()).getMapping() != null) {
-
-                for (MappingItem mapItem : res.getProvision(anyTypeDAO.findUser()).getMapping().getItems()) {
-                    if (userId.getKey().equals(mapItem.getIntAttrName())) {
-                        beforeUserIdMappings.add(mapItem);
-                    }
-                }
-            }
-        }
-
-        ResourceTO resourceTO = new ResourceTO();
-        resourceTO.setKey("resource-issue42");
-        resourceTO.setConnector(100L);
-        resourceTO.setPropagationMode(PropagationMode.ONE_PHASE);
-        resourceTO.setEnforceMandatoryCondition(true);
-
-        ProvisionTO provisionTO = new ProvisionTO();
-        provisionTO.setAnyType(AnyTypeKind.USER.name());
-        provisionTO.setObjectClass(ObjectClass.ACCOUNT_NAME);
-        resourceTO.getProvisions().add(provisionTO);
-
-        MappingTO mapping = new MappingTO();
-        provisionTO.setMapping(mapping);
-
-        MappingItemTO item = new MappingItemTO();
-        item.setIntAttrName("userId");
-        item.setIntMappingType(IntMappingType.UserPlainSchema);
-        item.setExtAttrName("campo1");
-        item.setConnObjectKey(true);
-        item.setMandatoryCondition("false");
-        item.setPurpose(MappingPurpose.BOTH);
-        mapping.setConnObjectKeyItem(item);
-
-        ExternalResource resource = resourceDataBinder.create(resourceTO);
-        resource = resourceDAO.save(resource);
-        assertNotNull(resource);
-        assertNotNull(resource.getProvision(anyTypeDAO.findUser()).getMapping());
-        assertEquals(1, resource.getProvision(anyTypeDAO.findUser()).getMapping().getItems().size());
-
-        resourceDAO.flush();
-
-        ExternalResource actual = resourceDAO.find("resource-issue42");
-        assertNotNull(actual);
-        assertEquals(resource, actual);
-
-        userId = plainSchemaDAO.find("userId");
-
-        Set<MappingItem> afterUserIdMappings = new HashSet<>();
-        for (ExternalResource res : resourceDAO.findAll()) {
-            if (res.getProvision(anyTypeDAO.findUser()) != null
-                    && res.getProvision(anyTypeDAO.findUser()).getMapping() != null) {
-
-                for (MappingItem mapItem : res.getProvision(anyTypeDAO.findUser()).getMapping().getItems()) {
-                    if (userId.getKey().equals(mapItem.getIntAttrName())) {
-                        afterUserIdMappings.add(mapItem);
-                    }
-                }
-            }
-        }
-
-        assertEquals(beforeUserIdMappings.size(), afterUserIdMappings.size() - 1);
-    }
-}

http://git-wip-us.apache.org/repos/asf/syncope/blob/feba6991/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/LoggerServiceImpl.java
----------------------------------------------------------------------
diff --git a/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/LoggerServiceImpl.java b/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/LoggerServiceImpl.java
index 2ae9136..4379754 100644
--- a/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/LoggerServiceImpl.java
+++ b/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/LoggerServiceImpl.java
@@ -48,9 +48,7 @@ public class LoggerServiceImpl extends AbstractServiceImpl implements LoggerServ
             case AUDIT:
                 try {
                     logic.disableAudit(AuditLoggerName.fromLoggerName(name));
-                } catch (IllegalArgumentException e) {
-                    throw new BadRequestException(e);
-                } catch (ParseException e) {
+                } catch (IllegalArgumentException | ParseException e) {
                     throw new BadRequestException(e);
                 }
                 break;
@@ -88,15 +86,15 @@ public class LoggerServiceImpl extends AbstractServiceImpl implements LoggerServ
     }
 
     @Override
-    public void update(final LoggerType type, final String name, final LoggerTO logger) {
+    public void update(final LoggerType type, final LoggerTO logger) {
         switch (type) {
             case LOG:
-                logic.setLogLevel(name, logger.getLevel().getLevel());
+                logic.setLogLevel(logger.getKey(), logger.getLevel().getLevel());
                 break;
 
             case AUDIT:
                 try {
-                    logic.enableAudit(AuditLoggerName.fromLoggerName(name));
+                    logic.enableAudit(AuditLoggerName.fromLoggerName(logger.getKey()));
                 } catch (Exception e) {
                     throw new BadRequestException(e);
                 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/feba6991/fit/core-reference/src/main/resources/log4j2.xml
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/main/resources/log4j2.xml b/fit/core-reference/src/main/resources/log4j2.xml
index b50d9cb..df1de40 100644
--- a/fit/core-reference/src/main/resources/log4j2.xml
+++ b/fit/core-reference/src/main/resources/log4j2.xml
@@ -103,6 +103,9 @@ under the License.
       <appender-ref ref="connid"/>
     </asyncLogger>
     
+    <asyncLogger name="org.apache.syncope" additivity="false" level="ERROR">
+      <appender-ref ref="main"/>
+    </asyncLogger>
     <asyncLogger name="org.apache.syncope.core.provisioning" additivity="false" level="INFO">
       <appender-ref ref="main"/>
     </asyncLogger>
@@ -115,6 +118,9 @@ under the License.
     <asyncLogger name="org.quartz" additivity="false" level="INFO">
       <appender-ref ref="main"/>
     </asyncLogger>
+    <asyncLogger name="org.activiti" additivity="false" level="ERROR">
+      <appender-ref ref="main"/>
+    </asyncLogger>
     <asyncLogger name="org.apache.camel" additivity="false" level="ERROR">
       <appender-ref ref="main"/>
     </asyncLogger>

http://git-wip-us.apache.org/repos/asf/syncope/blob/feba6991/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/LoggerITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/LoggerITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/LoggerITCase.java
index 40fe8a1..fb93618 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/LoggerITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/LoggerITCase.java
@@ -76,7 +76,7 @@ public class LoggerITCase extends AbstractITCase {
         LoggerTO logger = new LoggerTO();
         logger.setKey("TEST");
         logger.setLevel(LoggerLevel.INFO);
-        loggerService.update(LoggerType.LOG, logger.getKey(), logger);
+        loggerService.update(LoggerType.LOG, logger);
         logger = loggerService.read(LoggerType.LOG, logger.getKey());
         assertNotNull(logger);
         assertEquals(LoggerLevel.INFO, logger.getLevel());
@@ -106,10 +106,9 @@ public class LoggerITCase extends AbstractITCase {
         assertFalse(audits.contains(auditLoggerName));
 
         LoggerTO loggerTO = new LoggerTO();
-        String name = auditLoggerName.toLoggerName();
-        loggerTO.setKey(name);
+        loggerTO.setKey(auditLoggerName.toLoggerName());
         loggerTO.setLevel(LoggerLevel.DEBUG);
-        loggerService.update(LoggerType.AUDIT, name, loggerTO);
+        loggerService.update(LoggerType.AUDIT, loggerTO);
 
         audits = CollectionWrapper.wrapLogger(loggerService.list(LoggerType.AUDIT));
         assertNotNull(audits);


Mime
View raw message