當前位置: 首頁>>代碼示例>>Java>>正文


Java AccessController.doPrivileged方法代碼示例

本文整理匯總了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();
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:9,代碼來源:SocketAccess.java

示例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);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:24,代碼來源:ClassLoader.java

示例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);
}
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:33,代碼來源:HttpRequest.java

示例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());
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:23,代碼來源:XRCompositeManager.java

示例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;
}
 
開發者ID:vindell,項目名稱:spring-boot-starter-disruptor,代碼行數:22,代碼來源:DisruptorEventAwareProcessor.java

示例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;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:21,代碼來源:SocketAdaptor.java

示例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.");
    }
}
 
開發者ID:rosette-api,項目名稱:rosette-elasticsearch-plugin,代碼行數:25,代碼來源:CategoriesProcessor.java

示例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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:RTFReader.java

示例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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:JRELocaleProviderAdapter.java

示例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);
       }
    });
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:24,代碼來源:ObjectStreamClassUtil_1_3.java

示例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);
		}
	}
}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:11,代碼來源:PersistentValve.java

示例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));
                }
            });
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:PlainView.java

示例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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:BootstrapLogger.java

示例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.
        }
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:33,代碼來源:ConfigFile.java

示例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);
    }

}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:16,代碼來源:ResponseFacade.java


注:本文中的java.security.AccessController.doPrivileged方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。