@Override public List<Group> getAuthorizedGroups(Context c, DSpaceObject o, int actionID) throws java.sql.SQLException { List<ResourcePolicy> policies = getPoliciesActionFilter(c, o, actionID); List<Group> groups = new ArrayList<Group>(); for (ResourcePolicy resourcePolicy : policies) { if (resourcePolicy.getGroup() != null && resourcePolicyService.isDateValid(resourcePolicy)) { groups.add(resourcePolicy.getGroup()); } } return groups; }
private boolean willChangeStatus(Item item) throws SQLException { List<ResourcePolicy> policies = authorizeService.getPoliciesActionFilter(context, item, Constants.READ); for (ResourcePolicy policy : policies) { if ((policy.getGroup() != null) && (policy.getGroup().getName().equals("Anonymous"))) { if (policy.getStartDate() != null && policy.getStartDate().after(new Date())) { return true; } if (policy.getEndDate() != null && policy.getEndDate().after(new Date())) { return true; } } } return false; }
@Override public boolean isAnIdenticalPolicyAlreadyInPlace(Context c, DSpaceObject o, ResourcePolicy rp) throws SQLException { return isAnIdenticalPolicyAlreadyInPlace(c, o, rp.getGroup(), rp.getAction(), rp.getID()); }
List<ResourcePolicy> policies = authorizeService.getPoliciesActionFilter(context, item, Constants.READ); for (ResourcePolicy policy : policies) { if ((policy.getGroup() != null) && (policy.getGroup().getName().equals("Anonymous"))) { if (policy.getStartDate() != null) { dates.add(policy.getStartDate());
protected void grantGroupAllItemPolicies(Context context, Item item, Group group) throws AuthorizeException, SQLException { if (group != null) { //A list of policies the user has for this item List<Integer> groupHasPolicies = new ArrayList<Integer>(); List<ResourcePolicy> itempols = authorizeService.getPolicies(context, item); for (ResourcePolicy resourcePolicy : itempols) { if (group.equals(resourcePolicy.getGroup())) { //The user has already got this policy so it it to the list groupHasPolicies.add(resourcePolicy.getAction()); } } //Make sure we don't add duplicate policies if (!groupHasPolicies.contains(Constants.READ)) { addGroupPolicyToItem(context, item, Constants.READ, group); } if (!groupHasPolicies.contains(Constants.WRITE)) { addGroupPolicyToItem(context, item, Constants.WRITE, group); } if (!groupHasPolicies.contains(Constants.DELETE)) { addGroupPolicyToItem(context, item, Constants.DELETE, group); } if (!groupHasPolicies.contains(Constants.ADD)) { addGroupPolicyToItem(context, item, Constants.ADD, group); } if (!groupHasPolicies.contains(Constants.REMOVE)) { addGroupPolicyToItem(context, item, Constants.REMOVE, group); } } }
/** * Return a hash code for this object. * * @return int hash of object */ @Override public int hashCode() { int hash = 7; hash = 19 * hash + this.getAction(); if (this.getGroup() != null) { hash = 19 * hash + this.getGroup().hashCode(); } else { hash = 19 * hash + -1; } if (this.getEPerson() != null) { hash = 19 * hash + this.getEPerson().hashCode(); } else { hash = 19 * hash + -1; } hash = 19 * hash + (this.getStartDate() != null ? this.getStartDate().hashCode() : 0); hash = 19 * hash + (this.getEndDate() != null ? this.getEndDate().hashCode() : 0); return hash; }
@Override public void additionalIndex(Context context, DSpaceObject dso, SolrInputDocument document) { try { List<ResourcePolicy> policies = authorizeService.getPoliciesActionFilter(context, dso, Constants.READ); for (ResourcePolicy resourcePolicy : policies) { String fieldValue; if (resourcePolicy.getGroup() != null) { //We have a group add it to the value fieldValue = "g" + resourcePolicy.getGroup().getID(); } else { //We have an eperson add it to the value fieldValue = "e" + resourcePolicy.getEPerson().getID(); } document.addField("read", fieldValue); //remove the policy from the cache to save memory context.uncacheEntity(resourcePolicy); } } catch (SQLException e) { log.error(LogManager.getHeader(context, "Error while indexing resource policies", "DSpace object: (id " + dso.getID() + " type " + dso.getType() + ")")); } }
System.out.println("CHECK WARNING: Item " + item.getHandle() + ", Bundle " + bn .getName() + " allows READ by " + ((rp.getEPerson() != null) ? "Group " + rp.getGroup().getName() : "EPerson " + rp.getEPerson().getFullName())); System.out.println("CHECK WARNING: Item " + item.getHandle() + ", Bitstream " + bs .getName() + " (in Bundle " + bn.getName() + ") allows READ by " + ((rp.getEPerson() != null) ? "Group " + rp.getGroup().getName() : "EPerson " + rp.getEPerson().getFullName()));
Group group = policy.getGroup(); EPerson person = policy.getEPerson();
/** * Add the default policies, which have not been already added to the given DSpace object * * @param context The relevant DSpace Context. * @param dso The DSpace Object to add policies to * @param defaultCollectionPolicies list of policies * @throws SQLException An exception that provides information on a database access error or other errors. * @throws AuthorizeException Exception indicating the current user of the context does not have permission * to perform a particular action. */ protected void addDefaultPoliciesNotInPlace(Context context, DSpaceObject dso, List<ResourcePolicy> defaultCollectionPolicies) throws SQLException, AuthorizeException { for (ResourcePolicy defaultPolicy : defaultCollectionPolicies) { if (!authorizeService .isAnIdenticalPolicyAlreadyInPlace(context, dso, defaultPolicy.getGroup(), Constants.READ, defaultPolicy.getID())) { ResourcePolicy newPolicy = resourcePolicyService.clone(context, defaultPolicy); newPolicy.setdSpaceObject(dso); newPolicy.setAction(Constants.READ); newPolicy.setRpType(ResourcePolicy.TYPE_INHERITED); resourcePolicyService.update(context, newPolicy); } } }
Group group = dspacePolicy.getGroup(); if (group != null) { this.groupId = group.getID().toString();
@Override public void addPolicies(Context c, List<ResourcePolicy> policies, DSpaceObject dest) throws SQLException, AuthorizeException { // now add them to the destination object List<ResourcePolicy> newPolicies = new LinkedList<>(); for (ResourcePolicy srp : policies) { ResourcePolicy rp = resourcePolicyService.create(c); // copy over values rp.setdSpaceObject(dest); rp.setAction(srp.getAction()); rp.setEPerson(srp.getEPerson()); rp.setGroup(srp.getGroup()); rp.setStartDate(srp.getStartDate()); rp.setEndDate(srp.getEndDate()); rp.setRpName(srp.getRpName()); rp.setRpDescription(srp.getRpDescription()); rp.setRpType(srp.getRpType()); // and add policy to list of new policies newPolicies.add(rp); } resourcePolicyService.update(c, newPolicies); }
@Override public ResourcePolicy clone(Context context, ResourcePolicy resourcePolicy) throws SQLException, AuthorizeException { ResourcePolicy clone = create(context); clone.setGroup(resourcePolicy.getGroup()); clone.setEPerson(resourcePolicy.getEPerson()); clone.setStartDate((Date) ObjectUtils.clone(resourcePolicy.getStartDate())); clone.setEndDate((Date) ObjectUtils.clone(resourcePolicy.getEndDate())); clone.setRpType((String) ObjectUtils.clone(resourcePolicy.getRpType())); clone.setRpDescription((String) ObjectUtils.clone(resourcePolicy.getRpDescription())); update(context, clone); return clone; }
int groupsMatched = 0; for (ResourcePolicy otherPolicy : otherPolicies) { if (otherPolicy.getGroup() == group) { otherAuthorizations.append(otherPolicy.getActionText()).append(", "); groupsMatched++;
Group policyGroup = policy.getGroup();
Group policyGroup = policy.getGroup();