Browse Source

Remove security manager after nosql test completion.

pull/1500/head
Igor Kulikov 8 years ago
parent
commit
72453499af
  1. 8
      application/src/test/java/org/thingsboard/server/rules/RuleEngineSqlTestSuite.java
  2. 72
      application/src/test/java/org/thingsboard/server/system/SystemSqlTestSuite.java
  3. 1
      dao/src/test/java/org/thingsboard/server/dao/CustomCassandraCQLUnit.java

8
application/src/test/java/org/thingsboard/server/rules/RuleEngineSqlTestSuite.java

@ -28,14 +28,6 @@ import java.util.Arrays;
"org.thingsboard.server.rules.lifecycle.sql.*Test"}) "org.thingsboard.server.rules.lifecycle.sql.*Test"})
public class RuleEngineSqlTestSuite { public class RuleEngineSqlTestSuite {
static {
SecurityManager appsm = System.getSecurityManager();
System.out.println("SECURITY MANAGER = " + appsm);
if (appsm != null) {
System.out.println("SECURITY MANAGER CLASS = " + appsm.getClass());
}
}
@ClassRule @ClassRule
public static CustomSqlUnit sqlUnit = new CustomSqlUnit( public static CustomSqlUnit sqlUnit = new CustomSqlUnit(
Arrays.asList("sql/schema-ts.sql", "sql/schema-entities.sql", "sql/system-data.sql"), Arrays.asList("sql/schema-ts.sql", "sql/schema-entities.sql", "sql/system-data.sql"),

72
application/src/test/java/org/thingsboard/server/system/SystemSqlTestSuite.java

@ -15,21 +15,11 @@
*/ */
package org.thingsboard.server.system; package org.thingsboard.server.system;
import net.bytebuddy.asm.AsmVisitorWrapper;
import net.bytebuddy.asm.MemberSubstitution;
import net.bytebuddy.matcher.ElementMatchers;
import org.apache.cassandra.cql3.functions.ThreadAwareSecurityManager;
import org.hibernate.HibernateException;
import org.hibernate.bytecode.internal.bytebuddy.ByteBuddyState;
import org.hibernate.bytecode.internal.bytebuddy.HibernateMethodLookupDispatcher;
import org.junit.ClassRule; import org.junit.ClassRule;
import org.junit.extensions.cpsuite.ClasspathSuite; import org.junit.extensions.cpsuite.ClasspathSuite;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.thingsboard.server.dao.CustomSqlUnit; import org.thingsboard.server.dao.CustomSqlUnit;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Arrays; import java.util.Arrays;
/** /**
@ -46,68 +36,6 @@ public class SystemSqlTestSuite {
if (appsm != null) { if (appsm != null) {
System.out.println("SECURITY MANAGER CLASS = " + appsm.getClass()); System.out.println("SECURITY MANAGER CLASS = " + appsm.getClass());
} }
AsmVisitorWrapper.ForDeclaredMethods getDeclaredMethodMemberSubstitution;
AsmVisitorWrapper.ForDeclaredMethods getMethodMemberSubstitution;
//if ( System.getSecurityManager() != null ) {
getDeclaredMethodMemberSubstitution = getDeclaredMethodMemberSubstitution();
getMethodMemberSubstitution = getMethodMemberSubstitution();
//}
//else {
// getDeclaredMethodMemberSubstitution = null;
// getMethodMemberSubstitution = null;
//}
System.out.println("getDeclaredMethodMemberSubstitution = " + getDeclaredMethodMemberSubstitution);
System.out.println("getMethodMemberSubstitution = " + getMethodMemberSubstitution);
}
private static class GetDeclaredMethodAction implements PrivilegedAction<Method> {
private final Class<?> clazz;
private final String methodName;
private final Class<?>[] parameterTypes;
private GetDeclaredMethodAction(Class<?> clazz, String methodName, Class<?>... parameterTypes) {
this.clazz = clazz;
this.methodName = methodName;
this.parameterTypes = parameterTypes;
}
@Override
public Method run() {
try {
Method method = clazz.getDeclaredMethod( methodName, parameterTypes );
return method;
}
catch (NoSuchMethodException e) {
throw new HibernateException( "Unable to prepare getDeclaredMethod()/getMethod() substitution", e );
}
}
}
private static AsmVisitorWrapper.ForDeclaredMethods getDeclaredMethodMemberSubstitution() {
// this should only be called if the security manager is enabled, thus the privileged calls
return MemberSubstitution.relaxed()
.method( ElementMatchers.is( AccessController.doPrivileged( new SystemSqlTestSuite.GetDeclaredMethodAction( Class.class,
"getDeclaredMethod", String.class, Class[].class ) ) ) )
.replaceWith(
AccessController.doPrivileged( new SystemSqlTestSuite.GetDeclaredMethodAction( HibernateMethodLookupDispatcher.class,
"getDeclaredMethod", Class.class, String.class, Class[].class ) ) )
.on( ElementMatchers.isTypeInitializer() );
}
private static AsmVisitorWrapper.ForDeclaredMethods getMethodMemberSubstitution() {
// this should only be called if the security manager is enabled, thus the privileged calls
return MemberSubstitution.relaxed()
.method( ElementMatchers.is( AccessController.doPrivileged( new SystemSqlTestSuite.GetDeclaredMethodAction( Class.class,
"getMethod", String.class, Class[].class ) ) ) )
.replaceWith(
AccessController.doPrivileged( new SystemSqlTestSuite.GetDeclaredMethodAction( HibernateMethodLookupDispatcher.class,
"getMethod", Class.class, String.class, Class[].class ) ) )
.on( ElementMatchers.isTypeInitializer() );
} }
@ClassRule @ClassRule

1
dao/src/test/java/org/thingsboard/server/dao/CustomCassandraCQLUnit.java

@ -82,6 +82,7 @@ public class CustomCassandraCQLUnit extends BaseCassandraUnit {
session = null; session = null;
cluster = null; cluster = null;
} }
System.setSecurityManager(null);
} }
// Getters for those who do not like to directly access fields // Getters for those who do not like to directly access fields

Loading…
Cancel
Save