- Timestamp:
- 2012-04-03T20:56:04+12:00 (12 years ago)
- Location:
- main/trunk/greenstone3
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/build.xml
r25321 r25338 1117 1117 </target> 1118 1118 1119 <target name="check-tomcat-running"> 1119 <target name="check-tomcat-running"><!--if you update this target, may want to change similar elements in config-admin--> 1120 1120 <!--can also try the "socket" condition in place of the "http" condition--> 1121 1121 <condition property="tomcat.isrunning"><!--<waitfor maxwait="5" maxwaitunit="second" timeoutproperty="tomcat.isstopped">--> … … 1179 1179 </if> 1180 1180 </target> 1181 1182 <!-- ======================= Admin Targets ============================ --> 1183 1184 <!-- This target won't work with Eclipse because the SecureInputHandler used below conflicts with it. 1185 See http://www.dcepler.net/post.cfm/hiding-password-input-in-ant 1186 But you can do: echo mypassword | ant config-admin --> 1187 <target name="config-admin" description="Reset admin password"> 1188 <input addproperty="admin.password" defaultvalue="admin" message="New admin password (3-8 characters):>"> 1189 <handler classname="org.apache.tools.ant.input.SecureInputHandler" /> <!-- password won't be visible on screen --> 1190 </input> 1191 <echo>PWD: ${admin.password}</echo> 1192 <antcall target="update-userdb"> 1193 <param name="user.username" value="admin"/> 1194 <param name="user.password" value="${admin.password}"/> 1195 <param name="user.groups" value=""/> 1196 <param name="user.status" value=""/> 1197 <param name="user.comment" value="Password updated."/> 1198 <param name="user.email" value=""/> 1199 </antcall> 1200 </target> 1201 1202 <target name="config-user" description="Add or modify users" depends="get-user-data,update-userdb"/> 1203 1204 <target name="get-user-data" description="Get user details"> 1205 <input addproperty="user.username" message="Username:>"/> 1206 <input addproperty="user.password" defaultvalue="" message="Password (3-8 characters):>"> 1207 <handler classname="org.apache.tools.ant.input.SecureInputHandler" /> <!-- password won't be visible on screen --> 1208 </input> 1209 <input addproperty="user.groups" defaultvalue="" message="Groups (comma-separated list):>"/> 1210 <input addproperty="user.status" defaultvalue="true" message="Enabled (true/false):>"/> 1211 <input addproperty="user.comment" defaultvalue="" message="Comment:>"/> 1212 <input addproperty="user.email" defaultvalue="" message="Email:>"/> 1213 </target> 1214 1215 <!-- This target won't work with Eclipse because the SecureInputHandler used below conflicts with it. 1216 See http://www.dcepler.net/post.cfm/hiding-password-input-in-ant 1217 But you can do: echo mypassword | ant config-admin --> 1218 <target name="update-userdb" description="Add or modify users"> 1219 <echo>username: ${user.username}</echo> 1220 <echo>groups: ${user.groups}</echo> 1221 1222 <!-- stop tomcat if running, since derby db is embedded and only allows connections from one jvm instance at a time 1223 See http://db.apache.org/derby/papers/DerbyTut/embedded_intro.html --> 1224 <!--<antcall target="check-tomcat-running"/>--><!--won't set the tomcat.isrunning property for use below--> 1225 <condition property="tomcat.isrunning"> 1226 <http url="http://${tomcat.server}:${tomcat.port}${app.path}"/><!--can also try the "socket" condition in place of the "http" condition--> 1227 </condition> 1228 <if> 1229 <bool> 1230 <istrue value="${tomcat.isrunning}"/> 1231 </bool> 1232 <antcall target="force-stop-tomcat"/> 1233 </if> 1234 1235 <!--<echo>${admin.password}</echo>--> <!-- for testing --> 1236 <java classname="org.greenstone.gsdl3.util.ModifyUsersDB"> 1237 <classpath refid="compile.classpath"/> <!--for ${web.lib}/gsdl3.jar and supporting files--> 1238 <arg file="${web.home}/sites/localsite/etc/usersDB"/> 1239 <arg value="${user.username}"/> 1240 <arg value="password=${user.password}"/> 1241 <arg value="groups=${user.groups}"/> 1242 <arg value="status=${user.status}"/> 1243 <arg value="comment=${user.comment}"/> 1244 <arg value="email=${user.email}"/> 1245 </java> 1246 1247 <!-- run tomcat again if it used to be running --> 1248 <if> 1249 <bool> 1250 <istrue value="${tomcat.isrunning}"/> 1251 </bool> 1252 <antcall target="start-tomcat"/> 1253 </if> 1254 </target> 1255 1181 1256 1182 1257 <!-- ======================= Axis Targets ============================ --> … … 1225 1300 </else> 1226 1301 1227 </if>1228 </target>1229 1230 <!-- This target won't work with Eclipse because the SecureInputHandler used below conflicts with it.1231 See http://www.dcepler.net/post.cfm/hiding-password-input-in-ant1232 But you can do: echo mypassword | ant config-admin -->1233 <target name="config-admin" description="Reset admin password">1234 <input addproperty="admin.password" defaultvalue="admin" message="New admin password (3-8 characters):>">1235 <handler classname="org.apache.tools.ant.input.SecureInputHandler" /> <!-- password won't be visible on screen -->1236 </input>1237 1238 <!-- stop tomcat if running, since derby db is embedded and only allows connections from one jvm instance at a time1239 See http://db.apache.org/derby/papers/DerbyTut/embedded_intro.html -->1240 1241 <!--<antcall target="check-tomcat-running"/>--><!--won't set the tomcat.isrunning property for use below-->1242 <condition property="tomcat.isrunning">1243 <http url="http://${tomcat.server}:${tomcat.port}${app.path}"/><!--can also try the "socket" condition in place of the "http" condition-->1244 </condition>1245 <if>1246 <bool>1247 <istrue value="${tomcat.isrunning}"/>1248 </bool>1249 <antcall target="force-stop-tomcat"/>1250 </if>1251 1252 <!--<echo>${admin.password}</echo>--> <!-- for testing -->1253 <java classname="org.greenstone.gsdl3.util.ChangePwdUsersDB">1254 <classpath refid="compile.classpath"/> <!--for ${web.lib}/gsdl3.jar and supporting files-->1255 <arg file="${web.home}/sites/localsite/etc/usersDB"/>1256 <arg value="admin"/>1257 <arg value="${admin.password}"/>1258 </java>1259 1260 <!-- run tomcat again if it used to be running -->1261 <if>1262 <bool>1263 <istrue value="${tomcat.isrunning}"/>1264 </bool>1265 <antcall target="start-tomcat"/>1266 1302 </if> 1267 1303 </target> -
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/txt2usersDB.java
r25308 r25338 21 21 import java.io.BufferedReader; 22 22 import java.io.IOException; 23 import java.io.File; 23 24 import java.io.FileReader; 24 25 import java.sql.SQLException; 26 27 import org.greenstone.gsdl3.service.Authentication; 25 28 26 29 public class txt2usersDB { 27 30 28 31 public static void main(String[] args) throws SQLException{ 29 30 if (args.length!=2){ 31 System.out.println("Usage: java org.greenstone.gsdl3.txt2usersDB full_path_of_the_text_file full_path_of_the_usersDB"); 32 boolean appending = false; 33 34 String usage = "Usage: java org.greenstone.gsdl3.txt2usersDB full_path_of_the_text_file full_path_of_the_usersDB [-append]"; 35 if (args.length < 2){ 36 System.out.println(usage); 32 37 System.exit(0); 33 38 } 39 File txtfile = new File(args[0]); 40 if(!txtfile.exists()) { 41 System.out.println("File " + args[0] + " does not exist."); 42 System.out.println(usage); 43 System.exit(0); 44 } 45 34 46 try { 35 47 BufferedReader in = new BufferedReader(new FileReader(args[0])); … … 37 49 DerbyWrapper dw=new DerbyWrapper(); 38 50 dw.connectDatabase(args[1],false); 39 boolean delete_rows = dw.deleteAllUser(); 40 dw.closeDatabase(); 41 if (!delete_rows){ 42 System.out.println("Couldn't delete rows of the users table"); 43 System.exit(0); 44 } 51 52 if(args.length > 2 && args[2].equals("-append")) { 53 appending = true; 54 } else { 55 // no appending, replace existing database: the text file 56 // represents the new database, so delete the existing DB first 57 boolean delete_rows = dw.deleteAllUser(); 58 dw.closeDatabase(); 59 if (!delete_rows){ 60 System.out.println("Couldn't delete rows of the users table"); 61 System.exit(0); 62 } 63 } 64 45 65 String username=null; 46 66 String password=null; … … 49 69 String comment=null; 50 70 String email=null; 71 51 72 while ((str = in.readLine()) != null) { 52 73 //ystem.out.println(str); … … 88 109 groups=str.substring(str.indexOf(">")+1,str.length()); 89 110 } 90 if (field.equals("password")){ 91 //password=dw.rot13(str.substring(str.indexOf(">")+1,str.length())); 111 if (field.equals("password")){ 92 112 password=str.substring(str.indexOf(">")+1,str.length()); 93 113 } … … 97 117 } 98 118 else if (str.equals("----------------------------------------------------------------------") 99 || str.equals("-------------------------------------")) { 119 || str.equals("-------------------------------------")) { 100 120 101 if ((username!=null) && (password!=null) && (groups!=null) && (accountstatus!=null) && (comment!=null) && (email!=null)) {121 if ((username!=null) && (password!=null) && (groups!=null) && (accountstatus!=null) && (comment!=null)) { 102 122 dw.connectDatabase(args[1],false); 103 dw.addUser(username, password, groups, accountstatus, comment, email); 123 124 // check if it's a new user or already exists in the database 125 UserQueryResult findUserResult = dw.findUser(username); 126 127 if(findUserResult == null) { // add new user 128 if(password.length() >= 3 && password.length() <= 8) { // if not yet encrypted, encrypt first 129 password = Authentication.hashPassword(password); 130 } // if > 8 chars, password for user being added was already encrypted (hashed-and-hexed) 131 dw.addUser(username, password, groups, accountstatus, comment, email); 132 } 133 134 else { // modify existing user 135 // if any of the other fields are not specified, get them from the database 136 UserTermInfo user = findUserResult.getUserTerms().get(0); 137 138 if(password.length() < 3 || password.length() > 8) { // includes empty string case 139 password = user.password; 140 } else { // need to first encrypt (hash-and-hex) the user-entered password 141 // Use the same encryption technique used by the Admin Authentication page 142 // This ensures that the password generated for a string remains consistent 143 password = Authentication.hashPassword(password); 144 } 145 groups = groups.equals("") ? user.groups : groups; 146 accountstatus = accountstatus.equals("") ? user.accountstatus : accountstatus; 147 comment = comment.equals("") ? user.comment : comment; 148 149 if (email == null) { // special checking for backwards compatibility since old DB did not have email field 150 email = ""; 151 } 152 if(user.email == null) { 153 user.email = ""; 154 } 155 if(email.equals("")) { 156 email = user.email; 157 } 158 159 //System.err.println("**** Password: " + password); 160 //System.err.println("**** " + username + " " + password + " " + groups + " " + accountstatus + " " + comment + " " + email); 161 dw.modifyUserInfo(username, password, groups, accountstatus, comment, email); 162 } 163 104 164 username=null; 105 165 password=null; … … 112 172 } 113 173 } 114 else { // encrypted passwords can span multiple lines for some reason 174 175 // only true back when when hashed passwords weren't being converted to hex 176 //else { // encrypted passwords can span multiple lines for some reason 115 177 // assume that is the case here 116 if(password != null) { 117 password = password + "\n" + str; 118 } 119 } 120 } 178 //if(password != null) { 179 // password = password + "\n" + str; 180 // } 181 //} 182 183 } 184 //dw.closeDatabase(); 121 185 in.close(); 122 186 } catch (IOException e) {
Note:
See TracChangeset
for help on using the changeset viewer.