DS-3346 change and remove deprecated setIgnoreAuthorization in favour of turnOff/restore

This commit is contained in:
Luigi Andrea Pascarelli
2016-09-28 23:39:24 +02:00
parent ebeda8cc29
commit f577074e69
21 changed files with 32 additions and 47 deletions

View File

@@ -132,8 +132,8 @@ public class CommunityFiliator
CommunityFiliator filiator = new CommunityFiliator(); CommunityFiliator filiator = new CommunityFiliator();
Context c = new Context(); Context c = new Context();
// ve are superuser! // we are superuser!
c.setIgnoreAuthorization(true); c.turnOffAuthorisationSystem();
try try
{ {

View File

@@ -237,7 +237,7 @@ public final class CreateAdministrator
{ {
// Of course we aren't an administrator yet so we need to // Of course we aren't an administrator yet so we need to
// circumvent authorisation // circumvent authorisation
context.setIgnoreAuthorization(true); context.turnOffAuthorisationSystem();
// Find administrator group // Find administrator group
Group admins = groupService.findByName(context, Group.ADMIN); Group admins = groupService.findByName(context, Group.ADMIN);

View File

@@ -101,7 +101,7 @@ public class MetadataExporter
{ {
// create a context // create a context
Context context = new Context(); Context context = new Context();
context.setIgnoreAuthorization(true); context.turnOffAuthorisationSystem();
OutputFormat xmlFormat = new OutputFormat(Method.XML, "UTF-8", true); OutputFormat xmlFormat = new OutputFormat(Method.XML, "UTF-8", true);
xmlFormat.setLineWidth(120); xmlFormat.setLineWidth(120);

View File

@@ -177,7 +177,7 @@ public class ItemExportCLITool {
} }
Context c = new Context(); Context c = new Context();
c.setIgnoreAuthorization(true); c.turnOffAuthorisationSystem();
if (myType == Constants.ITEM) if (myType == Constants.ITEM)
{ {

View File

@@ -1779,7 +1779,7 @@ public class ItemImportServiceImpl implements ItemImportService, InitializingBea
context = new Context(); context = new Context();
eperson = ePersonService.find(context, oldEPerson.getID()); eperson = ePersonService.find(context, oldEPerson.getID());
context.setCurrentUser(eperson); context.setCurrentUser(eperson);
context.setIgnoreAuthorization(true); context.turnOffAuthorisationSystem();
boolean isResume = theResumeDir!=null; boolean isResume = theResumeDir!=null;

View File

@@ -355,7 +355,7 @@ public class ItemUpdate {
context = new Context(); context = new Context();
iu.setEPerson(context, iu.eperson); iu.setEPerson(context, iu.eperson);
context.setIgnoreAuthorization(true); context.turnOffAuthorisationSystem();
HANDLE_PREFIX = ConfigurationManager.getProperty("handle.canonical.prefix"); HANDLE_PREFIX = ConfigurationManager.getProperty("handle.canonical.prefix");
if (HANDLE_PREFIX == null || HANDLE_PREFIX.length() == 0) if (HANDLE_PREFIX == null || HANDLE_PREFIX.length() == 0)
@@ -366,19 +366,20 @@ public class ItemUpdate {
iu.processArchive(context, sourcedir, itemField, metadataIndexName, alterProvenance, isTest); iu.processArchive(context, sourcedir, itemField, metadataIndexName, alterProvenance, isTest);
context.complete(); // complete all transactions context.complete(); // complete all transactions
context.setIgnoreAuthorization(false);
} }
catch (Exception e) catch (Exception e)
{ {
if (context != null && context.isValid()) if (context != null && context.isValid())
{ {
context.abort(); context.abort();
context.setIgnoreAuthorization(false);
} }
e.printStackTrace(); e.printStackTrace();
pr(e.toString()); pr(e.toString());
status = 1; status = 1;
} }
finally {
context.restoreAuthSystemState();
}
if (isTest) if (isTest)
{ {

View File

@@ -92,7 +92,7 @@ public class CreateStatReport {
// create context as super user // create context as super user
context = new Context(); context = new Context();
context.setIgnoreAuthorization(true); context.turnOffAuthorisationSystem();
//get paths to directories //get paths to directories
outputLogDirectory = ConfigurationManager.getProperty("log.report.dir") + File.separator; outputLogDirectory = ConfigurationManager.getProperty("log.report.dir") + File.separator;

View File

@@ -224,7 +224,7 @@ public class LogAnalyser
// create context as super user // create context as super user
Context context = new Context(); Context context = new Context();
context.setIgnoreAuthorization(true); context.turnOffAuthorisationSystem();
// set up our command line variables // set up our command line variables
String myLogDir = null; String myLogDir = null;

View File

@@ -161,7 +161,7 @@ public class ReportGenerator
{ {
// create context as super user // create context as super user
Context context = new Context(); Context context = new Context();
context.setIgnoreAuthorization(true); context.turnOffAuthorisationSystem();
String myFormat = null; String myFormat = null;
String myInput = null; String myInput = null;

View File

@@ -309,11 +309,11 @@ public class LDAPAuthentication
{ {
log.info(LogManager.getHeader(context, log.info(LogManager.getHeader(context,
"type=ldap-login", "type=ldap_but_already_email")); "type=ldap-login", "type=ldap_but_already_email"));
context.setIgnoreAuthorization(true); context.turnOffAuthorisationSystem();
eperson.setNetid(netid.toLowerCase()); eperson.setNetid(netid.toLowerCase());
ePersonService.update(context, eperson); ePersonService.update(context, eperson);
context.dispatchEvents(); context.dispatchEvents();
context.setIgnoreAuthorization(false); context.restoreAuthSystemState();
context.setCurrentUser(eperson); context.setCurrentUser(eperson);
// assign user to groups based on ldap dn // assign user to groups based on ldap dn
@@ -328,7 +328,7 @@ public class LDAPAuthentication
// TEMPORARILY turn off authorisation // TEMPORARILY turn off authorisation
try try
{ {
context.setIgnoreAuthorization(true); context.turnOffAuthorisationSystem();
eperson = ePersonService.create(context); eperson = ePersonService.create(context);
if (StringUtils.isNotEmpty(email)) if (StringUtils.isNotEmpty(email))
{ {
@@ -362,7 +362,7 @@ public class LDAPAuthentication
} }
finally finally
{ {
context.setIgnoreAuthorization(false); context.restoreAuthSystemState();
} }
log.info(LogManager.getHeader(context, "authenticate", log.info(LogManager.getHeader(context, "authenticate",
@@ -384,7 +384,7 @@ public class LDAPAuthentication
} }
finally finally
{ {
context.setIgnoreAuthorization(false); context.restoreAuthSystemState();
} }
} }
} }

View File

@@ -612,7 +612,7 @@ public class X509Authentication implements AuthenticationMethod
"from=x.509, email=" + email)); "from=x.509, email=" + email));
// TEMPORARILY turn off authorisation // TEMPORARILY turn off authorisation
context.setIgnoreAuthorization(true); context.turnOffAuthorisationSystem();
eperson = ePersonService.create(context); eperson = ePersonService.create(context);
eperson.setEmail(email); eperson.setEmail(email);
eperson.setCanLogIn(true); eperson.setCanLogIn(true);
@@ -620,7 +620,7 @@ public class X509Authentication implements AuthenticationMethod
eperson); eperson);
ePersonService.update(context, eperson); ePersonService.update(context, eperson);
context.dispatchEvents(); context.dispatchEvents();
context.setIgnoreAuthorization(false); context.restoreAuthSystemState();
context.setCurrentUser(eperson); context.setCurrentUser(eperson);
setSpecialGroupsFlag(request, email); setSpecialGroupsFlag(request, email);
return SUCCESS; return SUCCESS;

View File

@@ -42,7 +42,7 @@ public class FixDefaultPolicies
Context c = new Context(); Context c = new Context();
// turn off authorization // turn off authorization
c.setIgnoreAuthorization(true); c.turnOffAuthorisationSystem();
////////////////////// //////////////////////
// carnage begins here // carnage begins here

View File

@@ -79,7 +79,7 @@ public class PolicySet
Context c = new Context(); Context c = new Context();
// turn off authorization // turn off authorization
c.setIgnoreAuthorization(true); c.turnOffAuthorisationSystem();
////////////////////// //////////////////////
// carnage begins here // carnage begins here

View File

@@ -303,21 +303,6 @@ public class Context
ignoreAuth = previousState.booleanValue(); ignoreAuth = previousState.booleanValue();
} }
/**
* Specify whether the authorisation system should be ignored for this
* context. This should be used sparingly.
*
* @deprecated use turnOffAuthorisationSystem() for make the change and
* restoreAuthSystemState() when change are not more required
* @param b
* if <code>true</code>, authorisation should be ignored for this
* session.
*/
public void setIgnoreAuthorization(boolean b)
{
ignoreAuth = b;
}
/** /**
* Set extra information that should be added to any message logged in the * Set extra information that should be added to any message logged in the
* scope of this context. An example of this might be the session ID of the * scope of this context. An example of this might be the session ID of the

View File

@@ -155,7 +155,7 @@ public class CurationCli
} }
else else
{ {
c.setIgnoreAuthorization(true); c.turnOffAuthorisationSystem();
} }
Curator curator = new Curator(); Curator curator = new Curator();

View File

@@ -48,7 +48,7 @@ public class IndexClient {
public static void main(String[] args) throws SQLException, IOException, SearchServiceException { public static void main(String[] args) throws SQLException, IOException, SearchServiceException {
Context context = new Context(); Context context = new Context();
context.setIgnoreAuthorization(true); context.turnOffAuthorisationSystem();
String usage = "org.dspace.discovery.IndexClient [-cbhf] | [-r <handle>] | [-i <handle>] or nothing to update/clean an existing index."; String usage = "org.dspace.discovery.IndexClient [-cbhf] | [-r <handle>] | [-i <handle>] or nothing to update/clean an existing index.";
Options options = new Options(); Options options = new Options();

View File

@@ -115,7 +115,7 @@ public class EmbargoCLITool {
try try
{ {
context = new Context(); context = new Context();
context.setIgnoreAuthorization(true); context.turnOffAuthorisationSystem();
Date now = new Date(); Date now = new Date();
// scan items under embargo // scan items under embargo

View File

@@ -93,10 +93,9 @@ public class EmbargoServiceImpl implements EmbargoService
} }
} }
String slift = myLift.toString(); String slift = myLift.toString();
boolean ignoreAuth = context.ignoreAuthorization();
try try
{ {
context.setIgnoreAuthorization(true); context.turnOffAuthorisationSystem();
itemService.clearMetadata(context, item, lift_schema, lift_element, lift_qualifier, Item.ANY); itemService.clearMetadata(context, item, lift_schema, lift_element, lift_qualifier, Item.ANY);
itemService.addMetadata(context, item, lift_schema, lift_element, lift_qualifier, null, slift); itemService.addMetadata(context, item, lift_schema, lift_element, lift_qualifier, null, slift);
log.info("Set embargo on Item "+item.getHandle()+", expires on: "+slift); log.info("Set embargo on Item "+item.getHandle()+", expires on: "+slift);
@@ -107,7 +106,7 @@ public class EmbargoServiceImpl implements EmbargoService
} }
finally finally
{ {
context.setIgnoreAuthorization(ignoreAuth); context.restoreAuthSystemState();
} }
} }

View File

@@ -81,7 +81,7 @@ public class LicenseCleanup
{ {
Context ctx = new Context(); Context ctx = new Context();
ctx.setIgnoreAuthorization(true); ctx.turnOffAuthorisationSystem();
Iterator<Item> iter = itemService.findAll(ctx); Iterator<Item> iter = itemService.findAll(ctx);
Properties props = new Properties(); Properties props = new Properties();

View File

@@ -487,7 +487,7 @@ public class RegisterServlet extends EditProfileServlet
// Need to create new eperson // Need to create new eperson
// FIXME: TEMPORARILY need to turn off authentication, as usually // FIXME: TEMPORARILY need to turn off authentication, as usually
// only site admins can create e-people // only site admins can create e-people
context.setIgnoreAuthorization(true); context.turnOffAuthorisationSystem();
eperson = personService.create(context); eperson = personService.create(context);
eperson.setEmail(email); eperson.setEmail(email);
if (netid!=null) if (netid!=null)
@@ -495,7 +495,7 @@ public class RegisterServlet extends EditProfileServlet
eperson.setNetid(netid.toLowerCase()); eperson.setNetid(netid.toLowerCase());
} }
personService.update(context, eperson); personService.update(context, eperson);
context.setIgnoreAuthorization(false); context.restoreAuthSystemState();
} }
// Now set the current user of the context // Now set the current user of the context

View File

@@ -472,13 +472,13 @@ public class AuthenticationUtil
// Need to create new eperson // Need to create new eperson
// FIXME: TEMPORARILY need to turn off authentication, as usually // FIXME: TEMPORARILY need to turn off authentication, as usually
// only site admins can create e-people // only site admins can create e-people
context.setIgnoreAuthorization(true); context.turnOffAuthorisationSystem();
EPerson eperson = ePersonService.create(context); EPerson eperson = ePersonService.create(context);
eperson.setEmail(email); eperson.setEmail(email);
eperson.setCanLogIn(true); eperson.setCanLogIn(true);
eperson.setSelfRegistered(true); eperson.setSelfRegistered(true);
ePersonService.update(context, eperson); ePersonService.update(context, eperson);
context.setIgnoreAuthorization(false); context.restoreAuthSystemState();
// Give site auth a chance to set/override appropriate fields // Give site auth a chance to set/override appropriate fields
authenticationService.initEPerson(context, request, eperson); authenticationService.initEPerson(context, request, eperson);