Package org.dspace.authorize

Examples of org.dspace.authorize.ResourcePolicy


        {
            context = new Context();
            context.turnOffAuthorisationSystem();
            if (cris.getEpersonID() != null)
            {
                ResourcePolicy resourcePolicy = ResourcePolicy.create(context);
                resourcePolicy.setAction(Constants.ADMIN);
                resourcePolicy.setEPerson(cris.getDspaceUser());
                resourcePolicy.setResource(cris);
                resourcePolicy.setResourceType(CrisConstants.RP_TYPE_ID);
                resourcePolicy.setResourceID(cris.getID());
                resourcePolicy.update();
            }
            context.complete();
        }
        catch (Exception e)
        {
View Full Code Here


                    .equals(cris.getEpersonID()))
                    || (cris.getOldEpersonID() == null && cris.getEpersonID() != null))
            {
                if (cris.getEpersonID() != null)
                {
                    ResourcePolicy resourcePolicy = ResourcePolicy
                            .create(context);
                    resourcePolicy.setAction(Constants.ADMIN);
                    resourcePolicy.setEPerson(cris.getDspaceUser());
                    resourcePolicy.setResource(cris);
                    resourcePolicy.setResourceType(CrisConstants.RP_TYPE_ID);
                    resourcePolicy.setResourceID(cris.getID());
                    resourcePolicy.update();
                }
                if (cris.getOldEpersonID() != null)
                {
                    delete(cris.getOldEpersonID(), cris.getId(), context);
                }
View Full Code Here

        {
            // remove the default policy
            AuthorizeManager.removeAllPolicies(c, bs);

            // add the policy
            ResourcePolicy rp = ResourcePolicy.create(c);

            rp.setResource(bs);
            rp.setAction(actionID);
            rp.setGroup(g);

            rp.update();
        }
        else
        {
            if (actionID == Constants.READ)
            {
View Full Code Here

                        }

                        if (!clearOnly)
                        {
                            // now add the policy
                            ResourcePolicy rp = ResourcePolicy.create(c);

                            rp.setResource(myitem);
                            rp.setAction(actionID);
                            rp.setGroup(group);

                            rp.update();
                        }
                    }
                }
                else if (contentType == Constants.BUNDLE)
                {
                    // build list of all items in a collection
                    // build list of all bundles in those items
                    while (i.hasNext())
                    {
                        Item myitem = i.next();

                        Bundle[] bundles = myitem.getBundles();

                        for (int j = 0; j < bundles.length; j++)
                        {
                            Bundle t = bundles[j]; // t for target

                            // is this a replace? delete policies first
                            if (isReplace || clearOnly)
                            {
                                AuthorizeManager.removeAllPolicies(c, t);
                            }

                            if (!clearOnly)
                            {
                                // now add the policy
                                ResourcePolicy rp = ResourcePolicy.create(c);

                                rp.setResource(t);
                                rp.setAction(actionID);
                                rp.setGroup(group);

                                rp.update();
                            }
                        }
                    }
                }
                else if (contentType == Constants.BITSTREAM)
                {
                    // build list of all bitstreams in a collection
                    // iterate over items, bundles, get bitstreams
                    while (i.hasNext())
                    {
                        Item myitem = i.next();
                        System.out.println("Item " + myitem.getID());

                        Bundle[] bundles = myitem.getBundles();

                        for (int j = 0; j < bundles.length; j++)
                        {
                            System.out.println("Bundle " + bundles[j].getID());

                            Bitstream[] bitstreams = bundles[j].getBitstreams();

                            for (int k = 0; k < bitstreams.length; k++)
                            {
                                Bitstream t = bitstreams[k]; // t for target

                                if ( filter == null ||
                                     t.getName().indexOf( filter ) != -1 )
                                {
                                    // is this a replace? delete policies first
                                    if (isReplace || clearOnly)
                                    {
                                            AuthorizeManager.removeAllPolicies(c, t);
                                    }

                                    if (!clearOnly)
                                    {
                                            // now add the policy
                                            ResourcePolicy rp = ResourcePolicy.create(c);

                                            rp.setResource(t);
                                            rp.setAction(actionID);
                                            rp.setGroup(group);

                                            rp.update();
                                    }
                                }
                            }
                        }
                    }
View Full Code Here

                    + " has no default bitstream READ policies");
        }

        while (i.hasNext())
        {
            ResourcePolicy rp = (ResourcePolicy) i.next();
            rp.setAction(Constants.READ);
        }

        replaceAllBitstreamPolicies(policies);
    }
View Full Code Here

        // create the default authorization policy for communities
        // of 'anonymous' READ
        Group anonymousGroup = Group.find(context, 0);

        ResourcePolicy myPolicy = ResourcePolicy.create(context);
        myPolicy.setResource(c);
        myPolicy.setAction(Constants.READ);
        myPolicy.setGroup(anonymousGroup);
        myPolicy.update();

        context.addEvent(new Event(Event.CREATE, Constants.COMMUNITY, c.getID(), c.handle));

        // if creating a top-level Community, simulate an ADD event at the Site.
        if (parent == null)
View Full Code Here

           
            // "Editor" implies READ, WRITE, ADD permissions
            // "Observer" implies READ permissions
            if (policy == POLICY_EDITOR)
            {
                ResourcePolicy r = ResourcePolicy.create(context);
                r.setResource(item);
                r.setGroup(group);
                r.setAction(Constants.READ);
                r.update();
               
                r = ResourcePolicy.create(context);
                r.setResource(item);
                r.setGroup(group);
                r.setAction(Constants.WRITE);
                r.update();
               
                r = ResourcePolicy.create(context);
                r.setResource(item);
                r.setGroup(group);
                r.setAction(Constants.ADD);
                r.update();
               
            }
            else if (policy == POLICY_OBSERVER)
            {
                ResourcePolicy r = ResourcePolicy.create(context);
                r.setResource(item);
                r.setGroup(group);
                r.setAction(Constants.READ);
                r.update();
            }
        }
    }
View Full Code Here

        int actionID = parameters.getParameterAsInteger("actionID",-1);
        int page = parameters.getParameterAsInteger("page",0);
        String query = URLDecode(parameters.getParameter("query","-1"));
       
        // The current policy, if it exists (i.e. we are not creating a new one)
        ResourcePolicy policy = ResourcePolicy.find(context, policyID);
       
        // The currently set group; it's value depends on wether previously clicked the "Set" button to change
        // the associated group, came here to edit an existing group, or create a new one.
        Group currentGroup;
        if (groupID != -1) {
          currentGroup = Group.find(context, groupID);
        }
        else if (policy != null) {
          currentGroup = policy.getGroup();
        }
        else currentGroup = null;
       
        // Same for the current action; it can either blank (-1), manually set, or inherited from the current policy
        if (policy != null && actionID == -1)
          actionID = policy.getAction();
               
        String errorString = parameters.getParameter("errors",null);
    ArrayList<String> errors = new ArrayList<String>();
    if (errorString != null)
    {
      for (String error : errorString.split(","))
        errors.add(error);
    }
   
   
    /* Set up our current Dspace object */
    DSpaceObject dso;
    switch (objectType) {
      case Constants.COMMUNITY: dso = Community.find(context, objectID); break;
      case Constants.COLLECTION: dso = Collection.find(context, objectID); break;
      case Constants.ITEM: dso = org.dspace.content.Item.find(context, objectID); break;
      case Constants.BUNDLE: dso = Bundle.find(context, objectID); break;
      case Constants.BITSTREAM: dso = Bitstream.find(context, objectID); break;
      default: dso = null;
    }

   
        // DIVISION: edit-container-policies
        Division main = body.addInteractiveDivision("edit-policy",contextPath+"/admin/authorize",Division.METHOD_POST,"primary administrative authorization");
       
        if (policyID >= 0) {
          objectID = policy.getResourceID();
          objectType = policy.getResourceType();
          main.setHead(T_main_head_edit.parameterize(policyID,Constants.typeText[objectType],objectID));
        }
        else
          main.setHead(T_main_head_new.parameterize(Constants.typeText[objectType],objectID));
   
View Full Code Here

                    + " has no default item READ policies");
        }

        while (i.hasNext())
        {
            ResourcePolicy rp = (ResourcePolicy) i.next();
            rp.setAction(Constants.READ);
        }

        replaceAllItemPolicies(policies);

        policies = AuthorizeManager.getPoliciesActionFilter(ourContext, c,
                Constants.DEFAULT_BITSTREAM_READ);

        // change the action to just READ
        // just don't call update on the resourcepolicies!!!
        i = policies.iterator();

        if (!i.hasNext())
        {
            throw new java.sql.SQLException("Collection " + c.getID()
                    + " has no default bitstream READ policies");
        }

        while (i.hasNext())
        {
            ResourcePolicy rp = (ResourcePolicy) i.next();
            rp.setAction(Constants.READ);
        }

        replaceAllBitstreamPolicies(policies);
    }
View Full Code Here

    String idsString = parameters.getParameter("policyIDs", null);
   
    ArrayList<ResourcePolicy> policies = new ArrayList<ResourcePolicy>();
    for (String id : idsString.split(","))
    {
      ResourcePolicy policy = ResourcePolicy.find(context,Integer.valueOf(id));
      policies.add(policy);
    }
    // DIVISION: policies-confirm-delete
      Division deleted = body.addInteractiveDivision("policies-confirm-delete",contextPath+"/admin/authorize",Division.METHOD_POST,"primary administrative authorization");
      deleted.setHead(T_confirm_head);
      deleted.addPara(T_confirm_para);
     
      Table table = deleted.addTable("policies-confirm-delete",policies.size() + 1, 4);
        Row header = table.addRow(Row.ROLE_HEADER);
        header.addCell().addContent(T_head_id);
        header.addCell().addContent(T_head_action);
        header.addCell().addContent(T_head_group);
     
      for (ResourcePolicy policy : policies)
      {
        Row row = table.addRow();
        row.addCell().addContent(policy.getID());
          row.addCell().addContent(policy.getActionText());
          if (policy.getGroup() != null) row.addCell().addContent(policy.getGroup().getName());
          else row.addCell().addContent("...");
      }
      Para buttons = deleted.addPara();
      buttons.addButton("submit_confirm").setValue(T_submit_confirm);
      buttons.addButton("submit_cancel").setValue(T_submit_cancel);
View Full Code Here

TOP

Related Classes of org.dspace.authorize.ResourcePolicy

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.