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


Java NetPermission类代码示例

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


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

示例1: getKnownInstance

import java.net.NetPermission; //导入依赖的package包/类
/**
 * Creates one of the well-known permissions directly instead of
 * via reflection. Keep list short to not penalize non-JDK-defined
 * permissions.
 */
private static final Permission getKnownInstance(Class<?> claz,
    String name, String actions) {
    if (claz.equals(FilePermission.class)) {
        return new FilePermission(name, actions);
    } else if (claz.equals(SocketPermission.class)) {
        return new SocketPermission(name, actions);
    } else if (claz.equals(RuntimePermission.class)) {
        return new RuntimePermission(name, actions);
    } else if (claz.equals(PropertyPermission.class)) {
        return new PropertyPermission(name, actions);
    } else if (claz.equals(NetPermission.class)) {
        return new NetPermission(name, actions);
    } else if (claz.equals(AllPermission.class)) {
        return SecurityConstants.ALL_PERMISSION;
    } else {
        return null;
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:24,代码来源:PolicyFile.java

示例2: getKnownPermission

import java.net.NetPermission; //导入依赖的package包/类
/**
 * Creates one of the well-known permissions in the java.base module
 * directly instead of via reflection. Keep list short to not penalize
 * permissions from other modules.
 */
private static Permission getKnownPermission(Class<?> claz, String name,
                                             String actions) {
    if (claz.equals(FilePermission.class)) {
        return new FilePermission(name, actions);
    } else if (claz.equals(SocketPermission.class)) {
        return new SocketPermission(name, actions);
    } else if (claz.equals(RuntimePermission.class)) {
        return new RuntimePermission(name, actions);
    } else if (claz.equals(PropertyPermission.class)) {
        return new PropertyPermission(name, actions);
    } else if (claz.equals(NetPermission.class)) {
        return new NetPermission(name, actions);
    } else if (claz.equals(AllPermission.class)) {
        return SecurityConstants.ALL_PERMISSION;
    } else if (claz.equals(SecurityPermission.class)) {
        return new SecurityPermission(name, actions);
    } else {
        return null;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:PolicyFile.java

示例3: main

import java.net.NetPermission; //导入依赖的package包/类
public static void main (String args[]) throws Exception {
    Authenticator defaultAuth = Authenticator.getDefault();
    if (defaultAuth != null) {
        throw new RuntimeException("Unexpected authenticator: null expected");
    }
    MyAuthenticator auth = new MyAuthenticator();
    Authenticator.setDefault(auth);
    defaultAuth = Authenticator.getDefault();
    if (defaultAuth != auth) {
        throw new RuntimeException("Unexpected authenticator: auth expected");
    }
    System.setSecurityManager(new SecurityManager());
    try {
        defaultAuth = Authenticator.getDefault();
        throw new RuntimeException("Expected security exception not raised");
    } catch (AccessControlException s) {
        System.out.println("Got expected exception: " + s);
        if (!s.getPermission().equals(new NetPermission("requestPasswordAuthentication"))) {
            throw new RuntimeException("Unexpected permission check: " + s.getPermission());
        }
    }
    System.out.println("Test passed with default authenticator "
                       + defaultAuth);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:GetAuthenticatorTest.java

示例4: addCommonPermissions

import java.net.NetPermission; //导入依赖的package包/类
/**
 * Adds a couple of common permissions for both unsigned extensions as well as Groovy scripts.
 *
 * @param permissions
 *            the permissions object which will get the permissions added to it
 */
private static void addCommonPermissions(Permissions permissions) {
	permissions.add(new AudioPermission("play"));
	permissions.add(new AWTPermission("listenToAllAWTEvents"));
	permissions.add(new AWTPermission("setWindowAlwaysOnTop"));
	permissions.add(new AWTPermission("watchMousePointer"));
	permissions.add(new LoggingPermission("control", ""));
	permissions.add(new SocketPermission("*", "connect, listen, accept, resolve"));
	permissions.add(new URLPermission("http://-", "*:*"));
	permissions.add(new URLPermission("https://-", "*:*"));

	// because random Java library calls use sun classes which may or may not do an acess check,
	// we have to grant access to all of them
	// this is a very unfortunate permission and I would love to not have it
	// so if at any point in the future this won't be necessary any longer, remove it!!!
	permissions.add(new RuntimePermission("accessClassInPackage.sun.*"));

	permissions.add(new RuntimePermission("accessDeclaredMembers"));
	permissions.add(new RuntimePermission("getenv.*"));
	permissions.add(new RuntimePermission("getFileSystemAttributes"));
	permissions.add(new RuntimePermission("readFileDescriptor"));
	permissions.add(new RuntimePermission("writeFileDescriptor"));
	permissions.add(new RuntimePermission("queuePrintJob"));
	permissions.add(new NetPermission("specifyStreamHandler"));
}
 
开发者ID:rapidminer,项目名称:rapidminer-studio,代码行数:31,代码来源:PluginSandboxPolicy.java

示例5: showAuthenicationPrompt

import java.net.NetPermission; //导入依赖的package包/类
/**
 * Present a dialog to the user asking them for authentication information,
 * and returns the user's response. The caller must have
 * NetPermission("requestPasswordAuthentication") for this to work.
 *
 * @param host The host for with authentication is needed
 * @param port The port being accessed
 * @param prompt The prompt (realm) as presented by the server
 * @param type The type of server (proxy/web)
 * @return an array of objects representing user's authentication tokens
 * @throws SecurityException if the caller does not have the appropriate permissions.
 */
public static NamePassword showAuthenicationPrompt(String host, int port, String prompt, String type) {
    
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        NetPermission requestPermission
            = new NetPermission("requestPasswordAuthentication");
        sm.checkPermission(requestPermission);
    }

    final SecurityDialogMessage message = new SecurityDialogMessage(null);

    message.dialogType = DialogType.AUTHENTICATION;
    message.extras = new Object[] { host, port, prompt, type };

    DialogResult response = getUserResponse(message);
    OutputController.getLogger().log(OutputController.Level.MESSAGE_DEBUG, "Decided action for matching alaca at  was " + response);
    return (NamePassword) response;
}
 
开发者ID:GITNE,项目名称:icedtea-web,代码行数:31,代码来源:SecurityDialogs.java

示例6: checkPermission

import java.net.NetPermission; //导入依赖的package包/类
public void checkPermission(Permission permission) {
    if (permission instanceof NetPermission) {
        if ("setResponseCache".equals(permission.getName())) {
            throw new SecurityException();
        }
    }

    if (permission instanceof NetPermission) {
        if ("getResponseCache".equals(permission.getName())) {

            throw new SecurityException();
        }
    }

    if (permission instanceof RuntimePermission) {
        if ("setSecurityManager".equals(permission.getName())) {
            return;
        }
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:21,代码来源:OldResponseCacheTest.java

示例7: checkPermission

import java.net.NetPermission; //导入依赖的package包/类
public void checkPermission(Permission permission) {
    if (permission instanceof NetPermission) {
        if ("setCookieHandler".equals(permission.getName())) {
            throw new SecurityException();
        }
    }

    if (permission instanceof NetPermission) {
        if ("getCookieHandler".equals(permission.getName())) {
            throw new SecurityException();
        }
    }

    if (permission instanceof RuntimePermission) {
        if ("setSecurityManager".equals(permission.getName())) {
            return;
        }
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:20,代码来源:CookieHandlerTest.java

示例8: checkPermission

import java.net.NetPermission; //导入依赖的package包/类
public void checkPermission(Permission permission) {
	if (permission instanceof NetPermission) {
		if ("setResponseCache".equals(permission.getName())) {
			throw new SecurityException();
		}
	}

	if (permission instanceof NetPermission) {
		if ("getResponseCache".equals(permission.getName())) {
			throw new SecurityException();
		}
	}

	if (permission instanceof RuntimePermission) {
		if ("setSecurityManager".equals(permission.getName())) {
			return;
		}
	}
}
 
开发者ID:shannah,项目名称:cn1,代码行数:20,代码来源:ResponseCacheTest.java

示例9: checkPermission

import java.net.NetPermission; //导入依赖的package包/类
public void checkPermission(Permission permission) {
	if (permission instanceof NetPermission) {
		if ("getProxySelector".equals(permission.getName())) {
			throw new SecurityException();
		}
	}

	if (permission instanceof NetPermission) {
		if ("setProxySelector".equals(permission.getName())) {
			throw new SecurityException();
		}
	}

	if (permission instanceof RuntimePermission) {
		if ("setSecurityManager".equals(permission.getName())) {
			return;
		}
	}
}
 
开发者ID:shannah,项目名称:cn1,代码行数:20,代码来源:ProxySelectorTest.java

示例10: checkPermission

import java.net.NetPermission; //导入依赖的package包/类
/**
 * {@inheritDoc}
 *
 * @see java.lang.SecurityManager#checkPermission(java.security.Permission)
 */
@Override
public void checkPermission ( Permission perm ) {
    if ( perm instanceof RuntimePermission ) {
        if ( checkRuntimePermission((RuntimePermission) perm) ) {
            return;
        }
    }
    else if ( perm instanceof ReflectPermission ) {
        return;
    }
    else if ( perm instanceof LoggingPermission ) {
        return;
    }
    else if ( perm instanceof SecurityPermission ) {
        return;
    }
    else if ( perm instanceof PropertyPermission ) {
        return;
    }
    else if ( perm instanceof NetPermission && perm.getName().equals("specifyStreamHandler") ) {
        return;
    }
    else if ( perm instanceof FilePermission && perm.getActions().equals("read") ) {
        return;
    }
    else if ( perm instanceof SerializablePermission ) {
        return;
    }

    super.checkPermission(perm);
}
 
开发者ID:mbechler,项目名称:marshalsec,代码行数:37,代码来源:SideEffectSecurityManager.java

示例11: checkNetPermission

import java.net.NetPermission; //导入依赖的package包/类
public static void checkNetPermission(String target) {
    SecurityManager sm = System.getSecurityManager();
    if (sm == null) {
        return;
    }
    NetPermission np = new NetPermission(target);
    sm.checkPermission(np);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:Utils.java

示例12: LookupTestPolicy

import java.net.NetPermission; //导入依赖的package包/类
LookupTestPolicy() throws Exception {
    perms.add(new NetPermission("setProxySelector"));
    perms.add(new SocketPermission("localhost:1024-", "resolve,accept"));
    perms.add(new URLPermission("http://allowedAndFound.com:" + port + "/-", "*:*"));
    perms.add(new URLPermission("http://allowedButNotfound.com:" + port + "/-", "*:*"));
    perms.add(new FilePermission("<<ALL FILES>>", "read,write,delete"));
    //perms.add(new PropertyPermission("java.io.tmpdir", "read"));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:LookupTest.java

示例13: checkNetPermission

import java.net.NetPermission; //导入依赖的package包/类
static void checkNetPermission(String target) {
    SecurityManager sm = System.getSecurityManager();
    if (sm == null)
        return;
    NetPermission np = new NetPermission(target);
    sm.checkPermission(np);
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:8,代码来源:Utils.java

示例14: testSerializeWithXppDriverAndSun14ReflectionProviderAndActiveSecurityManager

import java.net.NetPermission; //导入依赖的package包/类
public void testSerializeWithXppDriverAndSun14ReflectionProviderAndActiveSecurityManager() {
    sm.addPermission(source, new RuntimePermission("accessClassInPackage.sun.reflect"));
    sm.addPermission(source, new RuntimePermission("accessClassInPackage.sun.misc"));
    sm.addPermission(source, new RuntimePermission("accessClassInPackage.sun.text.resources"));
    sm.addPermission(source, new RuntimePermission("accessClassInPackage.sun.util.resources"));
    sm.addPermission(source, new RuntimePermission("accessDeclaredMembers"));
    sm.addPermission(source, new RuntimePermission("createClassLoader"));
    sm.addPermission(source, new RuntimePermission("fileSystemProvider"));
    sm.addPermission(source, new RuntimePermission("loadLibrary.nio"));
    sm.addPermission(source, new RuntimePermission("modifyThreadGroup"));
    sm.addPermission(source, new RuntimePermission("reflectionFactoryAccess"));
    sm.addPermission(source, new PropertyPermission("ibm.dst.compatibility", "read"));
    sm.addPermission(source, new PropertyPermission("java.home", "read"));
    sm.addPermission(source, new PropertyPermission("java.nio.file.spi.DefaultFileSystemProvider", "read"));
    sm.addPermission(source, new PropertyPermission("java.security.debug", "read"));
    sm.addPermission(source, new PropertyPermission("javax.xml.datatype.DatatypeFactory", "read"));
    sm.addPermission(source, new PropertyPermission("jaxp.debug", "read"));
    sm.addPermission(source, new PropertyPermission("jdk.util.TimeZone.allowSetDefault", "read"));
    sm.addPermission(source, new PropertyPermission("sun.boot.class.path", "read"));
    sm.addPermission(source, new PropertyPermission("sun.nio.fs.chdirAllowed", "read"));
    sm.addPermission(source, new PropertyPermission("sun.timezone.ids.oldmapping", "read"));
    sm.addPermission(source, new PropertyPermission("user.country", "read"));
    sm.addPermission(source, new PropertyPermission("user.dir", "read"));
    sm.addPermission(source, new PropertyPermission("user.timezone", "read,write"));
    sm.addPermission(source, new ReflectPermission("suppressAccessChecks"));
    sm.addPermission(source, new NetPermission("specifyStreamHandler"));
    sm.setReadOnly();
    System.setSecurityManager(sm);

    xstream = new XStream();
    xstream.allowTypesByWildcard(AbstractAcceptanceTest.class.getPackage().getName()+".*objects.**");
    xstream.allowTypesByWildcard(this.getClass().getName()+"$*");

    assertBothWays();
}
 
开发者ID:x-stream,项目名称:xstream,代码行数:36,代码来源:SecurityManagerTest.java

示例15: testSerializeWithXppDriverAndPureJavaReflectionProviderAndActiveSecurityManager

import java.net.NetPermission; //导入依赖的package包/类
public void testSerializeWithXppDriverAndPureJavaReflectionProviderAndActiveSecurityManager() {
    sm.addPermission(source, new RuntimePermission("accessClassInPackage.sun.misc"));
    sm.addPermission(source, new RuntimePermission("accessClassInPackage.sun.text.resources"));
    sm.addPermission(source, new RuntimePermission("accessClassInPackage.sun.util.resources"));
    sm.addPermission(source, new RuntimePermission("accessDeclaredMembers"));
    sm.addPermission(source, new RuntimePermission("createClassLoader"));
    sm.addPermission(source, new RuntimePermission("fileSystemProvider"));
    sm.addPermission(source, new RuntimePermission("loadLibrary.nio"));
    sm.addPermission(source, new RuntimePermission("modifyThreadGroup"));
    sm.addPermission(source, new PropertyPermission("ibm.dst.compatibility", "read"));
    sm.addPermission(source, new PropertyPermission("java.home", "read"));
    sm.addPermission(source, new PropertyPermission("java.nio.file.spi.DefaultFileSystemProvider", "read"));
    sm.addPermission(source, new PropertyPermission("java.security.debug", "read"));
    sm.addPermission(source, new PropertyPermission("javax.xml.datatype.DatatypeFactory", "read"));
    sm.addPermission(source, new PropertyPermission("jaxp.debug", "read"));
    sm.addPermission(source, new PropertyPermission("jdk.util.TimeZone.allowSetDefault", "read"));
    sm.addPermission(source, new PropertyPermission("sun.boot.class.path", "read"));
    sm.addPermission(source, new PropertyPermission("sun.io.serialization.extendedDebugInfo", "read"));
    sm.addPermission(source, new PropertyPermission("sun.nio.fs.chdirAllowed", "read"));
    sm.addPermission(source, new PropertyPermission("sun.timezone.ids.oldmapping", "read"));
    sm.addPermission(source, new PropertyPermission("user.country", "read"));
    sm.addPermission(source, new PropertyPermission("user.dir", "read"));
    sm.addPermission(source, new PropertyPermission("user.timezone", "read,write"));
    sm.addPermission(source, new ReflectPermission("suppressAccessChecks"));
    sm.addPermission(source, new NetPermission("specifyStreamHandler"));
    sm.setReadOnly();
    System.setSecurityManager(sm);

    xstream = new XStream(new PureJavaReflectionProvider());
    xstream.allowTypesByWildcard(AbstractAcceptanceTest.class.getPackage().getName()+".*objects.**");
    xstream.allowTypesByWildcard(this.getClass().getName()+"$*");

    assertBothWays();
}
 
开发者ID:x-stream,项目名称:xstream,代码行数:35,代码来源:SecurityManagerTest.java


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