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;
}
}
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;
}
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");
}
}
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));
}
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;
}
Aggregations