Fix authentication problem in SwordV2 implementation (DS-3310).

This commit is contained in:
gressho
2018-01-04 10:59:35 +01:00
parent 258b4f00e9
commit bda2f8709c
2 changed files with 69 additions and 51 deletions

View File

@@ -271,6 +271,31 @@ public class Item extends DSpaceObject implements DSpaceObjectLegacySupport
return bundles;
}
/**
* Get the bundles matching a bundle name (name corresponds roughly to type)
*
* @param name
* name of bundle (ORIGINAL/TEXT/THUMBNAIL)
*
* @return the bundles in an unordered array
*/
public List<Bundle> getBundles(String name)
{
List<Bundle> matchingBundles = new ArrayList<Bundle>();
// now only keep bundles with matching names
List<Bundle> bunds = getBundles();
for (Bundle bundle : bunds)
{
if (name.equals(bundle.getName()))
{
matchingBundles.add(bundle);
}
}
return matchingBundles;
}
/**
* Add a bundle to the item, should not be made public since we don't want to skip business logic
* @param bundle the bundle to be added
@@ -298,35 +323,35 @@ public class Item extends DSpaceObject implements DSpaceObjectLegacySupport
* @return <code>true</code> if object passed in represents the same item
* as this object
*/
@Override
public boolean equals(Object obj)
{
if (obj == null)
{
return false;
}
Class<?> objClass = HibernateProxyHelper.getClassWithoutInitializingProxy(obj);
if (this.getClass() != objClass)
{
return false;
}
final Item otherItem = (Item) obj;
if (!this.getID().equals(otherItem.getID()))
{
return false;
}
@Override
public boolean equals(Object obj)
{
if (obj == null)
{
return false;
}
Class<?> objClass = HibernateProxyHelper.getClassWithoutInitializingProxy(obj);
if (this.getClass() != objClass)
{
return false;
}
final Item otherItem = (Item) obj;
if (!this.getID().equals(otherItem.getID()))
{
return false;
}
return true;
}
return true;
}
@Override
public int hashCode()
{
int hash = 5;
hash += 71 * hash + getType();
hash += 71 * hash + getID().hashCode();
return hash;
}
@Override
public int hashCode()
{
int hash = 5;
hash += 71 * hash + getType();
hash += 71 * hash + getID().hashCode();
return hash;
}
/**
* return type found in Constants

View File

@@ -291,7 +291,7 @@ public class SwordAuthenticator
* @throws DSpaceSwordException
*/
public boolean canSubmit(SwordContext swordContext, DSpaceObject dso,
VerboseDescription msg)
VerboseDescription msg)
throws DSpaceSwordException, SwordError
{
// determine if we can submit
@@ -547,7 +547,7 @@ public class SwordAuthenticator
* @throws DSpaceSwordException
*/
public List<Community> getCommunities(SwordContext swordContext,
Community community)
Community community)
throws DSpaceSwordException
{
// a community is allowed if the following conditions are met
@@ -731,7 +731,7 @@ public class SwordAuthenticator
* @throws DSpaceSwordException
*/
public List<Item> getAllowedItems(SwordContext swordContext,
org.dspace.content.Collection collection)
org.dspace.content.Collection collection)
throws DSpaceSwordException
{
// an item is allowed if the following conditions are met
@@ -765,7 +765,7 @@ public class SwordAuthenticator
}
// get the "ORIGINAL" bundle(s)
List<Bundle> bundles = item.getBundles();
List<Bundle> bundles = item.getBundles(Constants.CONTENT_BUNDLE_NAME);
// look up the READ policy on the community. This will include determining if the user is an administrator
// so we do not need to check that separately
@@ -786,16 +786,12 @@ public class SwordAuthenticator
{
for (Bundle bundle : bundles)
{
if (Constants.CONTENT_BUNDLE_NAME
.equals(bundle.getName()))
add = authorizeService.authorizeActionBoolean(
swordContext.getAuthenticatorContext(),
bundle, Constants.ADD);
if (!add)
{
add = authorizeService.authorizeActionBoolean(
swordContext.getAuthenticatorContext(),
bundle, Constants.ADD);
if (!add)
{
break;
}
break;
}
}
}
@@ -874,7 +870,7 @@ public class SwordAuthenticator
* @throws DSpaceSwordException
*/
public boolean canSubmitTo(SwordContext swordContext,
org.dspace.content.Collection collection)
org.dspace.content.Collection collection)
throws DSpaceSwordException
{
// a user can submit to a collection in the following conditions:
@@ -966,7 +962,7 @@ public class SwordAuthenticator
.authorizeActionBoolean(allowContext, item,
Constants.WRITE);
List<Bundle> bundles = item.getBundles();
List<Bundle> bundles = item.getBundles(Constants.CONTENT_BUNDLE_NAME);
boolean add = false;
if (bundles.isEmpty())
{
@@ -978,15 +974,12 @@ public class SwordAuthenticator
{
for (Bundle bundle : bundles)
{
if (Constants.CONTENT_BUNDLE_NAME.equals(bundle.getName()))
add = authorizeService
.authorizeActionBoolean(allowContext, bundle,
Constants.ADD);
if (!add)
{
add = authorizeService
.authorizeActionBoolean(allowContext, bundle,
Constants.ADD);
if (!add)
{
break;
}
break;
}
}
}