Search in sources :

Example 91 with ProtectionDomain

use of java.security.ProtectionDomain in project lombok by rzwitserloot.

the class EclipsePatcher method registerPatchScripts.

private static void registerPatchScripts(Instrumentation instrumentation, boolean reloadExistingClasses, boolean ecjOnly, Class<?> launchingContext) {
    ScriptManager sm = new ScriptManager();
    sm.registerTransformer(instrumentation);
    sm.setFilter(new Filter() {

        @Override
        public boolean shouldTransform(ClassLoader loader, String className, Class<?> classBeingDefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) {
            if (!(loader instanceof URLClassLoader))
                return true;
            ClassLoader parent = loader.getParent();
            if (parent == null)
                return true;
            return !parent.getClass().getName().startsWith("org.eclipse.jdt.apt.core.internal.AnnotationProcessorFactoryLoader");
        }
    });
    final boolean forceBaseResourceNames = !"".equals(System.getProperty("shadow.override.lombok", ""));
    sm.setTransplantMapper(new TransplantMapper() {

        public String mapResourceName(int classFileFormatVersion, String resourceName) {
            if (classFileFormatVersion < 50 || forceBaseResourceNames)
                return resourceName;
            return "Class50/" + resourceName;
        }
    });
    if (!ecjOnly) {
        EclipseLoaderPatcher.patchEquinoxLoaders(sm, launchingContext);
        patchCatchReparse(sm);
        patchIdentifierEndReparse(sm);
        patchRetrieveEllipsisStartPosition(sm);
        patchRetrieveRightBraceOrSemiColonPosition(sm);
        patchSetGeneratedFlag(sm);
        patchDomAstReparseIssues(sm);
        patchHideGeneratedNodes(sm);
        patchPostCompileHookEclipse(sm);
        patchFixSourceTypeConverter(sm);
        patchDisableLombokForCodeFormatterAndCleanup(sm);
        patchListRewriteHandleGeneratedMethods(sm);
        patchSyntaxAndOccurrencesHighlighting(sm);
        patchSortMembersOperation(sm);
        patchExtractInterface(sm);
        patchAboutDialog(sm);
        patchEclipseDebugPatches(sm);
    } else {
        patchPostCompileHookEcj(sm);
    }
    patchAvoidReparsingGeneratedCode(sm);
    patchLombokizeAST(sm);
    patchEcjTransformers(sm, ecjOnly);
    patchExtensionMethod(sm, ecjOnly);
    patchRenameField(sm);
    if (reloadExistingClasses)
        sm.reloadClasses(instrumentation);
}
Also used : ProtectionDomain(java.security.ProtectionDomain) Filter(lombok.patcher.Filter) TransplantMapper(lombok.patcher.TransplantMapper) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) ScriptManager(lombok.patcher.ScriptManager)

Example 92 with ProtectionDomain

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

the class TransformUtils method addField.

public static TransformCallback addField(final String fieldAccessorClassName) {
    return 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(fieldAccessorClassName);
            return target.toBytecode();
        }
    };
}
Also used : ProtectionDomain(java.security.ProtectionDomain) Instrumentor(com.navercorp.pinpoint.bootstrap.instrument.Instrumentor) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass)

Example 93 with ProtectionDomain

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

the class AgentClassLoaderTest method getProjectLibDir.

private String getProjectLibDir() {
    // not really necessary, but useful for testing protectionDomain
    ProtectionDomain protectionDomain = AgentClassLoader.class.getProtectionDomain();
    CodeSource codeSource = protectionDomain.getCodeSource();
    URL location = codeSource.getLocation();
    logger.debug("lib location:{}", location);
    String path = location.getPath();
    // file:/D:/nhn_source/pinpoint_project/pinpoint-tomcat-profiler/target/classes/
    int dirPath = path.lastIndexOf("target/classes/");
    if (dirPath == -1) {
        throw new RuntimeException("target/classes/ not found");
    }
    String projectDir = path.substring(1, dirPath);
    return projectDir + "src/test/lib";
}
Also used : ProtectionDomain(java.security.ProtectionDomain) CodeSource(java.security.CodeSource) URL(java.net.URL)

Example 94 with ProtectionDomain

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

the class ActiveMQClientPlugin method addMessageDispatchChannelEditor.

private void addMessageDispatchChannelEditor() {
    TransformCallback messageDispatchChannelTransformer = 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);
            // MessageDispatchChannel is an interface (5.4.0+)
            if (!target.isInterceptable()) {
                return null;
            }
            final InstrumentMethod enqueue = target.getDeclaredMethod("enqueue", "org.apache.activemq.command.MessageDispatch");
            if (enqueue != null) {
                enqueue.addInterceptor(ActiveMQClientConstants.ACTIVEMQ_MESSAGE_DISPATCH_CHANNEL_ENQUEUE_INTERCEPTOR_FQCN);
            }
            final InstrumentMethod dequeue = target.getDeclaredMethod("dequeue", "long");
            if (dequeue != null) {
                dequeue.addInterceptor(ActiveMQClientConstants.ACTIVEMQ_MESSAGE_DISPATCH_CHANNEL_DEQUEUE_INTERCEPTOR_FQCN);
            }
            return target.toBytecode();
        }
    };
    transformTemplate.transform(ActiveMQClientConstants.ACTIVEMQ_MESSAGE_DISPATCH_CHANNEL_FQCN, messageDispatchChannelTransformer);
    transformTemplate.transform(ActiveMQClientConstants.ACTIVEMQ_MESSAGE_DISPATCH_CHANNEL_FIFO_FQCN, messageDispatchChannelTransformer);
    transformTemplate.transform(ActiveMQClientConstants.ACTIVEMQ_MESSAGE_DISPATCH_CHANNEL_SIMPLE_PRIORITY_FQCN, messageDispatchChannelTransformer);
}
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) InstrumentMethod(com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod)

Example 95 with ProtectionDomain

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

the class CassandraPlugin method addDefaultPreparedStatementTransformer.

private void addDefaultPreparedStatementTransformer() {
    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 (!target.isInterceptable()) {
                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");
            return target.toBytecode();
        }
    };
    transformTemplate.transform("com.datastax.driver.core.DefaultPreparedStatement", 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)

Aggregations

ProtectionDomain (java.security.ProtectionDomain)148 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)39 InstrumentException (com.navercorp.pinpoint.bootstrap.instrument.InstrumentException)28 AccessControlContext (java.security.AccessControlContext)24 Permissions (java.security.Permissions)22 InstrumentMethod (com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod)20 Permission (java.security.Permission)17 URL (java.net.URL)16 Policy (java.security.Policy)16 Test (org.junit.Test)16 File (java.io.File)12 PermissionCollection (java.security.PermissionCollection)12 IOException (java.io.IOException)11 Method (java.lang.reflect.Method)8 URI (java.net.URI)8 HashSet (java.util.HashSet)8 Principal (java.security.Principal)7