public void initGroups() { // After every migrate, ensure default Groups are setup correctly. Context context = null; try { context = new Context(); context.turnOffAuthorisationSystem(); // While it's not really a formal "registry", we need to ensure the // default, required Groups exist in the DSpace database groupService.initDefaultGroupNames(context); context.restoreAuthSystemState(); // Commit changes and close context context.complete(); } catch (Exception e) { log.error("Error attempting to add/update default DSpace Groups", e); throw new RuntimeException(e); } finally { // Clean up our context, if it still exists & it was never completed if (context != null && context.isValid()) { context.abort(); } } }
@Override public void authorizeAction(Context c, DSpaceObject o, int action, boolean useInheritance) throws AuthorizeException, SQLException { authorizeAction(c, c.getCurrentUser(), o, action, useInheritance); }
@Override public List<Collection> getAvailableSubscriptions(Context context, EPerson eperson) throws SQLException { List<Collection> collections; if (eperson != null) { context.setCurrentUser(eperson); } collections = collectionService.findAuthorized(context, null, Constants.ADD); return collections; }
/** * Construct the context object member variable of this class * using the passed IP address as part of the loggable * information * * @throws DSpaceSwordException can be thrown by the internals of the DSpace SWORD implementation */ private Context constructContext() throws DSpaceSwordException { Context context = new Context(); // Set the session ID and IP address context.setExtraLogInfo("session_id=0"); return context; }
/** * Initialize the Duplicate Detector and trigger parsing and running the command * @param args Command Line arguments */ public static void main(String args[]) { log.debug("Starting Duplicate Detector"); DSpace dspace = new DSpace(); // get a context Context context = new Context(); context.setMode(Context.Mode.READ_ONLY); // turn off Auth context.turnOffAuthorisationSystem(); DuplicateDetector detector = new DuplicateDetector(); detector.runCLI(context, args, detector); context.restoreAuthSystemState(); context.abort(); }
@Override public void end(Context ctx) throws Exception { if (itemsToProcess != null) { for (Item item : itemsToProcess) { ctx.turnOffAuthorisationSystem(); try { itemService.update(ctx, item); } finally { ctx.restoreAuthSystemState(); } } } itemsToProcess = null; }
/** * List accounts having no password salt. * * @throws SQLException if database error */ private static void findUnsalted() throws SQLException { Context myContext = new Context(); List<EPerson> ePersons = ePersonService.findUnsalted(myContext); for (EPerson ePerson : ePersons) { System.out.println(ePerson.getEmail()); } myContext.abort(); // No changes to commit } }
/** * Commit the primary context held by this class, and abort the authenticated * user's context if it is different. This ensures that only changes written * through the appropriate user's context is persisted, and all other * operations are flushed. You should, in general, not try to commit the contexts directly * when using the SWORD API. * * @throws DSpaceSWORDException on database error. */ public void commit() throws DSpaceSWORDException { try { // commit the primary context if (context != null && context.isValid()) { context.complete(); } // the secondary context is for filtering permissions by only, and is // never committed, so we abort here if (authenticatorContext != null && authenticatorContext.isValid()) { authenticatorContext.abort(); } } catch (SQLException e) { throw new DSpaceSWORDException(e); } } }
public static void main(String[] args) { LOG.debug("Starting DOI organiser "); // setup Context Context context = new Context(); // Started from commandline, don't use the authentication system. context.turnOffAuthorisationSystem(); DOIOrganiser organiser = new DOIOrganiser(context, new DSpace().getSingletonService(DOIIdentifierProvider.class)); // run command line interface runCLI(context, organiser, args); try { context.complete(); } catch (SQLException sqle) { System.err.println("Cannot save changes to database: " + sqle.getMessage()); System.exit(-1); } }
private static Context getAnonContext() { if (anonContext == null) { anonContext = new Context(); } return anonContext; }
protected void makeSureMetadataExist(Context context, String schema, String element, String qualifier) { try { context.turnOffAuthorisationSystem(); boolean create = false; MetadataSchema mdschema = metadataSchemaService.find(context, schema); context.complete(); context.restoreAuthSystemState(); } catch (Exception e) { e.printStackTrace();
context.setCurrentUser(eperson); context.turnOffAuthorisationSystem(); System.out.println("Deleting: " + item.getHandle()); collectionService.removeItem(context, collection, item); context.uncacheEntity(item);// Dispatch events every 50 items if (i % 50 == 0) { context.dispatchEvents(); i = 0; harvestedCollectionService.update(context, hc); context.restoreAuthSystemState(); context.dispatchEvents(); } catch (Exception e) { System.out.println("Changes could not be committed"); System.exit(1); } finally { context.restoreAuthSystemState();
org.dspace.core.Context context = new org.dspace.core.Context(); .getAuthorities(); for (SimpleGrantedAuthority grantedAuthority : specialGroups) { context.setSpecialGroup(EPersonServiceFactory.getInstance().getGroupService() .findByName(context, grantedAuthority.getAuthority()) .getID()); context.setCurrentUser( EPersonServiceFactory.getInstance().getEPersonService().findByEmail(context, authentication.getName()));
c = new Context(); HttpSession session = request.getSession(); c.setSpecialGroup(groupIDs[i]); log.debug("Adding Special Group id="+String.valueOf(groupIDs[i])); c.setExtraLogInfo("session_id=" + request.getSession().getId() + ":ip_addr=" + ip); c.setCurrentLocale(sessionLocale);
/** * Returns the context object used in the current curation thread. * This is primarily a utility method to allow tasks access to the context when necessary. * <p> * If the context is null or not set, then this just returns * a brand new Context object representing an Anonymous User. * * @return curation thread's Context object (or a new, anonymous Context if no curation Context exists) * @throws SQLException An exception that provides information on a database access error or other errors. */ public static Context curationContext() throws SQLException { // Return curation context or new context if undefined/invalid Context curCtx = curationCtx.get(); if (curCtx == null || !curCtx.isValid()) { //Create a new context (represents an Anonymous User) curCtx = new Context(); //Save it to current execution thread curationCtx.set(curCtx); } return curCtx; }
context = new Context(); context.setExtraLogInfo("session_id=" + request.getSession().getId()); context.setSpecialGroup(groupIDs[i]); log.debug("Adding Special Group id="+String.valueOf(groupIDs[i])); context.setExtraLogInfo("session_id=" + request.getSession().getId() + ":ip_addr=" + ip);
private void updateFileName(DBConnection dspaceDbConnection, Context c, Item item, String fName) throws Exception { try{ c.turnOffAuthorisationSystem() Bundle[] bundles = item.getBundles("ORIGINAL"); for (int i = 0; i < bundles.length; i++) { Bitstream[] bitstreams = bundles[i].getBitstreams(); for (int j = 0; j < bitstreams.length; j++) { bitstreams[j].setName(fileName); bitstreams[j].update(); log.info("file name change:" + fileName); } } c.commit(); } finally { c.restoreAuthSystemState() }
(HttpServletResponse) objectModel.get(HttpEnvironment.HTTP_RESPONSE_OBJECT); EPerson eperson = context.getCurrentUser(); context.setCurrentUser(eperson);