Java Code Examples for java.security.ProtectionDomain

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project arquillian-container-gae, under directory /gae-embedded/src/main/java/org/jboss/arquillian/container/appengine/embedded/.

Source file: AppEngineSetup.java

  24 
vote

/** 
 * Add class owner location to java.ext.dirs. This method should be invoked in privileged block.
 * @param clazz the class
 */
static void addToJavaExtDirs(Class<?> clazz){
  if (clazz == null)   throw new IllegalArgumentException("Null class");
  ProtectionDomain domain=clazz.getProtectionDomain();
  CodeSource source=domain.getCodeSource();
  URL location=source.getLocation();
  String addon=location.getPath();
  String ext=System.getProperty("java.ext.dirs");
  if (ext == null) {
    System.setProperty("java.ext.dirs",addon);
  }
 else {
    System.setProperty("java.ext.dirs",ext + File.pathSeparator + addon);
  }
}
 

Example 2

From project james-hupa, under directory /client/src/main/java/org/apache/hupa/.

Source file: Launcher.java

  22 
vote

public static void main(String[] args) throws Exception {
  int port=Integer.parseInt(System.getProperty("port","8282"));
  String bindAddress=System.getProperty("host","0.0.0.0");
  InetSocketAddress a=new InetSocketAddress(bindAddress,port);
  Server server=new Server(a);
  ProtectionDomain domain=Launcher.class.getProtectionDomain();
  URL location=domain.getCodeSource().getLocation();
  WebAppContext webapp=new WebAppContext();
  webapp.setContextPath("/");
  webapp.setWar(location.toExternalForm());
  server.setHandler(webapp);
  server.start();
  server.join();
}
 

Example 3

From project jbosgi-framework, under directory /itest/src/test/java/org/jboss/test/osgi/framework/fragments/.

Source file: FragmentTestCase.java

  22 
vote

@Test public void testProtectionDomainEquality() throws Exception {
  Bundle hostA=installBundle(getHostA());
  Bundle fragA=installBundle(getFragmentA());
  hostA.start();
  assertLoadClass(hostA,FragBeanA.class.getName());
  Class<?> fragBeanClass=hostA.loadClass(FragBeanA.class.getName());
  ProtectionDomain fragDomain=fragBeanClass.getProtectionDomain();
  assertLoadClass(hostA,SubBeanA.class.getName());
  Class<?> hostBeanClass=hostA.loadClass(SubBeanA.class.getName());
  ProtectionDomain hostDomain=hostBeanClass.getProtectionDomain();
  assertNotSame(hostDomain,fragDomain);
  hostA.uninstall();
  fragA.uninstall();
}
 

Example 4

From project qi4j-libraries, under directory /http/src/main/java/org/qi4j/library/http/.

Source file: JettyMixin.java

  22 
vote

private String rootResourceBase(String resourcePath){
  if (resourcePath.length() == 0) {
    ProtectionDomain domain=getClass().getProtectionDomain();
    CodeSource source=domain.getCodeSource();
    URL location=source.getLocation();
    String basePath=location.getPath();
    File base=new File(basePath);
    return base.getAbsolutePath();
  }
 else {
    return resourcePath;
  }
}
 

Example 5

From project rundeck, under directory /rundeck-launcher/launcher/src/main/java/com/dtolabs/rundeck/.

Source file: ExpandRunServer.java

  22 
vote

/** 
 * Return file for the enclosing jar
 * @return
 * @throws URISyntaxException
 */
private static File thisJarFile(){
  final ProtectionDomain protectionDomain=ExpandRunServer.class.getProtectionDomain();
  final URL location=protectionDomain.getCodeSource().getLocation();
  try {
    return new File(location.toURI());
  }
 catch (  URISyntaxException e) {
    throw new RuntimeException(e);
  }
}
 

Example 6

From project android-client_1, under directory /src/org/apache/harmony/javax/security/auth/.

Source file: SubjectDomainCombiner.java

  21 
vote

/** 
 * 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 twoprovided arrays, or  {@code null}.
 * @see ProtectionDomain
 */
public ProtectionDomain[] combine(ProtectionDomain[] currentDomains,ProtectionDomain[] assignedDomains){
  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];
  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;
    }
  }
  if (assignedDomains != null) {
    System.arraycopy(assignedDomains,0,pd,cur,assignedDomains.length);
  }
  return pd;
}
 

Example 7

From project AsmackService, under directory /src/org/apache/harmony/javax/security/auth/.

Source file: SubjectDomainCombiner.java

  21 
vote

/** 
 * 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 twoprovided arrays, or  {@code null}.
 * @see ProtectionDomain
 */
public ProtectionDomain[] combine(ProtectionDomain[] currentDomains,ProtectionDomain[] assignedDomains){
  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];
  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;
    }
  }
  if (assignedDomains != null) {
    System.arraycopy(assignedDomains,0,pd,cur,assignedDomains.length);
  }
  return pd;
}
 

Example 8

From project core_5, under directory /exo.core.component.security.core/src/test/java/org/exoplatform/services/security/.

Source file: BaseSecurityTest.java

  21 
vote

/** 
 * Run privileged action with given privileges.
 */
public <T>T doActionWithPermissions(PrivilegedExceptionAction<T> action,Permission... permissions) throws Exception {
  Permissions allPermissions=new Permissions();
  for (  Permission permission : permissions) {
    if (permission != null) {
      allPermissions.add(permission);
    }
  }
  ProtectionDomain[] protectionDomains=new ProtectionDomain[]{new ProtectionDomain(new CodeSource(getCodeSource(),(java.security.cert.Certificate[])null),allPermissions)};
  return AccessController.doPrivileged(action,new AccessControlContext(protectionDomains));
}
 

Example 9

From project indextank-engine, under directory /cojen-2.2.1-sources/org/cojen/classfile/.

Source file: RuntimeClassFile.java

  21 
vote

private static ProtectionDomain prepareDomain(ProtectionDomain domain,ClassLoader loader){
  if (domain == null) {
    return null;
  }
  return new ProtectionDomain(domain.getCodeSource(),domain.getPermissions(),loader,domain.getPrincipals());
}
 

Example 10

From project jahspotify, under directory /executable-war/src/main/java/jahspotify/web/.

Source file: EmbeddedJettyServer.java

  21 
vote

public static void main(String[] args) throws Exception {
  int port=Integer.parseInt(System.getProperty("port","8080"));
  System.out.println("port = " + port);
  Server server=new Server();
  Connector connector=new SelectChannelConnector();
  connector.setPort(port);
  server.addConnector(connector);
  ProtectionDomain domain=EmbeddedJettyServer.class.getProtectionDomain();
  URL location=domain.getCodeSource().getLocation();
  System.out.println("location = " + location);
  WebAppContext webapp=new WebAppContext();
  webapp.setContextPath("/jahspotify");
  webapp.setDescriptor(location.toExternalForm() + "/WEB-INF/web.xml");
  webapp.setServer(server);
  webapp.setWar(location.toExternalForm());
  server.setHandler(webapp);
  server.start();
  server.join();
}
 

Example 11

From project kernel_1, under directory /exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/secure/.

Source file: AbstractSecureCollectionsTest.java

  21 
vote

/** 
 * Run privileged action with given privileges.
 */
protected <T>T doActionWithPermissions(PrivilegedExceptionAction<T> action,Permission... permissions) throws PrivilegedActionException {
  Permissions allPermissions=new Permissions();
  for (  Permission permission : permissions) {
    if (permission != null) {
      allPermissions.add(permission);
    }
  }
  ProtectionDomain[] protectionDomains=new ProtectionDomain[]{new ProtectionDomain(new CodeSource(getCodeSource(),(java.security.cert.Certificate[])null),allPermissions)};
  return AccessController.doPrivileged(action,new AccessControlContext(protectionDomains));
}
 

Example 12

From project scisoft-ui, under directory /uk.ac.diamond.scisoft/src/uk/ac/diamond/scisoft/.

Source file: Activator.java

  21 
vote

/** 
 * (non-Javadoc)
 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
 */
@Override public void start(BundleContext context) throws Exception {
  super.start(context);
  plugin=this;
  try {
    String logloc=System.getProperty("log.folder");
    if (logloc == null || "".equals(logloc)) {
      System.out.println("Log folder property not set, setting this manually to the temp directory");
      String tmpDir=System.getProperty("user.home") + "/.dawn/";
      System.setProperty("log.folder",tmpDir);
    }
    System.out.println("log.folder java property set to '" + System.getProperty("log.folder") + "'");
    System.out.println("Starting to Configure Logger");
    LoggerContext loggerContext=(LoggerContext)LoggerFactory.getILoggerFactory();
    loggerContext.reset();
    System.out.println("Logger Context Reset");
    ProtectionDomain pd=Activator.class.getProtectionDomain();
    CodeSource cs=pd.getCodeSource();
    URL url=cs.getLocation();
    File file=new File(url.getFile(),"logging/log_configuration.xml");
    url=file.toURI().toURL();
    if (file.exists()) {
      System.out.println("Logging Configuration File found at '" + url + "'");
    }
 else {
      System.out.println("Logging Configuration File Not found at '" + url + "'");
    }
    JoranConfigurator configurator=new JoranConfigurator();
    configurator.setContext(loggerContext);
    String host=url.getHost();
    if (host == null || host.length() == 0)     configurator.doConfigure(file);
 else     configurator.doConfigure(url);
    System.out.println("Logging Configuration complete");
  }
 catch (  Exception e) {
    System.out.println("Could not set up logging properly, loggin to stdout for now, error follows");
    e.printStackTrace();
    LoggerContext loggerContext=(LoggerContext)LoggerFactory.getILoggerFactory();
    loggerContext.reset();
  }
}
 

Example 13

From project snappy-java, under directory /src/main/java/org/xerial/snappy/.

Source file: SnappyLoader.java

  21 
vote

private static Class<?> injectSnappyNativeLoader(){
  try {
    final String nativeLoaderClassName="org.xerial.snappy.SnappyNativeLoader";
    ClassLoader rootClassLoader=getRootClassLoader();
    byte[] byteCode=getByteCode("/org/xerial/snappy/SnappyNativeLoader.bytecode");
    final String[] classesToPreload=new String[]{"org.xerial.snappy.SnappyNativeAPI","org.xerial.snappy.SnappyNative","org.xerial.snappy.SnappyErrorCode"};
    List<byte[]> preloadClassByteCode=new ArrayList<byte[]>(classesToPreload.length);
    for (    String each : classesToPreload) {
      preloadClassByteCode.add(getByteCode(String.format("/%s.class",each.replaceAll("\\.","/"))));
    }
    Class<?> classLoader=Class.forName("java.lang.ClassLoader");
    Method defineClass=classLoader.getDeclaredMethod("defineClass",new Class[]{String.class,byte[].class,int.class,int.class,ProtectionDomain.class});
    ProtectionDomain pd=System.class.getProtectionDomain();
    defineClass.setAccessible(true);
    try {
      defineClass.invoke(rootClassLoader,nativeLoaderClassName,byteCode,0,byteCode.length,pd);
      for (int i=0; i < classesToPreload.length; ++i) {
        byte[] b=preloadClassByteCode.get(i);
        defineClass.invoke(rootClassLoader,classesToPreload[i],b,0,b.length,pd);
      }
    }
  finally {
      defineClass.setAccessible(false);
    }
    return rootClassLoader.loadClass(nativeLoaderClassName);
  }
 catch (  Exception e) {
    e.printStackTrace(System.err);
    throw new SnappyError(SnappyErrorCode.FAILED_TO_LOAD_NATIVE_LIBRARY,e.getMessage());
  }
}
 

Example 14

From project springside4, under directory /examples/showcase/src/main/java/org/springside/examples/showcase/.

Source file: Main.java

  21 
vote

private static Server createServer(String contextPath,int port){
  System.setProperty("org.apache.jasper.compiler.disablejsr199","true");
  Server server=new Server(port);
  server.setStopAtShutdown(true);
  ProtectionDomain protectionDomain=Main.class.getProtectionDomain();
  URL location=protectionDomain.getCodeSource().getLocation();
  String warFile=location.toExternalForm();
  WebAppContext context=new WebAppContext(warFile,contextPath);
  context.setServer(server);
  String currentDir=new File(location.getPath()).getParent();
  File workDir=new File(currentDir,"work");
  context.setTempDirectory(workDir);
  server.setHandler(context);
  return server;
}
 

Example 15

From project wissl, under directory /src/main/java/fr/msch/wissl/launcher/.

Source file: Launcher.java

  21 
vote

static void startServer(int port){
  Server server=new Server();
  SocketConnector connector=new SocketConnector();
  connector.setPort(port);
  server.setConnectors(new Connector[]{connector});
  WebAppContext context=new WebAppContext();
  context.setServer(server);
  context.setContextPath("/");
  ProtectionDomain protectionDomain=Launcher.class.getProtectionDomain();
  URL location=protectionDomain.getCodeSource().getLocation();
  context.setWar(location.toExternalForm());
  server.setHandler(context);
  try {
    server.start();
  }
 catch (  Exception e) {
    e.printStackTrace();
    error("Failed to start server");
  }
}
 

Example 16

From project blueprint-namespaces, under directory /blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/.

Source file: BlueprintContainerImpl.java

  19 
vote

private AccessControlContext createAccessControlContext(){
  return new AccessControlContext(AccessController.getContext(),new DomainCombiner(){
    public ProtectionDomain[] combine(    ProtectionDomain[] arg0,    ProtectionDomain[] arg1){
      return new ProtectionDomain[]{new ProtectionDomain(null,null){
        public boolean implies(        Permission permission){
          return bundleContext.getBundle().hasPermission(permission);
        }
      }
};
    }
  }
);
}
 

Example 17

From project byteman, under directory /agent/src/main/java/org/jboss/byteman/agent/.

Source file: Transformer.java

  19 
vote

/** 
 * use the supplied bytes to define a class and try creating an instance via the empty constructor printing details of any errors which occur
 * @param classname
 * @param protectionDomain
 * @param bytes
 * @return the bytes if all goes well otherwise null
 */
public byte[] verify(String classname,ProtectionDomain protectionDomain,byte[] bytes){
  try {
    Class clazz=super.defineClass(classname,bytes,0,bytes.length,protectionDomain);
    clazz.newInstance();
  }
 catch (  Throwable th) {
    System.out.println("Transformer:verifyTransformedBytes " + th);
    return null;
  }
  return bytes;
}
 

Example 18

From project capedwarf-blue, under directory /bytecode/src/main/java/org/jboss/capedwarf/bytecode/.

Source file: JavassistTransformer.java

  19 
vote

public byte[] transform(ClassLoader loader,String className,Class<?> classBeingRedefined,ProtectionDomain protectionDomain,byte[] classfileBuffer) throws IllegalClassFormatException {
  try {
    ClassPool pool=new ClassPool();
    pool.appendClassPath(new LoaderClassPath(loader));
    CtClass clazz=pool.makeClass(new ByteArrayInputStream(classfileBuffer));
    transform(clazz);
    return clazz.toBytecode();
  }
 catch (  Exception e) {
    throw new IllegalClassFormatException(e.getMessage());
  }
}
 

Example 19

From project DeuceSTM, under directory /src/java/org/deuce/transform/asm/.

Source file: Agent.java

  19 
vote

public byte[] transform(ClassLoader loader,String className,Class<?> classBeingRedefined,ProtectionDomain protectionDomain,byte[] classfileBuffer) throws IllegalClassFormatException {
  try {
    if (loader != null)     return transform(className,classfileBuffer,false).get(0).getBytecode();
  }
 catch (  Exception e) {
    logger.log(Level.SEVERE,"Fail on class transform: " + className,e);
  }
  return classfileBuffer;
}
 

Example 20

From project dimdwarf, under directory /dimdwarf-aop/src/main/java/net/orfjackal/dimdwarf/aop/conf/.

Source file: AbstractTransformationChain.java

  19 
vote

public byte[] transform(ClassLoader loader,String className,Class<?> classBeingRedefined,ProtectionDomain protectionDomain,byte[] classfileBuffer) throws IllegalClassFormatException {
  ClassReader cr=new ClassReader(classfileBuffer);
  ClassWriter cw;
  if (enableAdditiveTransformationOptimization()) {
    cw=new ClassWriter(cr,0);
  }
 else {
    cw=new ClassWriter(0);
  }
  ClassVisitor cv=getAdapters(cw);
  cr.accept(cv,0);
  return cw.toByteArray();
}
 

Example 21

From project etherpad, under directory /infrastructure/rhino1_7R1/src/org/mozilla/javascript/.

Source file: SecurityUtilities.java

  19 
vote

public static ProtectionDomain getProtectionDomain(final Class clazz){
  return (ProtectionDomain)AccessController.doPrivileged(new PrivilegedAction(){
    public Object run(){
      return clazz.getProtectionDomain();
    }
  }
);
}
 

Example 22

From project fakereplace, under directory /core/src/main/java/org/fakereplace/transformation/.

Source file: ClassLoaderTransformer.java

  19 
vote

@Override public boolean transform(final ClassLoader loader,final String className,final Class<?> classBeingRedefined,final ProtectionDomain protectionDomain,final ClassFile file) throws IllegalClassFormatException, BadBytecode {
  if (classBeingRedefined != null && ClassLoader.class.isAssignableFrom(classBeingRedefined)) {
    return ClassLoaderInstrumentation.redefineClassLoader(file);
  }
 else   if (classBeingRedefined == null && className.endsWith("ClassLoader")) {
    return ClassLoaderInstrumentation.redefineClassLoader(file);
  }
  return false;
}
 

Example 23

From project glg2d, under directory /src/test/java/glg2d/misc/.

Source file: InstrumentPaint.java

  19 
vote

public static void agentmain(String agentargs,Instrumentation instrumentation) throws UnmodifiableClassException, NotFoundException {
  final ClassPool pool=ClassPool.getDefault();
  final String snippet=getInstrumentationCode();
  instrumentation.addTransformer(new ClassFileTransformer(){
    @Override public byte[] transform(    ClassLoader loader,    String className,    Class<?> classBeingRedefined,    ProtectionDomain protectionDomain,    byte[] classfileBuffer) throws IllegalClassFormatException {
      if (!className.equals("javax/swing/JComponent")) {
        return classfileBuffer;
      }
      System.err.println("Redefining: " + className);
      try {
        CtClass c=pool.makeClass(new ByteArrayInputStream(classfileBuffer));
        CtMethod method=c.getMethod("paint","(Ljava/awt/Graphics;)V");
        method.insertBefore(snippet);
        return c.toBytecode();
      }
 catch (      Exception e) {
        e.printStackTrace();
        return classfileBuffer;
      }
    }
  }
,true);
  instrumentation.retransformClasses(JComponent.class);
}
 

Example 24

From project handlebars.java_1, under directory /handlebars-parboiled-processor/src/main/java/com/github/jknack/handlebars/.

Source file: ParboiledAgent.java

  19 
vote

public static void premain(final String args,final Instrumentation instrumentation) throws Exception {
  final String actionClass=INTERNAL_PATH + "/Action$";
  System.out.println("Action class pattern: " + actionClass);
  final String parserClass=INTERNAL_PATH + "/Parser$$";
  System.out.println("Parser class pattern: " + parserClass);
  instrumentation.addTransformer(new ClassFileTransformer(){
    @Override public byte[] transform(    final ClassLoader loader,    final String className,    final Class<?> classBeingRedefined,    final ProtectionDomain protectionDomain,    final byte[] byteCode) throws IllegalClassFormatException {
      if (className.startsWith(actionClass) || className.startsWith(parserClass)) {
        write(className,byteCode);
      }
      return byteCode;
    }
  }
);
}
 

Example 25

From project java-gae-verifier, under directory /src/org/mozilla/javascript/.

Source file: SecurityUtilities.java

  19 
vote

public static ProtectionDomain getProtectionDomain(final Class<?> clazz){
  return (ProtectionDomain)AccessController.doPrivileged(new PrivilegedAction<Object>(){
    public Object run(){
      return clazz.getProtectionDomain();
    }
  }
);
}
 

Example 26

From project javassist, under directory /src/main/javassist/.

Source file: ClassPool.java

  19 
vote

public Object run() throws Exception {
  Class cl=Class.forName("java.lang.ClassLoader");
  defineClass1=cl.getDeclaredMethod("defineClass",new Class[]{String.class,byte[].class,int.class,int.class});
  defineClass2=cl.getDeclaredMethod("defineClass",new Class[]{String.class,byte[].class,int.class,int.class,ProtectionDomain.class});
  definePackage=cl.getDeclaredMethod("definePackage",new Class[]{String.class,String.class,String.class,String.class,String.class,String.class,String.class,java.net.URL.class});
  return null;
}
 

Example 27

From project jboss-classfilewriter, under directory /src/main/java/org/jboss/classfilewriter/.

Source file: ClassFile.java

  19 
vote

public Object run() throws Exception {
  Class<?> cl=Class.forName("java.lang.ClassLoader",false,null);
  defineClass1=cl.getDeclaredMethod("defineClass",new Class[]{String.class,byte[].class,int.class,int.class});
  defineClass1.setAccessible(true);
  defineClass2=cl.getDeclaredMethod("defineClass",new Class[]{String.class,byte[].class,int.class,int.class,ProtectionDomain.class});
  defineClass2.setAccessible(true);
  return null;
}
 

Example 28

From project jboss-modules, under directory /src/main/java/org/jboss/modules/.

Source file: ConcurrentClassLoader.java

  19 
vote

/** 
 * Atomically define or load the named class.  If the class is already defined, the existing class is returned.
 * @param className the class name to define or load
 * @param bytes the bytes to use to define the class
 * @param off the offset into the byte array at which the class bytes begin
 * @param len the number of bytes in the class
 * @param protectionDomain the protection domain for the defined class
 * @return the class
 */
protected final Class<?> defineOrLoadClass(final String className,final byte[] bytes,int off,int len,ProtectionDomain protectionDomain){
  try {
    final Class<?> definedClass=defineClass(className,bytes,off,len,protectionDomain);
    return definedClass;
  }
 catch (  LinkageError e) {
    final Class<?> loadedClass=findLoadedClass(className);
    if (loadedClass != null) {
      return loadedClass;
    }
    throw e;
  }
}
 

Example 29

From project jboss-rmi-api_spec, under directory /src/main/java/org/jboss/com/sun/corba/se/impl/orbutil/.

Source file: ORBUtility.java

  19 
vote

public static String getClassSecurityInfo(final Class<?> cl){
  String result=AccessController.doPrivileged(new PrivilegedAction<String>(){
    public String run(){
      StringBuffer sb=new StringBuffer(500);
      ProtectionDomain pd=cl.getProtectionDomain();
      Policy policy=Policy.getPolicy();
      PermissionCollection pc=policy.getPermissions(pd);
      sb.append("\nPermissionCollection ");
      sb.append(pc.toString());
      sb.append(pd.toString());
      return sb.toString();
    }
  }
);
  return result;
}
 

Example 30

From project jcarder, under directory /src/com/enea/jcarder/agent/instrument/.

Source file: ClassTransformer.java

  19 
vote

public byte[] transform(final ClassLoader classLoader,final String jvmInternalClassName,final Class<?> classBeingRedefined,final ProtectionDomain protectionDomain,final byte[] originalClassBuffer) throws IllegalClassFormatException {
  String className=jvmInternalClassName.replace('/','.');
  try {
    return instrument(classLoader,originalClassBuffer,className);
  }
 catch (  Throwable t) {
    mLogger.severe("Failed to transform the class " + className + ": "+ t.getMessage());
    dumpClassToFile(originalClassBuffer,mOriginalClassesDir,className);
    return null;
  }
}
 

Example 31

From project JDave, under directory /jdave-unfinalizer/src/java/jdave/unfinalizer/internal/.

Source file: DelegatingClassFileTransformer.java

  19 
vote

public byte[] transform(final ClassLoader loader,final String className,final Class<?> classBeingRedefined,final ProtectionDomain protectionDomain,final byte[] classfileBuffer){
  if (loader == null) {
    return classfileBuffer;
  }
  return delegator.transform(classfileBuffer);
}
 

Example 32

From project jeppetto, under directory /jeppetto-enhance/src/main/java/org/iternine/jeppetto/enhance/.

Source file: ClassLoadingUtil.java

  19 
vote

/** 
 * Installs the given  {@code CtClass} into the given class-loader and returnsit as a new class.
 * @param ctClass class to load
 * @param loader class-loader to install into
 * @param domain protection domain, may be null
 * @param < T > class type
 * @return new class
 * @throws CannotCompileException if the class cannot be compiled
 */
public static <T>Class<T> toClass(CtClass ctClass,ClassLoader loader,ProtectionDomain domain) throws CannotCompileException {
  try {
    byte[] byteCode=ctClass.toBytecode();
    if (domain == null) {
      return bruteForceDefineClass(DEFINE_METHOD_NO_DOMAIN,loader,ctClass.getName(),byteCode,0,byteCode.length);
    }
 else {
      return bruteForceDefineClass(DEFINE_METHOD_WITH_DOMAIN,loader,ctClass.getName(),byteCode,0,byteCode.length,domain);
    }
  }
 catch (  Exception e) {
    ExceptionUtil.propagateIfInstanceOf(e,CannotCompileException.class);
    ExceptionUtil.propagateIfPossible(e);
    throw new CannotCompileException(e);
  }
 finally {
    ctClass.prune();
  }
}
 

Example 33

From project jokre, under directory /src/main/java/org/jboss/jokre/agent/.

Source file: Jokre.java

  19 
vote

/** 
 * transformer entry point
 * @param loader
 * @param className
 * @param classBeingRedefined
 * @param protectionDomain
 * @param classfileBuffer
 * @return
 * @throws IllegalClassFormatException
 */
public byte[] transform(ClassLoader loader,String className,Class<?> classBeingRedefined,ProtectionDomain protectionDomain,byte[] classfileBuffer) throws IllegalClassFormatException {
  byte[] bytes=classfileBuffer;
  if (isMapImplementorClass(className)) {
    bytes=jokreTransformer.extendMapImplementorAPI(loader,className,classBeingRedefined,protectionDomain,bytes);
  }
  String classNameExternal=className.replace('/','.');
  List<String> methodNames=updated.listMethods(classNameExternal);
  if (methodNames != null) {
    bytes=jokreTransformer.transform(loader,className,classBeingRedefined,protectionDomain,bytes,methodNames);
    updated.transformed(classNameExternal,methodNames);
  }
  return bytes;
}
 

Example 34

From project makegood, under directory /com.piece_framework.makegood.aspect/lib/javassist-3.11.0/src/main/javassist/.

Source file: ClassPool.java

  19 
vote

public Object run() throws Exception {
  Class cl=Class.forName("java.lang.ClassLoader");
  defineClass1=cl.getDeclaredMethod("defineClass",new Class[]{String.class,byte[].class,int.class,int.class});
  defineClass2=cl.getDeclaredMethod("defineClass",new Class[]{String.class,byte[].class,int.class,int.class,ProtectionDomain.class});
  return null;
}
 

Example 35

From project openengsb-framework, under directory /components/weaver/service/src/main/java/org/openengsb/core/weaver/service/internal/.

Source file: ModelAgent.java

  19 
vote

@Override public byte[] transform(ClassLoader classLoader,String className,Class<?> clazz,ProtectionDomain domain,byte[] bytecode) throws IllegalClassFormatException {
  if (!shouldBeEnhanced(className)) {
    return bytecode;
  }
  try {
    byte[] result=ManipulationUtils.enhanceModel(bytecode);
    return result != null ? result : bytecode;
  }
 catch (  IOException e) {
    LOGGER.error("IOException while enhancing model",e);
  }
catch (  CannotCompileException e) {
    LOGGER.error("CannotCompileException while enhancing model",e);
  }
  return bytecode;
}
 

Example 36

From project openwebbeans, under directory /webbeans-impl/src/main/java/org/apache/webbeans/proxy/asm/.

Source file: AsmProxyFactory.java

  19 
vote

public Method run(){
  try {
    Method mtd=unsafeClass.getDeclaredMethod("defineClass",String.class,byte[].class,int.class,int.class,ClassLoader.class,ProtectionDomain.class);
    mtd.setAccessible(true);
    return mtd;
  }
 catch (  Exception e) {
    throw new IllegalStateException("Cannot get sun.misc.Unsafe.defineClass",e);
  }
}
 

Example 37

From project pad, under directory /infrastructure/rhino1_7R1/src/org/mozilla/javascript/.

Source file: SecurityUtilities.java

  19 
vote

public static ProtectionDomain getProtectionDomain(final Class clazz){
  return (ProtectionDomain)AccessController.doPrivileged(new PrivilegedAction(){
    public Object run(){
      return clazz.getProtectionDomain();
    }
  }
);
}
 

Example 38

From project pepe, under directory /pepe/src/edu/stanford/pepe/.

Source file: PepeAgent.java

  19 
vote

/** 
 * Invoked by the JVM when a class is first loaded. Initiates the bytecode transformation.
 */
@SuppressWarnings("unchecked") public byte[] transform(ClassLoader loader,String className,Class<?> classBeingRedefined,ProtectionDomain protectionDomain,byte[] classfileBuffer) throws IllegalClassFormatException {
  if ((!InstrumentationPolicy.isTypeInstrumentable(className) || InstrumentationPolicy.isSpecialJavaClass(className)) && !InstrumentationPolicy.isSpecialPepeClass(className)) {
    return null;
  }
  try {
    ClassNode cn=new ClassNode();
    ClassReader cr=new ClassReader(classfileBuffer);
    cr.accept(cn,0);
    for (    FieldNode fn : (List<FieldNode>)cn.fields) {
      if (fn.name.equals(ShadowFieldRewriter.TAINT_MARK)) {
        logger.info("Skipping already instrumented class " + cn.name);
        return null;
      }
    }
    logger.info("Transforming class " + className);
    return instrumentClass(cn);
  }
 catch (  Exception t) {
    logger.severe("PEPE: Exception while transforming " + className);
    t.printStackTrace();
    logger.severe("PEPE: Not transforming " + className);
    return null;
  }
catch (  Error e) {
    logger.severe("PEPE: Error while transforming " + className);
    e.printStackTrace();
    logger.severe("PEPE: Not transforming " + className);
    throw new Error(e);
  }
}
 

Example 39

From project platform_external_javassist, under directory /src/main/javassist/.

Source file: ClassPool.java

  19 
vote

public Object run() throws Exception {
  Class cl=Class.forName("java.lang.ClassLoader");
  defineClass1=cl.getDeclaredMethod("defineClass",new Class[]{String.class,byte[].class,int.class,int.class});
  defineClass2=cl.getDeclaredMethod("defineClass",new Class[]{String.class,byte[].class,int.class,int.class,ProtectionDomain.class});
  return null;
}
 

Example 40

From project revoc, under directory /src/main/java/no/kantega/labs/revoc/agent/.

Source file: RevocClassTransformer.java

  19 
vote

public byte[] transform(ClassLoader classLoader,String className,Class<?> classBeingRedefined,ProtectionDomain protectionDomain,byte[] classFileBuffer) throws IllegalClassFormatException {
  if (!shouldFilter(classLoader,className,packages)) {
    return null;
  }
 else {
    return instrumentClass(className,classFileBuffer,classLoader);
  }
}
 

Example 41

From project Rhino-for-J2ME-CDC1.1, under directory /src/org/mozilla/javascript/.

Source file: SecurityUtilities.java

  19 
vote

public static ProtectionDomain getProtectionDomain(final Class clazz){
  return (ProtectionDomain)AccessController.doPrivileged(new PrivilegedAction(){
    public Object run(){
      return clazz.getProtectionDomain();
    }
  }
);
}
 

Example 42

From project slf4j_1, under directory /slf4j-ext/src/main/java/org/slf4j/instrumentation/.

Source file: LogTransformer.java

  19 
vote

public byte[] transform(ClassLoader loader,String className,Class<?> clazz,ProtectionDomain domain,byte[] bytes){
  try {
    return transform0(className,clazz,domain,bytes);
  }
 catch (  Exception e) {
    System.err.println("Could not instrument " + className);
    e.printStackTrace();
    return bytes;
  }
}
 

Example 43

From project spring-js, under directory /src/main/java/org/springframework/context/weaving/.

Source file: AspectJWeavingEnabler.java

  19 
vote

public byte[] transform(ClassLoader loader,String className,Class<?> classBeingRedefined,ProtectionDomain protectionDomain,byte[] classfileBuffer) throws IllegalClassFormatException {
  if (className.startsWith("org.aspectj") || className.startsWith("org/aspectj")) {
    return classfileBuffer;
  }
  return this.delegate.transform(loader,className,classBeingRedefined,protectionDomain,classfileBuffer);
}
 

Example 44

From project titanpad, under directory /infrastructure/rhino1_7R1/src/org/mozilla/javascript/.

Source file: SecurityUtilities.java

  19 
vote

public static ProtectionDomain getProtectionDomain(final Class clazz){
  return (ProtectionDomain)AccessController.doPrivileged(new PrivilegedAction(){
    public Object run(){
      return clazz.getProtectionDomain();
    }
  }
);
}
 

Example 45

From project TProfiler, under directory /src/main/java/com/taobao/profile/instrument/.

Source file: ProfTransformer.java

  19 
vote

public byte[] transform(ClassLoader loader,String className,Class<?> classBeingRedefined,ProtectionDomain protectionDomain,byte[] classfileBuffer) throws IllegalClassFormatException {
  if (ProfFilter.IsNotNeedInjectClassLoader(loader.getClass().getName())) {
    return classfileBuffer;
  }
  if (!ProfFilter.IsNeedInject(className)) {
    return classfileBuffer;
  }
  if (ProfFilter.IsNotNeedInject(className)) {
    return classfileBuffer;
  }
  if (Manager.instance().isDebugMode()) {
    System.out.println(" ---- TProfiler Debug: " + loader.getClass().getName() + " ---- "+ className);
  }
  Profiler.instrumentClassCount.getAndIncrement();
  try {
    ClassReader reader=new ClassReader(classfileBuffer);
    ClassWriter writer=new ClassWriter(ClassWriter.COMPUTE_MAXS);
    ClassAdapter adapter=new ProfClassAdapter(writer,className);
    reader.accept(adapter,0);
    return writer.toByteArray();
  }
 catch (  Exception e) {
    e.printStackTrace();
    return classfileBuffer;
  }
}
 

Example 46

From project TProfiler_1, under directory /src/main/java/com/taobao/profile/instrument/.

Source file: ProfTransformer.java

  19 
vote

public byte[] transform(ClassLoader loader,String className,Class<?> classBeingRedefined,ProtectionDomain protectionDomain,byte[] classfileBuffer) throws IllegalClassFormatException {
  if (!ProfFilter.IsNeedInject(className)) {
    return classfileBuffer;
  }
  if (ProfFilter.IsNotNeedInject(className)) {
    return classfileBuffer;
  }
  Profiler.instrumentClassCount++;
  try {
    ClassReader reader=new ClassReader(classfileBuffer);
    ClassWriter writer=new ClassWriter(ClassWriter.COMPUTE_MAXS);
    ClassAdapter adapter=new ProfClassAdapter(writer,className);
    reader.accept(adapter,0);
    return writer.toByteArray();
  }
 catch (  Exception e) {
    e.printStackTrace();
    return classfileBuffer;
  }
}
 

Example 47

From project virgo.kernel, under directory /org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/equinox/.

Source file: KernelBundleClassLoader.java

  19 
vote

/** 
 * Constructs a new <code>ServerBundleClassLoader</code>.
 * @param parent the parent <code>ClassLoader</code>.
 * @param delegate the delegate for this ClassLoader</code>
 * @param domain the domain for this ClassLoader</code>
 * @param bundledata the bundledata for this ClassLoader</code>
 * @param classpath the classpath for this ClassLoader</code>
 */
KernelBundleClassLoader(ClassLoader parent,ClassLoaderDelegate delegate,ProtectionDomain domain,BaseData bundledata,String[] classpath){
  super(parent,delegate,domain,bundledata,classpath);
  this.classpath=classpath;
  this.bundleScope=OsgiFrameworkUtils.getScopeName(bundledata.getBundle());
  this.instrumentedPackages=findInstrumentedPackages(bundledata.getBundle());
}