Changeset 34116


Ignore:
Timestamp:
2020-05-20T14:44:53+12:00 (4 years ago)
Author:
kjdon
Message:

use global.properties, not build.properties. therefore call this with gsdl3home, not gsdl3srchome. get tomcat context from global.properties. still todo - get servlet name from input args, can't assume library.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/ServletRealmCheck.java

    r32429 r34116  
    3939 * to see if any of these allow the user to edit that collection.
    4040 *
    41  * Run as java org.greenstone.gsdl3.util.ServletRealmCheck <GS3SRCHOME> <un> <pwd> [colname]
     41 * Run as java org.greenstone.gsdl3.util.ServletRealmCheck <GSDL3HOME> <un> <pwd> [colname]
    4242 *
    43  * GS3\src\java>"C:\Program Files\Java\jdk1.6.0_22\bin\java"
    44  *      -classpath "GS3\web\WEB-INF\lib\gsdl3.jar;GS3\web\WEB-INF\lib\derby.jar"
    45  *      org.greenstone.gsdl3.util.ServletRealmCheck "GS3" admin <pw> 2>&1
     43 * >java -classpath "greenstone3\web\WEB-INF\lib\gsdl3.jar;greenstone3\web\WEB-INF\lib\gutil.jar"
     44 *      org.greenstone.gsdl3.util.ServletRealmCheck "greenstone3\web" <un> <pw> [colname] 2>&1
    4645 *
    47  * Tries URL: http://hostname:8383/greenstone3/library?a=s&sa=authenticated-ping&excerptid=gs_content&un=admin&pw=<pw>[&col=demo]
     46 * Tries URL: http://hostname:port/context/library?a=s&sa=authenticated-ping&excerptid=gs_content&un=<un>&pw=<pw>[&col=colname]
    4847 * The &excerptid=gs_content in the URL will return just the <div id="gs_content" /> part of the
    4948 * page that we're interested in.
     
    5150 * Result: either prints out an error message ("Authentication failed...") or a positive result,
    5251 * which is the user's groups. For the admin user example: administrator,all-collections-editor.
     52 * If no collection is specified, will print the user groups.
     53 * If a collection is specified, will only print user groups if the user has access to the collection.
    5354 *
    5455*/
     
    5859   
    5960    if (args.length < 3 || args.length > 4){
    60         System.out.println("Run with: <GSDL3SRCHOME> <un> <pwd> [collection-name]");       
     61        System.out.println("Run with: <GSDL3HOME> <un> <pwd> [collection-name]");       
    6162        System.exit(0);
    6263    }
    6364   
    64     String gsdl3srchome = args[0];
     65    String gsdl3home = args[0];
    6566    String username = args[1];
    6667    String password = args[2];
     
    7374   
    7475   
    75     // Load the build.properties file, get the GS3 server URL and send authenticated-ping and print the return result
     76    // Load the global.properties file, get the GS3 server URL and send authenticated-ping and print the return result
    7677   
    7778    //http://www.mkyong.com/java/java-properties-file-examples/
    78     Properties buildProps = new Properties();
     79    Properties globalProps = new Properties();
    7980    InputStream input = null;
    8081 
    8182    try {
    82         File buildPropsFile = new File(gsdl3srchome, "build.properties");
    83         input = new FileInputStream(buildPropsFile);
     83        File globalPropsFile = new File(gsdl3home, "WEB-INF" +File.separatorChar+ "classes"+ File.separatorChar+"global.properties");
     84        input = new FileInputStream(globalPropsFile);
    8485 
    8586        // load a properties file
    86         buildProps.load(input);
     87        globalProps.load(input);
    8788 
    8889        // get the property value and print it out
    89         String servername = buildProps.getProperty("tomcat.server");
    90         ProtocolPortProperties protocolPortProps = new ProtocolPortProperties(buildProps); // can throw Exception
     90        String servername = globalProps.getProperty("tomcat.server");
     91        ProtocolPortProperties protocolPortProps = new ProtocolPortProperties(globalProps); // can throw Exception
    9192        String protocol = protocolPortProps.getProtocol();
    9293        String port = protocolPortProps.getPort();
    9394        int portNum = Integer.parseInt(port);
    9495       
     96        String context = globalProps.getProperty("tomcat.context");
    9597        // Appending &excerptid=gs_content will get just the <div ... id="gs_content"/> from the final web page:
    96         String urlSuffix = "/greenstone3/library?a=s&sa=authenticated-ping&excerptid=gs_content&un="+username+"&pw="+password;
     98        // TODO dynamically get library name
     99        String urlSuffix = "/"+context+"/library?a=s&sa=authenticated-ping&excerptid=gs_content&un="+username+"&pw="+password;
    97100        if(collection != null) {
    98101            urlSuffix = urlSuffix + "&col="+collection;
     
    122125       
    123126        // Now we finally have what we actually want to print out for the caller to use
    124         System.out.print(result); // don't add newline to end
     127        System.out.print(result + ","); // don't add newline to end
    125128       
    126129    } catch (Exception ex) {
    127         System.err.println("Got exception " + ex.getMessage());
    128         ex.printStackTrace();
     130        System.err.println("Authentication failed: Java error: " + ex.getMessage());
     131        ex.printStackTrace();
    129132    } finally {
    130133        if (input != null) {
Note: See TracChangeset for help on using the changeset viewer.