Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 40 package org.dspace.administer; 41 42 import java.io.BufferedReader ; 43 import java.io.InputStreamReader ; 44 45 import org.dspace.core.Context; 46 import org.dspace.eperson.EPerson; 47 import org.dspace.eperson.Group; 48 49 60 public class CreateAdministrator 61 { 62 68 public static void main(String [] argv) 69 { 70 Context context = null; 71 BufferedReader input = null; 72 73 try 74 { 75 input = new BufferedReader (new InputStreamReader (System.in)); 77 78 context = new Context(); 79 80 context.setIgnoreAuthorization(true); 83 84 System.out.println("Creating an initial administrator account"); 85 86 boolean dataOK = false; 87 88 String email = null; 89 String firstName = null; 90 String lastName = null; 91 String password1 = null; 92 String password2 = null; 93 94 while (!dataOK) 95 { 96 System.out.print("E-mail address: "); 97 System.out.flush(); 98 99 email = input.readLine().trim(); 100 101 System.out.print("First name: "); 102 System.out.flush(); 103 104 firstName = input.readLine().trim(); 105 106 System.out.print("Last name: "); 107 System.out.flush(); 108 109 lastName = input.readLine().trim(); 110 111 System.out.println("WARNING: Password will appear on-screen."); 112 System.out.print("Password: "); 113 System.out.flush(); 114 115 password1 = input.readLine().trim(); 116 117 System.out.print("Again to confirm: "); 118 System.out.flush(); 119 120 password2 = input.readLine().trim(); 121 122 if (!password1.equals("") && password1.equals(password2)) 123 { 124 System.out.print("Is the above data correct? (y or n): "); 126 System.out.flush(); 127 128 String s = input.readLine().trim(); 129 130 if (s.toLowerCase().startsWith("y")) 131 { 132 dataOK = true; 133 } 134 } 135 else 136 { 137 System.out.println("Passwords don't match"); 138 } 139 } 140 141 Group admins = Group.find(context, 1); 143 144 if (admins == null) 145 { 146 System.out.println("Error, no admin group (group 1) found"); 147 System.exit(1); 148 } 149 150 EPerson eperson = EPerson.create(context); 152 153 eperson.setEmail(email); 154 eperson.setLastName(lastName); 155 eperson.setFirstName(firstName); 156 eperson.setPassword(password1); 157 eperson.setCanLogIn(true); 158 eperson.setRequireCertificate(false); 159 eperson.setSelfRegistered(false); 160 eperson.update(); 161 162 admins.addMember(eperson); 163 admins.update(); 164 165 context.complete(); 166 167 System.out.println("Administrator account created"); 168 169 System.exit(0); 170 } 171 catch (Exception e) 172 { 173 System.err.println("Exception occurred:" + e); 174 e.printStackTrace(); 175 176 if (context != null) 177 { 178 context.abort(); 179 } 180 181 System.exit(1); 182 } 183 } 184 } 185
| Popular Tags
|