java.net.NetPermission Java Examples
The following examples show how to use
java.net.NetPermission.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GetAuthenticatorTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
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); }
Example #2
Source File: PluginSandboxPolicy.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
/** * 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("showWindowWithoutWarningBanner")); 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")); }
Example #3
Source File: PolicyFile.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
/** * 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; } }
Example #4
Source File: PolicyFile.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
/** * 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; } }
Example #5
Source File: PolicyFile.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * 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; } }
Example #6
Source File: PolicyFile.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * 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; } }
Example #7
Source File: PolicyFile.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
/** * 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; } }
Example #8
Source File: PolicyFile.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
/** * 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; } }
Example #9
Source File: PolicyFile.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
/** * 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; } }
Example #10
Source File: PolicyFile.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
/** * 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; } }
Example #11
Source File: PolicyFile.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * 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; } }
Example #12
Source File: PolicyFile.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * 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; } }
Example #13
Source File: PolicyFile.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** * 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; } }
Example #14
Source File: PolicyFile.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * 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; } }
Example #15
Source File: PolicyFile.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * 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; } }
Example #16
Source File: PolicyFile.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * 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; } }
Example #17
Source File: SideEffectSecurityManager.java From marshalsec with MIT License | 5 votes |
/** * {@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); }
Example #18
Source File: LookupTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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")); }
Example #19
Source File: Utils.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void checkNetPermission(String target) { SecurityManager sm = System.getSecurityManager(); if (sm == null) { return; } NetPermission np = new NetPermission(target); sm.checkPermission(np); }
Example #20
Source File: DefaultPolicyBuilder.java From onos with Apache License 2.0 | 4 votes |
public static org.onosproject.security.Permission getOnosPermission(Permission permission) { if (permission instanceof AppPermission) { return new org.onosproject.security.Permission(AppPermission.class.getName(), permission.getName(), ""); } else if (permission instanceof FilePermission) { return new org.onosproject.security.Permission( FilePermission.class.getName(), permission.getName(), permission.getActions()); } else if (permission instanceof SerializablePermission) { return new org.onosproject.security.Permission( SerializablePermission.class.getName(), permission.getName(), permission.getActions()); } else if (permission instanceof NetPermission) { return new org.onosproject.security.Permission( NetPermission.class.getName(), permission.getName(), permission.getActions()); } else if (permission instanceof RuntimePermission) { return new org.onosproject.security.Permission( RuntimePermission.class.getName(), permission.getName(), permission.getActions()); } else if (permission instanceof SocketPermission) { return new org.onosproject.security.Permission( SocketPermission.class.getName(), permission.getName(), permission.getActions()); } else if (permission instanceof SQLPermission) { return new org.onosproject.security.Permission( SQLPermission.class.getName(), permission.getName(), permission.getActions()); } else if (permission instanceof PropertyPermission) { return new org.onosproject.security.Permission( PropertyPermission.class.getName(), permission.getName(), permission.getActions()); } else if (permission instanceof LoggingPermission) { return new org.onosproject.security.Permission( LoggingPermission.class.getName(), permission.getName(), permission.getActions()); } else if (permission instanceof SSLPermission) { return new org.onosproject.security.Permission( SSLPermission.class.getName(), permission.getName(), permission.getActions()); } else if (permission instanceof AuthPermission) { return new org.onosproject.security.Permission( AuthPermission.class.getName(), permission.getName(), permission.getActions()); } else if (permission instanceof PrivateCredentialPermission) { return new org.onosproject.security.Permission( PrivateCredentialPermission.class.getName(), permission.getName(), permission.getActions()); } else if (permission instanceof DelegationPermission) { return new org.onosproject.security.Permission( DelegationPermission.class.getName(), permission.getName(), permission.getActions()); } else if (permission instanceof javax.security.auth.kerberos.ServicePermission) { return new org.onosproject.security.Permission( javax.security.auth.kerberos.ServicePermission.class.getName(), permission.getName(), permission.getActions()); } else if (permission instanceof AudioPermission) { return new org.onosproject.security.Permission( AudioPermission.class.getName(), permission.getName(), permission.getActions()); } else if (permission instanceof AdaptPermission) { return new org.onosproject.security.Permission( AdaptPermission.class.getName(), permission.getName(), permission.getActions()); } else if (permission instanceof BundlePermission) { return new org.onosproject.security.Permission( BundlePermission.class.getName(), permission.getName(), permission.getActions()); } else if (permission instanceof CapabilityPermission) { return new org.onosproject.security.Permission( CapabilityPermission.class.getName(), permission.getName(), permission.getActions()); } else if (permission instanceof PackagePermission) { return new org.onosproject.security.Permission( PackagePermission.class.getName(), permission.getName(), permission.getActions()); } else if (permission instanceof ServicePermission) { return new org.onosproject.security.Permission( ServicePermission.class.getName(), permission.getName(), permission.getActions()); } else if (permission instanceof AdminPermission) { return new org.onosproject.security.Permission( AdminPermission.class.getName(), permission.getName(), permission.getActions()); //} else if (permission instanceof ConfigurationPermission) { // return new org.onosproject.security.Permission( // ConfigurationPermission.class.getName(), permission.getName(), permission.getActions()); } return null; }
Example #21
Source File: DefaultPolicyBuilder.java From onos with Apache License 2.0 | 4 votes |
private static Permission getPermission(org.onosproject.security.Permission permission) { String classname = permission.getClassName(); String name = permission.getName(); String actions = permission.getActions(); if (classname == null || name == null) { return null; } classname = classname.trim(); name = name.trim(); actions = actions.trim(); if (AppPermission.class.getName().equals(classname)) { return new AppPermission(name); } else if (FilePermission.class.getName().equals(classname)) { return new FilePermission(name, actions); } else if (SerializablePermission.class.getName().equals(classname)) { return new SerializablePermission(name, actions); } else if (NetPermission.class.getName().equals(classname)) { return new NetPermission(name, actions); } else if (RuntimePermission.class.getName().equals(classname)) { return new RuntimePermission(name, actions); } else if (SocketPermission.class.getName().equals(classname)) { return new SocketPermission(name, actions); } else if (SQLPermission.class.getName().equals(classname)) { return new SQLPermission(name, actions); } else if (PropertyPermission.class.getName().equals(classname)) { return new PropertyPermission(name, actions); } else if (LoggingPermission.class.getName().equals(classname)) { return new LoggingPermission(name, actions); } else if (SSLPermission.class.getName().equals(classname)) { return new SSLPermission(name, actions); } else if (AuthPermission.class.getName().equals(classname)) { return new AuthPermission(name, actions); } else if (PrivateCredentialPermission.class.getName().equals(classname)) { return new PrivateCredentialPermission(name, actions); } else if (DelegationPermission.class.getName().equals(classname)) { return new DelegationPermission(name, actions); } else if (javax.security.auth.kerberos.ServicePermission.class.getName().equals(classname)) { return new javax.security.auth.kerberos.ServicePermission(name, actions); } else if (AudioPermission.class.getName().equals(classname)) { return new AudioPermission(name, actions); } else if (AdaptPermission.class.getName().equals(classname)) { return new AdaptPermission(name, actions); } else if (BundlePermission.class.getName().equals(classname)) { return new BundlePermission(name, actions); } else if (CapabilityPermission.class.getName().equals(classname)) { return new CapabilityPermission(name, actions); } else if (PackagePermission.class.getName().equals(classname)) { return new PackagePermission(name, actions); } else if (ServicePermission.class.getName().equals(classname)) { return new ServicePermission(name, actions); } else if (AdminPermission.class.getName().equals(classname)) { return new AdminPermission(name, actions); //} else if (ConfigurationPermission.class.getName().equals(classname)) { // return new ConfigurationPermission(name, actions); } else if (ReflectPermission.class.getName().equals(classname)) { return new ReflectPermission(name, actions); } //AllPermission, SecurityPermission, UnresolvedPermission //AWTPermission, ReflectPermission not allowed return null; }