List of usage examples for java.security AccessController doPrivileged
@CallerSensitive public static <T> T doPrivileged(PrivilegedExceptionAction<T> action) throws PrivilegedActionException
From source file:com.scoredev.scores.HighScore.java
public HighScore(String gameName) { this.gameName = gameName; AccessController.doPrivileged(new PrivilegedAction() { public Object run() { String path = System.getProperty("user.home") + File.separator + ".highscore"; highScoreFile = new File(path); return null; }//from www . j a v a 2 s.c o m }); }
From source file:com.amazonaws.http.conn.ssl.privileged.PrivilegedMasterSecretValidator.java
/** * Double check the master secret of an SSL session is not null * /* w w w . j a va 2s . co m*/ * @param socket * connected socket * @return True if master secret is valid (i.e. non-null) or master secret cannot be validated, * false otherwise */ public boolean isMasterSecretValid(final Socket socket) { return AccessController.doPrivileged(new PrivilegedAction<Boolean>() { @Override public Boolean run() { return privilegedIsMasterSecretValid(socket); } }); }
From source file:org.eclipse.gemini.blueprint.config.internal.adapter.CustomListenerAdapterUtils.java
/** * Specialised reflection utility that determines all methods that accept two parameters such: * //from ww w .j av a 2s.c o m * <pre> methodName(Type serviceType, Type1 arg) * * methodName(Type serviceType, Type2 arg) * * methodName(AnotherType serviceType, Type1 arg) * * methodName(Type serviceType) </pre> * * It will return a map which has the serviceType (first argument) as type and contains as list the variants of * methods using the second argument. This method is normally used by listeners when determining custom methods. * * @param target * @param methodName * @param possibleArgumentTypes * @param modifier * @return */ static Map<Class<?>, List<Method>> determineCustomMethods(final Class<?> target, final String methodName, final Class<?>[] possibleArgumentTypes, final boolean onlyPublic) { if (!StringUtils.hasText(methodName)) { return Collections.emptyMap(); } Assert.notEmpty(possibleArgumentTypes); if (System.getSecurityManager() != null) { return AccessController.doPrivileged(new PrivilegedAction<Map<Class<?>, List<Method>>>() { public Map<Class<?>, List<Method>> run() { return doDetermineCustomMethods(target, methodName, possibleArgumentTypes, onlyPublic); } }); } else { return doDetermineCustomMethods(target, methodName, possibleArgumentTypes, onlyPublic); } }
From source file:org.elasticsearch.hadoop.util.ecs.HostData.java
private static String getPropOrNull(String prop) { try {/* w w w.ja v a 2s.c o m*/ // TODO: Should these privileged blocks be moved further up the call stack? return AccessController.doPrivileged(new GetPropAction(prop)); } catch (SecurityException se) { return null; } }
From source file:org.commoncrawl.util.shared.MMapUtils.java
/** * Try to unmap the buffer, this method silently fails if no support * for that in the JVM. On Windows, this leads to the fact, * that mmapped files cannot be modified or deleted. *//*from www . j a va 2 s.c om*/ final static void cleanMapping(final ByteBuffer buffer) throws IOException { if (getUseUnmap()) { try { AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() { public Object run() throws Exception { final Method getCleanerMethod = buffer.getClass().getMethod("cleaner"); getCleanerMethod.setAccessible(true); final Object cleaner = getCleanerMethod.invoke(buffer); if (cleaner != null) { cleaner.getClass().getMethod("clean").invoke(cleaner); } return null; } }); } catch (PrivilegedActionException e) { final IOException ioe = new IOException("unable to unmap the mapped buffer"); ioe.initCause(e.getCause()); throw ioe; } } }
From source file:com.ibm.xsp.extlib.relational.jdbc.datasource.dbcp.DbcpResourceFactory.java
/** * /*from ww w . j a v a2 s.c o m*/ */ public DbcpResourceFactory(final String dataSourceName, final String driverClass, final String url, final String userName, final String password, final int maxActive, final int maxIdle) throws PoolException { try { connectionPoolDataSource = AccessController .doPrivileged(new PrivilegedExceptionAction<ConnectionPoolDataSource>() { public ConnectionPoolDataSource run() throws Exception { //Using the generic connection pool adapter from DBCP, todo, look how to use the connection pool datasource provided by each driver DriverAdapterCPDS adapter = new DriverAdapterCPDS(); adapter.setMaxActive(maxActive); adapter.setMaxIdle(maxIdle); adapter.setUrl(url); adapter.setUser(userName); adapter.setPassword(password); adapter.setDriver(driverClass); SharedPoolDataSource tds = new SharedPoolDataSource(); tds.setConnectionPoolDataSource(adapter); tds.setMaxActive(maxActive); ds = tds; return adapter; } }); } catch (Exception e) { // "Unable to initialize the shared connection pool DataSource" String msg = com.ibm.xsp.extlib.relational.RelationalResourceHandler .getSpecialAudienceString("DbcpPoolDataSource.Unabletoinitializethesharedconnec");//$NON-NLS-1$ throw new PoolException(e, msg); } }
From source file:SecuritySupport.java
static FileInputStream getFileInputStream(final File file) throws FileNotFoundException { try {//from w ww . j a va2s. c o m return (FileInputStream) AccessController.doPrivileged(new PrivilegedExceptionAction() { public Object run() throws FileNotFoundException { return new FileInputStream(file); } }); } catch (PrivilegedActionException e) { throw (FileNotFoundException) e.getException(); } }
From source file:edu.ku.brc.af.core.SchemaI18NService.java
/** * Returns the instance of the AppContextMgr. * @return the instance of the AppContextMgr. *///from ww w. j ava2s. c o m public static SchemaI18NService getInstance() { if (instance != null) { return instance; } // else String factoryNameStr = AccessController.doPrivileged(new PrivilegedAction<String>() { public String run() { return System.getProperty(factoryName); } }); if (factoryNameStr != null) { try { instance = (SchemaI18NService) Class.forName(factoryNameStr).newInstance(); return instance; } catch (Exception e) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(SchemaI18NService.class, e); InternalError error = new InternalError( "Can't instantiate SchemaI18NService factory " + factoryNameStr); //$NON-NLS-1$ error.initCause(e); throw error; } } throw new RuntimeException("The System porpoerty [" + factoryName + "] has not been set up!"); //$NON-NLS-1$ //$NON-NLS-2$ }
From source file:org.apache.xml.security.Init.java
/** * Method init/*from w w w . j a v a 2 s .c o m*/ * */ public synchronized static void init() { if (alreadyInitialized) { return; } InputStream is = AccessController.doPrivileged(new PrivilegedAction<InputStream>() { public InputStream run() { String cfile = System.getProperty("org.apache.xml.security.resource.config"); if (cfile == null) { return null; } return getClass().getResourceAsStream(cfile); } }); if (is == null) { dynamicInit(); } else { fileInit(is); } alreadyInitialized = true; }
From source file:com.ibm.xsp.extlib.relational.jdbc.datasource.dbcp.DbcpPoolDataSource.java
/** * //from w w w.java2 s .c om */ public DbcpPoolDataSource(final String dataSourceName, final String driverClass, final String url, final String username, final String password, final int minIdle, final int maxIdle, final int maxActive, final long maxWait) throws PoolException { try { ds = AccessController.doPrivileged(new PrivilegedExceptionAction<DataSource>() { public DataSource run() throws Exception { // create a driver connection factory driver = JDBCDriverLoader.loadDriver(driverClass); Properties properties = new Properties(); properties.setProperty("user", username); // $NON-NLS-1$ properties.setProperty("password", (StringUtil.isEmpty(password) ? "" : password)); // $NON-NLS-1$ ConnectionFactory connectionFactory = new DriverConnectionFactory(driver, url, properties); // create the pool pool = new GenericObjectPool(); pool.setMaxActive(maxActive); pool.setMaxWait(maxWait); pool.setMaxIdle(maxIdle); pool.setMinIdle(minIdle); // create the pool object factory PoolableConnectionFactory factory = new PoolableConnectionFactory(connectionFactory, pool, null, null, false, true); pool.setFactory(factory); // finally create the datasource PoolingDataSource bds = new PoolingDataSource(pool); return bds; } }); } catch (Exception e) { String msg = "Unable to initialize the shared connection pool DataSource"; // $NLX-DbcpPoolDataSource.Unabletoinitializethesharedconnec-1$[["connection pool" is a technical term related to databases]] // Note, this resource key is used elsewhere in this plugin // "Unable to initialize the shared connection pool DataSource" //String msg = com.ibm.xsp.extlib.relational.ResourceHandler.getSpecialAudienceString("DbcpPoolDataSource.Unabletoinitializethesharedconnec");//$NON-NLS-1$ throw new PoolException(e, msg); } }