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;
}
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();
}
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);
}
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);
}
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;
}
}
Aggregations