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.elasticsearch.client.RestClientBuilder.java

/**
 * Creates a new {@link RestClient} based on the provided configuration.
 *///from w  w w .j av a  2s .c  o m
public RestClient build() {
    if (failureListener == null) {
        failureListener = new RestClient.FailureListener();
    }
    CloseableHttpAsyncClient httpClient = AccessController
            .doPrivileged(new PrivilegedAction<CloseableHttpAsyncClient>() {
                @Override
                public CloseableHttpAsyncClient run() {
                    return createHttpClient();
                }
            });
    RestClient restClient = new RestClient(httpClient, maxRetryTimeout, defaultHeaders, hosts, pathPrefix,
            failureListener);
    httpClient.start();
    return restClient;
}

From source file:SecuritySupport.java

long getLastModified(final File f) {
    return ((Long) AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {
            return new Long(f.lastModified());
        }//from w  w w  .  j  a  v a2  s .co m
    })).longValue();
}

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

@Override
public DiscoveryBossRemote getDiscoveryBoss() {
    return AccessController.doPrivileged(new PrivilegedAction<DiscoveryBossRemote>() {
        @Override/*w w  w. ja va2 s .c om*/
        public DiscoveryBossRemote run() {
            return getProxy(LookupUtil.getDiscoveryBoss(), DiscoveryBossRemote.class);
        }
    });
}

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

/**
 * Constructs a new sorted map from output stream provider names to provider
 * objects.//  w  w w  . ja  v a  2  s.  c o  m
 *
 * <p>
 * The map returned by this method will have one entry for each provider for
 * which support is available in the current Java virtual machine. If two or
 * more supported provider have the same name then the resulting map will
 * contain just one of them; which one it will contain is not specified.
 * </p>
 *
 * <p>
 * The invocation of this method, and the subsequent use of the resulting
 * map, may cause time-consuming disk or network I/O operations to occur.
 * This method is provided for applications that need to enumerate all of
 * the available providers, for example to allow user provider selection.
 * </p>
 *
 * <p>
 * This method may return different results at different times if new
 * providers are dynamically made available to the current Java virtual
 * machine.
 * </p>
 *
 * @return An immutable, map from names to provider objects
 * @since 1.13
 */
public static SortedMap<String, ArchiveStreamProvider> findAvailableArchiveOutputStreamProviders() {
    return AccessController.doPrivileged(new PrivilegedAction<SortedMap<String, ArchiveStreamProvider>>() {
        @Override
        public SortedMap<String, ArchiveStreamProvider> run() {
            TreeMap<String, ArchiveStreamProvider> map = new TreeMap<>();
            putAll(SINGLETON.getOutputStreamArchiveNames(), SINGLETON, map);
            for (ArchiveStreamProvider provider : findArchiveStreamProviders()) {
                putAll(provider.getOutputStreamArchiveNames(), provider, map);
            }
            return map;
        }
    });
}

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

public List<String> getColumnList(String database, String tableName, String columnNameMatching) {
    final String db = database;
    final String tblName = tableName;
    final String clmNameMatching = columnNameMatching;
    List<String> columnList = Subject.doAs(getLoginSubject(), new PrivilegedAction<List<String>>() {
        public List<String> run() {
            return getClmList(db, tblName, clmNameMatching);
        }//ww w.  j  ava 2  s .c o m
    });
    return columnList;
}

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

protected static ThreadContextDescriptor setThreadContext(final AxisService service) {
    ThreadContextDescriptor tc = new ThreadContextDescriptor();
    tc.oldMessageContext = (MessageContext) MessageContext.currentMessageContext.get();
    final ClassLoader contextClassLoader = getContextClassLoader_doPriv();
    tc.oldClassLoader = contextClassLoader;

    String serviceTCCL = (String) service.getParameterValue(Constants.SERVICE_TCCL);
    if (serviceTCCL != null) {
        serviceTCCL = serviceTCCL.trim().toLowerCase();
        //TODO//from  www  .  j a v  a  2 s  . c  o  m
        serviceTCCL = Constants.TCCL_COMPOSITE;
        //TODO

        if (serviceTCCL.equals(Constants.TCCL_COMPOSITE)) {
            final ClassLoader loader = (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() {
                public Object run() {
                    return new MultiParentClassLoader(new URL[] {},
                            new ClassLoader[] { service.getClassLoader(), contextClassLoader });
                }
            });
            org.apache.axis2.java.security.AccessController.doPrivileged(new PrivilegedAction() {
                public Object run() {
                    Thread.currentThread().setContextClassLoader(loader);
                    return null;
                }
            });
        } else if (serviceTCCL.equals(Constants.TCCL_SERVICE)) {
            org.apache.axis2.java.security.AccessController.doPrivileged(new PrivilegedAction() {
                public Object run() {
                    Thread.currentThread().setContextClassLoader(service.getClassLoader());
                    return null;
                }
            });
        }
    }
    return tc;
}

From source file:org.apache.axiom.attachments.AttachmentCacheMonitor.java

private boolean deleteFile(final String fileName) {
    Boolean privRet = (Boolean) AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {
            return _deleteFile(fileName);
        }//  w  w w . ja va2s. c o m
    });
    return privRet.booleanValue();
}

From source file:org.javascool.polyfilewriter.Gateway.java

/**
 * List files into a directory./*  w ww  .  j av a2  s  .  c o  m*/
 *
 * @param location The directory to list
 * @return A string with a structure as this
 *         [
 *         {"name":"toto.java","isFile":true,"isHidden":false,"path":"/home/user/toto.java"},
 *         ]
 */
public String listDirectory(final String location) throws Exception {
    assertSafeUsage();
    try {
        final File[] list = AccessController.doPrivileged(new PrivilegedAction<File[]>() {
            public File[] run() {
                return new File(location).listFiles();
            }
        });
        final JSONArray files = new JSONArray();
        for (int i = 0; i < list.length; i++) {
            final int c = i;
            files.add(AccessController.doPrivileged(new PrivilegedAction<JSONObject>() {
                public JSONObject run() {
                    JSONObject obj = new JSONObject();
                    obj.put("name", list[c].getName());
                    obj.put("path", list[c].getAbsolutePath());
                    obj.put("isHidden", list[c].isHidden());
                    obj.put("isFile", list[c].isFile());
                    return obj;
                }
            }));
        }
        return files.toJSONString();
    } catch (Exception e) {
        popException(e);
        throw e;
    }
}

From source file:org.apache.hama.bsp.BSPApplicationMaster.java

/**
 * Connects to the Resource Manager./*from  w ww  .  ja  va2  s .c om*/
 * 
 * @param yarnConf
 * @return a new RPC connection to the Resource Manager.
 */
private ApplicationMasterProtocol getYarnRPCConnection(Configuration yarnConf) throws IOException {
    // Connect to the Scheduler of the ResourceManager.
    UserGroupInformation currentUser = UserGroupInformation.createRemoteUser(appAttemptId.toString());
    Credentials credentials = UserGroupInformation.getCurrentUser().getCredentials();

    final InetSocketAddress rmAddress = NetUtils.createSocketAddr(yarnConf
            .get(YarnConfiguration.RM_SCHEDULER_ADDRESS, YarnConfiguration.DEFAULT_RM_SCHEDULER_ADDRESS));

    Token<? extends TokenIdentifier> amRMToken = setupAndReturnAMRMToken(rmAddress, credentials.getAllTokens());
    currentUser.addToken(amRMToken);

    final Configuration conf = yarnConf;

    ApplicationMasterProtocol client = currentUser.doAs(new PrivilegedAction<ApplicationMasterProtocol>() {
        @Override
        public ApplicationMasterProtocol run() {
            return (ApplicationMasterProtocol) yarnRPC.getProxy(ApplicationMasterProtocol.class, rmAddress,
                    conf);
        }
    });
    LOG.info("Connecting to ResourceManager at " + rmAddress);
    return client;
}

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

@Override
public DriftManagerRemote getDriftManager() {
    return AccessController.doPrivileged(new PrivilegedAction<DriftManagerRemote>() {
        @Override/*from   w w  w  . ja  v  a 2 s  .com*/
        public DriftManagerRemote run() {
            return getProxy(LookupUtil.getDriftManager(), DriftManagerRemote.class);
        }
    });
}