/** * @return true if user has been authenticated in this context */ public static boolean isAuthenticated() { if (Daemon.isDaemonThread()) { return true; } else { return getAuthenticatedUser() != null; } }
/** * @return the current thread daemon user or null if not assigned * @since 2.0.0, 1.12.0, 1.11.6, 1.10.4, 1.9.11 */ public static User getDaemonThreadUser() { if (isDaemonThread()) { User user = daemonThreadUser.get(); if (user == null) { user = Context.getContextDAO().getUserByUuid(DAEMON_USER_UUID); daemonThreadUser.set(user); } return user; } else { return null; } }
/** * 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); }
/** * 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(); }
/** * 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(); }
public static Thread runInNewDaemonThread(final Runnable runnable) { if (!isDaemonThread()) { throw new APIAuthenticationException("Only daemon threads can spawn new daemon threads");