Changeset 26206 for main


Ignore:
Timestamp:
2012-09-18T18:10:37+12:00 (12 years ago)
Author:
ak19
Message:

Fixes to get Remote Greenstone 3 working with client-gli: 1. client-GLI should not start the local GS3 server, since client-GLI will be running against a remote server. 2. The encryption process for authentication had been changed for GS3, so now Authentication.java has a main function which is invoked by gliserver's gsdlCGI.pm to encrypt the password. 4. UsersDB when converted to txt for parsing by gliserver.pl has a different structure, so gliserver.pl needs to take that into account. 5. util.pm's functions for prepending and appending to environment variables needs to use an OS dependant path separator. This was not noticed when testing the remote GS server on 32 bit linux so far, but the windows style path separator (semicolon) used so far didn't work on the 64 bit linux test machine.

Location:
main/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java

    r24905 r26206  
    372372                    isLocalLibrary = LocalLibraryServer.start(gsdl_path, local_library_path);
    373373                }
    374                 else {
     374                else if (!isGsdlRemote) { // local GS3, start the local tomcat
    375375                    GS3ServerThread thread = new GS3ServerThread(gsdl3_src_path, "restart");
    376376                    thread.start();
  • main/trunk/greenstone2/common-src/cgi-bin/gliserver.pl

    r25963 r26206  
    230230    # Get the user account information from the usersDB database
    231231    my %users_db_data = ();
    232     foreach my $users_db_entry (split(/-{70}/, $users_db_content)) {
    233     if ($users_db_entry =~ m/\n?\[(.+)\]\n/) {
     232
     233    # a line dividing one user entry from another is made up of 70 hyphens for GS2 (37 hyphens for GS3)
     234    my $horizontal_divider = ($gsdl_cgi->greenstone_version() == 2) ? q/-{70}/ : q/-{37}/;
     235    foreach my $users_db_entry (split($horizontal_divider, $users_db_content)) {   
     236    if ($users_db_entry =~ m/\n?\[(.+)\]\n/ || $users_db_entry =~ m/\n?USERNAME = ([^\n]*)\n/) { # GS2 and GS3 formats
    234237        $users_db_data{$1} = $users_db_entry;
    235238    }
     
    243246
    244247    # Check password
    245     my ($valid_user_password) = ($user_data =~ m/\<password\>(.*)/);
     248    my $pwdLine = ($gsdl_cgi->greenstone_version() == 2) ? q/\<password\>(.*)/ : q/\n?PASSWORD = (.*)\n/;
     249    my ($valid_user_password) = ($user_data =~ m/$pwdLine/);
    246250    if ($user_password ne $valid_user_password) {
    247251    $gsdl_cgi->generate_error("Authentication failed: incorrect password.");
     
    249253
    250254    # Check group
    251     my ($user_groups) = ($user_data =~ m/\<groups\>(.*)/);
     255    my $groupLine = ($gsdl_cgi->greenstone_version() == 2) ? q/\<groups\>(.*)/ : q/\n?GROUPS = (.*)\n/;
     256    my ($user_groups) = ($user_data =~ m/$groupLine/);
    252257
    253258    if ($collection eq "") {
  • main/trunk/greenstone2/common-src/cgi-bin/gsdlCGI.pm

    r25078 r26206  
    517517    }
    518518    $ENV{'GSDL3HOME'} = $gsdl3home;
    519     }
    520    
     519    }
    521520   
    522521    my $gsdl_bin_script = &util::filename_cat($gsdlhome,"bin","script");
     
    751750}
    752751
     752# used with old GS3 authentication
    753753sub rot13()
    754754{
     
    775775}
    776776
     777# used along with new GS3 authentication
     778sub hash_pwd()
     779{
     780    my $self = shift @_;
     781    my ($password)=@_;
     782
     783    my $gsdl3srchome = $ENV{'GSDL3SRCHOME'};
     784   
     785    my $java = get_java_path();
     786    my $java_gsdl3_classpath = &util::filename_cat($gsdl3srchome, "web", "WEB-INF", "lib", "gsdl3.jar");
     787    my $java_remaining_classpath = &util::filename_cat($gsdl3srchome, "web", "WEB-INF", "lib", "*"); # log4j etc
     788    my $java_classpath;
     789    my $gsdlos = $ENV{'GSDLOS'};
     790    if ($gsdlos !~ m/windows/){
     791    $java_classpath = $java_gsdl3_classpath . ":" . $java_remaining_classpath;
     792    }else{
     793    $java_classpath = $java_gsdl3_classpath . ";" . $java_remaining_classpath;
     794    }
     795   
     796    my $java_command="\"$java\" -classpath \"$java_classpath\" org.greenstone.gsdl3.service.Authentication \"$password\""; # 2>&1";
     797    my $hashedpwd = `$java_command`;
     798
     799    return $hashedpwd;
     800}
     801
    777802sub encrypt_password
    778803{
     
    781806    if (defined $self->param("pw")) { ##
    782807    if ($self->{'greenstone_version'} == 3) { # GS3 is in Java, so needs different encryption
    783         $self->param('-name' => "pw", '-value' => $self->rot13($self->clean_param("pw")));
     808        #$self->param('-name' => "pw", '-value' => $self->rot13($self->clean_param("pw"))); ## when using old GS3 authentication
     809
     810        my $hashedPwd = $self->hash_pwd($self->clean_param("pw")); # for GS3's new Authentication
     811        $self->param('-name' => "pw", '-value' => $hashedPwd);
    784812    }
    785813    else { # GS2 (and versions of GS other than 3?)
  • main/trunk/greenstone2/perllib/util.pm

    r26017 r26206  
    10171017    return $OID;
    10181018}
     1019
    10191020sub envvar_prepend {
    10201021    my ($var,$val) = @_;
     1022
     1023    # 64 bit linux can't handle ";" as path separator, so make sure to set this to the right one for the OS
     1024    my $pathsep = (defined $ENV{'GSDLOS'} && $ENV{'GSDLOS'} !~ m/windows/) ? ":" : ";";
    10211025
    10221026    # do not prepend any value/path that's already in the environment variable
     
    10271031    }
    10281032    elsif($ENV{$var} !~ m/$escaped_val/) {
    1029     $ENV{$var} = "$val;".$ENV{$var};
     1033    $ENV{$var} = "$val".$pathsep.$ENV{$var};
    10301034    }
    10311035}
     
    10331037sub envvar_append {
    10341038    my ($var,$val) = @_;
     1039
     1040    # 64 bit linux can't handle ";" as path separator, so make sure to set this to the right one for the OS
     1041    my $pathsep = (defined $ENV{'GSDLOS'} && $ENV{'GSDLOS'} !~ m/windows/) ? ":" : ";";
    10351042   
    10361043    # do not append any value/path that's already in the environment variable
    1037    
     1044
    10381045    my $escaped_val = &filename_to_regex($val); # escape any backslashes and brackets for upcoming regex
    10391046    if (!defined($ENV{$var})) {
     
    10411048    }
    10421049    elsif($ENV{$var} !~ m/$escaped_val/) {
    1043     $ENV{$var} .= ";$val";
     1050    $ENV{$var} = $ENV{$var}.$pathsep."$val";
    10441051    }
    10451052}
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/Authentication.java

    r25852 r26206  
    10371037        return collect_list_node;
    10381038    }
     1039
     1040    // main() method - calls hashPassword() on any String argument, printing this to stdout
     1041    // This main() is invoked by gliserver.pl perl code to encrypt passwords identically to Java code.
     1042    public static void main(String[] args) {
     1043    if(args.length < 1) {
     1044        System.err.println("Usage: Authentication <string to encrypt>");
     1045        System.exit(-1);
     1046    }
     1047    // just hash the first argument
     1048    String hash = Authentication.hashPassword(args[0]);
     1049    System.out.println(hash);
     1050    }
    10391051}
Note: See TracChangeset for help on using the changeset viewer.