/** * Convenience method. Passes through to userContext.getAllRoles(User) */ public static Set<Role> getAllRoles(User user) throws Exception { return getUserContext().getAllRoles(); }
/** * Convenience method. Passes through to {@link UserContext#setLocale(Locale)} */ public static void setLocale(Locale locale) { getUserContext().setLocale(locale); }
/** * Constructor to initialize variables */ public Hl7InArchivesMigrateThread() { this.userContext = Context.getUserContext(); setProgressStatusMap(new HashMap<>()); progressStatusMap.put(HL7Constants.NUMBER_TRANSFERRED_KEY, 0); progressStatusMap.put(HL7Constants.NUMBER_OF_FAILED_TRANSFERS_KEY, 0); }
/** * Convenience method that returns the default location of the authenticated user. It should * return the user's specified location from the user properties if any is set. * * @should return the user specified location if any is set */ public static Location getUserDefaultLocation() { return Context.getUserContext().getLocation(); }
/** * Convenience method. Passes through to {@link UserContext#addProxyPrivilege(String)} */ public static void addProxyPrivilege(String privilege) { getUserContext().addProxyPrivilege(privilege); }
/** * Convenience method. Passes through to {@link UserContext#removeProxyPrivilege(String)} */ public static void removeProxyPrivilege(String privilege) { getUserContext().removeProxyPrivilege(privilege); }
/** * Refresh the authenticated user object in the current UserContext. This should be used when * updating information in the database about the current user and it needs to be reflecting in * the (cached) {@link #getAuthenticatedUser()} User object. * * @since 1.5 * @should get fresh values from the database */ public static void refreshAuthenticatedUser() { if (Daemon.isDaemonThread()) { return; } log.debug("Refreshing authenticated user"); getUserContext().refreshAuthenticatedUser(); }
/** * Convenience method. Passes through to userContext.hasPrivilege(String) * * @should give daemon user full privileges */ public static boolean hasPrivilege(String privilege) { // the daemon threads have access to all things if (Daemon.isDaemonThread()) { return true; } return getUserContext().hasPrivilege(privilege); }
/** * Used to authenticate user within the context * * @param username user's identifier token for login * @param password user's password for authenticating to context * @throws ContextAuthenticationException * @should not authenticate with null username and password * @should not authenticate with null password * @should not authenticate with null username * @should not authenticate with null password and proper username * @should not authenticate with null password and proper system id */ public static void authenticate(String username, String password) throws ContextAuthenticationException { log.debug("Authenticating with username: {}", username); if (Daemon.isDaemonThread()) { log.error("Authentication attempted while operating on a " + "daemon thread, authenticating is not necessary or allowed"); return; } getUserContext().authenticate(username, password, getContextDAO()); }
/** * @return "active" user who has been authenticated, otherwise <code>null</code> */ public static User getAuthenticatedUser() { if (Daemon.isDaemonThread()) { return Daemon.getDaemonThreadUser(); } return getUserContext().getAuthenticatedUser(); }
/** * Convenience method. Passes through to {@link UserContext#getLocale()} * * @should not fail if session hasn't been opened */ public static Locale getLocale() { // if a session hasn't been opened, just fetch the default if (!isSessionOpen()) { return LocaleUtility.getDefaultLocale(); } return getUserContext().getLocale(); }
/** * logs out the "active" (authenticated) user within context * * @see #authenticate * @should not fail if session hasn't been opened yet */ public static void logout() { if (!isSessionOpen()) { return; // fail early if there isn't even a session open } log.debug("Logging out : {}", getAuthenticatedUser()); getUserContext().logout(); // reset the UserContext object (usually cleared out by closeSession() // soon after this) setUserContext(new UserContext()); }
/** * @see Context#getUserContext() */ @Test(expected = APIException.class) public void getUserContext_shouldFailIfSessionHasntBeenOpened() { Context.closeSession(); Context.getUserContext(); // trigger the api exception }
/** * Become a different user. (You should only be able to do this as a superuser.) * * @param systemId * @throws ContextAuthenticationException * @should change locale when become another user */ public static void becomeUser(String systemId) throws ContextAuthenticationException { log.info("systemId: {}", systemId); User user = getUserContext().becomeUser(systemId); // if assuming identity procedure finished successfully, we should change context locale parameter Locale locale = null; if (user.getUserProperties().containsKey(OpenmrsConstants.USER_PROPERTY_DEFAULT_LOCALE)) { String localeString = user.getUserProperty(OpenmrsConstants.USER_PROPERTY_DEFAULT_LOCALE); locale = LocaleUtility.fromSpecification(localeString); } // when locale parameter is not valid or does not exist if (locale == null) { locale = LocaleUtility.getDefaultLocale(); } Context.setLocale(locale); }
public void setUserContext(UserContext userContext) { if (!userContextMocked) { try { realUserContext = Context.getUserContext(); } catch (Exception e) { //let's not fail if context is not configured } userContextMocked = true; } Context.setUserContext(userContext); this.userContext = userContext; authenticateMockUser(); }
@Test(expected = APIAuthenticationException.class) public void before_shouldThrowAPIAuthenticationException() { Context.getUserContext().logout(); Context.getConceptService().getConcept(3); }
testStr = HtmlFormEntryUtil.getTestStr(includeStr.substring(includeOrExcludeTestIndex)); testRoles = testStr.split(","); User currentUser = Context.getUserContext().getAuthenticatedUser(); try { Set<Role> assignedRoles = currentUser.getAllRoles(); testStr = HtmlFormEntryUtil.getTestStr(includeStr.substring(includeOrExcludeTestIndex)) ; testRoles = testStr.split(","); User currentUser = Context.getUserContext().getAuthenticatedUser(); try { Set<Role> assignedRoles = currentUser.getAllRoles();
Context.getUserContext().setLocale(new Locale("en", "US"));