- Timestamp:
- 2023-02-01T16:38:58+13:00 (15 months ago)
- Location:
- main/trunk/gli/src/org/greenstone/gatherer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java
r37188 r37236 92 92 static private Dimension size = new Dimension(800, 540); 93 93 static public RemoteGreenstoneServer remoteGreenstoneServer = null; 94 static public WebswingAuthenticator webswingAuthenticator = null; 95 94 96 95 97 /** Has the exit flag been set? */ … … 273 275 { 274 276 275 277 if (isWebswing) { 278 // library_url must be defined in the options 279 if (library_url_string == null) { 280 System.err.println("Please set library_url option as a webswing option"); 281 System.exit(0); 282 } 283 // we need to authenticate the user 284 webswingAuthenticator = new WebswingAuthenticator(); 285 if (!webswingAuthenticator.authenticate(library_url_string)) { 286 System.err.println("authentication error"); 287 System.exit(0); 288 } 289 } 276 290 // Create the debug stream if required 277 291 if (debug_enabled) { … … 1947 1961 } 1948 1962 1963 1964 static public class WebswingAuthenticator 1965 extends GAuthenticator 1966 { 1967 static protected String username; 1968 static protected HashSet<String> groups; 1969 1970 public boolean authenticate(String library_url_string) { 1971 PasswordAuthentication pa = getPasswordAuthentication(); 1972 if (pa == null) { 1973 // user cancelled - how do we show error? 1974 System.err.println("Authentication cancelled. You cannot access webswing gli without Greenstone user account"); 1975 return false; 1976 1977 } 1978 username = pa.getUserName(); 1979 1980 String password = new String(pa.getPassword()); 1981 String result; 1982 try { 1983 String new_url = library_url_string+"?a=s&sa=authenticated-ping&excerptid=gs_content&un="+username+"&pw="+password; 1984 URL authenticationURL = new URL(new_url); 1985 HttpURLConnection conn = (HttpURLConnection)authenticationURL.openConnection(); 1986 BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); 1987 result = ""; 1988 String line = null; 1989 1990 while((line = reader.readLine()) != null) { 1991 result += line; 1992 } 1993 } catch (Exception e) { 1994 System.err.println("There was an exception "+e.getMessage()); 1995 return false; 1996 } 1997 // Parse out the content nested inside <div ... id="gs_content"> </div> 1998 int start = result.indexOf("id=\"gs_content\""); 1999 if(start != -1) { 2000 start = result.indexOf(">", start); 2001 int end = result.indexOf("<", start); 2002 result = result.substring(start+1, end); 2003 result = result.trim(); 2004 } 2005 if (result.startsWith("Authentication failed:")) { 2006 System.err.println("Authentication Error: "+result); 2007 return false; 2008 } 2009 groups = new HashSet<String>(); 2010 String[] contents = result.split(","); 2011 for (int i=0; i<contents.length; i++) { 2012 String g = contents[i]; 2013 if (g.equals("all-collections-editor") || g.equals("personal-collections-editor") || g.endsWith("-collection-editor")) { 2014 groups.add(g); 2015 } 2016 } 2017 if (groups.size()==0) { 2018 return false; // user has no editing priveleges 2019 } 2020 return true; 2021 } 2022 2023 public boolean canEditCollection(String collection) { 2024 if (groups.contains("all-collections-editor")) { 2025 return true; 2026 } 2027 if (groups.contains("personal-collections-editor") && collection.startsWith(username+"-")) { 2028 return true; 2029 } 2030 if (groups.contains(collection+"-collection-editor")) { 2031 return true; 2032 } 2033 return false; 2034 } 2035 2036 2037 2038 public PasswordAuthentication getAuthentication(String username, String password) 2039 { 2040 return getPasswordAuthentication(username,password); 2041 } 2042 2043 public PasswordAuthentication getAuthentication() 2044 { 2045 return getPasswordAuthentication(); 2046 } 2047 2048 2049 protected String getMessageString() 2050 { 2051 return Dictionary.get("RemoteGreenstoneServer.Authentication_Message"); 2052 } 2053 2054 2055 } 2056 2057 1949 2058 } -
main/trunk/gli/src/org/greenstone/gatherer/gui/OpenCollectionDialog.java
r29016 r37236 324 324 325 325 if(collection_folder.isDirectory() && !collection_foldername.equals(StaticStrings.MODEL_COLLECTION_NAME)) { 326 326 327 // this 'file_name' has already been prefixed by 'etc' 327 328 String file_name; … … 345 346 else { 346 347 // add this collection. We want to allow non gli collections, so add anything that has a config file. 347 data.add(collection_configuration); 348 // webswing - check whether we are allowed to edit this coll 349 if (Gatherer.isWebswing) { 350 if (Gatherer.webswingAuthenticator.canEditCollection(collection_foldername)) { 351 data.add(collection_configuration); 352 } 353 } 354 else { 355 data.add(collection_configuration); 356 } 348 357 } 349 358 }
Note:
See TracChangeset
for help on using the changeset viewer.