Search in sources :

Example 81 with Permission

use of java.security.Permission in project hazelcast by hazelcast.

the class HadoopFileSourceFactory method configureFn.

private static <T> ConsumerEx<Configuration> configureFn(FileSourceConfiguration<T> fsc, JobConfigurer configurer, FileFormat<T> fileFormat) {
    return new ConsumerEx<Configuration>() {

        @Override
        public void acceptEx(Configuration configuration) throws Exception {
            try {
                configuration.setBoolean(FileInputFormat.INPUT_DIR_NONRECURSIVE_IGNORE_SUBDIRS, true);
                configuration.setBoolean(FileInputFormat.INPUT_DIR_RECURSIVE, false);
                configuration.setBoolean(HadoopSources.SHARED_LOCAL_FS, fsc.isSharedFileSystem());
                configuration.setBoolean(HadoopSources.IGNORE_FILE_NOT_FOUND, fsc.isIgnoreFileNotFound());
                for (Entry<String, String> option : fsc.getOptions().entrySet()) {
                    configuration.set(option.getKey(), option.getValue());
                }
                // Some methods we use to configure actually take a Job
                Job job = Job.getInstance(configuration);
                Path inputPath = getInputPath(fsc, configuration);
                FileInputFormat.addInputPath(job, inputPath);
                configurer.configure(job, fileFormat);
                // original configuration instance
                for (Entry<String, String> entry : job.getConfiguration()) {
                    configuration.set(entry.getKey(), entry.getValue());
                }
            } catch (IOException e) {
                throw new JetException("Could not create a source", e);
            }
        }

        @Override
        public List<Permission> permissions() {
            String keyFile = fsc.getOptions().get("google.cloud.auth.service.account.json.keyfile");
            if (keyFile != null) {
                return asList(ConnectorPermission.file(keyFile, ACTION_READ), ConnectorPermission.file(fsc.getPath(), ACTION_READ));
            }
            return singletonList(ConnectorPermission.file(fsc.getPath(), ACTION_READ));
        }
    };
}
Also used : ConsumerEx(com.hazelcast.function.ConsumerEx) Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) FileSourceConfiguration(com.hazelcast.jet.pipeline.file.impl.FileSourceConfiguration) ConnectorPermission(com.hazelcast.security.permission.ConnectorPermission) Permission(java.security.Permission) IOException(java.io.IOException) JetException(com.hazelcast.jet.JetException) Job(org.apache.hadoop.mapreduce.Job) AvroJob(org.apache.avro.mapreduce.AvroJob)

Example 82 with Permission

use of java.security.Permission in project undertow by undertow-io.

the class DirectByteBufferDeallocatorTestCase method directByteBufferDeallocatorInstantiationTest.

@Test
public void directByteBufferDeallocatorInstantiationTest() {
    Exception exception = null;
    Policy.setPolicy(new Policy() {

        @Override
        public boolean implies(ProtectionDomain pd, Permission perm) {
            return true;
        }
    });
    System.setSecurityManager(new SecurityManager());
    try {
        DirectByteBufferDeallocator.free(null);
    } catch (Exception e) {
        exception = e;
    }
    Assert.assertNull("An exception was thrown with security manager enabled", exception);
    System.setSecurityManager(null);
    try {
        DirectByteBufferDeallocator.free(null);
    } catch (Exception e) {
        exception = e;
    }
    Assert.assertNull("An exception was thrown without security manager enabled", exception);
}
Also used : Policy(java.security.Policy) ProtectionDomain(java.security.ProtectionDomain) Permission(java.security.Permission) Test(org.junit.Test)

Example 83 with Permission

use of java.security.Permission in project hazelcast by hazelcast.

the class ActionConstantsTest method getPermission_CountdownLatch.

@Test
public void getPermission_CountdownLatch() {
    Permission permission = ActionConstants.getPermission("foo", CountDownLatchService.SERVICE_NAME);
    assertNotNull(permission);
    assertTrue(permission instanceof CountDownLatchPermission);
}
Also used : Permission(java.security.Permission) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 84 with Permission

use of java.security.Permission in project hazelcast by hazelcast.

the class ActionConstantsTest method getPermission_List.

@Test
public void getPermission_List() {
    Permission permission = ActionConstants.getPermission("foo", ListService.SERVICE_NAME);
    assertNotNull(permission);
    assertTrue(permission instanceof ListPermission);
}
Also used : Permission(java.security.Permission) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 85 with Permission

use of java.security.Permission in project hazelcast by hazelcast.

the class ActionConstantsTest method getPermission_Semaphore.

@Test
public void getPermission_Semaphore() {
    Permission permission = ActionConstants.getPermission("foo", SemaphoreService.SERVICE_NAME);
    assertNotNull(permission);
    assertTrue(permission instanceof SemaphorePermission);
}
Also used : Permission(java.security.Permission) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

Permission (java.security.Permission)236 Test (org.junit.Test)55 PermissionCollection (java.security.PermissionCollection)39 FilePermission (java.io.FilePermission)38 Permissions (java.security.Permissions)31 ProtectionDomain (java.security.ProtectionDomain)27 IOException (java.io.IOException)20 AllPermission (java.security.AllPermission)20 QuickTest (com.hazelcast.test.annotation.QuickTest)17 File (java.io.File)17 URL (java.net.URL)16 AccessControlException (java.security.AccessControlException)14 Principal (java.security.Principal)14 PropertyPermission (java.util.PropertyPermission)14 Policy (java.security.Policy)13 MBeanPermission (javax.management.MBeanPermission)13 AccessControlContext (java.security.AccessControlContext)12 CodeSource (java.security.CodeSource)11 SecurityPermission (java.security.SecurityPermission)11 ArrayList (java.util.ArrayList)10