r1305 - in xwiki-tools: . cryptpasswords cryptpasswords/lib

Sergiu Dumitriu sdumitriu at users.forge.objectweb.org
Mon Sep 11 21:23:07 CEST 2006


Author: sdumitriu
Date: 2006-09-11 21:23:06 +0200 (Mon, 11 Sep 2006)
New Revision: 1305

Added:
   xwiki-tools/cryptpasswords/
   xwiki-tools/cryptpasswords/crypt.groovy
   xwiki-tools/cryptpasswords/crypt.sh
   xwiki-tools/cryptpasswords/env.sh
   xwiki-tools/cryptpasswords/hibernate.cfg.xml
   xwiki-tools/cryptpasswords/lib/
   xwiki-tools/cryptpasswords/lib/commons-cli-1.0.jar
Log:
Adding cryptpasswords tool for converting password properties from simple unencrypted string to MD5 hashes

Added: xwiki-tools/cryptpasswords/crypt.groovy
===================================================================
--- xwiki-tools/cryptpasswords/crypt.groovy	2006-09-11 16:16:45 UTC (rev 1304)
+++ xwiki-tools/cryptpasswords/crypt.groovy	2006-09-11 19:23:06 UTC (rev 1305)
@@ -0,0 +1,69 @@
+package xwiki.export;
+
+import com.xpn.xwiki.*;
+import com.xpn.xwiki.objects.classes.*;
+
+println "Starting password encryption"
+println "===== WARNING!!! ====="
+println "This action should only be performed once."
+println "Otherwise, all passwords will be double encrypted,"
+println "  blocking all access for existing users."
+
+println "Continue? [y/n]"
+cont = System.in.readLine()
+
+if(cont.toLowerCase().startsWith("n")) {
+    println "Good."
+    System.exit(0);
+}
+
+context = new XWikiContext();
+
+context.setUser("XWiki.superadmin");
+config = new XWikiConfig();
+config.put("xwiki.store.class", "com.xpn.xwiki.store.XWikiHibernateStore");
+config.put("xwiki.store.hibernate.path", "./hibernate.cfg.xml");
+config.put("xwiki.store.hibernate.updateschema", "1");
+config.put("xwiki.virtual", "1");
+println "Starting xwiki"
+xwiki = new XWiki(config, context);
+context.setWiki(xwiki);
+
+db = "xwiki"
+// Change this to export a different database
+// db = "mydb"
+
+println("Encrypting all passwords in database " + db)
+context.setDatabase(db);
+
+classes = xwiki.getClassList(context)
+for(xclassname in classes) {
+  // See if this class has password fields
+  xclass = xwiki.getDocument(xclassname, context).getxWikiClass();
+  props = xclass.getProperties();
+  for(prop in props) {
+    if(prop instanceof com.xpn.xwiki.objects.classes.PasswordClass){
+      sql = ", BaseObject as obj where obj.name="+ xwiki.getFullNameSQL()+ " and obj.className='" + xclassname + "'";
+      results = xwiki.getStore().searchDocumentsNames(sql, context);
+      for(docname in results) {
+        doc = xwiki.getDocument(docname, context);
+        for(obj in doc.getObjects(xclassname)){
+	  pwdprop = obj.get(prop.getName());
+	  unencryptedPassword = pwdprop.getValue();
+	  encryptedPassword = PasswordClass.getPasswordDigest(unencryptedPassword);
+	  pwdprop.setValue(encryptedPassword);
+	  doc.setMetaDataDirty(true);
+	  xwiki.saveDocument(doc, context);
+	}
+      }
+    }
+  }
+}
+/*
+sql = ", BaseObject as obj where obj.name="+ xwiki.getFullNameSQL()+ " and obj.className='XWiki.XWikiUsers'";
+results = xwiki.getStore().searchDocumentsNames(sql, context);
+results.each { item -> print "${item}-" }
+println "";
+*/
+println "Finished."
+System.exit(0)
\ No newline at end of file

Added: xwiki-tools/cryptpasswords/crypt.sh
===================================================================
--- xwiki-tools/cryptpasswords/crypt.sh	2006-09-11 16:16:45 UTC (rev 1304)
+++ xwiki-tools/cryptpasswords/crypt.sh	2006-09-11 19:23:06 UTC (rev 1305)
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+source env.sh
+
+java groovy.lang.GroovyShell crypt.groovy


Property changes on: xwiki-tools/cryptpasswords/crypt.sh
___________________________________________________________________
Name: svn:executable
   + *

Added: xwiki-tools/cryptpasswords/env.sh
===================================================================
--- xwiki-tools/cryptpasswords/env.sh	2006-09-11 16:16:45 UTC (rev 1304)
+++ xwiki-tools/cryptpasswords/env.sh	2006-09-11 19:23:06 UTC (rev 1305)
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+XWIKIHOME=../../xwiki/trunk
+XWIKILIB=${XWIKIHOME}/lib
+TOOLSLIB=./lib
+
+TOOLSPATH="${TOOLSLIB}/commons-cli-1.0.jar"
+
+XWIKIPATH="${XWIKIHOME}/release/xwiki.jar"
+for lib in `ls "${XWIKILIB}"`
+do
+	XWIKIPATH="${XWIKIPATH}:${XWIKILIB}/$lib"
+done
+
+export CP="${TOOLSPATH}:${XWIKIPATH}"
+# For windows + cygwin:
+#export CLASSPATH=`cygpath --path --windows "$CP"`
+export CLASSPATH="${TOOLSPATH}:${XWIKIPATH}"


Property changes on: xwiki-tools/cryptpasswords/env.sh
___________________________________________________________________
Name: svn:executable
   + *

Added: xwiki-tools/cryptpasswords/hibernate.cfg.xml
===================================================================
--- xwiki-tools/cryptpasswords/hibernate.cfg.xml	2006-09-11 16:16:45 UTC (rev 1304)
+++ xwiki-tools/cryptpasswords/hibernate.cfg.xml	2006-09-11 19:23:06 UTC (rev 1305)
@@ -0,0 +1,32 @@
+<?xml version='1.0' encoding='utf-8'?>
+<!DOCTYPE hibernate-configuration PUBLIC 
+  "-//Hibernate/Hibernate Configuration DTD//EN"
+  "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
+<hibernate-configuration>
+<session-factory>
+<property name="show_sql">false</property>
+<property name="use_outer_join">true</property>
+
+<property name="dbcp.defaultAutoCommit">false</property>
+<property name="dbcp.maxActive">50</property>
+<property name="dbcp.maxIdle">5</property>
+<property name="dbcp.maxWait">30000</property>
+<property name="dbcp.whenExhaustedAction">1</property>
+<property name="dbcp.ps.whenExhaustedAction">1</property>
+<property name="dbcp.ps.maxActive">20</property>
+<property name="dbcp.ps.maxWait">120000</property>
+<property name="dbcp.ps.maxIdle">20</property>
+
+<property name="connection.url">jdbc:mysql://localhost/iteach</property>
+<property name="connection.username">iteach</property>
+<property name="connection.password">iteachpwd</property>
+<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
+<property name="connection.provider_class">com.xpn.xwiki.store.DBCPConnectionProvider</property>
+<property name="connection.pool_size">5</property>
+<property name="statement_cache.size">5</property>
+<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
+<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
+<!-- Mapping files -->
+<mapping resource="xwiki.hbm.xml"/>
+</session-factory>
+</hibernate-configuration>

Added: xwiki-tools/cryptpasswords/lib/commons-cli-1.0.jar
===================================================================
(Binary files differ)


Property changes on: xwiki-tools/cryptpasswords/lib/commons-cli-1.0.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream





More information about the Xwiki-notifications mailing list