@Inject public ConsoleConfigHandlerImpl( DNWrapper dnUtils, PrivilegedAction<SSOToken> ssoTokenPrivilegedAction) { this.dnUtils = dnUtils; changeListeners = new CopyOnWriteArrayList<>(); try { configManager = new ServiceConfigManager(ssoTokenPrivilegedAction.run(), SERVICE_NAME, SERVICE_VERSION); configManager.addListener(new ConfigChangeHandler()); } catch (SMSException | SSOException e) { throw new ConfigRetrievalException("Unable to retrieve the config manager", e); } }
@Override public <T> T runAs(PrivilegedAction<T> action) { T result = null; UserGroupInformation previous = null; try { previous = (UserGroupInformation) callStatic("getCurrentUGI"); try { if (ugi != null) { callStatic( "setCurrentUser", new Class[] {UserGroupInformation.class}, new Object[] {ugi}); } result = action.run(); } finally { callStatic( "setCurrentUser", new Class[] {UserGroupInformation.class}, new Object[] {previous}); } } catch (RuntimeException re) { throw re; } catch (Exception e) { throw new UndeclaredThrowableException(e, "Unexpected exception in runAs()"); } return result; }
public static <T> T run(PrivilegedAction<T> action) { return (System.getSecurityManager() != null) ? AccessController.doPrivileged(action) : action.run(); }