本文整理汇总了Java中java.security.AccessController.doPrivileged方法的典型用法代码示例。如果您正苦于以下问题:Java AccessController.doPrivileged方法的具体用法?Java AccessController.doPrivileged怎么用?Java AccessController.doPrivileged使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.security.AccessController
的用法示例。
在下文中一共展示了AccessController.doPrivileged方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doPrivilegedIOException
import java.security.AccessController; //导入方法依赖的package包/类
public static <T> T doPrivilegedIOException(PrivilegedExceptionAction<T> operation) throws IOException {
SpecialPermission.check();
try {
return AccessController.doPrivileged(operation);
} catch (PrivilegedActionException e) {
throw (IOException) e.getCause();
}
}
示例2: checkPackageAccess
import java.security.AccessController; //导入方法依赖的package包/类
private void checkPackageAccess(Class<?> cls, ProtectionDomain pd) {
final SecurityManager sm = System.getSecurityManager();
if (sm != null) {
if (ReflectUtil.isNonPublicProxyClass(cls)) {
for (Class<?> intf: cls.getInterfaces()) {
checkPackageAccess(intf, pd);
}
return;
}
final String name = cls.getName();
final int i = name.lastIndexOf('.');
if (i != -1) {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
sm.checkPackageAccess(name.substring(0, i));
return null;
}
}, new AccessControlContext(new ProtectionDomain[] {pd}));
}
}
domains.add(pd);
}
示例3: 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);
}
示例4: XRCompositeManager
import java.security.AccessController; //导入方法依赖的package包/类
private XRCompositeManager(XRSurfaceData surface) {
con = new XRBackendNative();
String gradProp =
AccessController.doPrivileged(new PrivilegedAction<String>() {
public String run() {
return System.getProperty("sun.java2d.xrgradcache");
}
});
enableGradCache = gradProp == null ||
!(gradProp.equalsIgnoreCase("false") ||
gradProp.equalsIgnoreCase("f"));
XRPaints.register(this);
initResources(surface);
maskBuffer = new MaskTileManager(this, surface.getXid());
textRenderer = new XRTextRenderer(this);
maskImage = new XRMaskImage(this, surface.getXid());
}
示例5: postProcessBeforeInitialization
import java.security.AccessController; //导入方法依赖的package包/类
@Override
public Object postProcessBeforeInitialization(final Object bean, String beanName) throws BeansException {
AccessControlContext acc = null;
if (System.getSecurityManager() != null && (bean instanceof DisruptorEventPublisherAware )) {
acc = getAccessControlContext();
}
if (acc != null) {
AccessController.doPrivileged(new PrivilegedAction<Object>() {
@Override
public Object run() {
invokeAwareInterfaces(bean);
return null;
}
}, acc);
}
else {
invokeAwareInterfaces(bean);
}
return bean;
}
示例6: getOutputStream
import java.security.AccessController; //导入方法依赖的package包/类
public OutputStream getOutputStream() throws IOException {
if (!sc.isOpen())
throw new SocketException("Socket is closed");
if (!sc.isConnected())
throw new SocketException("Socket is not connected");
if (!sc.isOutputOpen())
throw new SocketException("Socket output is shutdown");
OutputStream os = null;
try {
os = AccessController.doPrivileged(
new PrivilegedExceptionAction<OutputStream>() {
public OutputStream run() throws IOException {
return Channels.newOutputStream(sc);
}
});
} catch (java.security.PrivilegedActionException e) {
throw (IOException)e.getException();
}
return os;
}
示例7: processDocument
import java.security.AccessController; //导入方法依赖的package包/类
@Override
public void processDocument(String inputText, IngestDocument ingestDocument) throws Exception {
// call /categories endpoint and set the top result in the field
DocumentRequest<CategoriesOptions> request = new DocumentRequest.Builder<CategoriesOptions>().content(inputText).build();
CategoriesResponse response;
try {
// RosApi client binding's Jackson needs elevated privilege
response = AccessController.doPrivileged((PrivilegedAction<CategoriesResponse>) () ->
rosAPI.getHttpRosetteAPI().perform(HttpRosetteAPI.CATEGORIES_SERVICE_PATH, request, CategoriesResponse.class)
);
} catch (HttpRosetteAPIException ex) {
LOGGER.error(ex.getErrorResponse().getMessage());
throw new ElasticsearchException(ex.getErrorResponse().getMessage(), ex);
}
if (response.getCategories() != null
&& !response.getCategories().isEmpty()
&& response.getCategories().get(0) != null
&& !Strings.isNullOrEmpty(response.getCategories().get(0).getLabel())) {
ingestDocument.setFieldValue(targetField, response.getCategories().get(0).getLabel());
} else {
throw new ElasticsearchException(TYPE + " ingest processor failed to categorize document.");
}
}
示例8: getCharacterSet
import java.security.AccessController; //导入方法依赖的package包/类
/** Looks up a named character set. A character set is a 256-entry
* array of characters, mapping unsigned byte values to their Unicode
* equivalents. The character set is loaded if necessary.
*
* @return the character set
*/
public static Object
getCharacterSet(final String name)
throws IOException
{
char[] set = characterSets.get(name);
if (set == null) {
InputStream charsetStream = AccessController.doPrivileged(
new PrivilegedAction<InputStream>() {
public InputStream run() {
return RTFReader.class.getResourceAsStream("charsets/" + name + ".txt");
}
});
set = readCharset(charsetStream);
defineCharacterSet(name, set);
}
return set;
}
示例9: getDecimalFormatSymbolsProvider
import java.security.AccessController; //导入方法依赖的package包/类
@Override
public DecimalFormatSymbolsProvider getDecimalFormatSymbolsProvider() {
if (decimalFormatSymbolsProvider == null) {
DecimalFormatSymbolsProvider provider = AccessController.doPrivileged(
(PrivilegedAction<DecimalFormatSymbolsProvider>) () ->
new DecimalFormatSymbolsProviderImpl(
getAdapterType(),
getLanguageTagSet("FormatData")));
synchronized (this) {
if (decimalFormatSymbolsProvider == null) {
decimalFormatSymbolsProvider = provider;
}
}
}
return decimalFormatSymbolsProvider;
}
示例10: getSerialVersion
import java.security.AccessController; //导入方法依赖的package包/类
private static Long getSerialVersion(final long csuid, final Class cl)
{
return (Long) AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
long suid;
try {
final Field f = cl.getDeclaredField("serialVersionUID");
int mods = f.getModifiers();
if (Modifier.isStatic(mods) &&
Modifier.isFinal(mods) && Modifier.isPrivate(mods)) {
suid = csuid;
} else {
suid = _computeSerialVersionUID(cl);
}
} catch (NoSuchFieldException ex) {
suid = _computeSerialVersionUID(cl);
//} catch (IllegalAccessException ex) {
// suid = _computeSerialVersionUID(cl);
}
return new Long(suid);
}
});
}
示例11: unbind
import java.security.AccessController; //导入方法依赖的package包/类
private void unbind() {
if (clBindRequired) {
if (Globals.IS_SECURITY_ENABLED) {
PrivilegedAction<Void> pa = new PrivilegedSetTccl(MY_CLASSLOADER);
AccessController.doPrivileged(pa);
} else {
Thread.currentThread().setContextClassLoader(MY_CLASSLOADER);
}
}
}
示例12: checkFPMethodOverridden
import java.security.AccessController; //导入方法依赖的package包/类
private static boolean checkFPMethodOverridden(final Class<?> className,
final String methodName,
final FPMethodArgs methodArgs) {
return AccessController
.doPrivileged(new PrivilegedAction<Boolean>() {
@Override
public Boolean run() {
return isFPMethodOverridden(methodName, className,
methodArgs.getMethodArguments(false),
methodArgs.getMethodArguments(true));
}
});
}
示例13: newThread
import java.security.AccessController; //导入方法依赖的package包/类
@Override
public Thread newThread(Runnable r) {
ExecutorService owner = getExecutor();
Thread thread = AccessController.doPrivileged(new PrivilegedAction<Thread>() {
@Override
public Thread run() {
Thread t = InnocuousThread.newThread(new BootstrapMessageLoggerTask(owner, r));
t.setName("BootstrapMessageLoggerTask-"+t.getName());
return t;
}
}, null, new RuntimePermission("enableContextClassLoaderOverride"));
thread.setDaemon(true);
return thread;
}
示例14: Spi
import java.security.AccessController; //导入方法依赖的package包/类
public Spi(final Configuration.Parameters params) throws IOException {
// call in a doPrivileged
//
// we have already passed the Configuration.getInstance
// security check. also this class is not freely accessible
// (it is in the "sun" package).
try {
AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
public Void run() throws IOException {
if (params == null) {
init();
} else {
if (!(params instanceof URIParameter)) {
throw new IllegalArgumentException
("Unrecognized parameter: " + params);
}
URIParameter uriParam = (URIParameter)params;
url = uriParam.getURI().toURL();
init();
}
return null;
}
});
} catch (PrivilegedActionException pae) {
throw (IOException)pae.getException();
}
// if init() throws some other RuntimeException,
// let it percolate up naturally.
}
示例15: setDateHeader
import java.security.AccessController; //导入方法依赖的package包/类
@Override
public void setDateHeader(String name, long date) {
if (isCommitted()) {
return;
}
if(Globals.IS_SECURITY_ENABLED) {
AccessController.doPrivileged(new DateHeaderPrivilegedAction
(name, date, false));
} else {
response.setDateHeader(name, date);
}
}