Search in sources :

Example 26 with ProtectionDomain

use of java.security.ProtectionDomain in project pinpoint by naver.

the class OraclePlugin method addCallableStatementTransformer.

private void addCallableStatementTransformer() {
    TransformCallback transformer = new TransformCallback() {

        @Override
        public byte[] doInTransform(Instrumentor instrumentor, ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
            InstrumentClass target = instrumentor.getInstrumentClass(loader, className, classfileBuffer);
            if (className.equals(CLASS_CALLABLE_STATEMENT)) {
                if (instrumentor.exist(loader, CLASS_CALLABLE_STATEMENT_WRAPPER)) {
                    return null;
                }
            }
            target.addField("com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor");
            target.addField("com.navercorp.pinpoint.bootstrap.plugin.jdbc.ParsingResultAccessor");
            target.addField("com.navercorp.pinpoint.bootstrap.plugin.jdbc.BindValueAccessor");
            target.addScopedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.CallableStatementRegisterOutParameterInterceptor", OracleConstants.ORACLE_SCOPE);
            return target.toBytecode();
        }
    };
    transformTemplate.transform(CLASS_CALLABLE_STATEMENT, transformer);
    transformTemplate.transform(CLASS_CALLABLE_STATEMENT_WRAPPER, transformer);
}
Also used : ProtectionDomain(java.security.ProtectionDomain) Instrumentor(com.navercorp.pinpoint.bootstrap.instrument.Instrumentor) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) TransformCallback(com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformCallback) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass)

Example 27 with ProtectionDomain

use of java.security.ProtectionDomain in project pinpoint by naver.

the class MariaDBPlugin method addCallableStatementTransformer.

private void addCallableStatementTransformer() {
    TransformCallback transformer = new TransformCallback() {

        @Override
        public byte[] doInTransform(Instrumentor instrumentor, ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
            InstrumentClass target = instrumentor.getInstrumentClass(loader, className, classfileBuffer);
            target.addField("com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor");
            target.addField("com.navercorp.pinpoint.bootstrap.plugin.jdbc.ParsingResultAccessor");
            target.addField("com.navercorp.pinpoint.bootstrap.plugin.jdbc.BindValueAccessor");
            target.addScopedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.CallableStatementRegisterOutParameterInterceptor", MariaDBConstants.MARIADB_SCOPE);
            return target.toBytecode();
        }
    };
    transformTemplate.transform("org.mariadb.jdbc.AbstractCallableProcedureStatement", transformer);
    transformTemplate.transform("org.mariadb.jdbc.AbstractCallableFunctionStatement", transformer);
}
Also used : ProtectionDomain(java.security.ProtectionDomain) Instrumentor(com.navercorp.pinpoint.bootstrap.instrument.Instrumentor) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) TransformCallback(com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformCallback) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass)

Example 28 with ProtectionDomain

use of java.security.ProtectionDomain in project pinpoint by naver.

the class MariaDBPlugin method addPreparedStatementBindVariableTransformer.

private void addPreparedStatementBindVariableTransformer(final MariaDBConfig config) {
    TransformCallback transformer = new TransformCallback() {

        @Override
        public byte[] doInTransform(Instrumentor instrumentor, ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
            InstrumentClass target = instrumentor.getInstrumentClass(loader, className, classfileBuffer);
            target.addField("com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor");
            target.addField("com.navercorp.pinpoint.bootstrap.plugin.jdbc.ParsingResultAccessor");
            target.addField("com.navercorp.pinpoint.bootstrap.plugin.jdbc.BindValueAccessor");
            if (config.isTraceSqlBindValue()) {
                final PreparedStatementBindingMethodFilter excludes = PreparedStatementBindingMethodFilter.excludes("setRowId", "setNClob", "setSQLXML");
                target.addScopedInterceptor(excludes, "com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.PreparedStatementBindVariableInterceptor", MariaDBConstants.MARIADB_SCOPE, ExecutionPolicy.BOUNDARY);
            }
            return target.toBytecode();
        }
    };
    transformTemplate.transform("org.mariadb.jdbc.AbstractMariaDbPrepareStatement", transformer);
    // Class renamed in 1.5.6 - https://github.com/MariaDB/mariadb-connector-j/commit/16c8313960cf4fbc6b2b83136504d1ba9e662919
    transformTemplate.transform("org.mariadb.jdbc.AbstractPrepareStatement", transformer);
}
Also used : ProtectionDomain(java.security.ProtectionDomain) Instrumentor(com.navercorp.pinpoint.bootstrap.instrument.Instrumentor) PreparedStatementBindingMethodFilter(com.navercorp.pinpoint.bootstrap.plugin.jdbc.PreparedStatementBindingMethodFilter) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) TransformCallback(com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformCallback) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass)

Example 29 with ProtectionDomain

use of java.security.ProtectionDomain in project pinpoint by naver.

the class JavassistClassTest method testBeforeAddInterceptor.

@Test
public void testBeforeAddInterceptor() throws Exception {
    final TestClassLoader loader = getTestClassLoader();
    final String javassistClassName = "com.navercorp.pinpoint.test.javasssit.mock.TestObject";
    loader.addTransformer(javassistClassName, new TransformCallback() {

        @Override
        public byte[] doInTransform(Instrumentor instrumentor, ClassLoader classLoader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
            try {
                logger.info("modify className:{} cl:{}", className, classLoader);
                InstrumentClass aClass = instrumentor.getInstrumentClass(classLoader, javassistClassName, classfileBuffer);
                String methodName = "callA";
                InstrumentMethod callaMethod = aClass.getDeclaredMethod(methodName);
                callaMethod.addInterceptor("com.navercorp.pinpoint.test.javasssit.TestBeforeInterceptor");
                byte[] bytes = aClass.toBytecode();
                return bytes;
            } catch (Throwable e) {
                e.printStackTrace();
                throw new RuntimeException(e.getMessage(), e);
            }
        }
    });
    Class<?> testObjectClazz = loader.loadClass(javassistClassName);
    final String methodName = "callA";
    logger.info("class:{}", testObjectClazz.toString());
    logger.info("class cl:{}", testObjectClazz.getClassLoader());
    final Object testObject = testObjectClazz.newInstance();
    Method callA = testObjectClazz.getMethod(methodName);
    callA.invoke(testObject);
    Interceptor interceptor = getInterceptor(loader, 0);
    assertEqualsIntField(interceptor, "call", 1);
    assertEqualsObjectField(interceptor, "className", "com.navercorp.pinpoint.test.javasssit.mock.TestObject");
    assertEqualsObjectField(interceptor, "methodName", methodName);
    assertEqualsObjectField(interceptor, "args", null);
    assertEqualsObjectField(interceptor, "target", testObject);
}
Also used : ProtectionDomain(java.security.ProtectionDomain) InstrumentException(com.navercorp.pinpoint.bootstrap.instrument.InstrumentException) Instrumentor(com.navercorp.pinpoint.bootstrap.instrument.Instrumentor) InstrumentMethod(com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod) Method(java.lang.reflect.Method) TransformCallback(com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformCallback) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) InstrumentMethod(com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod) TestClassLoader(com.navercorp.pinpoint.test.classloader.TestClassLoader) TestClassLoader(com.navercorp.pinpoint.test.classloader.TestClassLoader) Interceptor(com.navercorp.pinpoint.bootstrap.interceptor.Interceptor) Test(org.junit.Test)

Example 30 with ProtectionDomain

use of java.security.ProtectionDomain in project pinpoint by naver.

the class JavassistClassTest method testAddAfterInterceptor.

@Ignore
@Test
public void testAddAfterInterceptor() throws Exception {
    final TestClassLoader loader = getTestClassLoader();
    final String testClassObject = "com.navercorp.pinpoint.test.javasssit.mock.TestObject2";
    loader.addTransformer(testClassObject, new TransformCallback() {

        @Override
        public byte[] doInTransform(Instrumentor instrumentor, ClassLoader classLoader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
            try {
                logger.info("modify cl:{}", classLoader);
                InstrumentClass aClass = instrumentor.getInstrumentClass(classLoader, testClassObject, classfileBuffer);
                String methodName = "callA";
                aClass.getDeclaredMethod(methodName).addInterceptor("com.navercorp.pinpoint.profiler.interceptor.TestAfterInterceptor");
                String methodName2 = "callB";
                aClass.getDeclaredMethod(methodName2).addInterceptor("com.navercorp.pinpoint.profiler.interceptor.TestAfterInterceptor");
                return aClass.toBytecode();
            } catch (InstrumentException e) {
                throw new RuntimeException(e.getMessage(), e);
            }
        }
    });
    Class<?> testObjectClazz = loader.loadClass(testClassObject);
    final String methodName = "callA";
    logger.info("class:{}", testObjectClazz.toString());
    final Object testObject = testObjectClazz.newInstance();
    Method callA = testObjectClazz.getMethod(methodName);
    Object result = callA.invoke(testObject);
    Interceptor interceptor = getInterceptor(loader, 0);
    assertEqualsIntField(interceptor, "call", 1);
    assertEqualsObjectField(interceptor, "className", testClassObject);
    assertEqualsObjectField(interceptor, "methodName", methodName);
    assertEqualsObjectField(interceptor, "args", null);
    assertEqualsObjectField(interceptor, "target", testObject);
    assertEqualsObjectField(interceptor, "result", result);
    final String methodName2 = "callB";
    Method callBMethod = testObject.getClass().getMethod(methodName2);
    callBMethod.invoke(testObject);
    Interceptor interceptor2 = getInterceptor(loader, 1);
    assertEqualsIntField(interceptor2, "call", 1);
    assertEqualsObjectField(interceptor2, "className", testClassObject);
    assertEqualsObjectField(interceptor2, "methodName", methodName2);
    assertEqualsObjectField(interceptor2, "args", null);
    assertEqualsObjectField(interceptor2, "target", testObject);
    assertEqualsObjectField(interceptor2, "result", null);
}
Also used : ProtectionDomain(java.security.ProtectionDomain) InstrumentException(com.navercorp.pinpoint.bootstrap.instrument.InstrumentException) Instrumentor(com.navercorp.pinpoint.bootstrap.instrument.Instrumentor) InstrumentMethod(com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod) Method(java.lang.reflect.Method) TransformCallback(com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformCallback) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) TestClassLoader(com.navercorp.pinpoint.test.classloader.TestClassLoader) TestClassLoader(com.navercorp.pinpoint.test.classloader.TestClassLoader) Interceptor(com.navercorp.pinpoint.bootstrap.interceptor.Interceptor) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

ProtectionDomain (java.security.ProtectionDomain)122 InstrumentClass (com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass)44 Instrumentor (com.navercorp.pinpoint.bootstrap.instrument.Instrumentor)44 TransformCallback (com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformCallback)42 CodeSource (java.security.CodeSource)29 InstrumentException (com.navercorp.pinpoint.bootstrap.instrument.InstrumentException)28 Permissions (java.security.Permissions)21 InstrumentMethod (com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod)20 AccessControlContext (java.security.AccessControlContext)20 URL (java.net.URL)15 Policy (java.security.Policy)15 Test (org.junit.Test)15 Permission (java.security.Permission)14 PermissionCollection (java.security.PermissionCollection)11 File (java.io.File)10 IOException (java.io.IOException)6 Method (java.lang.reflect.Method)6 SocketPermission (java.net.SocketPermission)6 TestClassLoader (com.navercorp.pinpoint.test.classloader.TestClassLoader)5 FilePermission (java.io.FilePermission)5