syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject svn commit: r1463506 - in /syncope/trunk/core: ./ src/main/java/org/apache/syncope/core/init/ src/main/java/org/apache/syncope/core/persistence/beans/ src/main/java/org/apache/syncope/core/persistence/dao/impl/ src/main/java/org/apache/syncope/core/res...
Date Tue, 02 Apr 2013 12:40:45 GMT
Author: ilgrosso
Date: Tue Apr  2 12:40:45 2013
New Revision: 1463506

URL: http://svn.apache.org/r1463506
Log:
[SYNCOPE-276] Implemented feature for upgrading existing content of internal storage + authenticator
with MD5 fallback

Added:
    syncope/trunk/core/src/main/java/org/apache/syncope/core/init/ContentUpgrader.java   (with
props)
    syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/dao/impl/AbstractContentDealer.java
  (with props)
    syncope/trunk/core/src/main/java/org/apache/syncope/core/security/SyncopeMD5FallbackAuthenticationProvider.java
  (with props)
Modified:
    syncope/trunk/core/pom.xml
    syncope/trunk/core/src/main/java/org/apache/syncope/core/init/JobInstanceLoader.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/init/SpringContextInitializer.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/ExternalResource.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/Policy.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/ReportletConfInstance.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/SyncTask.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/dao/impl/ContentLoader.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/ResourceDataBinder.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/security/SyncopeAuthenticationProvider.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/util/PasswordEncoder.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/workflow/ActivitiDetector.java

Modified: syncope/trunk/core/pom.xml
URL: http://svn.apache.org/viewvc/syncope/trunk/core/pom.xml?rev=1463506&r1=1463505&r2=1463506&view=diff
==============================================================================
--- syncope/trunk/core/pom.xml (original)
+++ syncope/trunk/core/pom.xml Tue Apr  2 12:40:45 2013
@@ -1066,7 +1066,7 @@ under the License.
         <dependency>
           <groupId>mysql</groupId>
           <artifactId>mysql-connector-java</artifactId>
-          <version>5.1.23</version>
+          <version>5.1.24</version>
           <scope>test</scope>
         </dependency>
       </dependencies>

Added: syncope/trunk/core/src/main/java/org/apache/syncope/core/init/ContentUpgrader.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/init/ContentUpgrader.java?rev=1463506&view=auto
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/init/ContentUpgrader.java (added)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/init/ContentUpgrader.java Tue
Apr  2 12:40:45 2013
@@ -0,0 +1,304 @@
+/*
+ * 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.init;
+
+import java.lang.reflect.Field;
+import java.net.URI;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import javax.sql.DataSource;
+import org.apache.commons.lang.StringUtils;
+import org.apache.syncope.common.search.NodeCond;
+import org.apache.syncope.common.to.UserTO;
+import org.apache.syncope.common.types.AbstractPolicySpec;
+import org.apache.syncope.common.types.CipherAlgorithm;
+import org.apache.syncope.common.types.ConnConfProperty;
+import org.apache.syncope.core.persistence.beans.ConnInstance;
+import org.apache.syncope.core.persistence.beans.ExternalResource;
+import org.apache.syncope.core.persistence.beans.Notification;
+import org.apache.syncope.core.persistence.beans.Policy;
+import org.apache.syncope.core.persistence.beans.SyncTask;
+import org.apache.syncope.core.persistence.beans.SyncopeConf;
+import org.apache.syncope.core.persistence.beans.UserRequest;
+import org.apache.syncope.core.persistence.dao.ConfDAO;
+import org.apache.syncope.core.persistence.dao.ConnInstanceDAO;
+import org.apache.syncope.core.persistence.dao.NotificationDAO;
+import org.apache.syncope.core.persistence.dao.PolicyDAO;
+import org.apache.syncope.core.persistence.dao.ResourceDAO;
+import org.apache.syncope.core.persistence.dao.TaskDAO;
+import org.apache.syncope.core.persistence.dao.UserRequestDAO;
+import org.apache.syncope.core.persistence.dao.impl.AbstractContentDealer;
+import org.apache.syncope.core.util.ConnIdBundleManager;
+import org.apache.syncope.core.util.XMLSerializer;
+import org.apache.syncope.core.workflow.ActivitiDetector;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.datasource.DataSourceUtils;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.ReflectionUtils;
+
+/**
+ * Upgrade internal storage content according to format expected by this Syncope release.
+ */
+@Component
+public class ContentUpgrader extends AbstractContentDealer {
+
+    @Autowired
+    private DataSource dataSource;
+
+    @Autowired
+    private ConfDAO confDAO;
+
+    @Autowired
+    private ConnInstanceDAO connInstanceDAO;
+
+    @Autowired
+    private ResourceDAO resourceDAO;
+
+    @Autowired
+    private PolicyDAO policyDAO;
+
+    @Autowired
+    private NotificationDAO notificationDAO;
+
+    @Autowired
+    private TaskDAO taskDAO;
+
+    @Autowired
+    private UserRequestDAO userRequestDAO;
+
+    private void upgradeActiviti() {
+        JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
+
+        List<Map<String, Object>> byteArrays =
+                jdbcTemplate.queryForList("SELECT ID_, BYTES_ FROM ACT_GE_BYTEARRAY");
+        for (Map<String, Object> row : byteArrays) {
+            byte[] updated = new String((byte[]) row.get("BYTES_")).replaceAll(
+                    "org\\.apache.syncope\\.core\\.workflow\\.activiti\\.",
+                    "org.apache.syncope.core.workflow.user.activiti.task.").
+                    replaceAll("org\\.apache\\.syncope\\.client\\.to\\.",
+                    "org.apache.syncope.common.to").
+                    replaceAll("org\\.apache\\.syncope\\.types\\.",
+                    "org.apache.syncope.common.types").
+                    replaceAll("org/apache/syncope/types/",
+                    "org/apache/syncope/common/types/").
+                    getBytes();
+            jdbcTemplate.update("UPDATE ACT_GE_BYTEARRAY SET BYTES_=? WHERE ID_=?",
+                    new Object[] {updated, row.get("ID_")});
+        }
+    }
+
+    private String upgradeSyncopeConf() {
+        confDAO.delete("connid.bundles.directory");
+
+        URI localConnIdLocation = null;
+        for (URI location : ConnIdBundleManager.getConnManagers().keySet()) {
+            if ("file".equals(location.getScheme())) {
+                localConnIdLocation = location;
+            }
+        }
+        if (localConnIdLocation == null) {
+            throw new IllegalArgumentException("No local ConnId location was found, aborting");
+        }
+
+        SyncopeConf cipher = confDAO.find("password.cipher.algorithm");
+        if ("MD5".equals(cipher.getValue())) {
+            cipher.setValue(CipherAlgorithm.SMD5.name());
+        }
+
+        return localConnIdLocation.toString();
+    }
+
+    private void upgradeConnInstance(final String localConnIdLocation) {
+        Field xmlConfiguration = ReflectionUtils.findField(ConnInstance.class, "xmlConfiguration");
+        xmlConfiguration.setAccessible(true);
+        for (ConnInstance connInstance : connInstanceDAO.findAll()) {
+            connInstance.setLocation(localConnIdLocation);
+
+            try {
+                String oldConf = (String) xmlConfiguration.get(connInstance);
+                connInstance.setConfiguration(
+                        XMLSerializer.<HashSet<ConnConfProperty>>deserialize(
+                        oldConf.replaceAll("org\\.apache\\.syncope\\.types\\.ConnConfProperty",
+                        ConnConfProperty.class.getName())));
+            } catch (Exception e) {
+                LOG.error("While upgrading {}", connInstance, e);
+            }
+        }
+    }
+
+    private void upgradeExternalResource() {
+        Field xmlConfiguration = ReflectionUtils.findField(ExternalResource.class, "xmlConfiguration");
+        xmlConfiguration.setAccessible(true);
+        for (ExternalResource resource : resourceDAO.findAll()) {
+            try {
+                String oldConf = (String) xmlConfiguration.get(resource);
+                if (StringUtils.isNotBlank(oldConf)) {
+                    resource.setConnInstanceConfiguration(
+                            XMLSerializer.<HashSet<ConnConfProperty>>deserialize(
+                            oldConf.replaceAll("org\\.apache\\.syncope\\.types\\.ConnConfProperty",
+                            ConnConfProperty.class.getName())));
+                }
+            } catch (Exception e) {
+                LOG.error("While upgrading {}", resource, e);
+            }
+        }
+    }
+
+    private void upgradePolicy() {
+        Field specification = ReflectionUtils.findField(Policy.class, "specification");
+        specification.setAccessible(true);
+        for (Policy policy : policyDAO.findAll()) {
+            try {
+                String oldConf = (String) specification.get(policy);
+                policy.setSpecification(
+                        XMLSerializer.<AbstractPolicySpec>deserialize(
+                        oldConf.replaceAll("org\\.apache\\.syncope\\.types\\.",
+                        "org.apache.syncope.common.types.").
+                        replaceAll("alternativeSearchAttrs", "uAltSearchSchemas")));
+            } catch (Exception e) {
+                LOG.error("While upgrading {}", policy, e);
+            }
+        }
+    }
+
+    private void upgradeNotification() {
+        Field xmlAbout = ReflectionUtils.findField(Notification.class, "xmlAbout");
+        xmlAbout.setAccessible(true);
+        Field xmlRecipients = ReflectionUtils.findField(Notification.class, "xmlRecipients");
+        xmlRecipients.setAccessible(true);
+        for (Notification notification : notificationDAO.findAll()) {
+            try {
+                String oldAbout = (String) xmlAbout.get(notification);
+                if (oldAbout != null) {
+                    notification.setAbout(
+                            XMLSerializer.<NodeCond>deserialize(
+                            oldAbout.replaceAll("org\\.apache\\.syncope\\.client\\.search\\.",
+                            "org.apache.syncope.common.search.")));
+                }
+                String oldRecipients = (String) xmlRecipients.get(notification);
+                if (oldRecipients != null) {
+                    notification.setRecipients(
+                            XMLSerializer.<NodeCond>deserialize(
+                            oldRecipients.replaceAll("org\\.apache\\.syncope\\.client\\.search\\.",
+                            "org.apache.syncope.common.search.")));
+                }
+            } catch (Exception e) {
+                LOG.error("While upgrading {}", notification, e);
+            }
+        }
+    }
+
+    private void upgradeSyncTask() {
+        Field userTemplate = ReflectionUtils.findField(SyncTask.class, "userTemplate");
+        userTemplate.setAccessible(true);
+        for (SyncTask task : taskDAO.findAll(SyncTask.class)) {
+            try {
+                String oldUserTemplate = (String) userTemplate.get(task);
+                if (oldUserTemplate != null) {
+                    task.setUserTemplate(
+                            XMLSerializer.<UserTO>deserialize(
+                            oldUserTemplate.replaceAll("org\\.apache\\.syncope\\.client\\.to\\.",
+                            "org.apache.syncope.common.to.").
+                            replaceAll("propagationTOs",
+                            "propagationStatusTOs")));
+                }
+            } catch (Exception e) {
+                LOG.error("While upgrading {}", task, e);
+            }
+        }
+    }
+
+    private void upgradeReportletConf() {
+        JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
+
+        List<Map<String, Object>> rcInstances =
+                jdbcTemplate.queryForList("SELECT id, serializedInstance FROM ReportletConfInstance");
+        for (Map<String, Object> row : rcInstances) {
+            String updated = ((String) row.get("serializedInstance")).
+                    replaceAll("org\\.apache\\.syncope\\.client\\.report\\.",
+                    "org.apache.syncope.common.report.");
+            jdbcTemplate.update("UPDATE ReportletConfInstance SET serializedInstance=? WHERE
id=?",
+                    new Object[] {updated, row.get("id")});
+        }
+    }
+
+    private void upgradeUserRequest() {
+        Field payload = ReflectionUtils.findField(UserRequest.class, "payload");
+        payload.setAccessible(true);
+        for (UserRequest request : userRequestDAO.findAll()) {
+            try {
+                String oldPayload = (String) payload.get(request);
+                if (oldPayload != null) {
+                    payload.set(request,
+                            oldPayload.replaceAll("org\\.apache\\.syncope\\.client\\.to\\.",
+                            "org.apache.syncope.common.to.").
+                            replaceAll("org\\.apache\\.syncope\\.client\\.mod\\.",
+                            "org.apache.syncope.common.mod."));
+                }
+            } catch (Exception e) {
+                LOG.error("While upgrading {}", request, e);
+            }
+        }
+    }
+
+    @Transactional
+    public void upgrade() {
+        if (ActivitiDetector.isActivitiEnabledForUsers()) {
+            upgradeActiviti();
+        }
+
+        final String localConnIdLocation = upgradeSyncopeConf();
+
+        upgradeConnInstance(localConnIdLocation);
+
+        upgradeExternalResource();
+
+        upgradePolicy();
+
+        upgradeNotification();
+
+        upgradeSyncTask();
+
+        upgradeReportletConf();
+
+        upgradeUserRequest();
+
+        Connection conn = DataSourceUtils.getConnection(dataSource);
+        try {
+            createIndexes(conn);
+            createViews(conn);
+        } finally {
+            DataSourceUtils.releaseConnection(conn, dataSource);
+            if (conn != null) {
+                try {
+                    if (!conn.isClosed()) {
+                        conn.close();
+                    }
+                } catch (SQLException e) {
+                    LOG.error("While releasing connection", e);
+                }
+            }
+        }
+    }
+}

Propchange: syncope/trunk/core/src/main/java/org/apache/syncope/core/init/ContentUpgrader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: syncope/trunk/core/src/main/java/org/apache/syncope/core/init/ContentUpgrader.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: syncope/trunk/core/src/main/java/org/apache/syncope/core/init/ContentUpgrader.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/init/JobInstanceLoader.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/init/JobInstanceLoader.java?rev=1463506&r1=1463505&r2=1463506&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/init/JobInstanceLoader.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/init/JobInstanceLoader.java Tue
Apr  2 12:40:45 2013
@@ -212,11 +212,10 @@ public class JobInstanceLoader {
         unregisterJob(getJobName(report));
     }
 
-    @SuppressWarnings("unchecked")
     @Transactional
     public void load() {
         // 1. jobs for SchedTasks
-        Set<SchedTask> tasks = new HashSet(taskDAO.findAll(SchedTask.class));
+        Set<SchedTask> tasks = new HashSet<SchedTask>(taskDAO.findAll(SchedTask.class));
         tasks.addAll(taskDAO.findAll(SyncTask.class));
         for (SchedTask task : tasks) {
             try {

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/init/SpringContextInitializer.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/init/SpringContextInitializer.java?rev=1463506&r1=1463505&r2=1463506&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/init/SpringContextInitializer.java
(original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/init/SpringContextInitializer.java
Tue Apr  2 12:40:45 2013
@@ -22,15 +22,20 @@ import org.apache.syncope.core.persisten
 import org.apache.syncope.core.propagation.ConnectorFactory;
 import org.springframework.beans.factory.InitializingBean;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Configurable;
 import org.springframework.stereotype.Component;
 
 /**
  * Take care of all initializations needed by Syncope to run up and safe.
  */
 @Component
+@Configurable
 public class SpringContextInitializer implements InitializingBean {
 
     @Autowired
+    private ContentUpgrader contentUpgrader;
+
+    @Autowired
     private ConnectorFactory connFactory;
 
     @Autowired
@@ -48,8 +53,18 @@ public class SpringContextInitializer im
     @Autowired
     private WorkflowAdapterLoader workflowAdapterLoader;
 
+    private boolean upgrade = false;
+
+    public void setUpgrade(final boolean upgrade) {
+        this.upgrade = upgrade;
+    }
+
     @Override
     public void afterPropertiesSet() throws Exception {
+        if (upgrade) {
+            contentUpgrader.upgrade();
+        }
+
         workflowAdapterLoader.load();
         contentLoader.load();
         connFactory.load();

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/ExternalResource.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/ExternalResource.java?rev=1463506&r1=1463505&r2=1463506&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/ExternalResource.java
(original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/ExternalResource.java
Tue Apr  2 12:40:45 2013
@@ -312,25 +312,22 @@ public class ExternalResource extends Ab
         this.syncPolicy = syncPolicy;
     }
 
-    public void setConnectorConfigurationProperties(final Set<ConnConfProperty> properties)
{
-        // create new set to make sure it's a serializable set implementation.
-        xmlConfiguration = XMLSerializer.serialize(new HashSet<ConnConfProperty>(properties));
-    }
-
-    public Set<ConnConfProperty> getConfiguration() {
-        Set<ConnConfProperty> result = Collections.emptySet();
-
-        Set<ConnConfProperty> deserializedSet;
+    public Set<ConnConfProperty> getConnInstanceConfiguration() {
+        Set<ConnConfProperty> result = null;
         if (StringUtils.isNotBlank(xmlConfiguration)) {
-            deserializedSet = XMLSerializer.<HashSet<ConnConfProperty>>deserialize(xmlConfiguration);
-            if (deserializedSet != null) {
-                result = deserializedSet;
-            }
+            result = XMLSerializer.<HashSet<ConnConfProperty>>deserialize(xmlConfiguration);
+        }
+        if (result == null) {
+            result = Collections.emptySet();
         }
 
         return result;
     }
 
+    public void setConnInstanceConfiguration(final Set<ConnConfProperty> properties)
{
+        xmlConfiguration = XMLSerializer.serialize(new HashSet<ConnConfProperty>(properties));
+    }
+
     public String getUserializedSyncToken() {
         return userializedSyncToken;
     }
@@ -346,7 +343,7 @@ public class ExternalResource extends Ab
     }
 
     public void setUsyncToken(final SyncToken syncToken) {
-        userializedSyncToken = XMLSerializer.serialize(syncToken);
+        this.userializedSyncToken = XMLSerializer.serialize(syncToken);
     }
 
     public String getRserializedSyncToken() {
@@ -364,7 +361,7 @@ public class ExternalResource extends Ab
     }
 
     public void setRsyncToken(final SyncToken syncToken) {
-        rserializedSyncToken = XMLSerializer.serialize(syncToken);
+        this.rserializedSyncToken = XMLSerializer.serialize(syncToken);
     }
 
     public String getPropagationActionsClassName() {

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/Policy.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/Policy.java?rev=1463506&r1=1463505&r2=1463506&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/Policy.java
(original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/Policy.java
Tue Apr  2 12:40:45 2013
@@ -69,6 +69,6 @@ public abstract class Policy extends Abs
     }
 
     public <T extends AbstractPolicySpec> void setSpecification(final T policy) {
-        specification = XMLSerializer.serialize(policy);
+        this.specification = XMLSerializer.serialize(policy);
     }
 }

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/ReportletConfInstance.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/ReportletConfInstance.java?rev=1463506&r1=1463505&r2=1463506&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/ReportletConfInstance.java
(original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/ReportletConfInstance.java
Tue Apr  2 12:40:45 2013
@@ -59,7 +59,7 @@ public class ReportletConfInstance exten
     }
 
     public void setInstance(final ReportletConf instance) {
-        serializedInstance = instance == null
+        this.serializedInstance = instance == null
                 ? null
                 : XMLSerializer.serialize(instance);
     }

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/SyncTask.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/SyncTask.java?rev=1463506&r1=1463505&r2=1463506&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/SyncTask.java
(original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/SyncTask.java
Tue Apr  2 12:40:45 2013
@@ -84,7 +84,8 @@ public class SyncTask extends SchedTask 
     }
 
     @Override
-    public void setJobClassName(String jobClassName) {
+    public void setJobClassName(final String jobClassName) {
+        // fixed to SyncJob, cannot be changed
     }
 
     public ExternalResource getResource() {

Added: syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/dao/impl/AbstractContentDealer.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/dao/impl/AbstractContentDealer.java?rev=1463506&view=auto
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/dao/impl/AbstractContentDealer.java
(added)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/dao/impl/AbstractContentDealer.java
Tue Apr  2 12:40:45 2013
@@ -0,0 +1,108 @@
+/*
+ * 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.dao.impl;
+
+import java.io.InputStream;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.Properties;
+import org.apache.commons.io.IOUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public abstract class AbstractContentDealer {
+
+    protected static final Logger LOG = LoggerFactory.getLogger(AbstractContentDealer.class);
+
+    private static final String VIEWS_FILE = "/views.xml";
+
+    private static final String INDEXES_FILE = "/indexes.xml";
+
+    protected void createIndexes(final Connection conn) {
+        LOG.debug("Creating indexes");
+
+        InputStream indexesStream = null;
+        Properties indexes = new Properties();
+        try {
+            indexesStream = getClass().getResourceAsStream(INDEXES_FILE);
+            indexes.loadFromXML(indexesStream);
+        } catch (Exception e) {
+            throw new RuntimeException("Error loading properties from stream", e);
+        } finally {
+            IOUtils.closeQuietly(indexesStream);
+        }
+
+        for (String idx : indexes.stringPropertyNames()) {
+            LOG.debug("Creating index {}", indexes.get(idx).toString());
+            PreparedStatement statement = null;
+            try {
+                final String updateIndexed = indexes.get(idx).toString();
+                statement = conn.prepareStatement(updateIndexed);
+                statement.executeUpdate();
+            } catch (SQLException e) {
+                LOG.error("Could not create index ", e);
+            } finally {
+                closeStatement(statement);
+            }
+        }
+    }
+
+    protected void createViews(final Connection conn) {
+        LOG.debug("Creating views");
+        InputStream viewsStream = null;
+        try {
+            viewsStream = getClass().getResourceAsStream(VIEWS_FILE);
+            Properties views = new Properties();
+            views.loadFromXML(viewsStream);
+
+            for (String idx : views.stringPropertyNames()) {
+                LOG.debug("Creating view {}", views.get(idx).toString());
+                PreparedStatement statement = null;
+                try {
+                    final String updateViews = views.get(idx).toString().replaceAll("\\n",
" ");
+                    statement = conn.prepareStatement(updateViews);
+                    statement.executeUpdate();
+                } catch (SQLException e) {
+                    LOG.error("Could not create view ", e);
+                } finally {
+                    if (statement != null) {
+                        statement.close();
+                    }
+                }
+            }
+
+            LOG.debug("Views created, go for indexes");
+        } catch (Exception e) {
+            LOG.error("While creating views", e);
+        } finally {
+            IOUtils.closeQuietly(viewsStream);
+        }
+    }
+
+    protected void closeStatement(final PreparedStatement statement) {
+        if (statement != null) {
+            try {
+                statement.close();
+            } catch (SQLException e) {
+                LOG.error("Error closing SQL statement", e);
+            }
+        }
+    }
+}

Propchange: syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/dao/impl/AbstractContentDealer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/dao/impl/AbstractContentDealer.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/dao/impl/AbstractContentDealer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/dao/impl/ContentLoader.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/dao/impl/ContentLoader.java?rev=1463506&r1=1463505&r2=1463506&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/dao/impl/ContentLoader.java
(original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/dao/impl/ContentLoader.java
Tue Apr  2 12:40:45 2013
@@ -23,15 +23,12 @@ import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
-import java.util.Properties;
 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.persistence.beans.SyncopeConf;
 import org.apache.syncope.core.util.ImportExport;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.jdbc.datasource.DataSourceUtils;
 import org.springframework.stereotype.Component;
@@ -41,13 +38,7 @@ import org.springframework.transaction.a
  * Initialize Database with default content if no data is present already.
  */
 @Component
-public class ContentLoader {
-
-    private static final String VIEWS_FILE = "/views.xml";
-
-    private static final String INDEXES_FILE = "/indexes.xml";
-
-    private static final Logger LOG = LoggerFactory.getLogger(ContentLoader.class);
+public class ContentLoader extends AbstractContentDealer {
 
     @Autowired
     private DataSource dataSource;
@@ -111,67 +102,6 @@ public class ContentLoader {
         }
     }
 
-    private void createViews(final Connection conn) {
-        LOG.debug("Creating views");
-        InputStream viewsStream = null;
-        try {
-            viewsStream = getClass().getResourceAsStream(VIEWS_FILE);
-            Properties views = new Properties();
-            views.loadFromXML(viewsStream);
-
-            for (String idx : views.stringPropertyNames()) {
-                LOG.debug("Creating view {}", views.get(idx).toString());
-                PreparedStatement statement = null;
-                try {
-                    final String updateViews = views.get(idx).toString().replaceAll("\\n",
" ");
-                    statement = conn.prepareStatement(updateViews);
-                    statement.executeUpdate();
-                } catch (SQLException e) {
-                    LOG.error("Could not create view ", e);
-                } finally {
-                    if (statement != null) {
-                        statement.close();
-                    }
-                }
-            }
-
-            LOG.debug("Views created, go for indexes");
-        } catch (Exception e) {
-            LOG.error("While creating views", e);
-        } finally {
-            IOUtils.closeQuietly(viewsStream);
-        }
-    }
-
-    private void createIndexes(final Connection conn) {
-        LOG.debug("Creating indexes");
-
-        InputStream indexesStream = null;
-        Properties indexes = new Properties();
-        try {
-            indexesStream = getClass().getResourceAsStream(INDEXES_FILE);
-            indexes.loadFromXML(indexesStream);
-        } catch (Exception e) {
-            throw new RuntimeException("Error loading properties from stream", e);
-        } finally {
-            IOUtils.closeQuietly(indexesStream);
-        }
-
-        for (String idx : indexes.stringPropertyNames()) {
-            LOG.debug("Creating index {}", indexes.get(idx).toString());
-            PreparedStatement statement = null;
-            try {
-                final String updateIndexed = indexes.get(idx).toString();
-                statement = conn.prepareStatement(updateIndexed);
-                statement.executeUpdate();
-            } catch (SQLException e) {
-                LOG.error("Could not create index ", e);
-            } finally {
-                closeStatement(statement);
-            }
-        }
-    }
-
     private void loadDefaultContent() {
         SAXParserFactory factory = SAXParserFactory.newInstance();
         InputStream in = null;
@@ -187,14 +117,4 @@ public class ContentLoader {
             IOUtils.closeQuietly(in);
         }
     }
-
-    private void closeStatement(final PreparedStatement statement) {
-        if (statement != null) {
-            try {
-                statement.close();
-            } catch (SQLException e) {
-                LOG.error("Error closing SQL statement", e);
-            }
-        }
-    }
 }

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/ResourceDataBinder.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/ResourceDataBinder.java?rev=1463506&r1=1463505&r2=1463506&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/ResourceDataBinder.java
(original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/ResourceDataBinder.java
Tue Apr  2 12:40:45 2013
@@ -132,7 +132,7 @@ public class ResourceDataBinder {
         resource.setSyncPolicy(resourceTO.getSyncPolicy() == null
                 ? null : (SyncPolicy) policyDAO.find(resourceTO.getSyncPolicy()));
 
-        resource.setConnectorConfigurationProperties(new HashSet<ConnConfProperty>(resourceTO.getConnConfProperties()));
+        resource.setConnInstanceConfiguration(new HashSet<ConnConfProperty>(resourceTO.getConnConfProperties()));
 
         if (resourceTO.getUsyncToken() == null) {
             resource.setUserializedSyncToken(null);
@@ -223,7 +223,7 @@ public class ResourceDataBinder {
     public ConnInstance getConnInstance(final ExternalResource resource) {
         final ConnInstance connInstanceClone = (ConnInstance) SerializationUtils.clone(resource.getConnector());
 
-        return getConnInstance(connInstanceClone, resource.getConfiguration());
+        return getConnInstance(connInstanceClone, resource.getConnInstanceConfiguration());
     }
 
     public ConnInstance getConnInstance(final ResourceTO resourceTO) {
@@ -326,7 +326,7 @@ public class ResourceDataBinder {
         resourceTO.setSyncPolicy(resource.getSyncPolicy() == null
                 ? null : resource.getSyncPolicy().getId());
 
-        resourceTO.setConnectorConfigurationProperties(resource.getConfiguration());
+        resourceTO.setConnectorConfigurationProperties(resource.getConnInstanceConfiguration());
 
         resourceTO.setUsyncToken(resource.getUserializedSyncToken());
         resourceTO.setRsyncToken(resource.getRserializedSyncToken());

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/security/SyncopeAuthenticationProvider.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/security/SyncopeAuthenticationProvider.java?rev=1463506&r1=1463505&r2=1463506&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/security/SyncopeAuthenticationProvider.java
(original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/security/SyncopeAuthenticationProvider.java
Tue Apr  2 12:40:45 2013
@@ -45,7 +45,7 @@ public class SyncopeAuthenticationProvid
     /**
      * Logger.
      */
-    private static final Logger LOG = LoggerFactory.getLogger(SyncopeAuthenticationProvider.class);
+    protected static final Logger LOG = LoggerFactory.getLogger(SyncopeAuthenticationProvider.class);
 
     @Autowired
     private AuditManager auditManager;
@@ -115,7 +115,7 @@ public class SyncopeAuthenticationProvid
 
         String username = authentication.getName();
         if (adminUser.equals(username)) {
-            authenticated = PasswordEncoder.verify(
+            authenticated = authenticate(
                     authentication.getCredentials().toString(),
                     CipherAlgorithm.valueOf(adminPasswordAlgorithm),
                     adminPassword);
@@ -126,7 +126,7 @@ public class SyncopeAuthenticationProvid
                 if (user.isSuspended()) {
                     throw new DisabledException("User " + user.getUsername() + " is suspended");
                 }
-                authenticated = PasswordEncoder.verify(
+                authenticated = authenticate(
                         authentication.getCredentials().toString(),
                         user.getCipherAlgorithm(),
                         user.getPassword());
@@ -171,6 +171,12 @@ public class SyncopeAuthenticationProvid
         return token;
     }
 
+    protected boolean authenticate(final String password, final CipherAlgorithm cipherAlgorithm,
+            final String digestedPassword) {
+
+        return PasswordEncoder.verify(password, cipherAlgorithm, digestedPassword);
+    }
+
     @Override
     public boolean supports(final Class<? extends Object> type) {
         return type.equals(UsernamePasswordAuthenticationToken.class);

Added: syncope/trunk/core/src/main/java/org/apache/syncope/core/security/SyncopeMD5FallbackAuthenticationProvider.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/security/SyncopeMD5FallbackAuthenticationProvider.java?rev=1463506&view=auto
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/security/SyncopeMD5FallbackAuthenticationProvider.java
(added)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/security/SyncopeMD5FallbackAuthenticationProvider.java
Tue Apr  2 12:40:45 2013
@@ -0,0 +1,47 @@
+/*
+ * 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.security;
+
+import org.apache.syncope.common.types.CipherAlgorithm;
+import org.jasypt.commons.CommonUtils;
+import org.jasypt.digest.StandardStringDigester;
+
+/**
+ * Extend standard authentication by checking passwords using MD5 (not supported anymore
as per SYNCOPE-51).
+ */
+public class SyncopeMD5FallbackAuthenticationProvider extends SyncopeAuthenticationProvider
{
+
+    @Override
+    protected boolean authenticate(final String password, final CipherAlgorithm cipherAlgorithm,
+            final String digestedPassword) {
+
+        boolean authenticated = super.authenticate(password, cipherAlgorithm, digestedPassword);
+        // if "normal" authentication fails and cipher is SMD5, we're probably handling an
"old" MD5 password
+        if (!authenticated && CipherAlgorithm.SMD5 == cipherAlgorithm) {
+            StandardStringDigester digester = new StandardStringDigester();
+            digester.setAlgorithm("MD5");
+            digester.setIterations(1);
+            digester.setSaltSizeBytes(0);
+            digester.setStringOutputType(CommonUtils.STRING_OUTPUT_TYPE_HEXADECIMAL);
+
+            authenticated = digester.matches(password, digestedPassword);
+        }
+        return authenticated;
+    }
+}

Propchange: syncope/trunk/core/src/main/java/org/apache/syncope/core/security/SyncopeMD5FallbackAuthenticationProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: syncope/trunk/core/src/main/java/org/apache/syncope/core/security/SyncopeMD5FallbackAuthenticationProvider.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: syncope/trunk/core/src/main/java/org/apache/syncope/core/security/SyncopeMD5FallbackAuthenticationProvider.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/util/PasswordEncoder.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/PasswordEncoder.java?rev=1463506&r1=1463505&r2=1463506&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/util/PasswordEncoder.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/util/PasswordEncoder.java Tue
Apr  2 12:40:45 2013
@@ -31,6 +31,7 @@ import javax.crypto.NoSuchPaddingExcepti
 import javax.crypto.spec.SecretKeySpec;
 import org.apache.commons.lang.ArrayUtils;
 import org.apache.syncope.common.types.CipherAlgorithm;
+import org.jasypt.commons.CommonUtils;
 import org.jasypt.digest.StandardStringDigester;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -163,7 +164,7 @@ public final class PasswordEncoder {
             digester.setSaltSizeBytes(0);
         }
 
-        digester.setStringOutputType("hexadecimal");
+        digester.setStringOutputType(CommonUtils.STRING_OUTPUT_TYPE_HEXADECIMAL);
         return digester;
     }
 

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/workflow/ActivitiDetector.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/workflow/ActivitiDetector.java?rev=1463506&r1=1463505&r2=1463506&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/workflow/ActivitiDetector.java
(original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/workflow/ActivitiDetector.java
Tue Apr  2 12:40:45 2013
@@ -18,7 +18,6 @@
  */
 package org.apache.syncope.core.workflow;
 
-import java.io.IOException;
 import java.io.InputStream;
 import java.util.Properties;
 import org.apache.commons.io.IOUtils;
@@ -31,7 +30,7 @@ public class ActivitiDetector {
 
     private static final Logger LOG = LoggerFactory.getLogger(ActivitiDetector.class);
 
-    private static final String XX = "/workflow.properties";
+    private static final String WORKFLOW_PROPERTIES = "/workflow.properties";
 
     private static String uwfAdapterClassName;
 
@@ -39,24 +38,14 @@ public class ActivitiDetector {
 
     private static String activitiVersion;
 
-    static {
-        try {
-            init();
-        } catch (IOException e) {
-            LOG.error("Could not read from {}", XX, e);
-        }
-    }
-
     /**
      * Read classpath:/workflow.properties in order to determine the configured workflow
adapter class name.
-     *
-     * @throws IOException if anything goes wrong
      */
-    private static void init() throws IOException {
-        Properties props = new java.util.Properties();
+    static {
+        Properties props = new Properties();
         InputStream propStream = null;
         try {
-            propStream = ContentLoader.class.getResourceAsStream(XX);
+            propStream = ContentLoader.class.getResourceAsStream(WORKFLOW_PROPERTIES);
             props.load(propStream);
             uwfAdapterClassName = props.getProperty("uwfAdapter");
             rwfAdapterClassName = props.getProperty("rwfAdapter");



Mime
View raw message