/** * 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; } }
/** * 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; } }
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); }
/** * 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")); }
/** * 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; }
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; } } }
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; } } }
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; } } }
/** * {@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); }
public static void checkNetPermission(String target) { SecurityManager sm = System.getSecurityManager(); if (sm == null) { return; } NetPermission np = new NetPermission(target); sm.checkPermission(np); }
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")); }
static void checkNetPermission(String target) { SecurityManager sm = System.getSecurityManager(); if (sm == null) return; NetPermission np = new NetPermission(target); sm.checkPermission(np); }
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(); }
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(); }
protected boolean checkNetPermission(NetPermission perm) { /* * "specifyStreamHandler" seems the only tricky one. But because a URL cannot be used to write to file-system (although it can be used for * remote resources), it should be fine */ return true; }
public void checkPermission(Permission permission) { if (permission instanceof NetPermission) { throw new SecurityException(); } if (permission instanceof RuntimePermission) { if ("setSecurityManager".equals(permission.getName())) { return; } } }
/** * @tests java.net.NetPermission#NetPermission(java.lang.String) */ public void test_ConstructorLjava_lang_String() { // Test for method java.net.NetPermission(java.lang.String) NetPermission n = new NetPermission("requestPasswordAuthentication"); assertEquals("Returned incorrect name", "requestPasswordAuthentication", n.getName()); }
/** * @tests java.net.NetPermission#NetPermission(java.lang.String, * java.lang.String) */ public void test_ConstructorLjava_lang_StringLjava_lang_String() { // Test for method java.net.NetPermission(java.lang.String, // java.lang.String) NetPermission n = new NetPermission("requestPasswordAuthentication", null); assertEquals("Returned incorrect name", "requestPasswordAuthentication", n.getName()); }
private boolean checkNetPermission(final NetPermission perm) { // Allow only if called from a safe caller or JUnit return calledFromJUnit() || calledFromSafeCallers() || calledFrom("java.text.NumberFormat", "java.", "sun.") || calledFrom("java.awt.Toolkit", "java.", "sun."); }
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; }