Changeset 27075
- Timestamp:
- 2013-03-13T14:13:21+13:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/Authentication.java
r26914 r27075 128 128 129 129 protected static DerbyWrapper _derbyWrapper = null; 130 130 protected static boolean _derbyWrapperDoneForcedShutdown = false; 131 131 132 132 protected String _recaptchaPrivateKey = null; … … 138 138 } 139 139 140 public void cleanUp() { 141 142 super.cleanUp(); 143 144 if (!_derbyWrapperDoneForcedShutdown) { 145 146 // This boolean is used to ensure we always shutdown the derby server, even if it is never 147 // used by the Authentication server. This is because the Tomcat greenstone3.xml 148 // config file also specifies a connection to the database, which can result in the 149 // server being initialized when the servlet is first accessed. Note also, 150 // Authentication is a ServiceRack, meaning cleanUp() is called for each service 151 // supported, however we only need to shutdown the Derby server once. Again 152 // this boolean variable helps achieve this. 153 154 logger.info("Authentication Service performing forced shutdown of Derby Server ..."); 155 156 DerbyWrapper.shutdownDatabaseServer(); 157 _derbyWrapper = null; 158 _derbyWrapperDoneForcedShutdown = true; 159 } 140 public void cleanUp() 141 { 142 143 super.cleanUp(); 144 145 if (!_derbyWrapperDoneForcedShutdown) 146 { 147 148 // This boolean is used to ensure we always shutdown the derby server, even if it is never 149 // used by the Authentication server. This is because the Tomcat greenstone3.xml 150 // config file also specifies a connection to the database, which can result in the 151 // server being initialized when the servlet is first accessed. Note also, 152 // Authentication is a ServiceRack, meaning cleanUp() is called for each service 153 // supported, however we only need to shutdown the Derby server once. Again 154 // this boolean variable helps achieve this. 155 156 logger.info("Authentication Service performing forced shutdown of Derby Server ..."); 157 158 DerbyWrapper.shutdownDatabaseServer(); 159 _derbyWrapper = null; 160 _derbyWrapperDoneForcedShutdown = true; 161 } 160 162 161 163 } … … 282 284 try 283 285 { 284 285 286 UserQueryResult userQueryResult = _derbyWrapper.findUser(username); 287 286 288 Vector<UserTermInfo> terms = userQueryResult.getUserTerms(); 287 289 … … 314 316 ex.printStackTrace(); 315 317 } 316 317 318 318 319 closeDatabase(); … … 828 829 private void checkAdminUserExists() 829 830 { 830 831 openDatabase(); 831 832 832 833 UserQueryResult userQueryResult = _derbyWrapper.findUser(null, null); … … 856 857 private boolean openDatabase() 857 858 { 858 if (_derbyWrapper == null) { 859 _derbyWrapper = new DerbyWrapper(); 860 861 // check the usersDb database, if it isn't existing, check the etc dir, create the etc dir if it isn't existing, then create the user database and add a "admin" user 862 String usersDB_dir = this.site_home + File.separatorChar + "etc" + File.separatorChar + "usersDB"; 863 File usersDB_file = new File(usersDB_dir); 864 if (!usersDB_file.exists()) 865 { 866 String etc_dir = this.site_home + File.separatorChar + "etc"; 867 File etc_file = new File(etc_dir); 868 if (!etc_file.exists()) 869 { 870 boolean success = etc_file.mkdir(); 871 if (!success) 872 { 873 logger.error("Couldn't create the etc dir under " + this.site_home + "."); 874 return false; 875 } 876 } 877 _derbyWrapper.connectDatabase(usersDB_dir, true); 878 _derbyWrapper.createDatabase(); 879 } 880 else 881 { 882 _derbyWrapper.connectDatabase(usersDB_dir, false); 883 } 884 } 885 return true; 859 if (_derbyWrapper == null) 860 { 861 _derbyWrapper = new DerbyWrapper(); 862 863 // check the usersDb database, if it isn't existing, check the etc dir, create the etc dir if it isn't existing, then create the user database and add a "admin" user 864 String usersDB_dir = this.site_home + File.separatorChar + "etc" + File.separatorChar + "usersDB"; 865 File usersDB_file = new File(usersDB_dir); 866 if (!usersDB_file.exists()) 867 { 868 String etc_dir = this.site_home + File.separatorChar + "etc"; 869 File etc_file = new File(etc_dir); 870 if (!etc_file.exists()) 871 { 872 boolean success = etc_file.mkdir(); 873 if (!success) 874 { 875 logger.error("Couldn't create the etc dir under " + this.site_home + "."); 876 return false; 877 } 878 } 879 _derbyWrapper.connectDatabase(usersDB_dir, true); 880 _derbyWrapper.createDatabase(); 881 } 882 else 883 { 884 _derbyWrapper.connectDatabase(usersDB_dir, false); 885 } 886 } 887 return true; 886 888 } 887 889 … … 896 898 897 899 private int addUserInformationToNode(String username, Element serviceNode) 898 { 899 900 { 901 openDatabase(); 900 902 901 903 UserQueryResult userQueryResult = _derbyWrapper.findUser(username, null); … … 926 928 if (success) 927 929 { 928 929 930 closeDatabase(); 931 return NO_ERROR; 930 932 } 931 933 … … 936 938 private int addUser(String newUsername, String newPassword, String newGroups, String newStatus, String newComment, String newEmail) 937 939 { 938 940 openDatabase(); 939 941 940 942 newGroups = newGroups.replaceAll(" ", ""); … … 965 967 private boolean checkUserExists(String username) 966 968 { 967 969 boolean check_status = false; 968 970 969 971 openDatabase(); … … 981 983 catch (Exception ex) 982 984 { 983 984 985 // some error occurred accessing the database 986 ex.printStackTrace(); 985 987 } 986 988 … … 991 993 private String retrieveDataForUser(String username, String dataType) 992 994 { 993 995 openDatabase(); 994 996 995 997 String data = null;
Note:
See TracChangeset
for help on using the changeset viewer.