mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-16 14:33:09 +00:00
Fix authentication problem in SwordV2 implementation (DS-3310).
This commit is contained in:
@@ -271,6 +271,31 @@ public class Item extends DSpaceObject implements DSpaceObjectLegacySupport
|
|||||||
return bundles;
|
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
|
* 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
|
* @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
|
* @return <code>true</code> if object passed in represents the same item
|
||||||
* as this object
|
* as this object
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj)
|
public boolean equals(Object obj)
|
||||||
{
|
{
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Class<?> objClass = HibernateProxyHelper.getClassWithoutInitializingProxy(obj);
|
Class<?> objClass = HibernateProxyHelper.getClassWithoutInitializingProxy(obj);
|
||||||
if (this.getClass() != objClass)
|
if (this.getClass() != objClass)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final Item otherItem = (Item) obj;
|
final Item otherItem = (Item) obj;
|
||||||
if (!this.getID().equals(otherItem.getID()))
|
if (!this.getID().equals(otherItem.getID()))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode()
|
public int hashCode()
|
||||||
{
|
{
|
||||||
int hash = 5;
|
int hash = 5;
|
||||||
hash += 71 * hash + getType();
|
hash += 71 * hash + getType();
|
||||||
hash += 71 * hash + getID().hashCode();
|
hash += 71 * hash + getID().hashCode();
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return type found in Constants
|
* return type found in Constants
|
||||||
|
@@ -291,7 +291,7 @@ public class SwordAuthenticator
|
|||||||
* @throws DSpaceSwordException
|
* @throws DSpaceSwordException
|
||||||
*/
|
*/
|
||||||
public boolean canSubmit(SwordContext swordContext, DSpaceObject dso,
|
public boolean canSubmit(SwordContext swordContext, DSpaceObject dso,
|
||||||
VerboseDescription msg)
|
VerboseDescription msg)
|
||||||
throws DSpaceSwordException, SwordError
|
throws DSpaceSwordException, SwordError
|
||||||
{
|
{
|
||||||
// determine if we can submit
|
// determine if we can submit
|
||||||
@@ -547,7 +547,7 @@ public class SwordAuthenticator
|
|||||||
* @throws DSpaceSwordException
|
* @throws DSpaceSwordException
|
||||||
*/
|
*/
|
||||||
public List<Community> getCommunities(SwordContext swordContext,
|
public List<Community> getCommunities(SwordContext swordContext,
|
||||||
Community community)
|
Community community)
|
||||||
throws DSpaceSwordException
|
throws DSpaceSwordException
|
||||||
{
|
{
|
||||||
// a community is allowed if the following conditions are met
|
// a community is allowed if the following conditions are met
|
||||||
@@ -731,7 +731,7 @@ public class SwordAuthenticator
|
|||||||
* @throws DSpaceSwordException
|
* @throws DSpaceSwordException
|
||||||
*/
|
*/
|
||||||
public List<Item> getAllowedItems(SwordContext swordContext,
|
public List<Item> getAllowedItems(SwordContext swordContext,
|
||||||
org.dspace.content.Collection collection)
|
org.dspace.content.Collection collection)
|
||||||
throws DSpaceSwordException
|
throws DSpaceSwordException
|
||||||
{
|
{
|
||||||
// an item is allowed if the following conditions are met
|
// an item is allowed if the following conditions are met
|
||||||
@@ -765,7 +765,7 @@ public class SwordAuthenticator
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get the "ORIGINAL" bundle(s)
|
// 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
|
// 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
|
// so we do not need to check that separately
|
||||||
@@ -786,16 +786,12 @@ public class SwordAuthenticator
|
|||||||
{
|
{
|
||||||
for (Bundle bundle : bundles)
|
for (Bundle bundle : bundles)
|
||||||
{
|
{
|
||||||
if (Constants.CONTENT_BUNDLE_NAME
|
add = authorizeService.authorizeActionBoolean(
|
||||||
.equals(bundle.getName()))
|
swordContext.getAuthenticatorContext(),
|
||||||
|
bundle, Constants.ADD);
|
||||||
|
if (!add)
|
||||||
{
|
{
|
||||||
add = authorizeService.authorizeActionBoolean(
|
break;
|
||||||
swordContext.getAuthenticatorContext(),
|
|
||||||
bundle, Constants.ADD);
|
|
||||||
if (!add)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -874,7 +870,7 @@ public class SwordAuthenticator
|
|||||||
* @throws DSpaceSwordException
|
* @throws DSpaceSwordException
|
||||||
*/
|
*/
|
||||||
public boolean canSubmitTo(SwordContext swordContext,
|
public boolean canSubmitTo(SwordContext swordContext,
|
||||||
org.dspace.content.Collection collection)
|
org.dspace.content.Collection collection)
|
||||||
throws DSpaceSwordException
|
throws DSpaceSwordException
|
||||||
{
|
{
|
||||||
// a user can submit to a collection in the following conditions:
|
// a user can submit to a collection in the following conditions:
|
||||||
@@ -966,7 +962,7 @@ public class SwordAuthenticator
|
|||||||
.authorizeActionBoolean(allowContext, item,
|
.authorizeActionBoolean(allowContext, item,
|
||||||
Constants.WRITE);
|
Constants.WRITE);
|
||||||
|
|
||||||
List<Bundle> bundles = item.getBundles();
|
List<Bundle> bundles = item.getBundles(Constants.CONTENT_BUNDLE_NAME);
|
||||||
boolean add = false;
|
boolean add = false;
|
||||||
if (bundles.isEmpty())
|
if (bundles.isEmpty())
|
||||||
{
|
{
|
||||||
@@ -978,15 +974,12 @@ public class SwordAuthenticator
|
|||||||
{
|
{
|
||||||
for (Bundle bundle : bundles)
|
for (Bundle bundle : bundles)
|
||||||
{
|
{
|
||||||
if (Constants.CONTENT_BUNDLE_NAME.equals(bundle.getName()))
|
add = authorizeService
|
||||||
|
.authorizeActionBoolean(allowContext, bundle,
|
||||||
|
Constants.ADD);
|
||||||
|
if (!add)
|
||||||
{
|
{
|
||||||
add = authorizeService
|
break;
|
||||||
.authorizeActionBoolean(allowContext, bundle,
|
|
||||||
Constants.ADD);
|
|
||||||
if (!add)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user