/** * Send an Alert to all super users that modules did not start due to cyclic dependencies */ private static void notifySuperUsersAboutCyclicDependencies(Exception ex) { try { Context.addProxyPrivilege(PrivilegeConstants.MANAGE_ALERTS); Context.getAlertService().notifySuperUsers("Module.error.cyclicDependencies", ex, ex.getMessage()); } catch (Exception e) { log.error("Unable to send an alert to the super users", e); } finally { Context.removeProxyPrivilege(PrivilegeConstants.MANAGE_ALERTS); } }
/** * Start the scheduler given the following start up properties. * * @param p properties used to start the service */ public static void startup(Properties p) { // Override the Scheduler constants if specified by the user String val = p.getProperty("scheduler.username", null); if (val != null) { SchedulerConstants.SCHEDULER_DEFAULT_USERNAME = val; log.warn("Deprecated runtime property: scheduler.username. Value set in global_property in database now."); } val = p.getProperty("scheduler.password", null); if (val != null) { SchedulerConstants.SCHEDULER_DEFAULT_PASSWORD = val; log.warn("Deprecated runtime property: scheduler.username. Value set in global_property in database now."); } // TODO: do this for all services try { Context.addProxyPrivilege(PrivilegeConstants.MANAGE_SCHEDULER); Context.getSchedulerService().onStartup(); } finally { Context.removeProxyPrivilege(PrivilegeConstants.MANAGE_SCHEDULER); } }
/** * Send an Alert to all super users that the given module did not start successfully. * * @param mod The Module that failed */ private static void notifySuperUsersAboutModuleFailure(Module mod) { try { // Add the privileges necessary for notifySuperUsers Context.addProxyPrivilege(PrivilegeConstants.MANAGE_ALERTS); Context.addProxyPrivilege(PrivilegeConstants.GET_USERS); // Send an alert to all administrators Context.getAlertService().notifySuperUsers("Module.startupError.notification.message", null, mod.getName()); } finally { // Remove added privileges Context.removeProxyPrivilege(PrivilegeConstants.GET_USERS); Context.removeProxyPrivilege(PrivilegeConstants.MANAGE_ALERTS); } }
/** * Send an Alert to all super users that the given module did not start successfully. * * @param mod The Module that failed */ private static void notifySuperUsersAboutModuleFailure(Module mod) { try { // Add the privileges necessary for notifySuperUsers Context.addProxyPrivilege(PrivilegeConstants.MANAGE_ALERTS); // Send an alert to all administrators Context.getAlertService().notifySuperUsers("Module.startupError.notification.message", null, mod.getName()); } catch (Exception e) { log.error("Unable to send an alert to the super users", e); } finally { // Remove added privileges Context.removeProxyPrivilege(PrivilegeConstants.MANAGE_ALERTS); } }
/** * Shutdown the scheduler service that is statically associated with the Context class. */ public static void shutdown() { SchedulerService service = null; // ignores errors while getting the scheduler service try { service = Context.getSchedulerService(); } catch (Exception e) { // pass } // TODO: Do this for all services try { Context.addProxyPrivilege(PrivilegeConstants.MANAGE_SCHEDULER); // doesn't attempt shutdown if there was an error getting the scheduler service if (service != null) { service.onShutdown(); } } finally { Context.removeProxyPrivilege(PrivilegeConstants.MANAGE_SCHEDULER); } }
Context.removeProxyPrivilege(PrivilegeConstants.SQL_LEVEL_ACCESS); Context.removeProxyPrivilege(PrivilegeConstants.MANAGE_GLOBAL_PROPERTIES);
Context.removeProxyPrivilege(PrivilegeConstants.ADD_ORDERS); Context.closeSession();
Context.removeProxyPrivilege(PrivilegeConstants.MANAGE_ROLES); Context.removeProxyPrivilege(PrivilegeConstants.MANAGE_PRIVILEGES); Context.removeProxyPrivilege(PrivilegeConstants.MANAGE_GLOBAL_PROPERTIES); Context.removeProxyPrivilege(PrivilegeConstants.GET_GLOBAL_PROPERTIES);
Context.removeProxyPrivilege("");
Context.removeProxyPrivilege(PrivilegeConstants.MANAGE_GLOBAL_PROPERTIES); Context.removeProxyPrivilege(PrivilegeConstants.MANAGE_CONCEPT_SOURCES); Context.removeProxyPrivilege(PrivilegeConstants.GET_CONCEPT_SOURCES); Context.removeProxyPrivilege(PrivilegeConstants.MANAGE_IMPLEMENTATION_ID);
Context.removeProxyPrivilege(PrivilegeConstants.EDIT_COHORTS);
private void voidExistingObs(Obs obs, String changeMessage, Obs newObs) { // void out the original observation to keep it around for // historical purposes try { Context.addProxyPrivilege(PrivilegeConstants.DELETE_OBS); // fetch a clean copy of this obs from the database so that // we don't write the changes to the database when we save // the fact that the obs is now voided evictObsAndChildren(obs); obs = Context.getObsService().getObs(obs.getObsId()); //delete the previous file from the appdata/complex_obs folder if (newObs.hasPreviousVersion() && newObs.getPreviousVersion().isComplex()) { File previousFile = AbstractHandler.getComplexDataFile(obs); previousFile.delete(); } // calling this via the service so that AOP hooks are called Context.getObsService().voidObs(obs, changeMessage); } finally { Context.removeProxyPrivilege(PrivilegeConstants.DELETE_OBS); } }
/** * @see org.openmrs.api.UserService#setUserProperty(User, String, String) */ @Override public User setUserProperty(User user, String key, String value) { if (user != null) { if (!Context.hasPrivilege(PrivilegeConstants.EDIT_USERS) && !user.equals(Context.getAuthenticatedUser())) { throw new APIException("you.are.not.authorized.change.properties", new Object[] { user.getUserId() }); } user.setUserProperty(key, value); try { Context.addProxyPrivilege(PrivilegeConstants.EDIT_USERS); Context.getUserService().saveUser(user); } finally { Context.removeProxyPrivilege(PrivilegeConstants.EDIT_USERS); } } return user; }
/** * @see org.openmrs.api.UserService#removeUserProperty(org.openmrs.User, java.lang.String) */ @Override public User removeUserProperty(User user, String key) { if (user != null) { // if the current user isn't allowed to edit users and // the user being edited is not the current user, throw an // exception if (!Context.hasPrivilege(PrivilegeConstants.EDIT_USERS) && !user.equals(Context.getAuthenticatedUser())) { throw new APIException("you.are.not.authorized.change.properties", new Object[] { user.getUserId() }); } user.removeUserProperty(key); try { Context.addProxyPrivilege(PrivilegeConstants.EDIT_USERS); Context.getUserService().saveUser(user); } finally { Context.removeProxyPrivilege(PrivilegeConstants.EDIT_USERS); } } return user; }
Context.removeProxyPrivilege(PrivilegeConstants.GET_GLOBAL_PROPERTIES);
@RequestMapping(value = "/{userUuid}", method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) public void changeOthersPassword(@PathVariable("userUuid") String userUuid, @RequestBody Map<String, String> body) { String newPassword = body.get("newPassword"); Context.addProxyPrivilege(PrivilegeConstants.VIEW_USERS); Context.addProxyPrivilege("Get Users"); // support later versions of OpenMRS User user; try { user = userService.getUserByUuid(userUuid); } finally { Context.removeProxyPrivilege(PrivilegeConstants.VIEW_USERS); Context.removeProxyPrivilege("Get Users"); } if (user == null || user.getUserId() == null) { throw new NullPointerException(); } else { userService.changePassword(user, newPassword); } }
int actualSize = patientEncounters.size(); Context.removeProxyPrivilege(PrivilegeConstants.GET_ENCOUNTERS); Context.logout();
/** * @see org.openmrs.module.webservices.rest.web.resource.api.SearchHandler#search(org.openmrs.module.webservices.rest.web.RequestContext) */ @Override public PageableResult search(RequestContext context) throws ResponseException { String tag = context.getRequest().getParameter("tag"); List<Location> locations = new ArrayList<Location>(); try { Context.addProxyPrivilege(VIEW_LOCATIONS); //Not using PrivilegeConstants.VIEW_LOCATIONS which was removed in platform 1.11+ Context.addProxyPrivilege("Get Locations"); //1.11+ LocationTag locationTag = Context.getLocationService().getLocationTagByUuid(tag); if (locationTag == null) { locationTag = Context.getLocationService().getLocationTagByName(tag); } if (locationTag != null) { locations = Context.getLocationService().getLocationsByTag(locationTag); } } finally { Context.removeProxyPrivilege(VIEW_LOCATIONS); //Not using PrivilegeConstants.VIEW_LOCATIONS which was removed in platform 1.11+ Context.removeProxyPrivilege("Get Locations"); //1.11+ } return new NeedsPaging<Location>(locations, context); } }