You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by an...@apache.org on 2014/08/12 16:31:25 UTC
svn commit: r1617488 - in /syncope/branches/1_2_X: ./ core-upgrader/
core-upgrader/src/ core-upgrader/src/main/ core-upgrader/src/main/java/
core-upgrader/src/main/java/org/ core-upgrader/src/main/java/org/apache/
core-upgrader/src/main/java/org/apache...
Author: andreapatricelli
Date: Tue Aug 12 14:31:24 2014
New Revision: 1617488
URL: http://svn.apache.org/r1617488
Log:
added module core-upgrader to upgrade from 1.1.X to 1.2.X
Added:
syncope/branches/1_2_X/core-upgrader/ (with props)
syncope/branches/1_2_X/core-upgrader/pom.xml
syncope/branches/1_2_X/core-upgrader/src/
syncope/branches/1_2_X/core-upgrader/src/main/
syncope/branches/1_2_X/core-upgrader/src/main/java/
syncope/branches/1_2_X/core-upgrader/src/main/java/org/
syncope/branches/1_2_X/core-upgrader/src/main/java/org/apache/
syncope/branches/1_2_X/core-upgrader/src/main/java/org/apache/syncope/
syncope/branches/1_2_X/core-upgrader/src/main/java/org/apache/syncope/upgrader/
syncope/branches/1_2_X/core-upgrader/src/main/java/org/apache/syncope/upgrader/ContentUpgrader.java
syncope/branches/1_2_X/core-upgrader/src/main/java/org/apache/syncope/upgrader/util/
syncope/branches/1_2_X/core-upgrader/src/main/java/org/apache/syncope/upgrader/util/GuardedStringConverter.java
syncope/branches/1_2_X/core-upgrader/src/main/java/org/apache/syncope/upgrader/util/SyncopeDefParams.java
syncope/branches/1_2_X/core-upgrader/src/main/java/org/apache/syncope/upgrader/util/XMLDeserializer.java
syncope/branches/1_2_X/core-upgrader/src/main/resources/
syncope/branches/1_2_X/core-upgrader/src/main/resources/syncope-1.1.X-1.2.X.sql
syncope/branches/1_2_X/core-upgrader/src/main/resources/upgradeContext.xml
Modified:
syncope/branches/1_2_X/core/src/main/resources/log4j2.xml
syncope/branches/1_2_X/pom.xml
Propchange: syncope/branches/1_2_X/core-upgrader/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Aug 12 14:31:24 2014
@@ -0,0 +1 @@
+target
Added: syncope/branches/1_2_X/core-upgrader/pom.xml
URL: http://svn.apache.org/viewvc/syncope/branches/1_2_X/core-upgrader/pom.xml?rev=1617488&view=auto
==============================================================================
--- syncope/branches/1_2_X/core-upgrader/pom.xml (added)
+++ syncope/branches/1_2_X/core-upgrader/pom.xml Tue Aug 12 14:31:24 2014
@@ -0,0 +1,83 @@
+<?xml version="1.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.
+-->
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.syncope</groupId>
+ <artifactId>syncope</artifactId>
+ <version>1.2.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.apache.syncope</groupId>
+ <artifactId>core-upgrader</artifactId>
+ <packaging>jar</packaging>
+
+ <name>Apache Syncope Upgrader</name>
+ <description>Apache Syncope Upgrader from 1.1.X to 1.2.X</description>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <xstream.version>1.4.7</xstream.version>
+ </properties>
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.syncope</groupId>
+ <artifactId>syncope-core</artifactId>
+ <version>${project.version}</version>
+ <classifier>classes</classifier>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.syncope</groupId>
+ <artifactId>syncope-common</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.thoughtworks.xstream</groupId>
+ <artifactId>xstream</artifactId>
+ <version>${xstream.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ <filtering>true</filtering>
+ </resource>
+ <resource>
+ <directory>..</directory>
+ <targetPath>META-INF</targetPath>
+ <includes>
+ <include>LICENSE</include>
+ <include>NOTICE</include>
+ </includes>
+ </resource>
+ </resources>
+ </build>
+</project>
Added: syncope/branches/1_2_X/core-upgrader/src/main/java/org/apache/syncope/upgrader/ContentUpgrader.java
URL: http://svn.apache.org/viewvc/syncope/branches/1_2_X/core-upgrader/src/main/java/org/apache/syncope/upgrader/ContentUpgrader.java?rev=1617488&view=auto
==============================================================================
--- syncope/branches/1_2_X/core-upgrader/src/main/java/org/apache/syncope/upgrader/ContentUpgrader.java (added)
+++ syncope/branches/1_2_X/core-upgrader/src/main/java/org/apache/syncope/upgrader/ContentUpgrader.java Tue Aug 12 14:31:24 2014
@@ -0,0 +1,739 @@
+/*
+ * 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.upgrader;
+
+import org.apache.syncope.upgrader.util.XMLDeserializer;
+import org.apache.syncope.upgrader.util.SyncopeDefParams;
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Resource;
+import javax.sql.DataSource;
+import org.activiti.engine.RepositoryService;
+import org.activiti.engine.repository.Model;
+import org.activiti.engine.repository.ProcessDefinition;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.syncope.common.report.UserReportletConf;
+import org.apache.syncope.common.to.RoleTO;
+import org.apache.syncope.common.to.UserTO;
+import org.apache.syncope.common.types.AbstractPolicySpec;
+import org.apache.syncope.common.types.AttributableType;
+import org.apache.syncope.common.types.AttributeSchemaType;
+import org.apache.syncope.common.types.ConnConfProperty;
+import org.apache.syncope.core.persistence.beans.AbstractAttr;
+import org.apache.syncope.core.persistence.beans.AbstractAttrTemplate;
+import org.apache.syncope.core.persistence.beans.AbstractDerAttr;
+import org.apache.syncope.core.persistence.beans.AbstractSchema;
+import org.apache.syncope.core.persistence.beans.AbstractVirAttr;
+import org.apache.syncope.core.persistence.beans.ConnInstance;
+import org.apache.syncope.core.persistence.beans.ExternalResource;
+import org.apache.syncope.core.persistence.beans.Policy;
+import org.apache.syncope.core.persistence.beans.PropagationTask;
+import org.apache.syncope.core.persistence.beans.SyncTask;
+import org.apache.syncope.core.persistence.beans.conf.CAttr;
+import org.apache.syncope.core.persistence.beans.conf.CSchema;
+import org.apache.syncope.core.persistence.beans.membership.MAttr;
+import org.apache.syncope.core.persistence.beans.membership.MAttrTemplate;
+import org.apache.syncope.core.persistence.beans.membership.MDerAttr;
+import org.apache.syncope.core.persistence.beans.membership.MDerAttrTemplate;
+import org.apache.syncope.core.persistence.beans.membership.MDerSchema;
+import org.apache.syncope.core.persistence.beans.membership.MSchema;
+import org.apache.syncope.core.persistence.beans.membership.MVirAttr;
+import org.apache.syncope.core.persistence.beans.membership.MVirAttrTemplate;
+import org.apache.syncope.core.persistence.beans.membership.MVirSchema;
+import org.apache.syncope.core.persistence.beans.membership.Membership;
+import org.apache.syncope.core.persistence.beans.role.RAttr;
+import org.apache.syncope.core.persistence.beans.role.RAttrTemplate;
+import org.apache.syncope.core.persistence.beans.role.RDerAttr;
+import org.apache.syncope.core.persistence.beans.role.RDerAttrTemplate;
+import org.apache.syncope.core.persistence.beans.role.RDerSchema;
+import org.apache.syncope.core.persistence.beans.role.RSchema;
+import org.apache.syncope.core.persistence.beans.role.RVirAttr;
+import org.apache.syncope.core.persistence.beans.role.RVirAttrTemplate;
+import org.apache.syncope.core.persistence.beans.role.RVirSchema;
+import org.apache.syncope.core.persistence.beans.role.SyncopeRole;
+import org.apache.syncope.core.persistence.dao.AttrDAO;
+import org.apache.syncope.core.persistence.dao.AttrTemplateDAO;
+import org.apache.syncope.core.persistence.dao.ConfDAO;
+import org.apache.syncope.core.persistence.dao.ConnInstanceDAO;
+import org.apache.syncope.core.persistence.dao.DerAttrDAO;
+import org.apache.syncope.core.persistence.dao.DerSchemaDAO;
+import org.apache.syncope.core.persistence.dao.MembershipDAO;
+import org.apache.syncope.core.persistence.dao.PolicyDAO;
+import org.apache.syncope.core.persistence.dao.ResourceDAO;
+import org.apache.syncope.core.persistence.dao.RoleDAO;
+import org.apache.syncope.core.persistence.dao.SchemaDAO;
+import org.apache.syncope.core.persistence.dao.TaskDAO;
+import org.apache.syncope.core.persistence.dao.VirAttrDAO;
+import org.apache.syncope.core.persistence.dao.VirSchemaDAO;
+import org.apache.syncope.core.util.AttributableUtil;
+import org.apache.syncope.core.util.POJOHelper;
+import org.apache.syncope.core.util.ResourceWithFallbackLoader;
+import org.apache.syncope.core.workflow.user.activiti.ActivitiImportUtils;
+import org.apache.syncope.core.workflow.user.activiti.ActivitiUserWorkflowAdapter;
+import org.identityconnectors.framework.common.objects.Attribute;
+import org.identityconnectors.framework.common.objects.SyncToken;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.context.annotation.DependsOn;
+import org.springframework.dao.DataAccessException;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.orm.jpa.JpaTransactionManager;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.TransactionStatus;
+import org.springframework.transaction.support.TransactionCallbackWithoutResult;
+import org.springframework.transaction.support.TransactionTemplate;
+import org.springframework.util.ReflectionUtils;
+
+@Component
+@DependsOn("springContextInitializer")
+public class ContentUpgrader implements InitializingBean {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ContentUpgrader.class);
+
+ private JdbcTemplate jdbcTemplate;
+
+ @Autowired
+ private DataSource dataSource;
+
+ @Autowired
+ private ResourceDAO resourceDAO;
+
+ @Autowired
+ private SchemaDAO schemaDAO;
+
+ @Autowired
+ private DerSchemaDAO derSchemaDAO;
+
+ @Autowired
+ private VirSchemaDAO virSchemaDAO;
+
+ @Autowired
+ private ConfDAO confDAO;
+
+ @Autowired
+ private ConnInstanceDAO connInstanceDAO;
+
+ @Autowired
+ private PolicyDAO policyDAO;
+
+ @Autowired
+ private TaskDAO taskDAO;
+
+ @Autowired
+ private AttrDAO attrDAO;
+
+ @Autowired
+ private DerAttrDAO derAttrDAO;
+
+ @Autowired
+ private VirAttrDAO virAttrDAO;
+
+ @Autowired
+ private AttrTemplateDAO attrTemplateDAO;
+
+ @Autowired
+ private RoleDAO roleDAO;
+
+ @Autowired
+ private MembershipDAO membershipDAO;
+
+ @Autowired
+ private ActivitiImportUtils importUtils;
+
+ @Autowired
+ private RepositoryService repositoryService;
+
+ @Autowired
+ @Qualifier("transactionManager")
+ protected JpaTransactionManager txManager;
+
+ @Resource(name = "userWorkflowXML")
+ private ResourceWithFallbackLoader userWorkflowXML;
+
+ private boolean continueUpgrade = true;
+
+ private boolean deleteOldWorkflow = false;
+
+ @Override
+ public void afterPropertiesSet() throws Exception {
+ jdbcTemplate = new JdbcTemplate(dataSource);
+ final TransactionTemplate txTemplate = new TransactionTemplate(txManager);
+
+ txTemplate.execute(new TransactionCallbackWithoutResult() {
+
+ @Override
+ protected void doInTransactionWithoutResult(final TransactionStatus status) {
+ try {
+ doUpgradePhaseOne();
+ } catch (Exception e) {
+ LOG.error("Upgrade STOPPED: an error occurred during upgrade", e);
+ }
+ }
+ });
+
+ if (continueUpgrade) {
+ txTemplate.execute(new TransactionCallbackWithoutResult() {
+
+ @Override
+ protected void doInTransactionWithoutResult(final TransactionStatus status) {
+ try {
+ doUpgradePhaseTwo();
+ } catch (Exception e) {
+ LOG.error("Upgrade STOPPED: an error occurred during upgrade", e);
+ }
+ }
+ });
+ } else {
+ LOG.error("Upgrade STOPPED: can not continue due to previous errors, see exceptions above.");
+ return;
+ }
+ LOG.info("Upgrade completed SUCCESSFULLY.");
+ }
+
+ public void doUpgradePhaseOne() throws Exception {
+ LOG.info("Beginning upgrade PHASE 1...");
+ upgradeSyncopeConf();
+ upgradeExternalResource();
+ upgradeConnInstance();
+ updgradePropagationTask();
+ upgradeSyncTask();
+ upgradePolicy();
+ upgradeReportletConf();
+ upgradeWorkflow();
+ addTemplatesToRoles();
+ addTemplatesToMemberships();
+ LOG.info("Upgrade PHASE 1 completed.");
+ }
+
+ private void doUpgradePhaseTwo() throws IOException {
+ LOG.info("Beginning upgrade PHASE 2...");
+ addTemplatesToRAttrs();
+ addTemplatesToMAttrs();
+ LOG.info("Upgrade PHASE 2 completed.");
+ }
+
+ public void setDeleteOldWorkflow(final boolean deleteOldWorkflow) {
+ this.deleteOldWorkflow = deleteOldWorkflow;
+ }
+
+ private void upgradeExternalResource() throws Exception {
+ LOG.info("Upgrading ExternalResource table...");
+ final Field jsonConf = ReflectionUtils.findField(ExternalResource.class, "jsonConf");
+ jsonConf.setAccessible(true);
+ final Field uSyncToken = ReflectionUtils.findField(ExternalResource.class, "userializedSyncToken");
+ uSyncToken.setAccessible(true);
+ final Field rSyncToken = ReflectionUtils.findField(ExternalResource.class, "rserializedSyncToken");
+ rSyncToken.setAccessible(true);
+ for (ExternalResource resource : resourceDAO.findAll()) {
+ try {
+ final String oldConf = (String) jsonConf.get(resource);
+ if (StringUtils.isNotBlank(oldConf)) {
+ LOG.debug("Upgrading resource {} jsonConf", resource.getName());
+ resource.setConnInstanceConfiguration(
+ XMLDeserializer.<HashSet<ConnConfProperty>>deserialize(oldConf));
+ }
+
+ final String oldUSyncToken = (String) uSyncToken.get(resource);
+ final String oldRSyncToken = (String) rSyncToken.get(resource);
+
+ if (StringUtils.isNotBlank(oldUSyncToken)) {
+ LOG.debug("Upgrading resource {} userializedSyncToken", resource.getName());
+ resource.setUsyncToken(XMLDeserializer.<SyncToken>deserialize(oldUSyncToken));
+ }
+ if (StringUtils.isNotBlank(oldRSyncToken)) {
+ LOG.debug("Upgrading resource {} rserializedSyncToken", resource.getName());
+ resource.setRsyncToken(XMLDeserializer.<SyncToken>deserialize(oldRSyncToken));
+ }
+ } catch (Exception e) {
+ LOG.error("While upgrading resource {}", resource, e);
+ continueUpgrade = false;
+ throw e;
+ }
+ }
+ }
+
+ private void upgradeConnInstance() throws Exception {
+ LOG.info("Upgrading ConnInstance table...");
+ final Field jsonConf = ReflectionUtils.findField(ConnInstance.class, "jsonConf");
+ jsonConf.setAccessible(true);
+ for (ConnInstance connInstance : connInstanceDAO.findAll()) {
+ LOG.debug("Upgrading connInstance {} jsonConf", connInstance);
+ try {
+ final String oldConf = (String) jsonConf.get(connInstance);
+ connInstance.setConfiguration(XMLDeserializer.<HashSet<ConnConfProperty>>deserialize(oldConf));
+ } catch (Exception e) {
+ LOG.error("While upgrading connInstance {}", connInstance, e);
+ continueUpgrade = false;
+ throw e;
+ }
+ }
+ }
+
+ private void upgradePolicy() throws Exception {
+ LOG.info("Upgrading Policy table...");
+ final Field specification = ReflectionUtils.findField(Policy.class, "specification");
+ specification.setAccessible(true);
+ for (Policy policy : policyDAO.findAll()) {
+ LOG.debug("Upgrading policy {} specification", policy.getDescription());
+ try {
+ final String oldConf = (String) specification.get(policy);
+ policy.setSpecification(XMLDeserializer.<AbstractPolicySpec>deserialize(oldConf));
+ } catch (Exception e) {
+ LOG.error("While upgrading policy {}", policy, e);
+ continueUpgrade = false;
+ throw e;
+ }
+ }
+ }
+
+ private void upgradeSyncTask() throws Exception {
+ LOG.info("Upgrading Task table (sync tasks)...");
+ final Field userTemplate = ReflectionUtils.findField(SyncTask.class, "userTemplate");
+ userTemplate.setAccessible(true);
+ final Field roleTemplate = ReflectionUtils.findField(SyncTask.class, "roleTemplate");
+ roleTemplate.setAccessible(true);
+ for (SyncTask task : taskDAO.findAll(SyncTask.class)) {
+ try {
+ LOG.debug("Upgrading syncTask {} userTemplate", task.getName());
+ final String oldUserTemplate = (String) userTemplate.get(task);
+ final String oldRoleTemplate = (String) roleTemplate.get(task);
+ if (oldUserTemplate != null) {
+ task.setUserTemplate(XMLDeserializer.<UserTO>deserialize(oldUserTemplate));
+ }
+ if (oldRoleTemplate != null) {
+ LOG.debug("Upgrading syncTask {} roleTemplate", task.getName());
+ task.setRoleTemplate(XMLDeserializer.<RoleTO>deserialize(oldRoleTemplate));
+ }
+ } catch (Exception e) {
+ LOG.error("While upgrading syncTask {}", task, e);
+ continueUpgrade = false;
+ throw e;
+ }
+ }
+ }
+
+ private void updgradePropagationTask() throws Exception {
+ LOG.info("Upgrading Task table (propagation tasks)...");
+ final Field xmlAttributes = ReflectionUtils.findField(PropagationTask.class, "xmlAttributes");
+ xmlAttributes.setAccessible(true);
+ for (PropagationTask task : taskDAO.findAll(PropagationTask.class)) {
+ try {
+ final String oldXmlAttr = (String) xmlAttributes.get(task);
+ if (StringUtils.isNotBlank(oldXmlAttr)) {
+ LOG.debug("Upgrading propagationTask {} xmlAttributes", task.getId());
+ task.setAttributes(XMLDeserializer.<HashSet<Attribute>>deserialize(oldXmlAttr));
+ }
+ } catch (Exception e) {
+ LOG.error("While upgrading propagationTask {}", task, e);
+ continueUpgrade = false;
+ throw e;
+ }
+ }
+ }
+
+ private void upgradeReportletConf() {
+ LOG.info("Upgrading ReportletConf table...");
+ try {
+ final List<Map<String, Object>> reportletConfs = jdbcTemplate.queryForList(
+ "SELECT id, serializedInstance FROM ReportletConfInstance");
+ for (Map<String, Object> row : reportletConfs) {
+ final String serializedInstance = (String) row.get("serializedInstance");
+ if (StringUtils.isNotBlank(serializedInstance)) {
+ LOG.debug("Upgrading ReportletConf {} serializedInstance", row.get("id"));
+ final UserReportletConf set = XMLDeserializer.<UserReportletConf>deserialize(serializedInstance);
+ final String newSerializedInst = POJOHelper.serialize(set);
+ jdbcTemplate.update("UPDATE ReportletConfInstance set serializedInstance = ? WHERE id = ?",
+ new Object[] { newSerializedInst, row.get("id") });
+ }
+ }
+ } catch (DataAccessException e) {
+ LOG.error("Error accessing ReportletConfInstance table", e);
+ continueUpgrade = false;
+ throw e;
+ }
+ }
+
+ private void upgradeSyncopeConf() {
+ LOG.info("Upgrading SyncopeConf table...");
+ // get old syncope configuration from provisional table created ad hoc
+ final Map<String, String> syncopeConf = new HashMap<String, String>();
+ try {
+ final List<Map<String, Object>> syncopeConfs = jdbcTemplate.queryForList(
+ "SELECT * FROM SyncopeConf_temp");
+
+ for (Map<String, Object> row : syncopeConfs) {
+ final String confKey = (String) row.get("confKey");
+ if (StringUtils.isNotBlank(confKey) && !SyncopeDefParams.contains(confKey)) {
+ syncopeConf.put(confKey, (String) row.get("confValue"));
+ }
+ }
+
+ // delete provisional table
+ jdbcTemplate.update("DROP TABLE SyncopeConf_temp;");
+
+ } catch (DataAccessException e) {
+ LOG.error("Error accessing SyncopeConf table", e);
+ continueUpgrade = false;
+ throw e;
+ }
+
+ // save new, well-formed SyncopeConf and associated CSchema, CAttr and CAttrValue
+ for (Map.Entry<String, String> entry : syncopeConf.entrySet()) {
+ final String key = entry.getKey();
+ final String value = entry.getValue();
+ // 1. create CSChema
+ CSchema confSchema = new CSchema();
+ confSchema.setName(key);
+ confSchema.setType(AttributeSchemaType.String);
+ confSchema.setMultivalue(value.contains("|"));
+ confSchema.setUniqueConstraint(false);
+ confSchema.setReadonly(false);
+ confSchema = schemaDAO.save(confSchema);
+ // 2. create and save CAttr
+ final CAttr confAttr = new CAttr();
+ confAttr.setSchema(confSchema);
+ confAttr.setOwner(confDAO.get());
+ if (confSchema.isMultivalue()) {
+ for (String singleValue : value.split("|")) {
+ confAttr.addValue(singleValue, AttributableUtil.getInstance(AttributableType.CONFIGURATION));
+ }
+ } else {
+ confAttr.addValue(value, AttributableUtil.getInstance(AttributableType.CONFIGURATION));
+ }
+ confDAO.save(confAttr);
+ }
+ }
+
+ private void upgradeWorkflow() {
+ try {
+ LOG.info("Upgrading workflow version...");
+ final byte[] userWorkflowBytes = IOUtils.toString(userWorkflowXML.getResource().getInputStream()).getBytes();
+
+ // delete old workflow version if needed, Activiti 5.15.1 workflow referred to Syncope 1.1.X
+ if (deleteOldWorkflow) {
+ jdbcTemplate.update("DELETE FROM ACT_GE_BYTEARRAY WHERE NAME_ = ?;",
+ ActivitiUserWorkflowAdapter.WF_PROCESS_RESOURCE);
+ }
+ if (userWorkflowBytes != null && userWorkflowBytes.length > 0) {
+ // write default workflow value to database
+ LOG.debug("Importing default workflow for Syncope 1.2.X");
+
+ importUtils.fromXML(userWorkflowBytes);
+
+ // add activiti model to database
+ final Model model = repositoryService.newModel();
+
+ final ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().
+ processDefinitionKey(ActivitiUserWorkflowAdapter.WF_PROCESS_ID).latestVersion().singleResult();
+
+ model.setDeploymentId(processDefinition.getDeploymentId());
+ model.setName("User Workflow");
+ model.setVersion(1);
+ model.setMetaInfo("{\"name\":\"User Workflow\",\"revision\":2,\"description\":null}");
+ repositoryService.saveModel(model);
+
+ repositoryService.addModelEditorSource(repositoryService.createModelQuery().deploymentId(
+ processDefinition.getDeploymentId()).singleResult().getId(), userWorkflowBytes);
+
+ // update ACT_RU_EXECUTION table and ACT_RU_TASK tables for old database users with new process
+ // id associated to the new workflow
+ jdbcTemplate.update("UPDATE ACT_RU_EXECUTION SET PROC_DEF_ID_ = ?", processDefinition.getId());
+ jdbcTemplate.update("UPDATE ACT_RU_TASK SET PROC_DEF_ID_ = ?", processDefinition.getId());
+ }
+ } catch (IOException e) {
+ LOG.error("Error reading file {}", ActivitiUserWorkflowAdapter.WF_PROCESS_RESOURCE, e);
+ } catch (DataAccessException e) {
+ LOG.error("Error accessing table ACT_GE_BYTEARRAY", e);
+ }
+ }
+
+ private void addTemplatesToRoles() {
+ try {
+ LOG.info("Adding templates to roles");
+ for (SyncopeRole role : roleDAO.findAll()) {
+
+ final List<RAttr> newRattrs = new ArrayList<RAttr>();
+ final List<RAttrTemplate> newRattrTemplates = new ArrayList<RAttrTemplate>();
+
+ final List<RDerAttr> newRDerattrs = new ArrayList<RDerAttr>();
+ final List<RDerAttrTemplate> newRDerattrTemplates = new ArrayList<RDerAttrTemplate>();
+
+ final List<RVirAttr> newRVirattrs = new ArrayList<RVirAttr>();
+ final List<RVirAttrTemplate> newRVirattrTemplates = new ArrayList<RVirAttrTemplate>();
+
+ LOG.debug("Adding role templates to role {}", role);
+
+ //Create normal attributes templates
+ for (AbstractAttr attr : role.getAttrs()) {
+ final RAttrTemplate rAttrTemplate = new RAttrTemplate();
+ rAttrTemplate.setOwner(role);
+ LOG.debug("Creating template for role normal attribute {}", attr);
+ final String schemaName = jdbcTemplate.queryForObject(
+ "SELECT schema_name FROM RAttr WHERE id = ?;", String.class, attr.getId());
+
+ rAttrTemplate.setSchema(schemaDAO.find(schemaName, RSchema.class));
+ newRattrTemplates.add(rAttrTemplate);
+ }
+
+ //Create derived attributes templates
+ for (AbstractDerAttr derAttr : role.getDerAttrs()) {
+ final RDerAttrTemplate rDerattrTemplate = new RDerAttrTemplate();
+ rDerattrTemplate.setOwner(role);
+ LOG.debug("Creating template for role derived attribute {}", derAttr);
+ final String derSchemaName = jdbcTemplate.queryForObject(
+ "SELECT DERIVEDSCHEMA_NAME FROM RDerAttr WHERE id = ?;", String.class, derAttr.getId());
+
+ rDerattrTemplate.setSchema(derSchemaDAO.find(derSchemaName, RDerSchema.class));
+ newRDerattrTemplates.add(rDerattrTemplate);
+ }
+
+ //Create virtual attributes templates
+ for (AbstractVirAttr virAttr : role.getVirAttrs()) {
+ final RVirAttrTemplate rVirattrTemplate = new RVirAttrTemplate();
+ rVirattrTemplate.setOwner(role);
+ LOG.debug("Creating template for role virtual attribute {}", virAttr);
+ final String virSchemaName = jdbcTemplate.queryForObject(
+ "SELECT VIRTUALSCHEMA_NAME FROM RVirAttr WHERE id = ?;", String.class, virAttr.getId());
+ rVirattrTemplate.setSchema(virSchemaDAO.find(virSchemaName, RVirSchema.class));
+ newRVirattrTemplates.add(rVirattrTemplate);
+ }
+ role.setAttrs(newRattrs);
+ role.setDerAttrs(newRDerattrs);
+ role.setVirAttrs(newRVirattrs);
+ role.getAttrTemplates(RAttrTemplate.class).addAll(newRattrTemplates);
+ role.getAttrTemplates(RDerAttrTemplate.class).addAll(newRDerattrTemplates);
+ role.getAttrTemplates(RVirAttrTemplate.class).addAll(newRVirattrTemplates);
+ }
+ } catch (DataAccessException ex) {
+ LOG.error("Error accessing RAttr table", ex);
+ }
+ }
+
+ private void addTemplatesToRAttrs() {
+ try {
+ LOG.info("Adding templates to role attributes");
+ for (SyncopeRole role : roleDAO.findAll()) {
+
+ final List<RAttr> newRattrs = new ArrayList<RAttr>();
+ final List<RDerAttr> newRDerattrs = new ArrayList<RDerAttr>();
+ final List<RVirAttr> newRVirattrs = new ArrayList<RVirAttr>();
+
+ // add template to normal attributes
+ for (Long attrId : jdbcTemplate.queryForList("SELECT id FROM RAttr WHERE OWNER_ID = ?", Long.class,
+ role.getId())) {
+ final RAttr rAttr = attrDAO.find(attrId, RAttr.class);
+
+ LOG.debug("Adding template to role attribute {}", rAttr);
+
+ final String schemaName = jdbcTemplate.queryForObject(
+ "SELECT schema_name FROM RAttr WHERE id = ?;", String.class, attrId);
+
+ rAttr.setTemplate(getTemplate(role, schemaName, RAttrTemplate.class));
+ newRattrs.add(rAttr);
+ }
+
+ // add template to derived attributes
+ for (Long attrId : jdbcTemplate.queryForList("SELECT id FROM RDerAttr WHERE OWNER_ID = ?", Long.class,
+ role.getId())) {
+ final RDerAttr rDerAttr = derAttrDAO.find(attrId, RDerAttr.class);
+
+ LOG.debug("Adding template to role attribute {}", rDerAttr);
+
+ final String derSchemaName = jdbcTemplate.queryForObject(
+ "SELECT DERIVEDSCHEMA_NAME FROM RDerAttr WHERE id = ?;", String.class, attrId);
+
+ rDerAttr.setTemplate(getTemplate(role, derSchemaName, RDerAttrTemplate.class));
+ newRDerattrs.add(rDerAttr);
+ }
+
+ // add template to virtual attributes
+ for (Long attrId : jdbcTemplate.queryForList("SELECT id FROM RVirAttr WHERE OWNER_ID = ?", Long.class,
+ role.getId())) {
+ final RVirAttr rVirAttr = virAttrDAO.find(attrId, RVirAttr.class);
+
+ LOG.debug("Adding template to role attribute {}", rVirAttr);
+
+ final String virSchemaName = jdbcTemplate.queryForObject(
+ "SELECT VIRTUALSCHEMA_NAME FROM RVirAttr WHERE id = ?;", String.class, attrId);
+
+ rVirAttr.setTemplate(getTemplate(role, virSchemaName, RVirAttrTemplate.class));
+ newRVirattrs.add(rVirAttr);
+ }
+ role.setAttrs(newRattrs);
+ role.setDerAttrs(newRDerattrs);
+ role.setVirAttrs(newRVirattrs);
+ }
+
+ // drop obsolete columns
+ jdbcTemplate.update("ALTER TABLE RAttr DROP COLUMN schema_name;");
+ jdbcTemplate.update("ALTER TABLE RDerAttr DROP COLUMN DERIVEDSCHEMA_NAME;");
+ jdbcTemplate.update("ALTER TABLE RVirAttr DROP COLUMN VIRTUALSCHEMA_NAME;");
+
+ } catch (DataAccessException ex) {
+ LOG.error("Error accessing RAttr or RAttrTemplate table", ex);
+ }
+ }
+
+ private void addTemplatesToMemberships() {
+ try {
+ LOG.info("Adding templates to memberships");
+ for (Membership membership : membershipDAO.findAll()) {
+
+ final List<MAttr> newMattrs = new ArrayList<MAttr>();
+ final List<MAttrTemplate> newMattrTemplates = new ArrayList<MAttrTemplate>();
+
+ final List<MDerAttr> newMDerattrs = new ArrayList<MDerAttr>();
+ final List<MDerAttrTemplate> newMDerattrTemplates = new ArrayList<MDerAttrTemplate>();
+
+ final List<MVirAttr> newMVirattrs = new ArrayList<MVirAttr>();
+ final List<MVirAttrTemplate> newMVirattrTemplates = new ArrayList<MVirAttrTemplate>();
+
+ LOG.debug("Adding template to membership {}", membership);
+
+ //Create normal attributes templates
+ for (AbstractAttr attr : membership.getAttrs()) {
+ final MAttrTemplate mAttrTemplate = new MAttrTemplate();
+ mAttrTemplate.setOwner(membership.getSyncopeRole());
+ final String schemaName = jdbcTemplate.queryForObject(
+ "SELECT schema_name FROM MAttr WHERE id = ?;", String.class, attr.getId());
+
+ mAttrTemplate.setSchema(schemaDAO.find(schemaName, MSchema.class));
+ newMattrTemplates.add(mAttrTemplate);
+ }
+
+ //Create derived attributes templates
+ for (AbstractDerAttr mDerAttr : membership.getDerAttrs()) {
+ final MDerAttrTemplate mDerattrTemplate = new MDerAttrTemplate();
+ mDerattrTemplate.setOwner(membership.getSyncopeRole());
+ final String mDerSchemaName = jdbcTemplate.queryForObject(
+ "SELECT DERIVEDSCHEMA_NAME FROM MDerAttr WHERE id = ?;", String.class, mDerAttr.getId());
+
+ mDerattrTemplate.setSchema(derSchemaDAO.find(mDerSchemaName, MDerSchema.class));
+ newMDerattrTemplates.add(mDerattrTemplate);
+ }
+
+ //Create virtual attributes templates
+ for (AbstractVirAttr mVirAttr : membership.getVirAttrs()) {
+ final MVirAttrTemplate mVirattrTemplate = new MVirAttrTemplate();
+ mVirattrTemplate.setOwner(membership.getSyncopeRole());
+ final String virSchemaName = jdbcTemplate.queryForObject(
+ "SELECT VIRTUALSCHEMA_NAME FROM MVirAttr WHERE id = ?;", String.class, mVirAttr.getId());
+
+ mVirattrTemplate.setSchema(virSchemaDAO.find(virSchemaName, MVirSchema.class));
+ newMVirattrTemplates.add(mVirattrTemplate);
+ }
+ membership.setAttrs(newMattrs);
+ membership.setDerAttrs(newMDerattrs);
+ membership.setVirAttrs(newMVirattrs);
+ membership.getSyncopeRole().getAttrTemplates(MAttrTemplate.class).addAll(newMattrTemplates);
+ membership.getSyncopeRole().getAttrTemplates(MDerAttrTemplate.class).addAll(newMDerattrTemplates);
+ membership.getSyncopeRole().getAttrTemplates(MVirAttrTemplate.class).addAll(newMVirattrTemplates);
+ }
+ } catch (DataAccessException ex) {
+ LOG.error("Error accessing MAttr, MDerAttr or MVirAttr table", ex);
+ }
+ }
+
+ private void addTemplatesToMAttrs() {
+ try {
+ LOG.info("Adding templates to membership attributes");
+ for (Membership membership : membershipDAO.findAll()) {
+
+ final List<MAttr> newMattrs = new ArrayList<MAttr>();
+ final List<MDerAttr> newMDerattrs = new ArrayList<MDerAttr>();
+ final List<MVirAttr> newMVirattrs = new ArrayList<MVirAttr>();
+
+ // add template to normal attributes
+ for (Long attrId : jdbcTemplate.queryForList("SELECT id FROM MAttr WHERE OWNER_ID = ?", Long.class,
+ membership.getId())) {
+ final MAttr mAttr = attrDAO.find(attrId, MAttr.class);
+
+ LOG.debug("Adding template to membership normal attribute {}", mAttr);
+
+ final String schemaName = jdbcTemplate.queryForObject(
+ "SELECT schema_name FROM MAttr WHERE id = ?;", String.class, attrId);
+
+ mAttr.setTemplate(getTemplate(membership, schemaName, MAttrTemplate.class));
+ newMattrs.add(mAttr);
+ }
+
+ // add template to derived attributes
+ for (Long attrId : jdbcTemplate.queryForList("SELECT id FROM MDerAttr WHERE OWNER_ID = ?", Long.class,
+ membership.getId())) {
+ final MDerAttr mDerAttr = derAttrDAO.find(attrId, MDerAttr.class);
+
+ LOG.debug("Adding template to membership derived attribute {}", mDerAttr);
+
+ final String derSchemaName = jdbcTemplate.queryForObject(
+ "SELECT DERIVEDSCHEMA_NAME FROM MDerAttr WHERE id = ?;", String.class, attrId);
+
+ mDerAttr.setTemplate(getTemplate(membership, derSchemaName, MDerAttrTemplate.class));
+ newMDerattrs.add(mDerAttr);
+ }
+
+ // add template to virtual attributes
+ for (Long attrId : jdbcTemplate.queryForList("SELECT id FROM MVirAttr WHERE OWNER_ID = ?", Long.class,
+ membership.getId())) {
+ final MVirAttr mVirAttr = virAttrDAO.find(attrId, MVirAttr.class);
+
+ LOG.debug("Adding template to membership virtual attribute {}", mVirAttr);
+
+ final String virSchemaName = jdbcTemplate.queryForObject(
+ "SELECT VIRTUALSCHEMA_NAME FROM MVirAttr WHERE id = ?;", String.class, attrId);
+
+ mVirAttr.setTemplate(getTemplate(membership, virSchemaName, MVirAttrTemplate.class));
+ newMVirattrs.add(mVirAttr);
+ }
+ membership.setAttrs(newMattrs);
+ membership.setDerAttrs(newMDerattrs);
+ membership.setVirAttrs(newMVirattrs);
+ }
+
+ // delete obsolete columns
+ jdbcTemplate.update("ALTER TABLE MAttr DROP COLUMN schema_name;");
+ jdbcTemplate.update("ALTER TABLE MDerAttr DROP COLUMN DERIVEDSCHEMA_NAME;");
+ jdbcTemplate.update("ALTER TABLE MVirAttr DROP COLUMN VIRTUALSCHEMA_NAME;");
+ } catch (DataAccessException ex) {
+ LOG.error("Error accessing MAttr or MAttrTemplate table", ex);
+ }
+ }
+
+ private <T extends AbstractAttrTemplate<K>, K extends AbstractSchema> T getTemplate(final Object obj,
+ final String schemaName, final Class<T> reference) {
+ T attrTemplate = null;
+ for (Number number : attrTemplateDAO.findBySchemaName(schemaName, reference)) {
+ final T attrTemplateTemp = attrTemplateDAO.find((Long) number, reference);
+
+ if (attrTemplateTemp.getOwner().equals(obj instanceof SyncopeRole ? (SyncopeRole) obj : ((Membership) obj).
+ getSyncopeRole())) {
+ attrTemplate = attrTemplateTemp;
+ }
+ }
+ return attrTemplate;
+ }
+}
Added: syncope/branches/1_2_X/core-upgrader/src/main/java/org/apache/syncope/upgrader/util/GuardedStringConverter.java
URL: http://svn.apache.org/viewvc/syncope/branches/1_2_X/core-upgrader/src/main/java/org/apache/syncope/upgrader/util/GuardedStringConverter.java?rev=1617488&view=auto
==============================================================================
--- syncope/branches/1_2_X/core-upgrader/src/main/java/org/apache/syncope/upgrader/util/GuardedStringConverter.java (added)
+++ syncope/branches/1_2_X/core-upgrader/src/main/java/org/apache/syncope/upgrader/util/GuardedStringConverter.java Tue Aug 12 14:31:24 2014
@@ -0,0 +1,128 @@
+/*
+ * 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.upgrader.util;
+
+import java.lang.reflect.Field;
+
+import org.identityconnectors.common.Base64;
+import org.identityconnectors.common.security.EncryptorFactory;
+import org.identityconnectors.common.security.GuardedString;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.thoughtworks.xstream.converters.Converter;
+import com.thoughtworks.xstream.converters.MarshallingContext;
+import com.thoughtworks.xstream.converters.UnmarshallingContext;
+import com.thoughtworks.xstream.io.HierarchicalStreamReader;
+import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
+
+/**
+ * Help in XStream serialization of GuardedString by (de)serializing instances using the default Encryptor (which works
+ * consistently across class loading) instead of a random Encryptor instance.
+ *
+ * @see XMLSerializer
+ * @see GuardedString
+ */
+public class GuardedStringConverter implements Converter {
+
+ private static final Logger LOG = LoggerFactory.getLogger(GuardedStringConverter.class);
+
+ @Override
+ public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
+ boolean readOnly = false;
+ try {
+ final Field readOnlyField = GuardedString.class.getDeclaredField("readOnly");
+ readOnlyField.setAccessible(true);
+ readOnly = readOnlyField.getBoolean(source);
+ } catch (Exception e) {
+ LOG.error("Could not get field value", e);
+ }
+ writer.startNode("readonly");
+ writer.setValue(Boolean.toString(readOnly));
+ writer.endNode();
+
+ boolean disposed = false;
+ try {
+ final Field disposedField = GuardedString.class.getDeclaredField("disposed");
+ disposedField.setAccessible(true);
+ disposed = disposedField.getBoolean(source);
+ } catch (Exception e) {
+ LOG.error("Could not get field value", e);
+ }
+ writer.startNode("disposed");
+ writer.setValue(Boolean.toString(disposed));
+ writer.endNode();
+
+ writer.startNode("encryptedBytes");
+ final StringBuilder cleartext = new StringBuilder();
+ ((GuardedString) source).access(new GuardedString.Accessor() {
+
+ @Override
+ public void access(final char[] clearChars) {
+ cleartext.append(clearChars);
+ }
+ });
+ final byte[] encryptedBytes =
+ EncryptorFactory.getInstance().getDefaultEncryptor().encrypt(cleartext.toString().getBytes());
+ writer.setValue(Base64.encode(encryptedBytes));
+ writer.endNode();
+ }
+
+ @Override
+ public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
+ reader.moveDown();
+ final boolean readOnly = Boolean.valueOf(reader.getValue());
+ reader.moveUp();
+
+ reader.moveDown();
+ final boolean disposed = Boolean.valueOf(reader.getValue());
+ reader.moveUp();
+
+ reader.moveDown();
+ final byte[] encryptedBytes = Base64.decode(reader.getValue());
+ reader.moveUp();
+
+ final byte[] clearBytes = EncryptorFactory.getInstance().getDefaultEncryptor().decrypt(encryptedBytes);
+
+ final GuardedString dest = new GuardedString(new String(clearBytes).toCharArray());
+
+ try {
+ final Field readOnlyField = GuardedString.class.getDeclaredField("readOnly");
+ readOnlyField.setAccessible(true);
+ readOnlyField.setBoolean(dest, readOnly);
+ } catch (Exception e) {
+ LOG.error("Could not set field value to {}", readOnly, e);
+ }
+
+ try {
+ final Field readOnlyField = GuardedString.class.getDeclaredField("disposed");
+ readOnlyField.setAccessible(true);
+ readOnlyField.setBoolean(dest, disposed);
+ } catch (Exception e) {
+ LOG.error("Could not set field value to {}", disposed, e);
+ }
+
+ return dest;
+ }
+
+ @Override
+ public boolean canConvert(final Class type) {
+ return type.equals(GuardedString.class);
+ }
+}
\ No newline at end of file
Added: syncope/branches/1_2_X/core-upgrader/src/main/java/org/apache/syncope/upgrader/util/SyncopeDefParams.java
URL: http://svn.apache.org/viewvc/syncope/branches/1_2_X/core-upgrader/src/main/java/org/apache/syncope/upgrader/util/SyncopeDefParams.java?rev=1617488&view=auto
==============================================================================
--- syncope/branches/1_2_X/core-upgrader/src/main/java/org/apache/syncope/upgrader/util/SyncopeDefParams.java (added)
+++ syncope/branches/1_2_X/core-upgrader/src/main/java/org/apache/syncope/upgrader/util/SyncopeDefParams.java Tue Aug 12 14:31:24 2014
@@ -0,0 +1,51 @@
+/*
+ * 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.upgrader.util;
+
+public enum SyncopeDefParams {
+
+ PASSWORD_CIPHER_ALGORITHM("password.cipher.algorithm"),
+ NOTIFICATION_JOB_CRON_EXPRESSION("notificationjob.cronExpression"),
+ NOTIFICATION_MAX_RETRIES("notification.maxRetries"),
+ TOKEN_LENGTH("token.length"),
+ TOKEN_EXPIRE_TIME("token.expireTime"),
+ SELF_REGISTRATION_ALLOWED("selfRegistration.allowed"),
+ AUTHENTICATION_STATUSES("authentication.statuses"),
+ LOG_LASTLOGIN_DATE("log.lastlogindate");
+
+ private final String name;
+
+ SyncopeDefParams(final String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public static boolean contains(final String param) {
+ boolean contains = false;
+ for (SyncopeDefParams defParam : values()) {
+ if (defParam.getName().equals(param)) {
+ contains = true;
+ }
+ }
+ return contains;
+ }
+}
Added: syncope/branches/1_2_X/core-upgrader/src/main/java/org/apache/syncope/upgrader/util/XMLDeserializer.java
URL: http://svn.apache.org/viewvc/syncope/branches/1_2_X/core-upgrader/src/main/java/org/apache/syncope/upgrader/util/XMLDeserializer.java?rev=1617488&view=auto
==============================================================================
--- syncope/branches/1_2_X/core-upgrader/src/main/java/org/apache/syncope/upgrader/util/XMLDeserializer.java (added)
+++ syncope/branches/1_2_X/core-upgrader/src/main/java/org/apache/syncope/upgrader/util/XMLDeserializer.java Tue Aug 12 14:31:24 2014
@@ -0,0 +1,52 @@
+/*
+ * 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.upgrader.util;
+
+import com.thoughtworks.xstream.XStream;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Helper class for deserialization of configuration objects, empowering XStream.
+ *
+ * @see http://xstream.codehaus.org/
+ */
+public final class XMLDeserializer {
+
+ private static final Logger LOG = LoggerFactory.getLogger(XMLDeserializer.class);
+
+ @SuppressWarnings("unchecked")
+ public static <T extends Object> T deserialize(final String serialized) {
+ T result = null;
+
+ final XStream xstream = new XStream();
+ xstream.registerConverter(new GuardedStringConverter());
+ try {
+ result = (T) xstream.fromXML(URLDecoder.decode(serialized, "UTF-8"));
+ } catch (UnsupportedEncodingException e) {
+ LOG.error("During deserialization: Bad serialized input string", e);
+ }
+ return result;
+ }
+
+ private XMLDeserializer() {
+ }
+}
\ No newline at end of file
Added: syncope/branches/1_2_X/core-upgrader/src/main/resources/syncope-1.1.X-1.2.X.sql
URL: http://svn.apache.org/viewvc/syncope/branches/1_2_X/core-upgrader/src/main/resources/syncope-1.1.X-1.2.X.sql?rev=1617488&view=auto
==============================================================================
--- syncope/branches/1_2_X/core-upgrader/src/main/resources/syncope-1.1.X-1.2.X.sql (added)
+++ syncope/branches/1_2_X/core-upgrader/src/main/resources/syncope-1.1.X-1.2.X.sql Tue Aug 12 14:31:24 2014
@@ -0,0 +1,104 @@
+-- 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.
+SET FOREIGN_KEY_CHECKS = 0;
+
+--SYNCOPE-451 upgrade table definitions to comply with new Apache OpenJpa 2.3.0 version
+ALTER TABLE ConnInstance_capabilities CHANGE COLUMN capabilities capabilities VARCHAR(20);
+ALTER TABLE ExternalResource CHANGE COLUMN createTraceLevel createTraceLevel VARCHAR(20);
+ALTER TABLE ExternalResource CHANGE COLUMN deleteTraceLevel deleteTraceLevel VARCHAR(20);
+ALTER TABLE ExternalResource CHANGE COLUMN syncTraceLevel syncTraceLevel VARCHAR(20);
+ALTER TABLE ExternalResource CHANGE COLUMN propagationMode propagationMode VARCHAR(20);
+ALTER TABLE ExternalResource CHANGE COLUMN updateTraceLevel updateTraceLevel VARCHAR(20);
+ALTER TABLE MSchema CHANGE COLUMN type type VARCHAR(20);
+ALTER TABLE RMappingItem CHANGE COLUMN intMappingType intMappingType VARCHAR(23);
+ALTER TABLE RMappingItem CHANGE COLUMN purpose purpose VARCHAR(20);
+ALTER TABLE RSchema CHANGE COLUMN type type VARCHAR(20);
+ALTER TABLE SyncopeLogger CHANGE COLUMN logLevel logLevel VARCHAR(20);
+ALTER TABLE SyncopeLogger CHANGE COLUMN logType logType VARCHAR(20);
+ALTER TABLE SyncopeUser CHANGE COLUMN cipherAlgorithm cipherAlgorithm VARCHAR(20);
+ALTER TABLE UMappingItem CHANGE COLUMN intMappingType intMappingType VARCHAR(23);
+ALTER TABLE UMappingItem CHANGE COLUMN purpose purpose VARCHAR(20);
+ALTER TABLE USchema CHANGE COLUMN type type VARCHAR(20);
+ALTER TABLE SyncopeUser CHANGE COLUMN password password VARCHAR(255);
+
+-- SYNCOPE5-524
+alter table ExternalResource change xmlConfiguration jsonConf text;
+alter table ConnInstance change xmlConfiguration jsonConf text;
+
+-- preliminary steps for upgrade of (refactored) role and membership attributes
+alter table RAttr drop foreign key RAttr_ibfk_2;
+alter table RDerAttr drop foreign key RDerAttr_ibfk_2;
+alter table RVirAttr drop foreign key RVirAttr_ibfk_2;
+
+alter table MAttr drop foreign key MAttr_ibfk_2;
+alter table MDerAttr drop foreign key MDerAttr_ibfk_2;
+alter table MVirAttr drop foreign key MVirAttr_ibfk_2;
+
+alter table UDerAttr drop foreign key UDerAttr_ibfk_2;
+alter table UDerAttr change DERIVEDSCHEMA_NAME DERSCHEMA_NAME VARCHAR(255);
+ALTER TABLE UDerAttr ADD CONSTRAINT UDerAttr_ibfk_2 FOREIGN KEY (DERSCHEMA_NAME) REFERENCES UDerSchema (name);
+
+alter table UVirAttr drop foreign key UVirAttr_ibfk_2;
+alter table UVirAttr change VIRTUALSCHEMA_NAME VIRSCHEMA_NAME VARCHAR(255);
+ALTER TABLE UVirAttr ADD CONSTRAINT UVirAttr_ibfk_2 FOREIGN KEY (VIRSCHEMA_NAME) REFERENCES UVirSchema (name);
+
+-- SYNCOPE-444, SYNCOPE-409, SYNCOPE-445
+ALTER TABLE Notification DROP COLUMN xmlAbout;
+ALTER TABLE Notification DROP COLUMN xmlRecipients;
+
+-- create a backup of SyncopeConf table into new SyncopeConf_temp table
+create table SyncopeConf_temp (confKey varchar(255) primary key, confValue varchar(255));
+insert into SyncopeConf_temp (confKey,confValue) select confKey,confValue from SyncopeConf;
+
+-- delete SyncopeConf table, it will be created and initilized respectively by OpenJpa and ContentInitializer
+DROP TABLE SyncopeConf;
+
+-- delete views and indexes, they will be recreated by ContentInitializer
+DROP VIEW user_search;
+DROP VIEW user_search_attr;
+DROP VIEW user_search_membership;
+DROP VIEW user_search_resource;
+DROP VIEW user_search_null_attr;
+DROP VIEW user_search_role_resource;
+DROP VIEW user_search_unique_attr;
+DROP VIEW role_search;
+DROP VIEW role_search_attr;
+DROP VIEW role_search_entitlements;
+DROP VIEW role_search_null_attr;
+DROP VIEW role_search_resource;
+DROP VIEW role_search_unique_attr;
+
+DROP INDEX UAttrValue_stringvalueIndex ON UAttrValue;
+DROP INDEX UAttrValue_datevalueIndex ON UAttrValue;
+DROP INDEX UAttrValue_longvalueIndex ON UAttrValue;
+DROP INDEX UAttrValue_doublevalueIndex ON UAttrValue;
+DROP INDEX UAttrValue_booleanvalueIndex ON UAttrValue;
+DROP INDEX MAttrValue_stringvalueIndex ON MAttrValue;
+DROP INDEX MAttrValue_datevalueIndex ON MAttrValue;
+DROP INDEX MAttrValue_longvalueIndex ON MAttrValue;
+DROP INDEX MAttrValue_doublevalueIndex ON MAttrValue;
+DROP INDEX MAttrValue_booleanvalueIndex ON MAttrValue;
+DROP INDEX RAttrValue_stringvalueIndex ON RAttrValue;
+DROP INDEX RAttrValue_datevalueIndex ON RAttrValue;
+DROP INDEX RAttrValue_longvalueIndex ON RAttrValue;
+DROP INDEX RAttrValue_doublevalueIndex ON RAttrValue;
+DROP INDEX RAttrValue_booleanvalueIndex ON RAttrValue;
+DROP INDEX Task_executedIndex ON Task;
+DROP INDEX ACT_RU_TASK_PARENT_TASK_ID_ ON ACT_RU_TASK;
+
+
+SET FOREIGN_KEY_CHECKS = 1;
\ No newline at end of file
Added: syncope/branches/1_2_X/core-upgrader/src/main/resources/upgradeContext.xml
URL: http://svn.apache.org/viewvc/syncope/branches/1_2_X/core-upgrader/src/main/resources/upgradeContext.xml?rev=1617488&view=auto
==============================================================================
--- syncope/branches/1_2_X/core-upgrader/src/main/resources/upgradeContext.xml (added)
+++ syncope/branches/1_2_X/core-upgrader/src/main/resources/upgradeContext.xml Tue Aug 12 14:31:24 2014
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:util="http://www.springframework.org/schema/util"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/context
+ http://www.springframework.org/schema/context/spring-context.xsd">
+
+ <context:annotation-config/>
+ <context:component-scan base-package="org.apache.syncope.upgrader"/>
+ <bean id="userWorkflowXML" class="org.apache.syncope.core.util.ResourceWithFallbackLoader">
+ <property name="primary" value="file:${conf.directory}/userWorkflow.bpmn20.xml"/>
+ <property name="fallback" value="classpath:userWorkflow.bpmn20.xml"/>
+ </bean>
+</beans>
Modified: syncope/branches/1_2_X/core/src/main/resources/log4j2.xml
URL: http://svn.apache.org/viewvc/syncope/branches/1_2_X/core/src/main/resources/log4j2.xml?rev=1617488&r1=1617487&r2=1617488&view=diff
==============================================================================
--- syncope/branches/1_2_X/core/src/main/resources/log4j2.xml (original)
+++ syncope/branches/1_2_X/core/src/main/resources/log4j2.xml Tue Aug 12 14:31:24 2014
@@ -69,6 +69,19 @@ under the License.
</Policies>
</RollingRandomAccessFile>
+ <!--upgrader-->
+ <RollingRandomAccessFile name="upgrader" fileName="${log.directory}/upgrader.log"
+ filePattern="${log.directory}/upgrader-%d{yyyy-MM-dd}.log.gz"
+ immediateFlush="false" append="true">
+ <PatternLayout>
+ <pattern>%d{HH:mm:ss.SSS} %-5level %logger - %msg%n</pattern>
+ </PatternLayout>
+ <Policies>
+ <TimeBasedTriggeringPolicy/>
+ <SizeBasedTriggeringPolicy size="250 MB"/>
+ </Policies>
+ </RollingRandomAccessFile>
+
<!-- Audit -->
<Jdbc name="audit" tableName="SYNCOPEAUDIT">
<ConnectionFactory class="org.apache.syncope.core.audit.AuditConnectionFactory" method="getConnection" />
@@ -142,7 +155,12 @@ under the License.
<asyncLogger name="org.apache.cxf" additivity="false" level="ERROR">
<appender-ref ref="rest"/>
</asyncLogger>
-
+
+ <!--upgrader logger-->
+ <asyncLogger name="org.apache.syncope.upgrader" additivity="false" level="OFF">
+ <appender-ref ref="upgrader"/>
+ </asyncLogger>
+
<logger name="syncope.audit" additivity="false" level="DEBUG">
<appender-ref ref="audit"/>
</logger>
Modified: syncope/branches/1_2_X/pom.xml
URL: http://svn.apache.org/viewvc/syncope/branches/1_2_X/pom.xml?rev=1617488&r1=1617487&r2=1617488&view=diff
==============================================================================
--- syncope/branches/1_2_X/pom.xml (original)
+++ syncope/branches/1_2_X/pom.xml Tue Aug 12 14:31:24 2014
@@ -408,7 +408,7 @@ under the License.
<dependencyManagement>
<dependencies>
-
+
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
@@ -1624,6 +1624,7 @@ under the License.
<module>console</module>
<module>standalone</module>
<module>installer</module>
+ <module>core-upgrader</module>
<module>deb</module>
</modules>
</project>