本文整理汇总了Java中java.security.AccessController类的典型用法代码示例。如果您正苦于以下问题:Java AccessController类的具体用法?Java AccessController怎么用?Java AccessController使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AccessController类属于java.security包,在下文中一共展示了AccessController类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setProperty
import java.security.AccessController; //导入依赖的package包/类
/**
* Set property to given value.
* <p>
* Specifying a null value will cause the property to be cleared
*
* @param name
* @param value
* @return previous value
*/
private static String setProperty(final String name, final String value) {
final PrivilegedAction<String> action;
if (value != null)
action = new PrivilegedAction<String>() {
@Override
public String run() {
return System.setProperty(name, value);
}
};
else
action = new PrivilegedAction<String>() {
@Override
public String run() {
return System.clearProperty(name);
}
};
return AccessController.doPrivileged(action);
}
示例2: clearStore
import java.security.AccessController; //导入依赖的package包/类
/**
* Clear all sessions from the Store.
*/
public void clearStore() {
if (store == null)
return;
try {
if (SecurityUtil.isPackageProtectionEnabled()){
try{
AccessController.doPrivileged(new PrivilegedStoreClear());
}catch(PrivilegedActionException ex){
Exception exception = ex.getException();
log.error("Exception clearing the Store: " + exception,
exception);
}
} else {
store.clear();
}
} catch (IOException e) {
log.error("Exception clearing the Store: " + e, e);
}
}
示例3: executeMethod
import java.security.AccessController; //导入依赖的package包/类
/**
* Executes the method of the specified <code>ApplicationContext</code>
* @param method The method object to be invoked.
* @param context The AppliationContext object on which the method
* will be invoked
* @param params The arguments passed to the called method.
*/
private Object executeMethod(final Method method,
final ApplicationContext context,
final Object[] params)
throws PrivilegedActionException,
IllegalAccessException,
InvocationTargetException {
if (SecurityUtil.isPackageProtectionEnabled()){
return AccessController.doPrivileged(new PrivilegedExceptionAction<Object>(){
@Override
public Object run() throws IllegalAccessException, InvocationTargetException{
return method.invoke(context, params);
}
});
} else {
return method.invoke(context, params);
}
}
示例4: checkVerboseLogSetting
import java.security.AccessController; //导入依赖的package包/类
/**
* Check if the system property org.newdawn.slick.verboseLog is set to true.
* If this is the case we activate the verbose logging mode
*/
public static void checkVerboseLogSetting() {
try {
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
String val = System.getProperty(Log.forceVerboseProperty);
if ((val != null) && (val.equalsIgnoreCase(Log.forceVerbosePropertyOnValue))) {
Log.setForcedVerboseOn();
}
return null;
}
});
} catch (Throwable e) {
// ignore, security failure - probably an applet
}
}
示例5: lookupViaProviders
import java.security.AccessController; //导入依赖的package包/类
private static URLStreamHandler lookupViaProviders(final String protocol) {
if (gate.get() != null)
throw new Error("Circular loading of URL stream handler providers detected");
gate.set(gate);
try {
return AccessController.doPrivileged(
new PrivilegedAction<>() {
public URLStreamHandler run() {
Iterator<URLStreamHandlerProvider> itr = providers();
while (itr.hasNext()) {
URLStreamHandlerProvider f = itr.next();
URLStreamHandler h = f.createURLStreamHandler(protocol);
if (h != null)
return h;
}
return null;
}
});
} finally {
gate.set(null);
}
}
示例6: initializeInputMethodSelectionKey
import java.security.AccessController; //导入依赖的package包/类
/**
* Initializes the input method selection key definition in preference trees
*/
private void initializeInputMethodSelectionKey() {
AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
// Look in user's tree
Preferences root = Preferences.userRoot();
inputMethodSelectionKey = getInputMethodSelectionKeyStroke(root);
if (inputMethodSelectionKey == null) {
// Look in system's tree
root = Preferences.systemRoot();
inputMethodSelectionKey = getInputMethodSelectionKeyStroke(root);
}
return null;
}
});
}
示例7: getAttribute
import java.security.AccessController; //导入依赖的package包/类
@Override
public Object getAttribute(final String name, final int scope) {
if (name == null) {
throw new NullPointerException(Localizer.getMessage("jsp.error.attribute.null_name"));
}
if (SecurityUtil.isPackageProtectionEnabled()) {
return AccessController.doPrivileged(new PrivilegedAction<Object>() {
@Override
public Object run() {
return doGetAttribute(name, scope);
}
});
} else {
return doGetAttribute(name, scope);
}
}
示例8: getDeclaredMethod
import java.security.AccessController; //导入依赖的package包/类
private static Method getDeclaredMethod(final Class cl, final String methodName, final Class[] args,
final int requiredModifierMask,
final int disallowedModifierMask) {
return (Method) AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
Method method = null;
try {
method =
cl.getDeclaredMethod(methodName, args);
int mods = method.getModifiers();
if ((mods & disallowedModifierMask) != 0 ||
(mods & requiredModifierMask) != requiredModifierMask) {
method = null;
}
//if (!Modifier.isPrivate(mods) ||
// Modifier.isStatic(mods)) {
// method = null;
//}
} catch (NoSuchMethodException e) {
// Since it is alright if methodName does not exist,
// no need to do anything special here.
}
return method;
}
});
}
示例9: handle
import java.security.AccessController; //导入依赖的package包/类
public void handle(final Callback[] callbacks)
throws java.io.IOException, UnsupportedCallbackException {
try {
java.security.AccessController.doPrivileged
(new java.security.PrivilegedExceptionAction<Void>() {
public Void run() throws java.io.IOException,
UnsupportedCallbackException {
ch.handle(callbacks);
return null;
}
}, acc);
} catch (java.security.PrivilegedActionException pae) {
if (pae.getException() instanceof java.io.IOException) {
throw (java.io.IOException)pae.getException();
} else {
throw (UnsupportedCallbackException)pae.getException();
}
}
}
示例10: getClassLoaderInfo
import java.security.AccessController; //导入依赖的package包/类
/**
* Retrieve the configuration associated with the specified classloader. If
* it does not exist, it will be created.
*
* @param classLoader The classloader for which we will retrieve or build the
* configuration
*/
protected synchronized ClassLoaderLogInfo getClassLoaderInfo(ClassLoader classLoader) {
if (classLoader == null) {
classLoader = ClassLoader.getSystemClassLoader();
}
ClassLoaderLogInfo info = classLoaderLoggers.get(classLoader);
if (info == null) {
final ClassLoader classLoaderParam = classLoader;
AccessController.doPrivileged(new PrivilegedAction<Void>() {
@Override
public Void run() {
try {
readConfiguration(classLoaderParam);
} catch (IOException e) {
// Ignore
}
return null;
}
});
info = classLoaderLoggers.get(classLoader);
}
return info;
}
示例11: registerCleaner
import java.security.AccessController; //导入依赖的package包/类
private static synchronized void registerCleaner(PoolCleaner cleaner) {
unregisterCleaner(cleaner);
cleaners.add(cleaner);
if (poolCleanTimer == null) {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(ConnectionPool.class.getClassLoader());
// Create the timer thread in a PrivilegedAction so that a
// reference to the web application class loader is not created
// via Thread.inheritedAccessControlContext
PrivilegedAction<Timer> pa = new PrivilegedNewTimer();
poolCleanTimer = AccessController.doPrivileged(pa);
} finally {
Thread.currentThread().setContextClassLoader(loader);
}
}
poolCleanTimer.schedule(cleaner, cleaner.sleepTime,cleaner.sleepTime);
}
示例12: initMainAppContext
import java.security.AccessController; //导入依赖的package包/类
private final static void initMainAppContext() {
// On the main Thread, we get the ThreadGroup, make a corresponding
// AppContext, and instantiate the Java EventQueue. This way, legacy
// code is unaffected by the move to multiple AppContext ability.
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
ThreadGroup currentThreadGroup =
Thread.currentThread().getThreadGroup();
ThreadGroup parentThreadGroup = currentThreadGroup.getParent();
while (parentThreadGroup != null) {
// Find the root ThreadGroup to construct our main AppContext
currentThreadGroup = parentThreadGroup;
parentThreadGroup = currentThreadGroup.getParent();
}
mainAppContext = SunToolkit.createNewAppContext(currentThreadGroup);
return null;
}
});
}
示例13: registerTarget
import java.security.AccessController; //导入依赖的package包/类
/**
* Registers a target for a tie. Adds the tie to an internal table and calls
* {@link Tie#setTarget} on the tie object.
* @param tie the tie to register.
* @param target the target for the tie.
*/
public void registerTarget(javax.rmi.CORBA.Tie tie, java.rmi.Remote target)
{
synchronized (exportedServants) {
// Do we already have this target registered?
if (lookupTie(target) == null) {
// No, so register it and set the target...
exportedServants.put(target,tie);
tie.setTarget(target);
// Do we need to instantiate our keep-alive thread?
if (keepAlive == null) {
// Yes. Instantiate our keep-alive thread and start
// it up...
keepAlive = (KeepAlive)AccessController.doPrivileged(new PrivilegedAction() {
public java.lang.Object run() {
return new KeepAlive();
}
});
keepAlive.start();
}
}
}
}
示例14: WindowsFileSystem
import java.security.AccessController; //导入依赖的package包/类
WindowsFileSystem(WindowsFileSystemProvider provider,
String dir)
{
this.provider = provider;
// parse default directory and check it is absolute
WindowsPathParser.Result result = WindowsPathParser.parse(dir);
if ((result.type() != WindowsPathType.ABSOLUTE) &&
(result.type() != WindowsPathType.UNC))
throw new AssertionError("Default directory is not an absolute path");
this.defaultDirectory = result.path();
this.defaultRoot = result.root();
PrivilegedAction<String> pa = new GetPropertyAction("os.version");
String osversion = AccessController.doPrivileged(pa);
String[] vers = Util.split(osversion, '.');
int major = Integer.parseInt(vers[0]);
int minor = Integer.parseInt(vers[1]);
// symbolic links available on Vista and newer
supportsLinks = (major >= 6);
// enumeration of data streams available on Windows Server 2003 and newer
supportsStreamEnumeration = (major >= 6) || (major == 5 && minor >= 2);
}
示例15: loadProperties
import java.security.AccessController; //导入依赖的package包/类
/** Load properties from a file.
This method tries to load properties from the filename give into
the passed properties object.
If the file cannot be found or something else goes wrong,
the method silently fails.
@param properties The properties bundle to store the values of the
properties file.
@param filename The filename of the properties file to load. This
filename is interpreted as relative to the subdirectory "lib" in
the JRE directory.
*/
static void loadProperties(final Properties properties,
final String filename) {
if(hasSecurityManager()) {
try {
// invoke the privileged action using 1.2 security
PrivilegedAction<Void> action = new PrivilegedAction<Void>() {
public Void run() {
loadPropertiesImpl(properties, filename);
return null;
}
};
AccessController.doPrivileged(action);
if(Printer.debug)Printer.debug("Loaded properties with JDK 1.2 security");
} catch (Exception e) {
if(Printer.debug)Printer.debug("Exception loading properties with JDK 1.2 security");
// try without using JDK 1.2 security
loadPropertiesImpl(properties, filename);
}
} else {
// not JDK 1.2 security, assume we already have permission
loadPropertiesImpl(properties, filename);
}
}