Search in sources :

Example 31 with AllPermission

use of java.security.AllPermission in project ignite by apache.

the class IgnitionComponentProxyTest method testStart.

/**
 */
@Test
public void testStart() {
    Supplier<Ignite> s = new Supplier<Ignite>() {

        @Override
        public Ignite get() {
            try {
                Permissions perms = new Permissions();
                perms.add(new AllPermission());
                AccessControlContext acc = AccessController.doPrivileged((PrivilegedAction<AccessControlContext>) () -> new AccessControlContext(AccessController.getContext(), new IgniteDomainCombiner(perms)));
                return AccessController.doPrivileged((PrivilegedExceptionAction<Ignite>) () -> {
                    String login = "node_" + G.allGrids().size();
                    return Ignition.start(optimize(getConfiguration(login, new TestSecurityPluginProvider(login, "", ALLOW_ALL, perms, globalAuth))));
                }, acc);
            } catch (Exception e) {
                throw new IgniteException(e);
            }
        }
    };
    check(s);
}
Also used : AccessControlContext(java.security.AccessControlContext) TestSecurityPluginProvider(org.apache.ignite.internal.processors.security.impl.TestSecurityPluginProvider) IgniteException(org.apache.ignite.IgniteException) Permissions(java.security.Permissions) AllPermission(java.security.AllPermission) Ignite(org.apache.ignite.Ignite) Supplier(java.util.function.Supplier) IgniteException(org.apache.ignite.IgniteException) Test(org.junit.Test)

Example 32 with AllPermission

use of java.security.AllPermission in project lwjgl by LWJGL.

the class AppletLoader method updateClassPath.

/**
 * Edits the ClassPath at runtime to include the jars
 * that have just been downloaded and then adds the
 * lwjgl natives folder property.
 *
 * @param path location where applet is stored
 * @throws Exception if it fails to add classpath
 */
protected void updateClassPath(final String path) throws Exception {
    setState(STATE_UPDATING_CLASSPATH);
    percentage = 95;
    URL[] urls = new URL[urlList.length];
    for (int i = 0; i < urlList.length; i++) {
        String file = new File(path, getJarName(urlList[i])).toURI().toString();
        // fix JVM bug where ! is not escaped
        file = file.replace("!", "%21");
        urls[i] = new URL(file);
    }
    // get AppletLoader certificates
    final Certificate[] certs = getCurrentCertificates();
    // detect if we are running on a mac and save result as boolean
    String osName = System.getProperty("os.name");
    final boolean isMacOS = (osName.startsWith("Mac") || osName.startsWith("Darwin"));
    // add downloaded jars to the classpath with required permissions
    classLoader = new URLClassLoader(urls) {

        protected PermissionCollection getPermissions(CodeSource codesource) {
            PermissionCollection perms = null;
            try {
                // no permissions
                perms = new Permissions();
                // if certificates match the AppletLoader certificates then we should be all set
                if (certificatesMatch(certs, codesource.getCertificates())) {
                    perms.add(new AllPermission());
                    return perms;
                }
                String host = getCodeBase().getHost();
                if (host != null && (host.length() > 0)) {
                    // add permission for downloaded jars to access host they were from
                    perms.add(new SocketPermission(host, "connect,accept"));
                } else if ("file".equals(codesource.getLocation().getProtocol())) {
                    // if running locally add file permission
                    String path = codesource.getLocation().getFile().replace('/', File.separatorChar);
                    perms.add(new FilePermission(path, "read"));
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return perms;
        }

        // allow non lwjgl native to be found from cache directory
        protected String findLibrary(String libname) {
            String libPath = path + "natives" + File.separator + LWJGLUtil.mapLibraryName(libname);
            if (new File(libPath).exists()) {
                return libPath;
            }
            return super.findLibrary(libname);
        }
    };
    debug_sleep(2000);
    // unload natives loaded by a previous instance of this lwjgl applet
    unloadNatives(path);
    // add natives files path to native class path
    System.setProperty("org.lwjgl.librarypath", path + "natives");
    // Make sure jinput knows about the new path too
    System.setProperty("net.java.games.input.librarypath", path + "natives");
    // set the library path, useful for non lwjgl natives
    System.setProperty("java.library.path", path + "natives");
    // mark natives as loaded
    natives_loaded = true;
}
Also used : PermissionCollection(java.security.PermissionCollection) SocketPermission(java.net.SocketPermission) CodeSource(java.security.CodeSource) FilePermission(java.io.FilePermission) URL(java.net.URL) AccessControlException(java.security.AccessControlException) IOException(java.io.IOException) URLClassLoader(java.net.URLClassLoader) Permissions(java.security.Permissions) AllPermission(java.security.AllPermission) JarFile(java.util.jar.JarFile) ZipFile(java.util.zip.ZipFile) File(java.io.File) Certificate(java.security.cert.Certificate)

Example 33 with AllPermission

use of java.security.AllPermission in project bytecode-viewer by Konloch.

the class ClassNodeLoader method getPermissions.

/**
 * @return This class loader's permissions
 */
private Permissions getPermissions() {
    Permissions permissions = new Permissions();
    permissions.add(new AllPermission());
    return permissions;
}
Also used : Permissions(java.security.Permissions) AllPermission(java.security.AllPermission)

Example 34 with AllPermission

use of java.security.AllPermission in project Payara by payara.

the class AuthorizationServiceImplTest method testIsPermissionGranted.

@Test
public void testIsPermissionGranted() throws Exception {
    assertSame("NOT_INITIALIZED", NOT_INITIALIZED, impl.getInitializationState());
    // Does not require service initialization
    impl.isPermissionGranted(new Subject(), new AllPermission());
}
Also used : AllPermission(java.security.AllPermission) Subject(javax.security.auth.Subject) Test(org.junit.Test)

Example 35 with AllPermission

use of java.security.AllPermission in project wildfly by wildfly.

the class DefaultImmutabilityTestCase method test.

protected void test(Immutability immutability) throws Exception {
    assertFalse(immutability.test(new Object()));
    assertFalse(immutability.test(new Date()));
    assertFalse(immutability.test(new AtomicInteger()));
    assertFalse(immutability.test(new AtomicLong()));
    assertTrue(immutability.test(null));
    assertTrue(immutability.test(Collections.emptyEnumeration()));
    assertTrue(immutability.test(Collections.emptyIterator()));
    assertTrue(immutability.test(Collections.emptyList()));
    assertTrue(immutability.test(Collections.emptyListIterator()));
    assertTrue(immutability.test(Collections.emptyMap()));
    assertTrue(immutability.test(Collections.emptyNavigableMap()));
    assertTrue(immutability.test(Collections.emptyNavigableSet()));
    assertTrue(immutability.test(Collections.emptySet()));
    assertTrue(immutability.test(Collections.emptySortedMap()));
    assertTrue(immutability.test(Collections.emptySortedSet()));
    assertTrue(immutability.test(Boolean.TRUE));
    assertTrue(immutability.test('a'));
    assertTrue(immutability.test(this.getClass()));
    assertTrue(immutability.test(Currency.getInstance(Locale.US)));
    assertTrue(immutability.test(Locale.getDefault()));
    assertTrue(immutability.test(Integer.valueOf(1).byteValue()));
    assertTrue(immutability.test(Integer.valueOf(1).shortValue()));
    assertTrue(immutability.test(1));
    assertTrue(immutability.test(1L));
    assertTrue(immutability.test(1F));
    assertTrue(immutability.test(1.0));
    assertTrue(immutability.test(BigInteger.valueOf(1)));
    assertTrue(immutability.test(BigDecimal.valueOf(1)));
    assertTrue(immutability.test(InetAddress.getLocalHost()));
    assertTrue(immutability.test(new InetSocketAddress(InetAddress.getLocalHost(), 80)));
    assertTrue(immutability.test(MathContext.UNLIMITED));
    assertTrue(immutability.test("test"));
    assertTrue(immutability.test(TimeZone.getDefault()));
    assertTrue(immutability.test(UUID.randomUUID()));
    assertTrue(immutability.test(TimeUnit.DAYS));
    File file = new File(System.getProperty("user.home"));
    assertTrue(immutability.test(file));
    assertTrue(immutability.test(file.toURI()));
    assertTrue(immutability.test(file.toURI().toURL()));
    assertTrue(immutability.test(FileSystems.getDefault().getRootDirectories().iterator().next()));
    assertTrue(immutability.test(new AllPermission()));
    assertTrue(immutability.test(DateTimeFormatter.BASIC_ISO_DATE));
    assertTrue(immutability.test(DecimalStyle.STANDARD));
    assertTrue(immutability.test(Duration.ZERO));
    assertTrue(immutability.test(Instant.now()));
    assertTrue(immutability.test(LocalDate.now()));
    assertTrue(immutability.test(LocalDateTime.now()));
    assertTrue(immutability.test(LocalTime.now()));
    assertTrue(immutability.test(MonthDay.now()));
    assertTrue(immutability.test(Period.ZERO));
    assertTrue(immutability.test(ValueRange.of(0L, 10L)));
    assertTrue(immutability.test(WeekFields.ISO));
    assertTrue(immutability.test(Year.now()));
    assertTrue(immutability.test(YearMonth.now()));
    assertTrue(immutability.test(ZoneOffset.UTC));
    assertTrue(immutability.test(ZoneRules.of(ZoneOffset.UTC).nextTransition(Instant.now())));
    assertTrue(immutability.test(ZoneOffsetTransitionRule.of(Month.JANUARY, 1, DayOfWeek.SUNDAY, LocalTime.MIDNIGHT, true, TimeDefinition.STANDARD, ZoneOffset.UTC, ZoneOffset.ofHours(1), ZoneOffset.ofHours(2))));
    assertTrue(immutability.test(ZoneRules.of(ZoneOffset.UTC)));
    assertTrue(immutability.test(ZonedDateTime.now()));
    assertTrue(immutability.test(new JCIPImmutableObject()));
    assertTrue(immutability.test(Collections.singleton("1")));
    assertTrue(immutability.test(Collections.singletonList("1")));
    assertTrue(immutability.test(Collections.singletonMap("1", "2")));
    assertTrue(immutability.test(Collections.singleton(new JCIPImmutableObject())));
    assertTrue(immutability.test(Collections.singletonList(new JCIPImmutableObject())));
    assertTrue(immutability.test(Collections.singletonMap("1", new JCIPImmutableObject())));
    assertTrue(immutability.test(new AbstractMap.SimpleImmutableEntry<>("1", new JCIPImmutableObject())));
    assertTrue(immutability.test(Collections.unmodifiableCollection(Arrays.asList("1", "2"))));
    assertTrue(immutability.test(Collections.unmodifiableList(Arrays.asList("1", "2"))));
    assertTrue(immutability.test(Collections.unmodifiableMap(Collections.singletonMap("1", "2"))));
    assertTrue(immutability.test(Collections.unmodifiableNavigableMap(new TreeMap<>(Collections.singletonMap("1", "2")))));
    assertTrue(immutability.test(Collections.unmodifiableNavigableSet(new TreeSet<>(Collections.singleton("1")))));
    assertTrue(immutability.test(Collections.unmodifiableSet(Collections.singleton("1"))));
    assertTrue(immutability.test(Collections.unmodifiableSortedMap(new TreeMap<>(Collections.singletonMap("1", "2")))));
    assertTrue(immutability.test(Collections.unmodifiableSortedSet(new TreeSet<>(Collections.singleton("1")))));
    Object mutableObject = new AtomicInteger();
    assertFalse(immutability.test(Collections.singletonList(mutableObject)));
    assertFalse(immutability.test(Collections.singletonMap("1", mutableObject)));
    assertFalse(immutability.test(new AbstractMap.SimpleImmutableEntry<>("1", mutableObject)));
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InetSocketAddress(java.net.InetSocketAddress) AllPermission(java.security.AllPermission) File(java.io.File) Date(java.util.Date) LocalDate(java.time.LocalDate)

Aggregations

AllPermission (java.security.AllPermission)38 PermissionCollection (java.security.PermissionCollection)14 Permissions (java.security.Permissions)14 Permission (java.security.Permission)9 Policy (java.security.Policy)8 CodeSource (java.security.CodeSource)6 File (java.io.File)5 FilePermission (java.io.FilePermission)5 ProtectionDomain (java.security.ProtectionDomain)5 Test (org.junit.Test)5 Deployment (org.jboss.arquillian.container.test.api.Deployment)3 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)3 InetSocketAddress (java.net.InetSocketAddress)2 SocketPermission (java.net.SocketPermission)2 URL (java.net.URL)2 URLClassLoader (java.net.URLClassLoader)2 PrivilegedActionException (java.security.PrivilegedActionException)2 LocalDate (java.time.LocalDate)2 Date (java.util.Date)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2