IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 38131 for trunk


Ignore:
Timestamp:
Apr 16, 2015, 9:36:01 AM (11 years ago)
Author:
bills
Message:

further prototyping of the access control code. Checking in in prepration
for moving to database based storage of the parameters

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pstamp/scripts/pstampparse.pl

    r38124 r38131  
    5959    die "req_id is required"  if !$req_id;
    6060    die "outdir is required"  if !$outdir;
    61     die "product is required" if !$product;
     61#    die "product is required" if !$product;
    6262} else {
    6363    # mode eq 'list_uri' (used for parser testing)
     
    9595# do not update the database
    9696$no_update = 1 if $mode ne "queue_job";
     97
     98$product = 'NULL' unless $product;
     99
     100# look up the default data store product.
     101my $defaultDSProduct = metadataLookupStr($ipprc->{_siteConfig}, 'PSTAMP_DATA_STORE_PRODUCT');
     102if (!defined $defaultDSProduct) {
     103    # Don't panic yet that it's not defined.
     104    #  exit ($PS_EXIT_CONFIG_ERROR);
     105    $defaultDSProduct = ''; # set to empty string to simplify some comparisions below
     106    print STDERR "Warning PSTAMP_DATA_STORE_PRODUCT not found in the site config.\n" if  $product eq 'NULL';
     107}
     108
     109my $productIsDefault = 0;
     110if ($product and $defaultDSProduct) {
     111    $productIsDefault = ($product eq $defaultDSProduct);
     112}
    97113
    98114my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     
    170186
    171187
    172 # Adjust the label for requests coming in over the web interface
     188# Adjust the label for requests coming in over the web upload interface
    173189
    174190my $label_changed = 0;
     
    200216}
    201217
     218# product passed in is either one specific to the submitting pstampDataStore or the default
     219# "pstampresults"
     220# Here, we need to decide whether to change that based on email
     221# WE can't use label (yet) because the PSI cgi script sets it to PSI
     222# Do we ever need to use label? Is it obsolete? Check test procedures.
     223
     224# XXX perhaps do this prior to label setting above after domain/user table is implemented
     225my $productForUser;
     226my $accessLevel = getUsersAccessLevel($email, \$label, \$productForUser);
     227if ($accessLevel < 0) {
     228    print STDERR "Data access is forbidden.\n";
     229    insertFakeJobForRow(undef, 0, $PSTAMP_NOT_AUTHORIZED);
     230}
     231
     232# if the product is the system default, set it to the product for the user@domain
     233if ($productIsDefault or $product eq 'NULL') {
     234    if ($productForUser) {
     235        $product = $productForUser;
     236    }
     237} else {
     238    if ($product eq 'NULL') {
     239        $product = $defaultDSProduct;
     240    }
     241}
     242if (!$product or $product eq 'NULL') {
     243    my_die("No product found.\n", $PS_EXIT_CONFIG_ERROR);
     244}
    202245
    203246{
     
    219262}
    220263
     264if ($accessLevel < 0) {
     265    exit 0;
     266}
     267
    221268if ($duplicate_req_name) {
    222269    exit 0;
     
    271318my $num_jobs = 0;
    272319
    273 my $accessLevel = getUsersAccessLevel($email, $label);
    274 if ($accessLevel < 0) {
    275     print STDERR "Data access forbidden.\n";
    276     insertFakeJobForRow(undef, 0, $PSTAMP_NOT_AUTHORIZED);
    277     exit 0;
    278 }
    279320
    280321foreach my $row (@$rows) {
     
    534575        # We do not adjust dates for stacks since they are not well defined enough.
    535576        # We'll need to filter them by accessLevel during the lookup
     577        my $stage = $row->{IMG_TYPE};
    536578        if ($stage ne 'stack' and adjustDateCuts($row, \$mjd_max)) {
    537579            # if lower limit was supplied by user we can leave the value alone
     
    12001242sub getUsersAccessLevel {
    12011243    my $email = shift;
    1202     my $label = shift;
     1244    my $r_label = shift;
     1245    my $r_product = shift;
     1246
     1247    my $label = $$r_label;
    12031248
    12041249    my $level = -1;
     
    12171262        # we've got an email check the domain
    12181263        my ($user, $domain) = split '@', $email;
    1219         if ($domain) {
     1264        unless ($user and $domain) {
     1265            print STDERR "Error $email is not an acceptable email adddress.\n";
     1266        } else {
    12201267            $domain = lc($domain);
    12211268            if ($domain eq 'ifa.hawaii.edu' or $domain eq 'qub.ac.uk') {
    1222                 $level = 0;
     1269                $level = 2;
    12231270            } else {
    12241271                # XXX check for special users
     
    12261273                $level = 1;
    12271274            }
    1228         } else {
    1229             print STDERR "Error: $email is not a valid email address\n";
    1230         }
     1275
     1276            #
     1277            if ($user eq 'bills' and $domain eq 'ifa.hawaii.edu') {
     1278                $$r_product = 'bills-results';
     1279            }
     1280        }
     1281
    12311282    }
    12321283
Note: See TracChangeset for help on using the changeset viewer.