/** * Refresh the authenticated user object in this 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 */ public void refreshAuthenticatedUser() { log.debug("Refreshing authenticated user"); if (user != null) { user = Context.getUserService().getUser(user.getUserId()); //update the stored location in the user's session setUserLocation(); } }
/** * Authenticate the user to this UserContext. * * @see org.openmrs.api.context.Context#authenticate(String, String) * @param username String login name * @param password String login password * @param contextDAO ContextDAO implementation to use for authentication * @return User that has been authenticated * @throws ContextAuthenticationException */ public User authenticate(String username, String password, ContextDAO contextDAO) throws ContextAuthenticationException { log.debug("Authenticating with username: {}", username); try { this.user = contextDAO.authenticate(username, password); notifyUserSessionListener(this.user, Event.LOGIN, Status.SUCCESS); } catch(ContextAuthenticationException e) { User loggingInUser = new User(); loggingInUser.setUsername(username); notifyUserSessionListener(loggingInUser, Event.LOGIN, Status.FAIL); throw e; } setUserLocation(); log.debug("Authenticated as: {}", this.user); return this.user; }