Search in sources :

Example 6 with AllPermission

use of java.security.AllPermission in project joda-time by JodaOrg.

the class TestDateTimeZone method testZoneInfoProviderResourceLoading.

public void testZoneInfoProviderResourceLoading() {
    final Set<String> ids = new HashSet<String>(DateTimeZone.getAvailableIDs());
    ids.remove(DateTimeZone.getDefault().getID());
    final String id = ids.toArray(new String[ids.size()])[new Random().nextInt(ids.size())];
    try {
        Policy.setPolicy(new Policy() {

            @Override
            public PermissionCollection getPermissions(CodeSource codesource) {
                Permissions p = new Permissions();
                // enable everything
                p.add(new AllPermission());
                return p;
            }

            @Override
            public void refresh() {
            }

            @Override
            public boolean implies(ProtectionDomain domain, Permission permission) {
                return !(permission instanceof FilePermission) && !permission.getName().contains(id);
            }
        });
        System.setSecurityManager(new SecurityManager());
        // will throw IllegalArgumentException if the resource can
        // not be loaded
        final DateTimeZone zone = DateTimeZone.forID(id);
        assertNotNull(zone);
    } finally {
        System.setSecurityManager(null);
        Policy.setPolicy(ALLOW);
    }
}
Also used : Policy(java.security.Policy) PermissionCollection(java.security.PermissionCollection) ProtectionDomain(java.security.ProtectionDomain) CodeSource(java.security.CodeSource) FilePermission(java.io.FilePermission) Random(java.util.Random) Permissions(java.security.Permissions) AllPermission(java.security.AllPermission) FilePermission(java.io.FilePermission) Permission(java.security.Permission) AllPermission(java.security.AllPermission) HashSet(java.util.HashSet)

Example 7 with AllPermission

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

the class BatchSubsystemSecurityTestCase method createDeployment.

@Deployment
public static Archive<?> createDeployment() {
    final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "batch-test.jar");
    jar.addClasses(AbstractElytronSetupTask.class, SecurityDomainSettingEJB.class, TimeoutUtil.class, IdentityBatchlet.class, FailingBatchlet.class, LongRunningBatchlet.class);
    jar.addAsManifestResource(BatchSubsystemSecurityTestCase.class.getPackage(), "assert-identity.xml", "batch-jobs/assert-identity.xml");
    jar.addAsManifestResource(BatchSubsystemSecurityTestCase.class.getPackage(), "failing-batchlet.xml", "batch-jobs/failing-batchlet.xml");
    jar.addAsManifestResource(BatchSubsystemSecurityTestCase.class.getPackage(), "long-running-batchlet.xml", "batch-jobs/long-running-batchlet.xml");
    jar.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
    jar.addAsManifestResource(PermissionUtils.createPermissionsXmlAsset(new AllPermission()), "permissions.xml");
    return jar;
}
Also used : AllPermission(java.security.AllPermission) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) Deployment(org.jboss.arquillian.container.test.api.Deployment)

Example 8 with AllPermission

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

the class ImmutabilityTestCase method test.

protected void test(Predicate<Object> 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(Character.valueOf('a')));
    assertTrue(immutability.test(this.getClass()));
    assertTrue(immutability.test(Currency.getInstance(Locale.US)));
    assertTrue(immutability.test(Locale.getDefault()));
    assertTrue(immutability.test(Byte.valueOf(Integer.valueOf(1).byteValue())));
    assertTrue(immutability.test(Short.valueOf(Integer.valueOf(1).shortValue())));
    assertTrue(immutability.test(Integer.valueOf(1)));
    assertTrue(immutability.test(Long.valueOf(1)));
    assertTrue(immutability.test(Float.valueOf(1)));
    assertTrue(immutability.test(Double.valueOf(1)));
    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(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)));
}
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)

Example 9 with AllPermission

use of java.security.AllPermission in project jdk8u_jdk by JetBrains.

the class MethodUtil method getPermissions.

protected PermissionCollection getPermissions(CodeSource codesource) {
    PermissionCollection perms = super.getPermissions(codesource);
    perms.add(new AllPermission());
    return perms;
}
Also used : PermissionCollection(java.security.PermissionCollection) AllPermission(java.security.AllPermission)

Example 10 with AllPermission

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

the class Main method main.

/**
     * @param args
     */
public static void main(String[] args) {
    String home = System.getProperties().getProperty(SLING_HOME);
    if (home == null) {
        home = new File(DEFAULT_STANBOL_HOME).getAbsolutePath();
        System.setProperty(SLING_HOME, home);
    }
    //else do not override user configured values
    List<String> argsList = new ArrayList<String>(Arrays.asList(args));
    if (argsList.contains(PRINTHELPARG)) {
        doHelp();
        System.exit(0);
    }
    if (argsList.contains(NOSECURITYARG)) {
        argsList.remove(NOSECURITYARG);
    } else {
        args = argsList.toArray(new String[argsList.size()]);
        Policy.setPolicy(new Policy() {

            @Override
            public PermissionCollection getPermissions(ProtectionDomain domain) {
                PermissionCollection result = new Permissions();
                result.add(new AllPermission());
                return result;
            }
        });
        System.setSecurityManager(new SecurityManager());
    }
    //now use the standard Apache Sling launcher to do the job
    org.apache.sling.launchpad.app.Main.main(argsList.toArray(new String[argsList.size()]));
}
Also used : Policy(java.security.Policy) ProtectionDomain(java.security.ProtectionDomain) PermissionCollection(java.security.PermissionCollection) ArrayList(java.util.ArrayList) Permissions(java.security.Permissions) AllPermission(java.security.AllPermission) File(java.io.File)

Aggregations

AllPermission (java.security.AllPermission)16 Policy (java.security.Policy)7 PermissionCollection (java.security.PermissionCollection)6 Permissions (java.security.Permissions)5 File (java.io.File)3 FilePermission (java.io.FilePermission)3 CodeSource (java.security.CodeSource)3 Permission (java.security.Permission)3 ProtectionDomain (java.security.ProtectionDomain)3 SocketPermission (java.net.SocketPermission)2 URL (java.net.URL)2 XPathExpressionException (javax.xml.xpath.XPathExpressionException)2 XPathFactoryConfigurationException (javax.xml.xpath.XPathFactoryConfigurationException)2 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 InetSocketAddress (java.net.InetSocketAddress)1 URLClassLoader (java.net.URLClassLoader)1 AccessControlException (java.security.AccessControlException)1 Certificate (java.security.cert.Certificate)1 LocalDate (java.time.LocalDate)1