Project

General

Profile

Revision 8201

Added by Jing Tao over 7 years ago

Add code to get organization information from the ldapconfig.

View differences:

src/perl/ldapweb.cgi
183 183
# custom LDAP properties hash
184 184
my $ldapCustom = $properties->splitToTree(qr/\./, 'ldap');
185 185

  
186
# This is a hash which has the keys of the organization's properties 'name', 'base', 'organization'.
186 187
my $orgProps = $properties->splitToTree(qr/\./, 'organization');
188

  
189
#This is a hash which has the keys of the ldap sub tree names of the organizations, such as 'NCEAS', 'LTER' and 'KU', and values are real name of the organization.
187 190
my $orgNames = $properties->splitToTree(qr/\./, 'organization.name');
188 191
# pull out properties available e.g. 'name', 'base'
189 192
my @orgData = keys(%$orgProps);
190 193

  
191
my @orgList;
194
my @orgList; #An array has the names (i.e, sub tree names, such as 'NCEAS', 'LTER' and 'KU')  of the all organizations in the metacat.properties. 
192 195
while (my ($oKey, $oVal) = each(%$orgNames)) {
193 196
    push(@orgList, $oKey);
194 197
}
......
221 224
            $ldapConfig->{$o}{'org'} = $filter;
222 225
        }
223 226
        if (!$ldapConfig->{$o}{'filter'}) {
224
            $ldapConfig->{$o}{'filter'} = $filter;
227
            #$ldapConfig->{$o}{'filter'} = $filter;
228
            $ldapConfig->{$o}{'filter'} = $ldapConfig->{$o}{'org'};
225 229
        }
226 230
        # also include DN, which is just org + base
227 231
        if ($ldapConfig->{$o}{'org'}) {
......
246 250
    }
247 251
}
248 252

  
253
### Determine the display organization list (such as NCEAS, Account ) in the ldap template files
254
my $displayOrgList;
255
$displayOrgList = $skinProperties->getProperty("ldap.templates.organizationList") or $displayOrgList = $properties->getProperty('ldap.templates.organizationList');
256

  
257

  
249 258
#--------------------------------------------------------------------------80c->
250 259
# Define the main program logic that calls subroutines to do the work
251 260
#--------------------------------------------------------------------------80c->
......
879 888
sub createTemporaryAccount {
880 889
    my $allParams = shift;
881 890
    my $org = $query->param('o'); 
882
    my $ou = $query->param('ou');
891
 
883 892

  
884 893
    
885 894
    ################## Search LDAP for matching o or ou that already exist
886
    my $orgAuthBase; 
887
    my $filter;   
888
    if($org) {
889
        $filter = "(o" 
890
                  . "=" . $org .
891
                 ")";
892
        $orgAuthBase = $ldapConfig->{$org}{'base'};
893
    } else {
894
        $filter = "(ou" 
895
                  . "=" . $ou .
896
                 ")";
897
        $orgAuthBase = $ldapConfig->{$ou}{'base'};
898
    }
895
    my $orgAuthBase = $ldapConfig->{$org}{'base'};; 
896
    my $filter = $ldapConfig->{$org}{'filter'};   
899 897
    my $tmpSearchBase = 'dc=tmp,' . $orgAuthBase; 
900 898
    debug("search filer " . $filter);
901 899
    debug("ldap server ". $ldapurl);
......
908 906
    my $ldapPassword = $ldapConfig->{$org}{'password'};
909 907
    debug("LDAP connection to $ldapurl...");    
910 908
    
909
     my @organizationInfo = split(/=/, $ldapConfig->{$org}{'org'}); #split 'o=NCEAS' or something like that
910
     my $organization = $organizationInfo[0]; # This will be 'o' or 'ou'
911
     my $organizationName = $organizationInfo[1]; # This will be 'NCEAS' or 'Account'
911 912
        
912 913
    if(!$found) {
913 914
        debug("generate the subtree in the dc=tmp===========================");
......
919 920
            $ldap->start_tls( verify => 'none');
920 921
            debug("Attempting to bind to LDAP server with dn = $ldapUsername, pwd = $ldapPassword");
921 922
            $ldap->bind( version => 3, dn => $ldapUsername, password => $ldapPassword );
922
            my $additions;
923
             if($org) {
924
                $additions = [ 
925
                'o'   => $org,
923
            my $additions; 
924
            $additions = [ 
925
                $organization   => $organizationName,
926 926
                'objectclass' => ['top', 'organization']
927 927
                ];
928
                $dn='o=' . $org . ',' . $tmpSearchBase;
929
             } else {
930
                $additions = [ 
931
                'ou'   => $ou,
932
                'objectclass' => ['top', 'organizationalUnit']
933
                ];
934
                $dn='ou=' . $ou . ',' . $tmpSearchBase;
935
             }
928
            $dn=$ldapConfig->{$org}{'org'} . ',' . $tmpSearchBase;
936 929
            # Do the insertion
937 930
            my $result = $ldap->add ( 'dn' => $dn, 'attr' => [ @$additions ]);
938 931
            if ($result->code()) {
......
972 965
                'userPassword' => $shapass,
973 966
                'employeeNumber' => $randomStr,
974 967
                'objectclass' => ['top', 'person', 'organizationalPerson', 
975
                                'inetOrgPerson', 'uidObject' ]
968
                                'inetOrgPerson', 'uidObject' ],
969
                $organization   => $organizationName
976 970
                ];
977 971
    if (defined($query->param('telephoneNumber')) && 
978 972
                $query->param('telephoneNumber') &&
......
986 980
                $$additions[$#$additions + 1] = 'title';
987 981
                $$additions[$#$additions + 1] = $query->param('title');
988 982
    }
989
    my $dn;
990
    my $orgStr;
991
    if($org) {
992
        $$additions[$#$additions + 1] = 'o';
993
        $$additions[$#$additions + 1] = $org;
994
        $dn='uid=' . $query->param('uid') . ',' . 'o=' . $org . ',' . $tmpSearchBase;
995
        $orgStr='o=' . $org;
996
    } else {
997
        $$additions[$#$additions + 1] = 'ou';
998
        $$additions[$#$additions + 1] = $ou;
999
        $dn='uid=' . $query->param('uid') . ',' . 'ou=' . $ou . ',' . $tmpSearchBase;
1000
        $orgStr='ou=' . $ou;
1001
    }
983

  
984
    
985
    #$$additions[$#$additions + 1] = 'o';
986
    #$$additions[$#$additions + 1] = $org;
987
    my $dn='uid=' . $query->param('uid') . ',' . $ldapConfig->{$org}{'org'} . ',' . $tmpSearchBase;
1002 988
    my $tmp = 1;
1003 989
    createAccount2($dn, $ldapUsername, $ldapPassword, $additions, $tmp, $allParams);
1004 990
    
1005 991
    
1006 992
    ####################send the verification email to the user
1007
    my $link = $contextUrl. '/cgi-bin/ldapweb.cgi?cfg=' . $skinName . '&' . 'stage=' . $emailVerification . '&' . 'dn=' . $dn . '&' . 'hash=' . $randomStr . '&' . $orgStr . '&uid=' . $query->param('uid');
993
    my $link = $contextUrl. '/cgi-bin/ldapweb.cgi?cfg=' . $skinName . '&' . 'stage=' . $emailVerification . '&' . 'dn=' . $dn . '&' . 'hash=' . $randomStr . '&' . $ldapConfig->{$org}{'org'} . '&uid=' . $query->param('uid');
1008 994
    
1009 995
    my $mailhost = $properties->getProperty('email.mailhost');
1010 996
    my $sender;

Also available in: Unified diff