Search in sources :

Example 11 with AccessControlException

use of java.security.AccessControlException in project elasticsearch by elastic.

the class StoreRecoveryTests method hardLinksSupported.

public boolean hardLinksSupported(Path path) throws IOException {
    try {
        Files.createFile(path.resolve("foo.bar"));
        Files.createLink(path.resolve("test"), path.resolve("foo.bar"));
        BasicFileAttributes destAttr = Files.readAttributes(path.resolve("test"), BasicFileAttributes.class);
        BasicFileAttributes sourceAttr = Files.readAttributes(path.resolve("foo.bar"), BasicFileAttributes.class);
        // we won't get here - no permission ;)
        return destAttr.fileKey() != null && destAttr.fileKey().equals(sourceAttr.fileKey());
    } catch (AccessControlException ex) {
        // if we run into that situation we know it's supported.
        return true;
    } catch (UnsupportedOperationException ex) {
        return false;
    }
}
Also used : AccessControlException(java.security.AccessControlException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

Example 12 with AccessControlException

use of java.security.AccessControlException in project javatari by ppeccin.

the class ROMLoader method load.

public static Cartridge load(URL url, boolean provided) {
    InputStream stream = null;
    try {
        URLConnection conn = url.openConnection();
        conn.setConnectTimeout(5000);
        stream = conn.getInputStream();
        return createFromExternalURL(stream, url.toString(), provided);
    } catch (AccessControlException ex) {
        generalErrorMessage(ex, url.toString());
    } catch (IOException ex) {
        generalErrorMessage(ex, url.toString());
    }
    return null;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) AccessControlException(java.security.AccessControlException) IOException(java.io.IOException) URLConnection(java.net.URLConnection)

Example 13 with AccessControlException

use of java.security.AccessControlException in project spring-framework by spring-projects.

the class ApplicationContextExpressionTests method systemPropertiesSecurityManager.

@Test
public void systemPropertiesSecurityManager() {
    GenericApplicationContext ac = new GenericApplicationContext();
    AnnotationConfigUtils.registerAnnotationConfigProcessors(ac);
    GenericBeanDefinition bd = new GenericBeanDefinition();
    bd.setBeanClass(TestBean.class);
    bd.getPropertyValues().add("country", "#{systemProperties.country}");
    ac.registerBeanDefinition("tb", bd);
    SecurityManager oldSecurityManager = System.getSecurityManager();
    try {
        System.setProperty("country", "NL");
        SecurityManager securityManager = new SecurityManager() {

            @Override
            public void checkPropertiesAccess() {
                throw new AccessControlException("Not Allowed");
            }

            @Override
            public void checkPermission(Permission perm) {
            // allow everything else
            }
        };
        System.setSecurityManager(securityManager);
        ac.refresh();
        TestBean tb = ac.getBean("tb", TestBean.class);
        assertEquals("NL", tb.getCountry());
    } finally {
        System.setSecurityManager(oldSecurityManager);
        System.getProperties().remove("country");
    }
}
Also used : GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) TestBean(org.springframework.tests.sample.beans.TestBean) Permission(java.security.Permission) AccessControlException(java.security.AccessControlException) Test(org.junit.Test)

Example 14 with AccessControlException

use of java.security.AccessControlException in project spring-framework by spring-projects.

the class EnvironmentSecurityManagerIntegrationTests method securityManagerDisallowsAccessToSystemEnvironmentAndDisallowsAccessToIndividualKey.

@Test
public void securityManagerDisallowsAccessToSystemEnvironmentAndDisallowsAccessToIndividualKey() {
    SecurityManager securityManager = new SecurityManager() {

        @Override
        public void checkPermission(Permission perm) {
            // ReadOnlySystemAttributesMap will come into play.
            if ("getenv.*".equals(perm.getName())) {
                throw new AccessControlException("Accessing the system environment is disallowed");
            }
            // be ignored.
            if (("getenv." + AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME).equals(perm.getName())) {
                throw new AccessControlException(format("Accessing system environment variable [%s] is disallowed", AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME));
            }
        }
    };
    System.setSecurityManager(securityManager);
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    AnnotatedBeanDefinitionReader reader = new AnnotatedBeanDefinitionReader(bf);
    reader.register(C1.class);
    assertThat(bf.containsBean("c1"), is(false));
}
Also used : Permission(java.security.Permission) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) AccessControlException(java.security.AccessControlException) AnnotatedBeanDefinitionReader(org.springframework.context.annotation.AnnotatedBeanDefinitionReader) Test(org.junit.Test)

Example 15 with AccessControlException

use of java.security.AccessControlException in project libgdx by libgdx.

the class Json method getFields.

private OrderedMap<String, FieldMetadata> getFields(Class type) {
    OrderedMap<String, FieldMetadata> fields = typeToFields.get(type);
    if (fields != null)
        return fields;
    Array<Class> classHierarchy = new Array();
    Class nextClass = type;
    while (nextClass != Object.class) {
        classHierarchy.add(nextClass);
        nextClass = nextClass.getSuperclass();
    }
    ArrayList<Field> allFields = new ArrayList();
    for (int i = classHierarchy.size - 1; i >= 0; i--) Collections.addAll(allFields, ClassReflection.getDeclaredFields(classHierarchy.get(i)));
    OrderedMap<String, FieldMetadata> nameToField = new OrderedMap(allFields.size());
    for (int i = 0, n = allFields.size(); i < n; i++) {
        Field field = allFields.get(i);
        if (field.isTransient())
            continue;
        if (field.isStatic())
            continue;
        if (field.isSynthetic())
            continue;
        if (!field.isAccessible()) {
            try {
                field.setAccessible(true);
            } catch (AccessControlException ex) {
                continue;
            }
        }
        if (ignoreDeprecated && field.isAnnotationPresent(Deprecated.class))
            continue;
        nameToField.put(field.getName(), new FieldMetadata(field));
    }
    typeToFields.put(type, nameToField);
    return nameToField;
}
Also used : ArrayList(java.util.ArrayList) AccessControlException(java.security.AccessControlException) Field(com.badlogic.gdx.utils.reflect.Field)

Aggregations

AccessControlException (java.security.AccessControlException)62 IOException (java.io.IOException)23 Test (org.junit.Test)12 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)9 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)8 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)7 File (java.io.File)6 InputStream (java.io.InputStream)6 Permission (java.security.Permission)6 ApplicationNotFoundException (org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException)5 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)4 HashSet (java.util.HashSet)4 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)4 FileNotFoundException (java.io.FileNotFoundException)3 ArrayList (java.util.ArrayList)3 UnsafeCharArrayWriter (jetbrick.template.utils.UnsafeCharArrayWriter)3 FileSystem (org.apache.hadoop.fs.FileSystem)3 BufferedInputStream (java.io.BufferedInputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileInputStream (java.io.FileInputStream)2