You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openmeetings.apache.org by so...@apache.org on 2016/03/15 05:22:39 UTC

svn commit: r1735019 - in /openmeetings/application: branches/3.1.x/openmeetings-db/src/main/java/org/apache/openmeetings/db/dao/server/ branches/3.1.x/openmeetings-install/src/main/java/org/apache/openmeetings/backup/ trunk/openmeetings-db/src/main/ja...

Author: solomax
Date: Tue Mar 15 04:22:38 2016
New Revision: 1735019

URL: http://svn.apache.org/viewvc?rev=1735019&view=rev
Log:
[OPENMEETINGS-1348] 2.1.0 backup with ldap users is imported as expected

Modified:
    openmeetings/application/branches/3.1.x/openmeetings-db/src/main/java/org/apache/openmeetings/db/dao/server/LdapConfigDao.java
    openmeetings/application/branches/3.1.x/openmeetings-install/src/main/java/org/apache/openmeetings/backup/BackupImport.java
    openmeetings/application/trunk/openmeetings-db/src/main/java/org/apache/openmeetings/db/dao/server/LdapConfigDao.java
    openmeetings/application/trunk/openmeetings-install/src/main/java/org/apache/openmeetings/backup/BackupImport.java

Modified: openmeetings/application/branches/3.1.x/openmeetings-db/src/main/java/org/apache/openmeetings/db/dao/server/LdapConfigDao.java
URL: http://svn.apache.org/viewvc/openmeetings/application/branches/3.1.x/openmeetings-db/src/main/java/org/apache/openmeetings/db/dao/server/LdapConfigDao.java?rev=1735019&r1=1735018&r2=1735019&view=diff
==============================================================================
--- openmeetings/application/branches/3.1.x/openmeetings-db/src/main/java/org/apache/openmeetings/db/dao/server/LdapConfigDao.java (original)
+++ openmeetings/application/branches/3.1.x/openmeetings-db/src/main/java/org/apache/openmeetings/db/dao/server/LdapConfigDao.java Tue Mar 15 04:22:38 2016
@@ -57,98 +57,6 @@ public class LdapConfigDao implements ID
 	@Autowired
 	private UserDao userDao;
 
-	public Long addLdapConfig(String name, Boolean addDomainToUserName,
-			String configFileName, String domain, Long insertedby,
-			Boolean isActive) {
-		try {
-
-			LdapConfig ldapConfig = new LdapConfig();
-			ldapConfig.setAddDomainToUserName(addDomainToUserName);
-			ldapConfig.setConfigFileName(configFileName);
-			ldapConfig.setDeleted(false);
-			ldapConfig.setDomain(domain);
-			ldapConfig.setActive(isActive);
-			ldapConfig.setName(name);
-			ldapConfig.setInserted(new Date());
-			if (insertedby != null) {
-				log.debug("addLdapConfig :1: " + userDao.get(insertedby));
-				ldapConfig.setInsertedby(userDao.get(insertedby));
-			}
-
-			log.debug("addLdapConfig :2: " + insertedby);
-
-			ldapConfig = em.merge(ldapConfig);
-			Long id = ldapConfig.getId();
-
-			if (id != null) {
-				return id;
-			} else {
-				throw new Exception("Could not store SOAPLogin");
-			}
-
-		} catch (Exception ex2) {
-			log.error("[addLdapConfig]: ", ex2);
-		}
-		return null;
-	}
-
-	public Long addLdapConfigByObject(LdapConfig ldapConfig) {
-		try {
-
-			ldapConfig.setDeleted(false);
-			ldapConfig.setInserted(new Date());
-
-			ldapConfig = em.merge(ldapConfig);
-			Long id = ldapConfig.getId();
-
-			if (id != null) {
-				return id;
-			} else {
-				throw new Exception("Could not store SOAPLogin");
-			}
-
-		} catch (Exception ex2) {
-			log.error("[addLdapConfig]: ", ex2);
-		}
-		return null;
-	}
-
-	public Long updateLdapConfig(Long id, String name,
-			Boolean addDomainToUserName, String configFileName, String domain,
-			Long updatedby, Boolean isActive) {
-		try {
-
-			LdapConfig ldapConfig = get(id);
-
-			if (ldapConfig == null) {
-				return -1L;
-			}
-
-			ldapConfig.setAddDomainToUserName(addDomainToUserName);
-			ldapConfig.setConfigFileName(configFileName);
-			ldapConfig.setDeleted(false);
-			ldapConfig.setDomain(domain);
-			ldapConfig.setActive(isActive);
-			ldapConfig.setName(name);
-			ldapConfig.setUpdated(new Date());
-			if (updatedby != null) {
-				log.debug("updateLdapConfig :1: " + userDao.get(updatedby));
-				ldapConfig.setUpdatedby(userDao.get(updatedby));
-			}
-
-			log.debug("updateLdapConfig :2: " + updatedby);
-
-			ldapConfig = em.merge(ldapConfig);
-			id = ldapConfig.getId();
-
-			return id;
-
-		} catch (Exception ex2) {
-			log.error("[updateLdapConfig]: ", ex2);
-		}
-		return -1L;
-	}
-
 	@Override
 	public LdapConfig get(Long id) {
 		try {
@@ -231,20 +139,19 @@ public class LdapConfigDao implements ID
 	@Override
 	public LdapConfig update(LdapConfig entity, Long userId) {
 		try {
+			entity.setDeleted(false);
 			if (entity.getId() == null) {
 				entity.setInserted(new Date());
 				if (userId != null) {
 					entity.setInsertedby(userDao.get(userId));
 				}
-				entity.setDeleted(false);
 				em.persist(entity);
 			} else {
 				entity.setUpdated(new Date());
 				if (userId != null) {
 					entity.setUpdatedby(userDao.get(userId));
 				}
-				entity.setDeleted(false);
-				em.merge(entity);
+				entity = em.merge(entity);
 			}
 		} catch (PersistenceException ex) {
 			log.error("[update LdapConfig]", ex);

Modified: openmeetings/application/branches/3.1.x/openmeetings-install/src/main/java/org/apache/openmeetings/backup/BackupImport.java
URL: http://svn.apache.org/viewvc/openmeetings/application/branches/3.1.x/openmeetings-install/src/main/java/org/apache/openmeetings/backup/BackupImport.java?rev=1735019&r1=1735018&r2=1735019&view=diff
==============================================================================
--- openmeetings/application/branches/3.1.x/openmeetings-install/src/main/java/org/apache/openmeetings/backup/BackupImport.java (original)
+++ openmeetings/application/branches/3.1.x/openmeetings-install/src/main/java/org/apache/openmeetings/backup/BackupImport.java Tue Mar 15 04:22:38 2016
@@ -30,6 +30,7 @@ import static org.apache.openmeetings.ut
 import static org.apache.openmeetings.util.OmFileHelper.profilesPrefix;
 import static org.apache.openmeetings.util.OpenmeetingsVariables.CONFIG_CRYPT_KEY;
 import static org.apache.openmeetings.util.OpenmeetingsVariables.webAppRootKey;
+import static org.apache.openmeetings.util.OpenmeetingsVariables.CONFIG_DEFAULT_LDAP_ID;
 
 import java.io.File;
 import java.io.FileInputStream;
@@ -121,6 +122,7 @@ import org.xml.sax.InputSource;
 
 public class BackupImport {
 	private static final Logger log = Red5LoggerFactory.getLogger(BackupImport.class, webAppRootKey);
+	private static final String LDAP_EXT_TYPE = "LDAP";
 
 	@Autowired
 	private AppointmentDao appointmentDao;
@@ -201,8 +203,10 @@ public class BackupImport {
 			}
 			// for each entry to be extracted
 			File fentry = new File(f, fName);
-			File dir = fentry.isDirectory() ? fentry : fentry.getParentFile();
-			dir.mkdirs();
+			File dir = zipentry.isDirectory() ? fentry : fentry.getParentFile();
+			if (!dir.exists()) {
+				dir.mkdirs();
+			}
 			if (fentry.isDirectory()) {
 				zipentry = zipinputstream.getNextEntry();
 				continue;
@@ -267,7 +271,35 @@ public class BackupImport {
 			}
 		}
 
-		log.info("Groups import complete, starting user import");
+		log.info("Groups import complete, starting LDAP config import");
+		/*
+		 * ##################### Import LDAP Configs
+		 */
+		Long defaultLdapId = configurationDao.getConfValue(CONFIG_DEFAULT_LDAP_ID, Long.class, null);
+		{
+			List<LdapConfig> list = readList(simpleSerializer, f, "ldapconfigs.xml", "ldapconfigs", LdapConfig.class, true);
+			for (LdapConfig c : list) {
+				if (!"local DB [internal]".equals(c.getName())) {
+					c = ldapConfigDao.update(c, null);
+					if (defaultLdapId == null) {
+						defaultLdapId = c.getId();
+					}
+				}
+			}
+		}
+
+		log.info("Ldap config import complete, starting OAuth2 server import");
+		/*
+		 * ##################### OAuth2 servers
+		 */
+		{
+			List<OAuthServer> list = readList(simpleSerializer, f, "oauth2servers.xml", "oauth2servers", OAuthServer.class, true);
+			for (OAuthServer s : list) {
+				auth2Dao.update(s, null);
+			}
+		}
+
+		log.info("OAuth2 servers import complete, starting user import");
 		/*
 		 * ##################### Import Users
 		 */
@@ -299,6 +331,14 @@ public class BackupImport {
 				if (u.getSipUser() != null && u.getSipUser().getId() != 0) {
 					u.getSipUser().setId(0);
 				}
+				if (LDAP_EXT_TYPE.equals(u.getExternalType()) && User.Type.external != u.getType()) {
+					log.warn("Found LDAP user in 'old' format, external_type == 'LDAP':: " + u);
+					u.setType(User.Type.ldap);
+					u.setExternalType(null);
+					if (u.getDomainId() == null) {
+						u.setDomainId(defaultLdapId); //domainId was not supported in old versions of OM
+					}
+				}
 				if (!Strings.isEmpty(u.getExternalType())) {
 					u.setType(User.Type.external);
 				}
@@ -426,20 +466,7 @@ public class BackupImport {
 			}
 		}
 
-		log.info("Meeting members import complete, starting ldap config import");
-		/*
-		 * ##################### Import LDAP Configs
-		 */
-		{
-			List<LdapConfig> list = readList(simpleSerializer, f, "ldapconfigs.xml", "ldapconfigs", LdapConfig.class, true);
-			for (LdapConfig c : list) {
-				if (!"local DB [internal]".equals(c.getName())) {
-					ldapConfigDao.addLdapConfigByObject(c);
-				}
-			}
-		}
-
-		log.info("Ldap config import complete, starting cluster servers import");
+		log.info("Meeting members import complete, starting cluster server import");
 		/*
 		 * ##################### Cluster servers
 		 */
@@ -450,18 +477,7 @@ public class BackupImport {
 			}
 		}
 
-		log.info("Cluster servers import complete, starting OAuth2 servers import");
-		/*
-		 * ##################### OAuth2 servers
-		 */
-		{
-			List<OAuthServer> list = readList(simpleSerializer, f, "oauth2servers.xml", "oauth2servers", OAuthServer.class, true);
-			for (OAuthServer s : list) {
-				auth2Dao.update(s, null);
-			}
-		}
-
-		log.info("OAuth2 servers import complete, starting recordings import");
+		log.info("Cluster servers import complete, starting recordings import");
 		/*
 		 * ##################### Import Recordings
 		 */

Modified: openmeetings/application/trunk/openmeetings-db/src/main/java/org/apache/openmeetings/db/dao/server/LdapConfigDao.java
URL: http://svn.apache.org/viewvc/openmeetings/application/trunk/openmeetings-db/src/main/java/org/apache/openmeetings/db/dao/server/LdapConfigDao.java?rev=1735019&r1=1735018&r2=1735019&view=diff
==============================================================================
--- openmeetings/application/trunk/openmeetings-db/src/main/java/org/apache/openmeetings/db/dao/server/LdapConfigDao.java (original)
+++ openmeetings/application/trunk/openmeetings-db/src/main/java/org/apache/openmeetings/db/dao/server/LdapConfigDao.java Tue Mar 15 04:22:38 2016
@@ -57,98 +57,6 @@ public class LdapConfigDao implements ID
 	@Autowired
 	private UserDao userDao;
 
-	public Long addLdapConfig(String name, Boolean addDomainToUserName,
-			String configFileName, String domain, Long insertedby,
-			Boolean isActive) {
-		try {
-
-			LdapConfig ldapConfig = new LdapConfig();
-			ldapConfig.setAddDomainToUserName(addDomainToUserName);
-			ldapConfig.setConfigFileName(configFileName);
-			ldapConfig.setDeleted(false);
-			ldapConfig.setDomain(domain);
-			ldapConfig.setActive(isActive);
-			ldapConfig.setName(name);
-			ldapConfig.setInserted(new Date());
-			if (insertedby != null) {
-				log.debug("addLdapConfig :1: " + userDao.get(insertedby));
-				ldapConfig.setInsertedby(userDao.get(insertedby));
-			}
-
-			log.debug("addLdapConfig :2: " + insertedby);
-
-			ldapConfig = em.merge(ldapConfig);
-			Long id = ldapConfig.getId();
-
-			if (id != null) {
-				return id;
-			} else {
-				throw new Exception("Could not store SOAPLogin");
-			}
-
-		} catch (Exception ex2) {
-			log.error("[addLdapConfig]: ", ex2);
-		}
-		return null;
-	}
-
-	public Long addLdapConfigByObject(LdapConfig ldapConfig) {
-		try {
-
-			ldapConfig.setDeleted(false);
-			ldapConfig.setInserted(new Date());
-
-			ldapConfig = em.merge(ldapConfig);
-			Long id = ldapConfig.getId();
-
-			if (id != null) {
-				return id;
-			} else {
-				throw new Exception("Could not store SOAPLogin");
-			}
-
-		} catch (Exception ex2) {
-			log.error("[addLdapConfig]: ", ex2);
-		}
-		return null;
-	}
-
-	public Long updateLdapConfig(Long id, String name,
-			Boolean addDomainToUserName, String configFileName, String domain,
-			Long updatedby, Boolean isActive) {
-		try {
-
-			LdapConfig ldapConfig = get(id);
-
-			if (ldapConfig == null) {
-				return -1L;
-			}
-
-			ldapConfig.setAddDomainToUserName(addDomainToUserName);
-			ldapConfig.setConfigFileName(configFileName);
-			ldapConfig.setDeleted(false);
-			ldapConfig.setDomain(domain);
-			ldapConfig.setActive(isActive);
-			ldapConfig.setName(name);
-			ldapConfig.setUpdated(new Date());
-			if (updatedby != null) {
-				log.debug("updateLdapConfig :1: " + userDao.get(updatedby));
-				ldapConfig.setUpdatedby(userDao.get(updatedby));
-			}
-
-			log.debug("updateLdapConfig :2: " + updatedby);
-
-			ldapConfig = em.merge(ldapConfig);
-			id = ldapConfig.getId();
-
-			return id;
-
-		} catch (Exception ex2) {
-			log.error("[updateLdapConfig]: ", ex2);
-		}
-		return -1L;
-	}
-
 	@Override
 	public LdapConfig get(Long id) {
 		try {
@@ -231,20 +139,19 @@ public class LdapConfigDao implements ID
 	@Override
 	public LdapConfig update(LdapConfig entity, Long userId) {
 		try {
+			entity.setDeleted(false);
 			if (entity.getId() == null) {
 				entity.setInserted(new Date());
 				if (userId != null) {
 					entity.setInsertedby(userDao.get(userId));
 				}
-				entity.setDeleted(false);
 				em.persist(entity);
 			} else {
 				entity.setUpdated(new Date());
 				if (userId != null) {
 					entity.setUpdatedby(userDao.get(userId));
 				}
-				entity.setDeleted(false);
-				em.merge(entity);
+				entity = em.merge(entity);
 			}
 		} catch (PersistenceException ex) {
 			log.error("[update LdapConfig]", ex);

Modified: openmeetings/application/trunk/openmeetings-install/src/main/java/org/apache/openmeetings/backup/BackupImport.java
URL: http://svn.apache.org/viewvc/openmeetings/application/trunk/openmeetings-install/src/main/java/org/apache/openmeetings/backup/BackupImport.java?rev=1735019&r1=1735018&r2=1735019&view=diff
==============================================================================
--- openmeetings/application/trunk/openmeetings-install/src/main/java/org/apache/openmeetings/backup/BackupImport.java (original)
+++ openmeetings/application/trunk/openmeetings-install/src/main/java/org/apache/openmeetings/backup/BackupImport.java Tue Mar 15 04:22:38 2016
@@ -30,6 +30,7 @@ import static org.apache.openmeetings.ut
 import static org.apache.openmeetings.util.OmFileHelper.profilesPrefix;
 import static org.apache.openmeetings.util.OpenmeetingsVariables.CONFIG_CRYPT_KEY;
 import static org.apache.openmeetings.util.OpenmeetingsVariables.webAppRootKey;
+import static org.apache.openmeetings.util.OpenmeetingsVariables.CONFIG_DEFAULT_LDAP_ID;
 
 import java.io.File;
 import java.io.FileInputStream;
@@ -121,6 +122,7 @@ import org.xml.sax.InputSource;
 
 public class BackupImport {
 	private static final Logger log = Red5LoggerFactory.getLogger(BackupImport.class, webAppRootKey);
+	private static final String LDAP_EXT_TYPE = "LDAP";
 
 	@Autowired
 	private AppointmentDao appointmentDao;
@@ -201,8 +203,10 @@ public class BackupImport {
 			}
 			// for each entry to be extracted
 			File fentry = new File(f, fName);
-			File dir = fentry.isDirectory() ? fentry : fentry.getParentFile();
-			dir.mkdirs();
+			File dir = zipentry.isDirectory() ? fentry : fentry.getParentFile();
+			if (!dir.exists()) {
+				dir.mkdirs();
+			}
 			if (fentry.isDirectory()) {
 				zipentry = zipinputstream.getNextEntry();
 				continue;
@@ -267,7 +271,35 @@ public class BackupImport {
 			}
 		}
 
-		log.info("Groups import complete, starting user import");
+		log.info("Groups import complete, starting LDAP config import");
+		/*
+		 * ##################### Import LDAP Configs
+		 */
+		Long defaultLdapId = configurationDao.getConfValue(CONFIG_DEFAULT_LDAP_ID, Long.class, null);
+		{
+			List<LdapConfig> list = readList(simpleSerializer, f, "ldapconfigs.xml", "ldapconfigs", LdapConfig.class, true);
+			for (LdapConfig c : list) {
+				if (!"local DB [internal]".equals(c.getName())) {
+					c = ldapConfigDao.update(c, null);
+					if (defaultLdapId == null) {
+						defaultLdapId = c.getId();
+					}
+				}
+			}
+		}
+
+		log.info("Ldap config import complete, starting OAuth2 server import");
+		/*
+		 * ##################### OAuth2 servers
+		 */
+		{
+			List<OAuthServer> list = readList(simpleSerializer, f, "oauth2servers.xml", "oauth2servers", OAuthServer.class, true);
+			for (OAuthServer s : list) {
+				auth2Dao.update(s, null);
+			}
+		}
+
+		log.info("OAuth2 servers import complete, starting user import");
 		/*
 		 * ##################### Import Users
 		 */
@@ -299,6 +331,14 @@ public class BackupImport {
 				if (u.getSipUser() != null && u.getSipUser().getId() != 0) {
 					u.getSipUser().setId(0);
 				}
+				if (LDAP_EXT_TYPE.equals(u.getExternalType()) && User.Type.external != u.getType()) {
+					log.warn("Found LDAP user in 'old' format, external_type == 'LDAP':: " + u);
+					u.setType(User.Type.ldap);
+					u.setExternalType(null);
+					if (u.getDomainId() == null) {
+						u.setDomainId(defaultLdapId); //domainId was not supported in old versions of OM
+					}
+				}
 				if (!Strings.isEmpty(u.getExternalType())) {
 					u.setType(User.Type.external);
 				}
@@ -426,20 +466,7 @@ public class BackupImport {
 			}
 		}
 
-		log.info("Meeting members import complete, starting ldap config import");
-		/*
-		 * ##################### Import LDAP Configs
-		 */
-		{
-			List<LdapConfig> list = readList(simpleSerializer, f, "ldapconfigs.xml", "ldapconfigs", LdapConfig.class, true);
-			for (LdapConfig c : list) {
-				if (!"local DB [internal]".equals(c.getName())) {
-					ldapConfigDao.addLdapConfigByObject(c);
-				}
-			}
-		}
-
-		log.info("Ldap config import complete, starting cluster servers import");
+		log.info("Meeting members import complete, starting cluster server import");
 		/*
 		 * ##################### Cluster servers
 		 */
@@ -450,18 +477,7 @@ public class BackupImport {
 			}
 		}
 
-		log.info("Cluster servers import complete, starting OAuth2 servers import");
-		/*
-		 * ##################### OAuth2 servers
-		 */
-		{
-			List<OAuthServer> list = readList(simpleSerializer, f, "oauth2servers.xml", "oauth2servers", OAuthServer.class, true);
-			for (OAuthServer s : list) {
-				auth2Dao.update(s, null);
-			}
-		}
-
-		log.info("OAuth2 servers import complete, starting recordings import");
+		log.info("Cluster servers import complete, starting recordings import");
 		/*
 		 * ##################### Import Recordings
 		 */