Search in sources :

Example 81 with ProtectionDomain

use of java.security.ProtectionDomain in project AsmackService by rtreffer.

the class SubjectDomainCombiner method combine.

/**
     * Merges the {@code ProtectionDomain} with the {@code Principal}s
     * associated with the subject of this {@code SubjectDomainCombiner}.
     *
     * @param currentDomains
     *            the {@code ProtectionDomain}s associated with the context of
     *            the current thread. The domains must be sorted according to
     *            the execution order, the most recent residing at the
     *            beginning.
     * @param assignedDomains
     *            the {@code ProtectionDomain}s from the parent thread based on
     *            code source and signers.
     * @return a single {@code ProtectionDomain} array computed from the two
     *         provided arrays, or {@code null}.
     * @see ProtectionDomain
     */
public ProtectionDomain[] combine(ProtectionDomain[] currentDomains, ProtectionDomain[] assignedDomains) {
    // get array length for combining protection domains
    int len = 0;
    if (currentDomains != null) {
        len += currentDomains.length;
    }
    if (assignedDomains != null) {
        len += assignedDomains.length;
    }
    if (len == 0) {
        return null;
    }
    ProtectionDomain[] pd = new ProtectionDomain[len];
    // for each current domain substitute set of principal with subject's
    int cur = 0;
    if (currentDomains != null) {
        Set<Principal> s = subject.getPrincipals();
        Principal[] p = s.toArray(new Principal[s.size()]);
        for (cur = 0; cur < currentDomains.length; cur++) {
            ProtectionDomain newPD;
            newPD = new ProtectionDomain(currentDomains[cur].getCodeSource(), currentDomains[cur].getPermissions(), currentDomains[cur].getClassLoader(), p);
            pd[cur] = newPD;
        }
    }
    // copy assigned domains
    if (assignedDomains != null) {
        System.arraycopy(assignedDomains, 0, pd, cur, assignedDomains.length);
    }
    return pd;
}
Also used : ProtectionDomain(java.security.ProtectionDomain) Principal(java.security.Principal)

Example 82 with ProtectionDomain

use of java.security.ProtectionDomain in project byte-buddy by raphw.

the class ClassLoadingStrategyDefaultTest method testObjectProperties.

@Test
public void testObjectProperties() throws Exception {
    ObjectPropertyAssertion.of(ClassLoadingStrategy.Default.class).apply();
    ObjectPropertyAssertion.of(ClassLoadingStrategy.Default.WrappingDispatcher.class).create(new ObjectPropertyAssertion.Creator<AccessControlContext>() {

        @Override
        public AccessControlContext create() {
            return new AccessControlContext(new ProtectionDomain[] { mock(ProtectionDomain.class) });
        }
    }).apply();
    ObjectPropertyAssertion.of(ClassLoadingStrategy.Default.InjectionDispatcher.class).create(new ObjectPropertyAssertion.Creator<AccessControlContext>() {

        @Override
        public AccessControlContext create() {
            return new AccessControlContext(new ProtectionDomain[] { mock(ProtectionDomain.class) });
        }
    }).skipSynthetic().apply();
}
Also used : ProtectionDomain(java.security.ProtectionDomain) AccessControlContext(java.security.AccessControlContext) ObjectPropertyAssertion(net.bytebuddy.test.utility.ObjectPropertyAssertion) Test(org.junit.Test)

Example 83 with ProtectionDomain

use of java.security.ProtectionDomain in project byte-buddy by raphw.

the class AgentBuilderDefaultTest method testBootstrapClassLoaderCapableInjectorFactoryReflection.

@Test
public void testBootstrapClassLoaderCapableInjectorFactoryReflection() throws Exception {
    AgentBuilder.Default.BootstrapInjectionStrategy bootstrapInjectionStrategy = mock(AgentBuilder.Default.BootstrapInjectionStrategy.class);
    ClassLoader classLoader = mock(ClassLoader.class);
    ProtectionDomain protectionDomain = mock(ProtectionDomain.class);
    assertThat(new AgentBuilder.Default.Transformation.Simple.Resolution.BootstrapClassLoaderCapableInjectorFactory(bootstrapInjectionStrategy, classLoader, protectionDomain).resolve(), is((ClassInjector) new ClassInjector.UsingReflection(classLoader, protectionDomain)));
    verifyZeroInteractions(bootstrapInjectionStrategy);
}
Also used : ProtectionDomain(java.security.ProtectionDomain) ClassInjector(net.bytebuddy.dynamic.loading.ClassInjector) Test(org.junit.Test)

Example 84 with ProtectionDomain

use of java.security.ProtectionDomain in project byte-buddy by raphw.

the class AgentBuilderDefaultTest method testBootstrapClassLoaderCapableInjectorFactoryInstrumentation.

@Test
public void testBootstrapClassLoaderCapableInjectorFactoryInstrumentation() throws Exception {
    AgentBuilder.Default.BootstrapInjectionStrategy bootstrapInjectionStrategy = mock(AgentBuilder.Default.BootstrapInjectionStrategy.class);
    ProtectionDomain protectionDomain = mock(ProtectionDomain.class);
    ClassInjector classInjector = mock(ClassInjector.class);
    when(bootstrapInjectionStrategy.make(protectionDomain)).thenReturn(classInjector);
    assertThat(new AgentBuilder.Default.Transformation.Simple.Resolution.BootstrapClassLoaderCapableInjectorFactory(bootstrapInjectionStrategy, null, protectionDomain).resolve(), is(classInjector));
    verify(bootstrapInjectionStrategy).make(protectionDomain);
    verifyNoMoreInteractions(bootstrapInjectionStrategy);
}
Also used : ProtectionDomain(java.security.ProtectionDomain) ClassInjector(net.bytebuddy.dynamic.loading.ClassInjector) Test(org.junit.Test)

Example 85 with ProtectionDomain

use of java.security.ProtectionDomain in project ratpack by ratpack.

the class ClosureUtil method findScript.

public static Path findScript(Closure<?> closure) {
    Class<?> clazz = closure.getClass();
    ProtectionDomain protectionDomain = clazz.getProtectionDomain();
    CodeSource codeSource = protectionDomain.getCodeSource();
    URL location = codeSource.getLocation();
    URI uri;
    try {
        uri = location.toURI();
    } catch (URISyntaxException e) {
        return null;
    }
    Path path;
    if (uri.toString().startsWith("file:/groovy/")) {
        path = findScriptByAnnotation(closure);
    } else {
        path = Paths.get(uri);
    }
    if (path != null && Files.exists(path)) {
        return path;
    } else {
        return null;
    }
}
Also used : ScriptPath(ratpack.groovy.script.internal.ScriptPath) Path(java.nio.file.Path) ProtectionDomain(java.security.ProtectionDomain) URISyntaxException(java.net.URISyntaxException) CodeSource(java.security.CodeSource) URI(java.net.URI) URL(java.net.URL)

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