当前位置: 首页>>代码示例>>Java>>正文


Java PrivilegedAction类代码示例

本文整理汇总了Java中java.security.PrivilegedAction的典型用法代码示例。如果您正苦于以下问题:Java PrivilegedAction类的具体用法?Java PrivilegedAction怎么用?Java PrivilegedAction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PrivilegedAction类属于java.security包,在下文中一共展示了PrivilegedAction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getDefaultProvider

import java.security.PrivilegedAction; //导入依赖的package包/类
/** Obtain the value of a default provider property.
    @param typeClass The type of the default provider property. This
    should be one of Receiver.class, Transmitter.class, Sequencer.class,
    Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
    Clip.class or Port.class.
    @return The complete value of the property, if available.
    If the property is not set, null is returned.
 */
private static synchronized String getDefaultProvider(Class typeClass) {
    if (!SourceDataLine.class.equals(typeClass)
            && !TargetDataLine.class.equals(typeClass)
            && !Clip.class.equals(typeClass)
            && !Port.class.equals(typeClass)
            && !Receiver.class.equals(typeClass)
            && !Transmitter.class.equals(typeClass)
            && !Synthesizer.class.equals(typeClass)
            && !Sequencer.class.equals(typeClass)) {
        return null;
    }
    String name = typeClass.getName();
    String value = AccessController.doPrivileged(
            (PrivilegedAction<String>) () -> System.getProperty(name));
    if (value == null) {
        value = getProperties().getProperty(name);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:31,代码来源:JDK13Services.java

示例2: main

import java.security.PrivilegedAction; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    String os = AccessController.doPrivileged(
                (PrivilegedAction<String>)() -> System.getProperty("os.name"));
    if (!os.toUpperCase(Locale.US).contains("WINDOWS")) {
        System.out.println("Not Windows. Skip test.");
        return;
    }

    kt("-genkeypair -alias a -dname CN=A");
    kt("-exportcert -file a.crt -alias a");
    Files.copy(Paths.get(System.getProperty("test.src"), "AlgOptions.jar"),
            Paths.get("test.jar"));
    sun.security.tools.jarsigner.Main.main(
            "-storepass changeit -keystore jks -certchain a.crt test.jar a"
                    .split(" "));

    // On Windows, if the file is still opened (or not if GC was
    // performed) and the next line would fail
    Files.delete(Paths.get("a.crt"));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:CertChainUnclosed.java

示例3: getMostSpecificStream

import java.security.PrivilegedAction; //导入依赖的package包/类
/**
 * Recursive
 */
private InputStream getMostSpecificStream(
        String key, String l, String c, String v) {
    final String filePath = baseName.replace('.', '/') + '/' + key
            + ((l == null) ? "" : ("_" + l))
            + ((c == null) ? "" : ("_" + c))
            + ((v == null) ? "" : ("_" + v))
            + ".text";
    // System.err.println("Seeking " + filePath);
    InputStream is = (InputStream) AccessController.doPrivileged(
        new PrivilegedAction() {

        public InputStream run() {
            return loader.getResourceAsStream(filePath);
        }
    });
    // N.b.  If were using Class.getRes... instead of ClassLoader.getRes...
    // we would need to prefix the path with "/".
    return (is == null && l != null)
        ? getMostSpecificStream(key, ((c == null) ? null : l),
                ((v == null) ? null : c), null)
        : is;
}
 
开发者ID:Julien35,项目名称:dev-courses,代码行数:26,代码来源:RefCapablePropertyResourceBundle.java

示例4: loadExpressionResolvers

import java.security.PrivilegedAction; //导入依赖的package包/类
/**
 * Load default {@link ExpressionResolver}s using Java {@link ServiceLoader} extensions only if
 * {@link #getExpressionResolverType()} is not null.
 * @param classLoader The ClassLoader to use. If <code>null</code>, this class ClassLoader or the default
 *        ClassLoader will be used.
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
protected synchronized void loadExpressionResolvers(ClassLoader classLoader) {
	final Class<? extends ExpressionResolver> expressionResolverType = getExpressionResolverType();
	if (expressionResolverType != null) {
		final ClassLoader cl = (classLoader != null) ? classLoader
				: (this.getClass().getClassLoader() != null) ? this.getClass().getClassLoader()
						: ClassUtils.getDefaultClassLoader();

		LOGGER.debug(() -> "Load ExpressionResolvers for classloader [" + cl
				+ "] using ServiceLoader with service name: " + expressionResolverType.getName());

		// load from META-INF/services
		Iterable<? extends ExpressionResolver> loaded = AccessController
				.doPrivileged(new PrivilegedAction<Iterable<? extends ExpressionResolver>>() {
					@Override
					public Iterable<? extends ExpressionResolver> run() {
						return ServiceLoader.load(expressionResolverType, classLoader);
					}
				});
		loaded.forEach(er -> {
			addExpressionResolver(er);
			LOGGER.debug(() -> "Registered ExpressionResolver [" + er.getClass().getName() + "]");
		});
	}
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:32,代码来源:AbstractDatastore.java

示例5: parsingComplete

import java.security.PrivilegedAction; //导入依赖的package包/类
private boolean parsingComplete() {
    if (this.input == null) {
        return false;
    }
    if (this.array == null) {
        if ((this.acc == null) && (null != System.getSecurityManager())) {
            throw new SecurityException("AccessControlContext is not set");
        }
        AccessController.doPrivileged(new PrivilegedAction<Void>() {
            public Void run() {
                XMLDecoder.this.handler.parse(XMLDecoder.this.input);
                return null;
            }
        }, this.acc);
        this.array = this.handler.getObjects();
    }
    return true;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:XMLDecoder.java

示例6: getSystemProperty

import java.security.PrivilegedAction; //导入依赖的package包/类
/**
 * Returns the requested System Property.  If a {@code SecurityException}
 * occurs, just return NULL
 * @param propName - System property to retrieve
 * @return The System property value or NULL if the property does not exist
 * or a {@code SecurityException} occurs.
 */
static private String getSystemProperty(final String propName) {
    String property = null;
    try {
        property = AccessController.doPrivileged(new PrivilegedAction<String>() {

            public String run() {
                return System.getProperty(propName);
            }
        }, null, new PropertyPermission(propName, "read"));
    } catch (SecurityException se) {
        trace("error getting " + propName + ":  "+ se);
        if (debug) {
            se.printStackTrace();
        }
    }
    return property;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:25,代码来源:RowSetProvider.java

示例7: clean

import java.security.PrivilegedAction; //导入依赖的package包/类
/**
 * Runs this cleaner, if it has not been run before.
 */
public void clean() {
    if (!remove(this))
        return;
    try {
        thunk.run();
    } catch (final Throwable x) {
        AccessController.doPrivileged(new PrivilegedAction<Void>() {
                public Void run() {
                    if (System.err != null)
                        new Error("Cleaner terminated abnormally", x)
                            .printStackTrace();
                    System.exit(1);
                    return null;
                }});
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:Cleaner.java

示例8: checkVerboseLogSetting

import java.security.PrivilegedAction; //导入依赖的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
	}
}
 
开发者ID:IngSW-unipv,项目名称:Progetto-C,代码行数:21,代码来源:Log.java

示例9: initialize

import java.security.PrivilegedAction; //导入依赖的package包/类
/**
 * UIManager.setLookAndFeel calls this method before the first
 * call (and typically the only call) to getDefaults().  Subclasses
 * should do any one-time setup they need here, rather than
 * in a static initializer, because look and feel class objects
 * may be loaded just to discover that isSupportedLookAndFeel()
 * returns false.
 *
 * @see #uninitialize
 * @see UIManager#setLookAndFeel
 */
public void initialize() {
    java.security.AccessController.doPrivileged(new PrivilegedAction<Void>() {
            public Void run() {
                System.loadLibrary("osxui");
                return null;
            }
        });

    java.security.AccessController.doPrivileged(new PrivilegedAction<Void>(){
        @Override
        public Void run() {
            JRSUIControl.initJRSUI();
            return null;
        }
    });

    super.initialize();
    final ScreenPopupFactory spf = new ScreenPopupFactory();
    spf.setActive(true);
    PopupFactory.setSharedInstance(spf);

    KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventPostProcessor(AquaMnemonicHandler.getInstance());
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:35,代码来源:AquaLookAndFeel.java

示例10: getAttributesScope

import java.security.PrivilegedAction; //导入依赖的package包/类
public int getAttributesScope(final String name) {

		if (name == null) {
			throw new NullPointerException(Localizer
					.getMessage("jsp.error.attribute.null_name"));
		}

		if (SecurityUtil.isPackageProtectionEnabled()) {
			return ((Integer) AccessController
					.doPrivileged(new PrivilegedAction() {
						public Object run() {
							return new Integer(doGetAttributeScope(name));
						}
					})).intValue();
		} else {
			return doGetAttributeScope(name);
		}
	}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:PageContextImpl.java

示例11: ThreadedSeedGenerator

import java.security.PrivilegedAction; //导入依赖的package包/类
/**
 * The constructor is only called once to construct the one
 * instance we actually use. It instantiates the message digest
 * and starts the thread going.
 */

ThreadedSeedGenerator() {
    pool = new byte[20];
    start = end = 0;

    final ThreadGroup[] finalsg = new ThreadGroup[1];
    Thread t = java.security.AccessController.doPrivileged
            ((PrivilegedAction<Thread>) () -> {
                ThreadGroup parent, group =
                        Thread.currentThread().getThreadGroup();
                while ((parent = group.getParent()) != null)
                    group = parent;
                finalsg[0] = new ThreadGroup
                        (group, "Dice SeedGenerator ThreadGroup");
                Thread newT = new Thread(finalsg[0],
                        ThreadedSeedGenerator.this,
                        "Dice SeedGenerator Thread");
                newT.setPriority(Thread.MIN_PRIORITY);
                newT.setDaemon(true);
                return newT;
            });
    seedGroup = finalsg[0];
    t.start();
}
 
开发者ID:patrickfav,项目名称:dice,代码行数:30,代码来源:JDKThreadedEntropySource.java

示例12: processDocument

import java.security.PrivilegedAction; //导入依赖的package包/类
@Override
public void processDocument(String inputText, IngestDocument ingestDocument) throws Exception {
    // call /name-translation endpoint and set the result in the field
    NameTranslationRequest request = new NameTranslationRequest.Builder(inputText, targetLanguage)
            .entityType(entityType)
            .targetScript(targetScript)
            .sourceLanguageOfUse(sourceLanguage)
            .sourceLanguageOfOrigin(sourceOrigin)
            .sourceScript(sourceScript).build();

    NameTranslationResponse response;
    try {
        // RosApi client binding's Jackson needs elevated privilege
        response = AccessController.doPrivileged((PrivilegedAction<NameTranslationResponse>) () ->
                rosAPI.getHttpRosetteAPI().perform(AbstractRosetteAPI.NAME_TRANSLATION_SERVICE_PATH, request, NameTranslationResponse.class)
        );
    } catch (HttpRosetteAPIException ex) {
        LOGGER.error(ex.getErrorResponse().getMessage());
        throw new ElasticsearchException(ex.getErrorResponse().getMessage(), ex);
    }

    ingestDocument.setFieldValue(targetField, response.getTranslation());
}
 
开发者ID:rosette-api,项目名称:rosette-elasticsearch-plugin,代码行数:24,代码来源:NameTranslationProcessor.java

示例13: checkConfiguration

import java.security.PrivilegedAction; //导入依赖的package包/类
/**
 * Prints warning message if installed Policy is the default Policy
 * implementation and globally granted permissions do not include
 * AllPermission or any ExecPermissions/ExecOptionPermissions.
 */
static void checkConfiguration() {
    Policy policy =
        AccessController.doPrivileged(new PrivilegedAction<Policy>() {
            public Policy run() {
                return Policy.getPolicy();
            }
        });
    if (!(policy instanceof PolicyFile)) {
        return;
    }
    PermissionCollection perms = getExecPermissions();
    for (Enumeration<Permission> e = perms.elements();
         e.hasMoreElements();)
    {
        Permission p = e.nextElement();
        if (p instanceof AllPermission ||
            p instanceof ExecPermission ||
            p instanceof ExecOptionPermission)
        {
            return;
        }
    }
    System.err.println(getTextResource("rmid.exec.perms.inadequate"));
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:30,代码来源:Activation.java

示例14: getCandidateMethods

import java.security.PrivilegedAction; //导入依赖的package包/类
/**
 * Retrieve all candidate methods for the given class, considering
 * the {@link RootBeanDefinition#isNonPublicAccessAllowed()} flag.
 * Called as the starting point for factory method determination.
 */
private Method[] getCandidateMethods(final Class<?> factoryClass, final RootBeanDefinition mbd) {
	if (System.getSecurityManager() != null) {
		return AccessController.doPrivileged(new PrivilegedAction<Method[]>() {
			@Override
			public Method[] run() {
				return (mbd.isNonPublicAccessAllowed() ?
						ReflectionUtils.getAllDeclaredMethods(factoryClass) : factoryClass.getMethods());
			}
		});
	}
	else {
		return (mbd.isNonPublicAccessAllowed() ?
				ReflectionUtils.getAllDeclaredMethods(factoryClass) : factoryClass.getMethods());
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:ConstructorResolver.java

示例15: unmarshalCustomCallData

import java.security.PrivilegedAction; //导入依赖的package包/类
/**
 * Sets a filter for invocation arguments, if a filter has been set.
 * Called by dispatch before the arguments are read.
 */
protected void unmarshalCustomCallData(ObjectInput in)
        throws IOException, ClassNotFoundException {
    if (filter != null &&
            in instanceof ObjectInputStream) {
        // Set the filter on the stream
        ObjectInputStream ois = (ObjectInputStream) in;

        AccessController.doPrivileged(new PrivilegedAction<Void>() {
            @Override
            public Void run() {
                ObjectInputFilter.Config.setObjectInputFilter(ois, filter);
                return null;
            }
        });
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:UnicastServerRef.java


注:本文中的java.security.PrivilegedAction类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。