Fixed checkAccess (did this change somehow? It used to work...)

This commit is contained in:
nathan 2016-02-14 15:18:30 +01:00
parent 398e2dccf9
commit 2b677e6cf4

View File

@ -31,7 +31,7 @@ import java.io.IOException;
* <p/> * <p/>
* A static "create" method, with any number of parameters, is required to create this class (which is done via reflection) * A static "create" method, with any number of parameters, is required to create this class (which is done via reflection)
*/ */
@SuppressWarnings({"deprecation", "unused"}) @SuppressWarnings({"deprecation", "unused", "Duplicates"})
public abstract public abstract
class SettingsStore { class SettingsStore {
@ -46,7 +46,7 @@ class SettingsStore {
// java < 8, it is SIGNIFICANTLY faster to call sun.reflect.Reflection.getCallerClass // java < 8, it is SIGNIFICANTLY faster to call sun.reflect.Reflection.getCallerClass
// java >= 8, Thread.stackTrace was fixed, so it is the now preferred method // java >= 8, Thread.stackTrace was fixed, so it is the now preferred method
if (OS.javaVersion < 8) { if (OS.javaVersion < 8) {
Class<?> callerClass = sun.reflect.Reflection.getCallerClass(3); Class<?> callerClass = sun.reflect.Reflection.getCallerClass(4);
if (callerClass == null) { if (callerClass == null) {
return null; return null;
@ -81,8 +81,7 @@ class SettingsStore {
String callerClass = getCallingClass(); String callerClass = getCallingClass();
// starts with will allow for anonymous inner classes. // starts with will allow for anonymous inner classes.
if (callerClass == null || !callerClass if (callerClass == null || !callerClass.equals(callingClass.getName())) {
.startsWith(callingClass.getName())) {
String message = "Security violation by: " + (callerClass == null ? "???" : callerClass); String message = "Security violation by: " + (callerClass == null ? "???" : callerClass);
Logger logger = LoggerFactory.getLogger(SettingsStore.class); Logger logger = LoggerFactory.getLogger(SettingsStore.class);
logger.error(message); logger.error(message);
@ -106,7 +105,7 @@ class SettingsStore {
boolean ok = false; boolean ok = false;
// starts with will allow for anonymous inner classes. // starts with will allow for anonymous inner classes.
if (callerClass != null) { if (callerClass != null) {
ok = callerClass.startsWith(callingClass1.getName()) || callerClass.startsWith(callingClass2.getName()); ok = callerClass.equals(callingClass1.getName()) || callerClass.equals(callingClass2.getName());
} }
if (!ok) { if (!ok) {
@ -131,9 +130,9 @@ class SettingsStore {
boolean ok = false; boolean ok = false;
// starts with will allow for anonymous inner classes. // starts with will allow for anonymous inner classes.
if (callerClass != null) { if (callerClass != null) {
ok = callerClass.startsWith(callingClass1.getName()) || ok = callerClass.equals(callingClass1.getName()) ||
callerClass.startsWith(callingClass2.getName()) || callerClass.equals(callingClass2.getName()) ||
callerClass.startsWith(callingClass3.getName()); callerClass.equals(callingClass3.getName());
} }
if (!ok) { if (!ok) {
@ -159,7 +158,7 @@ class SettingsStore {
// starts with will allow for anonymous inner classes. // starts with will allow for anonymous inner classes.
if (callerClass != null) { if (callerClass != null) {
for (Class<?> clazz : callingClasses) { for (Class<?> clazz : callingClasses) {
if (callerClass.startsWith(clazz.getName())) { if (callerClass.equals(clazz.getName())) {
ok = true; ok = true;
break; break;
} }
@ -190,8 +189,7 @@ class SettingsStore {
String callerClass = getCallingClass(); String callerClass = getCallingClass();
// starts with will allow for anonymous inner classes. // starts with will allow for anonymous inner classes.
if (callerClass == null || !callerClass if (callerClass == null || !callerClass.equals(callingClass.getName())) {
.startsWith(callingClass.getName())) {
String message = "Security violation by: " + (callerClass == null ? "???" : callerClass); String message = "Security violation by: " + (callerClass == null ? "???" : callerClass);
Logger logger = LoggerFactory.getLogger(SettingsStore.class); Logger logger = LoggerFactory.getLogger(SettingsStore.class);
logger.error(message); logger.error(message);
@ -219,7 +217,7 @@ class SettingsStore {
boolean ok = false; boolean ok = false;
// starts with will allow for anonymous inner classes. // starts with will allow for anonymous inner classes.
if (callerClass != null) { if (callerClass != null) {
ok = callerClass.startsWith(callingClass1.getName()) || callerClass.startsWith(callingClass2.getName()); ok = callerClass.equals(callingClass1.getName()) || callerClass.equals(callingClass2.getName());
} }
if (!ok) { if (!ok) {
@ -250,9 +248,9 @@ class SettingsStore {
boolean ok = false; boolean ok = false;
// starts with will allow for anonymous inner classes. // starts with will allow for anonymous inner classes.
if (callerClass != null) { if (callerClass != null) {
ok = callerClass.startsWith(callingClass1.getName()) || ok = callerClass.equals(callingClass1.getName()) ||
callerClass.startsWith(callingClass2.getName()) || callerClass.equals(callingClass2.getName()) ||
callerClass.startsWith(callingClass3.getName()); callerClass.equals(callingClass3.getName());
} }
if (!ok) { if (!ok) {
@ -280,7 +278,7 @@ class SettingsStore {
// starts with will allow for anonymous inner classes. // starts with will allow for anonymous inner classes.
if (callerClass != null) { if (callerClass != null) {
for (Class<?> clazz : callingClasses) { for (Class<?> clazz : callingClasses) {
if (callerClass.startsWith(clazz.getName())) { if (callerClass.equals(clazz.getName())) {
ok = true; ok = true;
break; break;
} }