List of usage examples for java.security PrivilegedAction PrivilegedAction
PrivilegedAction
From source file:org.mc4j.ems.connection.ConnectionFactory.java
/** * Build a connection provider given the settings. This should be the prefrence over connect. * Each request to connect will reuse the same classloader and provider rather than rebuilding * from scratch.//from ww w .j a v a 2s . co m * @param connectionSettings the connection settings for the connection * @return a ConnectionProvider that you can get live connection from. */ public ConnectionProvider getConnectionProvider(final ConnectionSettings connectionSettings) { String className = connectionSettings.getConnectionType().getConnectionNodeClassName(); try { // TODO GH: Does this need to be configurable per connection? ClassLoader loader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { public ClassLoader run() { return ClassLoaderFactory.getInstance().buildClassLoader(connectionSettings); } }); log.debug("Loading connection class [" + className + "] from ClassLoader [" + loader + "]..."); // TODO GH: Add intelligent classloader layer here that can either work // directly against current classloader or build a non-delegating child // to override with connection specific classes Class clazz = Class.forName(className, false, loader); ConnectionProvider connectionProvider = (ConnectionProvider) clazz.newInstance(); connectionProvider.initialize(connectionSettings); return connectionProvider; } catch (IllegalAccessException e) { throw new ConnectionException("Could not access ConnectionClass " + className, e); } catch (InstantiationException e) { throw new ConnectionException("Could not instantiate ConnectionClass " + className, e); } catch (ClassNotFoundException e) { throw new ConnectionException("Could not find ConnectionClass " + className, e); } }
From source file:org.apache.axis2.jaxws.lifecycle.BaseLifecycleManager.java
protected boolean isPostConstruct(final Method method) { Annotation[] annotations = (Annotation[]) AccessController.doPrivileged(new PrivilegedAction() { public Object run() { return method.getDeclaredAnnotations(); }//from ww w .j a v a2 s .co m }); for (Annotation annotation : annotations) { return PostConstruct.class.isAssignableFrom(annotation.annotationType()); } return false; }
From source file:edu.mayo.cts2.framework.webapp.rest.controller.AbstractMessageWrappingController.java
private void setDirectoryEntries(Directory directory, List<?> entries) { try {//from w w w . j a v a 2 s. c om final Field field = ReflectionUtils.findField(directory.getClass(), "_entryList"); AccessController.doPrivileged(new PrivilegedAction<Void>() { public Void run() { field.setAccessible(true); return null; } }); ReflectionUtils.setField(field, directory, entries); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.eclipse.gemini.blueprint.extender.internal.blueprint.event.EventAdminDispatcher.java
public void refreshFailure(final BlueprintEvent event) { if (dispatcher != null) { try {// w w w . j av a 2s . c o m if (System.getSecurityManager() != null) { AccessController.doPrivileged(new PrivilegedAction<Object>() { public Object run() { dispatcher.refreshFailure(event); return null; } }); } else { dispatcher.refreshFailure(event); } } catch (Throwable th) { log.warn("Cannot dispatch event " + event, th); } } }
From source file:org.apache.ranger.tagsync.sink.tagadmin.TagAdminRESTSink.java
private ServiceTags doUpload(ServiceTags serviceTags) throws Exception { if (!StringUtils.isEmpty(authenticationType) && authenticationType.trim().equalsIgnoreCase(AUTH_TYPE_KERBEROS) && SecureClientLogin.isKerberosCredentialExists(principal, keytab)) { try {/*from ww w. j a v a 2s . c o m*/ Subject sub = SecureClientLogin.loginUserFromKeytab(principal, keytab, nameRules); if (LOG.isDebugEnabled()) { LOG.debug("Using Principal = " + principal + ", keytab = " + keytab); } final ServiceTags serviceTag = serviceTags; ServiceTags ret = Subject.doAs(sub, new PrivilegedAction<ServiceTags>() { @Override public ServiceTags run() { try { return uploadServiceTags(serviceTag); } catch (Exception e) { LOG.error("Upload of service-tags failed with message ", e); } return null; } }); return ret; } catch (Exception e) { LOG.error("Upload of service-tags failed with message ", e); } return null; } else { return uploadServiceTags(serviceTags); } }
From source file:com.vmware.o11n.plugin.powershell.remote.impl.winrm.KerberosTokenGenerator.java
private void initiateSecurityContext() throws GSSException { GSSManager manager = GSSManager.getInstance(); GSSName gssSPN = manager.createName(spn, null); final GSSContext context = manager.createContext(gssSPN, new Oid(SPNEGO_OID), null, GSSContext.DEFAULT_LIFETIME); // The GSS context initiation has to be performed as a privilegedv action. this.serviceTicket = Subject.doAs(subject, new PrivilegedAction<byte[]>() { public byte[] run() { try { byte[] token = new byte[0]; context.requestMutualAuth(true); context.requestCredDeleg(true); return context.initSecContext(token, 0, token.length); } catch (GSSException e) { String msg = e.getMessage(); if (StringUtils.isBlank(msg)) { msg = "Authentication failed."; }/* w ww . ja v a2 s.c o m*/ log.error(msg, e); throw new AuthenticationException(msg, e); } } }); }
From source file:org.apache.ranger.audit.provider.kafka.KafkaAuditProvider.java
@Override public void stop() { LOG.info("stop() called"); if (producer != null) { try {/*from w w w .j a va 2 s . c o m*/ MiscUtil.executePrivilegedAction(new PrivilegedAction<Void>() { @Override public Void run() { producer.close(); return null; }; }); } catch (Throwable t) { LOG.error("Error closing Kafka producer"); } } }
From source file:org.apache.servicemix.platform.testing.support.SmxPlatform.java
public void start() throws Exception { Set<String> jars = getJars(Felix.class); ClassLoader classLoader = new GuardClassLoader(toURLs(jars.toArray(new String[jars.size()])), null); BundleActivator activator = new BundleActivator() { private ServiceRegistration registration; public void start(BundleContext context) { registration = context.registerService(MainService.class.getName(), new MainService() { public String[] getArgs() { return new String[0]; }//from www. j a v a 2s . c o m public int getExitCode() { return 0; } public void setExitCode(int exitCode) { } }, null); } public void stop(BundleContext context) { registration.unregister(); } }; List<BundleActivator> activations = new ArrayList<BundleActivator>(); activations.add(activator); Properties props = getConfigurationProperties(); props.put(FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP, activations); Thread.currentThread().setContextClassLoader(classLoader); Class cl = classLoader.loadClass(Felix.class.getName()); Constructor cns = cl.getConstructor(Map.class); platform = cns.newInstance(props); platform.getClass().getMethod("start").invoke(platform); Bundle systemBundle = (Bundle) platform; // call getBundleContext final Method getContext = systemBundle.getClass().getMethod("getBundleContext", null); AccessController.doPrivileged(new PrivilegedAction() { public Object run() { getContext.setAccessible(true); return null; } }); context = (BundleContext) getContext.invoke(systemBundle, null); }
From source file:org.apache.hadoop.yarn.client.RMProxy.java
/** * Get a proxy to the RM at the specified address. To be used to create a * RetryProxy./*from ww w . j a v a 2 s . co m*/ */ @Private static <T> T getProxy(final Configuration conf, final Class<T> protocol, final InetSocketAddress rmAddress) throws IOException { return UserGroupInformation.getCurrentUser().doAs(new PrivilegedAction<T>() { @Override public T run() { return (T) YarnRPC.create(conf).getProxy(protocol, rmAddress, conf); } }); }
From source file:SecuritySupport.java
ClassLoader getParentClassLoader(final ClassLoader cl) { return (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() { public Object run() { ClassLoader parent = null; try { parent = cl.getParent(); } catch (SecurityException ex) { }//w w w . j av a 2 s .com // eliminate loops in case of the boot // ClassLoader returning itself as a parent return (parent == cl) ? null : parent; } }); }