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.exoplatform.container.spring.SpringContainer.java

private <T> T getInstanceOfType(final Class<T> componentType) {
    T result;//from w  w  w  .  jav  a 2s  .co m
    PrivilegedAction<T> action = new PrivilegedAction<T>() {
        public T run() {
            String name = classToBeanName(componentType);
            if (ctx.containsBean(name) && componentType.isAssignableFrom(ctx.getType(name))) {
                return componentType.cast(ctx.getBean(name));
            }
            String[] names = ctx.getBeanNamesForType(componentType);
            if (names != null && names.length > 0) {
                return componentType.cast(ctx.getBean(names[0]));
            }
            return null;
        }
    };
    result = SecurityHelper.doPrivilegedAction(action);
    return result;
}

From source file:org.apache.axis2.jaxws.lifecycle.BaseLifecycleManager.java

protected Method getPreDestroyMethod() {
    // REVIEW: This method should not be called in performant situations.
    // Plus the super class methods are not being considered 
    //return Method with @PreDestroy Annotation
    if (instance != null) {
        final Class endpointClazz = instance.getClass();
        Method[] methods = (Method[]) AccessController.doPrivileged(new PrivilegedAction() {
            public Object run() {
                return endpointClazz.getMethods();
            }//w  w  w  . j av  a  2 s .c o m
        });

        for (Method method : methods) {
            if (isPreDestroy(method)) {
                return method;
            }
        }
    }
    return null;
}

From source file:org.apache.ranger.hive.client.HiveClient.java

public List<String> getTableList(String database, String tableNameMatching) {
    final String db = database;
    final String tblNameMatching = tableNameMatching;
    List<String> tableList = Subject.doAs(getLoginSubject(), new PrivilegedAction<List<String>>() {
        public List<String> run() {
            return getTblList(db, tblNameMatching);
        }/*  w  w w  . j av  a 2 s . c o m*/
    });
    return tableList;
}

From source file:org.beangle.model.persist.hibernate.internal.ChainedClassLoader.java

/**
 * Adds a class loader defining the given class, to the chained class loader
 * space.//from  w  w  w . j av  a2  s .co  m
 * 
 * @param clazz
 */
public void addClassLoader(final Class<?> clazz) {
    Validate.notNull(clazz, "a non-null class required");
    if (System.getSecurityManager() != null) {
        addClassLoader(AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
            public ClassLoader run() {
                return ClassUtils.getClassLoader(clazz);
            }
        }));
    } else {
        addClassLoader(ClassUtils.getClassLoader(clazz));
    }
}

From source file:org.apache.axis2.deployment.util.Utils.java

public static boolean loadHandler(ClassLoader loader1, HandlerDescription desc) throws DeploymentException {
    String handlername = desc.getClassName();
    Handler handler;/*from   ww w.  j a v a 2s. c om*/
    try {
        final Class handlerClass = Loader.loadClass(loader1, handlername);
        Package aPackage = (Package) org.apache.axis2.java.security.AccessController
                .doPrivileged(new PrivilegedAction() {
                    public Object run() {
                        return handlerClass.getPackage();
                    }
                });
        if (aPackage != null && aPackage.getName().equals("org.apache.axis2.engine")) {
            String name = handlerClass.getName();
            log.warn("Dispatcher " + name + " is now deprecated.");
            if (name.indexOf("InstanceDispatcher") != -1) {
                log.warn("Please remove the entry for " + handlerClass.getName() + "from axis2.xml");
            } else {
                log.warn(
                        "Please edit axis2.xml and replace with the same class in org.apache.axis2.dispatchers package");
            }
        }
        handler = (Handler) org.apache.axis2.java.security.AccessController
                .doPrivileged(new PrivilegedExceptionAction() {
                    public Object run() throws InstantiationException, IllegalAccessException {
                        return handlerClass.newInstance();
                    }
                });
        handler.init(desc);
        desc.setHandler(handler);
    } catch (ClassNotFoundException e) {
        if (handlername.indexOf("jaxws") > 0) {
            log.warn("[JAXWS] - unable to load " + handlername);
            return false;
        }
        throw new DeploymentException(e);
    } catch (Exception e) {
        throw new DeploymentException(e);
    }
    return true;
}

From source file:com.reelfx.controller.WindowsController.java

public void startRecording(AudioRecorder selectedAudio) {
    audioSource = selectedAudio;/* ww  w.j  a  v  a  2 s . c  o  m*/
    listener = this;

    recordingDone = false;

    AccessController.doPrivileged(new PrivilegedAction<Object>() {

        @Override
        public Object run() {

            deleteOutput();
            AudioRecorder.deleteOutput();
            stopped = false;
            if (audioSource != null) {
                mic = audioSource;
                mic.addProcessListener(listener);
                mic.startRecording();

                /*
                Mixer systemMixer = null;
                for(Mixer.Info info : AudioSystem.getMixerInfo())
                   // select the "stereo mix" on Windows
                    if(!info.getName().toLowerCase().contains("port")
                   && info.getName().toLowerCase().contains("stereo mix")
                   && AudioSystem.getMixer(info).getTargetLineInfo().length != 0)
                systemMixer = AudioSystem.getMixer(info);
                        
                if(systemMixer != null) {
                   systemAudio = new AudioRecorder(systemMixer);
                   //systemAudio.addProcessListener(listener);
                   systemAudio.startRecording();
                }
                */
            } else {
                logger.info("No audio source specified.");
                mic = null;
                systemAudio = null;
            }
            // start up ffmpeg
            screen.start();

            return null;
        }
    });
}

From source file:jenkins.scm.api.SCMHeadMixinEqualityGenerator.java

/**
 * Get the {@link SCMHeadMixin.Equality} instance to use.
 *
 * @param type the {@link SCMHead} type.
 * @return the {@link SCMHeadMixin.Equality} instance.
 *///from w  w  w .  java 2s  .  c  om
@NonNull
static SCMHeadMixin.Equality getOrCreate(@NonNull Class<? extends SCMHead> type) {
    lock.readLock().lock();
    try {
        SCMHeadMixin.Equality result = mixinEqualities.get(type);
        if (result != null) {
            return result;
        }
    } finally {
        lock.readLock().unlock();
    }
    lock.writeLock().lock();
    try {
        SCMHeadMixin.Equality result = mixinEqualities.get(type);
        if (result != null) {
            // somebody else created it while we were waiting for the write lock
            return result;
        }
        final ClassLoader loader = type.getClassLoader();
        SCMHeadMixinEqualityGenerator generator;
        generator = generators.get(loader);
        if (generator == null) {
            generator = AccessController.doPrivileged(new PrivilegedAction<SCMHeadMixinEqualityGenerator>() {
                @Override
                public SCMHeadMixinEqualityGenerator run() {
                    return new SCMHeadMixinEqualityGenerator(loader);
                }
            });
            generators.put(loader, generator);
        }
        result = generator.create(type);
        mixinEqualities.put(type, result);
        return result;
    } finally {
        lock.writeLock().unlock();
    }
}

From source file:org.apache.ranger.hadoop.client.HadoopFS.java

public List<String> listFiles(final String baseDir, final String fileMatching) {

    PrivilegedAction<List<String>> action = new PrivilegedAction<List<String>>() {
        @Override//from   w w  w .  ja  v  a 2  s .  c  o m
        public List<String> run() {
            return listFilesInternal(baseDir, fileMatching);
        }

    };
    return Subject.doAs(getLoginSubject(), action);
}

From source file:org.apache.river.container.classloading.VirtualFileSystemClassLoader.java

@Override
public Enumeration<URL> findResources(final String name) throws IOException {

    Enumeration result = (Enumeration) Security.doPrivileged(new PrivilegedAction<Enumeration>() {

        public Enumeration run() {
            List<URL> urlList = new ArrayList<URL>();
            try {

                List<FileObject> foList = findResourceFileObjects(name);
                for (FileObject fo : foList) {
                    urlList.add(fo.getURL());
                }//  w  w  w.jav  a  2s .  co m
            } catch (FileSystemException ex) {
                Logger.getLogger(VirtualFileSystemClassLoader.class.getName()).log(Level.SEVERE, null, ex);
            }
            return Collections.enumeration(urlList);
        }
    });
    return result;
}

From source file:tools.xor.util.ClassUtil.java

/** 
 * Invoke the given method as a privileged action, if necessary. 
 * @param target the object on which the method needs to be invoked
 * @param field we are reading or writing
 * @param value to set in the field/*w  w w.  j  a  v  a2  s  . c om*/
 * @param read true if this a read operation
 * @return result of the invocation
 * @throws InvocationTargetException while invoking the method
 * @throws IllegalAccessException when accessing the meta data
 */
public static Object invokeFieldAsPrivileged(final Object target, final Field field, final Object value,
        final boolean read) throws InvocationTargetException, IllegalAccessException {

    if (Modifier.isPublic(field.getModifiers())) {
        Object readValue = null;
        if (read)
            readValue = field.get(target);
        else
            field.set(target, value);
        return readValue;
    } else {
        return AccessController.doPrivileged(new PrivilegedAction<Object>() {
            public Object run() {
                field.setAccessible(true);
                Object readValue = null;
                try {
                    if (read)
                        readValue = field.get(target);
                    else
                        field.set(target, value);
                } catch (Exception e) {
                    throw wrapRun(e);
                }
                return readValue;
            }
        });
    }
}