Project

General

Profile

« Previous | Next » 

Revision 5424

Added by berkley over 14 years ago

fixed bug in access control where the sessionid was not correctly passed along so changes of privileges were not being made

View differences:

test/edu/ucsb/nceas/metacat/dataone/CrudServiceTest.java
710 710
	{
711 711
	    CrudService cs = CrudService.getInstance();
712 712
	    IdentifierManager im = IdentifierManager.getInstance();
713
	    cs.setAccess(token, id, "public", "read", "allow", "allowFirst");
714
	    if(systemMetadataToo)
715
	    {
716
	        String smidS = im.getSystemMetadataId(id.getValue());
717
	        Identifier smid = new Identifier();
718
	        smid.setValue(smidS);
719
	        cs.setAccess(token, smid, "public", "read", "allow", "allowFirst");
720
	    }
713
	    cs.setAccess(token, id, "public", "read", "allow", "allowFirst", systemMetadataToo);
721 714
	}
722 715
	
723 716
	/**
test/edu/ucsb/nceas/metacattest/IdentifierManagerTest.java
159 159
            String docid = insertTestDocument();
160 160
            String guid = "test:" + docid;
161 161
            im.createSystemMetadataMapping(guid, docid);
162
            String docid2 = im.getSystemMetadataId(guid);
162
            String docid2 = im.getSystemMetadataLocalId(guid);
163 163
            assertTrue(docid2.equals(docid));
164 164
        } catch (McdbDocNotFoundException e) {
165 165
          e.printStackTrace();
src/edu/ucsb/nceas/metacat/restservice/ResourceHandler.java
211 211
    private static final String FUNCTION_NAME_UPDATE = "update";
212 212
    private static final String FUNCTION_NAME_GENERATE_MISSING_SYSTEM_METADATA = "generatemissingsystemmetadata";
213 213

  
214
    private static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss'Z'");
214
    private static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
215 215
    
216 216
    private ServletContext servletContext;
217 217
    private Logger logMetacat;
......
244 244
            String resource = request.getServletPath();
245 245
            String verb = "";
246 246
            
247
            //System.out.println("handling verb " + httpVerb + " request with resource " + resource);
247
            System.out.println("handling verb " + httpVerb + " request with resource " + resource);
248 248
            boolean status = false;
249
            loadSessionData();
249 250

  
250 251
            if (resource != null) {
251 252
                resource = request.getServletPath().substring(1);
......
260 261
                    httpVerb == POST && 
261 262
                    params.get(FUNCTION_KEYWORD) != null) {
262 263
                    //System.out.println("function_keyword: " + params.get(FUNCTION_KEYWORD)[0]);
263
                    //System.out.println("function set access: " + FUNCTION_NAME_SET_ACCESS);
264 264
                        if (params.get(FUNCTION_KEYWORD)[0].equals(FUNCTION_NAME_LOGIN)) {
265 265
                            login();
266 266
                            status = true;
......
268 268
                            logout();
269 269
                            status = true;
270 270
                        } else if (params.get(FUNCTION_KEYWORD)[0].equals(FUNCTION_NAME_SET_ACCESS)) {
271
                            //System.out.println("setting access in resourceHandler");
272 271
                            setaccess();
273 272
                            status = true;
274 273
                            //System.out.println("done setting access");
......
285 284
                        }
286 285
                        else
287 286
                        {
288
                            loadSessionData();
289 287
                            String objectId = request.getPathInfo();
290 288
                            if (objectId != null && objectId.length() > 1) 
291 289
                            {
......
403 401
            Date toDate = null;
404 402
            String eventS = params.get("event")[0];
405 403
            Event event = null;
406
            SimpleDateFormat sdf = new SimpleDateFormat();
407 404
            if(fromDateS != null)
408 405
            {
409
                fromDate = CrudService.getInstance().parseDate(fromDateS);
410
                //fromDate = dateFormat.parse(fromDateS);
406
                //fromDate = CrudService.getInstance().parseDate(fromDateS);
407
                fromDate = dateFormat.parse(fromDateS);
411 408
            }
412 409
            if(toDateS != null)
413 410
            {
414
                toDate = CrudService.getInstance().parseDate(toDateS);
415
                //toDate = dateFormat.parse(toDateS);
411
                //toDate = CrudService.getInstance().parseDate(toDateS);
412
                toDate = dateFormat.parse(toDateS);
416 413
            }
417 414
            if(eventS != null)
418 415
            {
......
713 710
                StringReader sr = new StringReader(ol.toString());                
714 711
                out = response.getOutputStream();                
715 712
                // Serialize and write it to the output stream
716
                System.out.println("list size: " + ol.sizeObjectInfoList());
717 713
                
718 714
                try {
719 715
                    serializeServiceType(ObjectList.class, ol, out);
......
1098 1094
     * set the access perms on a document
1099 1095
     * @throws IOException
1100 1096
     */
1101
    private void setaccess() throws IOException
1097
    private void setaccess() throws Exception
1102 1098
    {
1103 1099
        try
1104 1100
        {
......
1111 1107
            String permissionType = params.get("permissionType")[0];
1112 1108
            String permissionOrder = params.get("permissionOrder")[0];
1113 1109
            String setSystemMetadata = params.get("setsystemmetadata")[0];
1114
            CrudService cs = CrudService.getInstance();
1115
            cs.setAccess(token, id, principal, permission, permissionType, permissionOrder);
1110
            boolean ssm = false;
1116 1111
            if(setSystemMetadata.equals("true") || setSystemMetadata.equals("TRUE") ||
1117
               setSystemMetadata.equals("yes"))
1118
            { //set the same perms on the system metadata doc
1119
                IdentifierManager im = IdentifierManager.getInstance();
1120
                String smidS = im.getSystemMetadataId(id.getValue());
1121
                Identifier smid = new Identifier();
1122
                smid.setValue(smidS);
1123
                cs.setAccess(token, smid, principal, permission, permissionType, permissionOrder);
1112
                    setSystemMetadata.equals("yes"))
1113
            {
1114
                ssm = true;
1124 1115
            }
1116
            CrudService cs = CrudService.getInstance();
1117
            cs.setAccess(token, id, principal, permission, permissionType, permissionOrder, ssm);
1125 1118
        }
1126 1119
        catch(Exception e)
1127 1120
        {
1128 1121
            printError("Error setting access in ResourceHandler: " + e.getMessage(), response);
1122
            throw e;
1129 1123
        }
1130 1124
    }
1131 1125

  
src/edu/ucsb/nceas/metacat/MetacatHandler.java
936 936
            String permission, String permissionType, String permissionOrder)
937 937
      throws Exception
938 938
    {
939
        Hashtable<String,String[]> params = new Hashtable();
939
        Hashtable<String,String[]> params = new Hashtable<String,String[]>();
940 940
        params.put("principal", new String[] {principal});
941 941
        params.put("permission", new String[] {permission});
942 942
        params.put("permType", new String[] {permissionType});
......
946 946
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
947 947
        PrintWriter out = new PrintWriter(baos);
948 948
        handleSetAccessAction(out, params, username, null, null);
949
        String resp = baos.toString();
950
        System.out.println("response from MetacatHandler.setAccess: " + resp);
949 951
    }
950 952
    
951 953
    /** read metadata or data from Metacat
......
2616 2618
        String[] permOrderList = params.get("permOrder");
2617 2619
        String[] qformatList = params.get("qformat");
2618 2620
        String[] accessBlock = params.get("accessBlock");
2619
        
2620 2621
        if(accessBlock != null) {
2621 2622
            if (docList == null) {
2622 2623
                errorList.addElement("MetaCatServlet.handleSetAccessAction - Doc id missing.  Please check your parameter list, it should look like: "
......
2624 2625
                outputResponse(successList, errorList, out);
2625 2626
                return;
2626 2627
            }
2627
            
2628 2628
            try {
2629 2629
                AccessControlForSingleFile accessControl = 
2630 2630
                    new AccessControlForSingleFile(docList[0]);
......
2633 2633
            } catch(AccessControlException ace) {
2634 2634
                errorList.addElement("MetaCatServlet.handleSetAccessAction - access control error when setting " + 
2635 2635
                    "access block: " + ace.getMessage());
2636
            } 
2636
            }
2637 2637
            outputResponse(successList, errorList, out);
2638 2638
            return;
2639 2639
        }
......
2686 2686
                    ple.printStackTrace(System.out);
2687 2687
                }
2688 2688
            }
2689
            
2690 2689
            String accessionNumber = docid;
2691 2690
            String owner = null;
2692 2691
            String publicId = null;
......
2707 2706
                error = "User - " + username + " does not have permission to set "
2708 2707
                        + "access control for docid - " + accessionNumber;
2709 2708
                errorList.addElement(error);
2709
                System.out.println("user " + username + " does not have permission to set " + 
2710
                        "access control for docid " + accessionNumber);
2710 2711
                continue;
2711 2712
            }
2712 2713
            
......
2724 2725
                error = "Could not set access control to document " + accessionNumber
2725 2726
                        + "because it is in a pakcage and it has a access file for it";
2726 2727
                errorList.addElement(error);
2728
                System.out.println("this is a beta4 or 6 document so we can't set the access element.");
2727 2729
                continue;
2728 2730
            }
2729
            
2730 2731
            // for every principle
2731 2732
            for (int j = 0; j < principalList.length; j++) {
2732 2733
                String principal = principalList[j];
src/edu/ucsb/nceas/metacat/dataone/SystemMetadataManager.java
51 51
        boolean hassm = false;
52 52
        try
53 53
        {
54
            String smid = idManager.getSystemMetadataId(guid);
54
            String smid = idManager.getSystemMetadataLocalId(guid);
55 55
            if(smid != null && !smid.trim().equals(""))
56 56
            {
57 57
                hassm = true;
src/edu/ucsb/nceas/metacat/dataone/CrudService.java
392 392
     * @return
393 393
     */
394 394
    public void setAccess(AuthToken token, Identifier id, String principal, String permission,
395
            String permissionType, String permissionOrder)
395
            String permissionType, String permissionOrder, boolean setSystemMetadata)
396 396
      throws ServiceFailure
397 397
    {
398 398
        try
......
409 409
            {
410 410
                permNum = "6";
411 411
            }
412
            System.out.println("user " + sessionData.getUserName() + 
413
                    " is setting access level " + permNum + " for permission " + 
414
                    permissionType + " on doc with localid " + docid);
412 415
            handler.setAccess(metacatUrl, sessionData.getUserName(), docid, 
413 416
                    principal, permNum, permissionType, permissionOrder);
414
            
417
            if(setSystemMetadata)
418
            {
419
                //set the same perms on the system metadata doc
420
                String smlocalid = im.getSystemMetadataLocalId(id.getValue());
421
                System.out.println("setting access on SM doc with localid " + smlocalid);
422
                //cs.setAccess(token, smid, principal, permission, permissionType, permissionOrder);
423
                handler.setAccess(metacatUrl, sessionData.getUserName(), smlocalid,
424
                        principal, permNum, permissionType, permissionOrder);
425
            }
415 426
            String username = sessionData.getUserName();
416 427
            EventLog.getInstance().log(metacatUrl,
417 428
                    username, im.getLocalId(id.getValue()), "setAccess");
......
627 638
              { //id can be null from tests.  should not happen in production.
628 639
                  ol.addObjectInfo(info);
629 640
              }
641
             
630 642
          }
631 643
      }
632 644
      catch(Exception e)
......
848 860
            catch(Exception ex)
849 861
            { //try to get the guid, if that doesn't work, just use the local id
850 862
                //throw new ServiceFailure("1030", "Error getting guid for localId " + 
851
                //        docid + ": " + ex.getMessage());
852
                System.out.println("skipping log record since the docid is null");
863
                //        docid + ": " + ex.getMessage());\
864
                
865
                //skip it if the guid can't be found
853 866
                continue;
854 867
            }
855 868
            
......
919 932
                
920 933
        try {
921 934
            IdentifierManager im = IdentifierManager.getInstance();
922
            final String localId = im.getSystemMetadataId(guid.getValue());
935
            final String localId = im.getSystemMetadataLocalId(guid.getValue());
923 936
            
924 937
            // Read system metadata from metacat's db
925 938
            final InputStreamFromOutputStream<String> objectStream = 
......
1251 1264
    {
1252 1265
        try
1253 1266
        {
1254
            String smId = IdentifierManager.getInstance().getSystemMetadataId(sm.getIdentifier().getValue());
1267
            String smId = IdentifierManager.getInstance().getSystemMetadataLocalId(sm.getIdentifier().getValue());
1255 1268
            sm.setDateSysMetadataModified(new Date());
1256 1269
            String xml = new String(serializeSystemMetadata(sm).toByteArray());
1257 1270
            Identifier id = new Identifier();
src/edu/ucsb/nceas/metacat/IdentifierManager.java
285 285
     */
286 286
    public String getLocalId(String guid) throws McdbDocNotFoundException
287 287
    {
288
        return this.getId(guid, TYPE_IDENTIFIER);
288
        return this.getLocalId(guid, TYPE_IDENTIFIER);
289 289
    }
290 290
    
291 291
    /**
......
474 474
        }
475 475
    }
476 476
    
477
    
478 477
    /**
479 478
     * return the localId of a system metadata document based on its guid
480 479
     */
481
    public String getSystemMetadataId(String guid)
480
    public String getSystemMetadataLocalId(String guid)
482 481
      throws McdbDocNotFoundException
483 482
    {
484
      return this.getId(guid, TYPE_SYSTEM_METADATA);
483
      return this.getLocalId(guid, TYPE_SYSTEM_METADATA);
485 484
    }
486 485
    
487 486
    /**
......
489 488
     * to get an id from the identifier table or 'systemmetadata' to get
490 489
     * the identifier from the systemidentifier table
491 490
     */
492
    private String getId(String guid, String type)
491
    private String getLocalId(String guid, String type)
493 492
      throws McdbDocNotFoundException
494 493
    {
495 494
      if(!type.equals(TYPE_IDENTIFIER) &&

Also available in: Unified diff