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


Java ProtectionDomain類代碼示例

本文整理匯總了Java中java.security.ProtectionDomain的典型用法代碼示例。如果您正苦於以下問題:Java ProtectionDomain類的具體用法?Java ProtectionDomain怎麽用?Java ProtectionDomain使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ProtectionDomain類屬於java.security包,在下文中一共展示了ProtectionDomain類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: combine

import java.security.ProtectionDomain; //導入依賴的package包/類
public ProtectionDomain[] combine(ProtectionDomain[] current,
                                  ProtectionDomain[] assigned) {
    // Add a new ProtectionDomain with the null codesource/signers, and
    // the empty permission set, to the end of the array containing the
    // 'current' protections domains, i.e. the ones that will be augmented
    // with the permissions granted to the set of principals present in
    // the supplied subject.
    //
    ProtectionDomain[] newCurrent;
    if (current == null || current.length == 0) {
        newCurrent = new ProtectionDomain[1];
        newCurrent[0] = pdNoPerms;
    } else {
        newCurrent = new ProtectionDomain[current.length + 1];
        for (int i = 0; i < current.length; i++) {
            newCurrent[i] = current[i];
        }
        newCurrent[current.length] = pdNoPerms;
    }
    return super.combine(newCurrent, assigned);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:22,代碼來源:JMXSubjectDomainCombiner.java

示例2: transform

import java.security.ProtectionDomain; //導入依賴的package包/類
public byte[] transform(ClassLoader loader, String className, Class classBeingRedefined,
                        ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {

    byte[] byteCode = classfileBuffer;

    if (className.equals("beans/Sleeping")) {

        try {
            ClassPool cp = ClassPool.getDefault();
            CtClass cc = cp.get("beans.Sleeping");
            CtMethod m = cc.getDeclaredMethod("sleepNow");
            m.addLocalVariable("elapsedTime", CtClass.longType);
            m.insertBefore("elapsedTime = System.currentTimeMillis();");
            m.insertAfter("{elapsedTime = System.currentTimeMillis() - elapsedTime;"
                    + "System.out.println(\"Method Executed in ms: \" + elapsedTime);}");
            byteCode = cc.toBytecode();
            cc.detach();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    return byteCode;
}
 
開發者ID:vitaly-chibrikov,項目名稱:otus_java_2017_10,代碼行數:25,代碼來源:SleepTransformer.java

示例3: transform

import java.security.ProtectionDomain; //導入依賴的package包/類
@Override
    public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {

        if(className.startsWith(TransformConfig.getInstance().getPackageScan())) {
            logger.log(Level.INFO, "-------------------CLASS---------------------");
            logger.log(Level.INFO, "className: " + className);
            ClassReader cr = new ClassReader(classfileBuffer);
            ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);

            ClassVisitor classVisitor = new HookClassAdapter(Opcodes.ASM5, cw);
            cr.accept(classVisitor, ClassReader.SKIP_FRAMES);
//            try {
//                FileOutputStream fos = new FileOutputStream(new File("classMod.class"));
//                fos.write(cw.toByteArray());
//                fos.close();
//            } catch (IOException e) {
//                e.printStackTrace();
//            }

            return cw.toByteArray();
        }
        return null;

    }
 
開發者ID:acmerli,項目名稱:fastAOP,代碼行數:25,代碼來源:CatchBlockClassTransformer.java

示例4: checkPerm

import java.security.ProtectionDomain; //導入依賴的package包/類
private static void checkPerm(PolicyFile p, ProtectionDomain pd)
            throws Exception {
    boolean foundIt = false;
    Enumeration perms = p.getPermissions(pd).elements();
    while (perms.hasMoreElements()) {
        Permission perm = (Permission)perms.nextElement();
        if (!(perm instanceof AllPermission)) {
            throw new SecurityException("expected AllPermission");
        } else {
            foundIt = true;
        }
    }
    if (!foundIt) {
        throw new SecurityException("expected AllPermission");
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:17,代碼來源:TokenStore.java

示例5: checkPackageAccess

import java.security.ProtectionDomain; //導入依賴的package包/類
final 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

示例6: main

import java.security.ProtectionDomain; //導入依賴的package包/類
public static void main(String[]args) throws Exception {
    final DomainCombiner dc = new DomainCombiner() {
        @Override
        public ProtectionDomain[] combine(ProtectionDomain[] currentDomains, ProtectionDomain[] assignedDomains) {
            return currentDomains; // basically a no-op
        }
    };

    // Get an instance of the saved ACC
    AccessControlContext saved = AccessController.getContext();
    // Simulate the stack ACC with a DomainCombiner attached
    AccessControlContext stack = new AccessControlContext(AccessController.getContext(), dc);

    // Now try to run JavaSecurityAccess.doIntersectionPrivilege() and assert
    // whether the DomainCombiner from the stack ACC is preserved
    boolean ret = SharedSecrets.getJavaSecurityAccess().doIntersectionPrivilege(new PrivilegedAction<Boolean>() {
        @Override
        public Boolean run() {
            return dc == AccessController.getContext().getDomainCombiner();
        }
    }, stack, saved);

    if (!ret) {
        System.exit(1);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:27,代碼來源:PreserveCombinerTest.java

示例7: transform

import java.security.ProtectionDomain; //導入依賴的package包/類
@Override
public byte[] transform(ClassLoader loader, String internalClassName, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
	if (internalClassName != null && classfileBuffer != null) {
		try {
			String className = internalClassName.replace('/', '.');
			for (String prefix : ignores)
				if (className.startsWith(prefix)) return null;

			TransformHandle handle = new TransformHandle(className, classfileBuffer);
			units.forEach(handle::accept);
			if (handle.getResult().isPresent()) {
				byte[] classBuffer = handle.getResult().get();
				if (debug) {
					saveClassFile(className, classBuffer);
				}
				return classBuffer;
			} else {
				return null;
			}
		} catch (Throwable e) {
			log("unable to transform {0}: {1}", internalClassName, e);
			e.printStackTrace();
		}
	}
	return null;
}
 
開發者ID:to2mbn,項目名稱:authlib-injector,代碼行數:27,代碼來源:ClassTransformer.java

示例8: implies

import java.security.ProtectionDomain; //導入依賴的package包/類
@Override
public boolean implies(ProtectionDomain pd, Permission perm) {
    System.out.println("CustomPolicy.implies");

    // If the protection domain is the same as CustomPolicy, then
    // we return true. This is to prevent recursive permission checks
    // that lead to StackOverflow errors when the policy implementation
    // performs a sensitive operation that triggers a permission check,
    // for example, as below.
    if (pd == policyPd) {
        return true;
    }

    // Do something that triggers a permission check to make sure that
    // we don't cause a StackOverflow error.
    String home = AccessController.doPrivileged(
        (PrivilegedAction<String>) () -> System.getProperty("user.home"));

    return true;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:CustomPolicy.java

示例9: getClassLoader

import java.security.ProtectionDomain; //導入依賴的package包/類
private ClassLoader getClassLoader(final ObjectName name) {
    if(clr == null){
        return null;
    }
    // Restrict to getClassLoader permission only
    Permissions permissions = new Permissions();
    permissions.add(new MBeanPermission("*", null, name, "getClassLoader"));
    ProtectionDomain protectionDomain = new ProtectionDomain(null, permissions);
    ProtectionDomain[] domains = {protectionDomain};
    AccessControlContext ctx = new AccessControlContext(domains);
    ClassLoader loader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
        public ClassLoader run() {
            return clr.getClassLoader(name);
        }
    }, ctx);
    return loader;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:18,代碼來源:MBeanInstantiator.java

示例10: getContext

import java.security.ProtectionDomain; //導入依賴的package包/類
/**
 * create a context that can read any directories (recursively)
 * mentioned in the class path. In the case of a jar, it has to
 * be the directory containing the jar, not just the jar, as jar
 * files might refer to other jar files.
 */

private static AccessControlContext getContext(File[] cp)
    throws java.net.MalformedURLException
{
    PathPermissions perms =
        new PathPermissions(cp);

    ProtectionDomain domain =
        new ProtectionDomain(new CodeSource(perms.getCodeBase(),
            (java.security.cert.Certificate[]) null),
        perms);

    AccessControlContext acc =
        new AccessControlContext(new ProtectionDomain[] { domain });

    return acc;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:24,代碼來源:Launcher.java

示例11: ClassLoader

import java.security.ProtectionDomain; //導入依賴的package包/類
private ClassLoader(Void unused, ClassLoader parent) {
    this.parent = parent;
    if (ParallelLoaders.isRegistered(this.getClass())) {
        parallelLockMap = new ConcurrentHashMap<>();
        package2certs = new ConcurrentHashMap<>();
        domains =
            Collections.synchronizedSet(new HashSet<ProtectionDomain>());
        assertionLock = new Object();
    } else {
        // no finer-grained lock; lock on the classloader instance
        parallelLockMap = null;
        package2certs = new Hashtable<>();
        domains = new HashSet<>();
        assertionLock = this;
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:17,代碼來源:ClassLoader.java

示例12: attemptSetNullSecurityManager

import java.security.ProtectionDomain; //導入依賴的package包/類
private void attemptSetNullSecurityManager()
{
	final Permissions permissions = new Permissions();
	permissions.add(new RuntimePermission("setSecurityManager"));
	final AccessControlContext context = new AccessControlContext(new ProtectionDomain[]{new ProtectionDomain(null,
		permissions)});
	AccessController.doPrivileged(new PrivilegedAction<Object>()
	{
		@Override
		public Object run()
		{
			LOGGER.info("About to call System.setSecurityManager(null)");
			System.setSecurityManager(null);
			LOGGER.info("Progressed beyond call to System.setSecurityManager(null)");
			return null;
		}
	}, context);
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:19,代碼來源:MacOpener.java

示例13: invoke

import java.security.ProtectionDomain; //導入依賴的package包/類
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
	String name = method.getName();
	if ("equals".equals(name)) {
		return proxy == args[0];
	}
	else if ("hashCode".equals(name)) {
		return hashCode();
	}
	else if ("toString".equals(name)) {
		return toString();
	}
	else if ("transform".equals(name)) {
		return transform((ClassLoader) args[0], (String) args[1], (Class<?>) args[2],
				(ProtectionDomain) args[3], (byte[]) args[4]);
	}
	else if ("unregisterClassLoader".equals(name)) {
		unregisterClassLoader((ClassLoader) args[0]);
		return null;
	}
	else {
		throw new IllegalArgumentException("Unknown method: " + method);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:25,代碼來源:JBossMCTranslatorAdapter.java

示例14: transform

import java.security.ProtectionDomain; //導入依賴的package包/類
@Override public byte[] transform(ClassLoader loader, String className,
        Class<?> classBeingRedefined,
        ProtectionDomain protectionDomain, byte[] classfileBuffer)
    throws IllegalClassFormatException {

    if (className.contains("TypeAnnotatedTestClass")) {
        try {
            // Here we remove and re-add the dummy fields. This shuffles the constant pool
            return asm(loader, className, classBeingRedefined, protectionDomain, classfileBuffer);
        } catch (Throwable e) {
            // The retransform native code that called this method does not propagate
            // exceptions. Instead of getting an uninformative generic error, catch
            // problems here and print it, then exit.
            e.printStackTrace();
            System.exit(1);
        }
    }
    return null;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:RedefineAnnotations.java

示例15: postDefineClass

import java.security.ProtectionDomain; //導入依賴的package包/類
private void postDefineClass(Class<?> c, ProtectionDomain pd)
{
    if (pd.getCodeSource() != null) {
        Certificate certs[] = pd.getCodeSource().getCertificates();
        if (certs != null)
            setSigners(c, certs);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:9,代碼來源:ClassLoader.java


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