Example usage for java.security PrivilegedAction PrivilegedAction

List of usage examples for java.security PrivilegedAction PrivilegedAction

Introduction

In this page you can find the example usage for java.security PrivilegedAction PrivilegedAction.

Prototype

PrivilegedAction

Source Link

Usage

From source file:org.rhq.enterprise.client.LocalClient.java

public DriftTemplateManagerRemote getDriftTemplateManager() {
    return AccessController.doPrivileged(new PrivilegedAction<DriftTemplateManagerRemote>() {
        @Override/*from  www . j  a v a 2 s  .  co  m*/
        public DriftTemplateManagerRemote run() {
            return getProxy(LookupUtil.getDriftTemplateManager(), DriftTemplateManagerRemote.class);
        }
    });
}

From source file:org.apache.struts2.jasper.runtime.PageContextImpl.java

public void setAttribute(final String name, final Object attribute) {

    if (name == null) {
        throw new NullPointerException(Localizer.getMessage("jsp.error.attribute.null_name"));
    }//from   w  w w . j  a v a  2s.  c  o  m

    if (SecurityUtil.isPackageProtectionEnabled()) {
        AccessController.doPrivileged(new PrivilegedAction() {
            public Object run() {
                doSetAttribute(name, attribute);
                return null;
            }
        });
    } else {
        doSetAttribute(name, attribute);
    }
}

From source file:org.apache.axis2.jaxws.description.builder.converter.JavaClassToDBCConverter.java

/**
 * This method is responsible for finding any interfaces implemented by the service class. We will
 * then set these as a list of fully qualified class names on the <code>DescriptionBuilderComposite</code>
 *
 * @param composite <code>DescriptionBuilderComposite</code>
 *//* w  ww.j  a  v  a 2 s.  co m*/
private void setInterfaces(DescriptionBuilderComposite composite) {
    Type[] interfaces = (Type[]) AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {
            return serviceClass.getGenericInterfaces();
        }
    });
    List<String> interfaceList = interfaces.length > 0 ? new ArrayList<String>() : null;
    for (int i = 0; i < interfaces.length; i++) {
        interfaceList.add(getNameFromType(interfaces[i]));
    }
    // We only want to set this list if we found interfaces b/c the
    // DBC news up an interface list as part of its static initialization.
    // Thus, if we set this list to null we may cause an NPE
    if (interfaceList != null) {
        composite.setInterfacesList(interfaceList);
    }
}

From source file:org.apache.axis2.jaxws.server.endpoint.injection.impl.WebServiceContextInjectorImpl.java

/**
 * Gets all of the fields in this class and the super classes
 *
 * @param beanClass/* w  ww. j  a v a 2 s .com*/
 * @return
 */
static private List<Field> getFields(final Class beanClass) {
    // This class must remain private due to Java 2 Security concerns
    List<Field> fields;
    fields = (List<Field>) AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {
            List<Field> fields = new ArrayList<Field>();
            Class cls = beanClass;
            while (cls != null) {
                Field[] fieldArray = cls.getDeclaredFields();
                for (Field field : fieldArray) {
                    fields.add(field);
                }
                cls = cls.getSuperclass();
            }
            return fields;
        }
    });

    return fields;
}

From source file:org.rhq.enterprise.client.LocalClient.java

@Override
public EventManagerRemote getEventManager() {
    return AccessController.doPrivileged(new PrivilegedAction<EventManagerRemote>() {
        @Override//from ww  w .j av a 2s  . c om
        public EventManagerRemote run() {
            return getProxy(LookupUtil.getEventManager(), EventManagerRemote.class);
        }
    });
}

From source file:org.springframework.security.kerberos.client.KerberosRestTemplate.java

@Override
protected final <T> T doExecute(final URI url, final HttpMethod method, final RequestCallback requestCallback,
        final ResponseExtractor<T> responseExtractor) throws RestClientException {

    try {/*  w  w  w  .  j  a  v  a2  s .c  om*/
        LoginContext lc = buildLoginContext();
        lc.login();
        Subject serviceSubject = lc.getSubject();
        return Subject.doAs(serviceSubject, new PrivilegedAction<T>() {

            @Override
            public T run() {
                return KerberosRestTemplate.this.doExecuteSubject(url, method, requestCallback,
                        responseExtractor);
            }
        });

    } catch (Exception e) {
        throw new RestClientException("Error running rest call", e);
    }
}

From source file:org.apache.tika.parser.pkg.TikaCompressorStreamFactory.java

public static SortedMap<String, CompressorStreamProvider> findAvailableCompressorInputStreamProviders() {
    return AccessController.doPrivileged(new PrivilegedAction<SortedMap<String, CompressorStreamProvider>>() {
        @Override/*from www  . j a  v a 2  s  . com*/
        public SortedMap<String, CompressorStreamProvider> run() {
            final TreeMap<String, CompressorStreamProvider> map = new TreeMap<>();
            putAll(SINGLETON.getInputStreamCompressorNames(), SINGLETON, map);
            for (final CompressorStreamProvider provider : findCompressorStreamProviders()) {
                putAll(provider.getInputStreamCompressorNames(), provider, map);
            }
            return map;
        }
    });
}

From source file:org.apache.axis2.engine.DependencyManager.java

private static ClassLoader getContextClassLoader_doPriv() {
    return (ClassLoader) org.apache.axis2.java.security.AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {
            return Thread.currentThread().getContextClassLoader();
        }//from ww w  .  ja  v  a  2  s  .  co m
    });
}

From source file:org.apache.hadoop.filecache.TaskDistributedCacheManager.java

/**
 * Creates a class loader that includes the designated
 * files and archives./*from w ww  .  jav a  2s  .c o  m*/
 */
public ClassLoader makeClassLoader(final ClassLoader parent) throws MalformedURLException {
    final URL[] urls = new URL[classPaths.size()];
    for (int i = 0; i < classPaths.size(); ++i) {
        urls[i] = new File(classPaths.get(i)).toURI().toURL();
    }
    return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
        @Override
        public ClassLoader run() {
            return new URLClassLoader(urls, parent);
        }
    });
}