private static Resource[] merge(Resource[] first, Resource[] second) {
    if (ArrayUtil.isEmpty(second)) return first;
    if (ArrayUtil.isEmpty(first)) return second;

    Resource[] tmp = new Resource[first.length + second.length];
    for (int i = 0; i < first.length; i++) {
      tmp[i] = first[i];
    }
    for (int i = 0; i < second.length; i++) {
      tmp[first.length + i] = second[i];
    }
    return tmp;
  }
Example #2
0
 private void checkSize(ConfigWeb config, Resource dir, long maxSize, ResourceFilter filter) {
   if (!dir.exists()) return;
   Resource res = null;
   int count = ArrayUtil.size(filter == null ? dir.list() : dir.list(filter));
   long size = ResourceUtil.getRealSize(dir, filter);
   PrintWriter out = config.getOutWriter();
   SystemOut.printDate(out, "check size of directory [" + dir + "]");
   SystemOut.printDate(out, "- current size	[" + size + "]");
   SystemOut.printDate(out, "- max size 	[" + maxSize + "]");
   int len = -1;
   while (count > 100000 || size > maxSize) {
     Resource[] files = filter == null ? dir.listResources() : dir.listResources(filter);
     if (len == files.length) break; // protect from inifinti loop
     len = files.length;
     for (int i = 0; i < files.length; i++) {
       if (res == null || res.lastModified() > files[i].lastModified()) {
         res = files[i];
       }
     }
     if (res != null) {
       size -= res.length();
       try {
         res.remove(true);
         count--;
       } catch (IOException e) {
         SystemOut.printDate(out, "cannot remove resource " + res.getAbsolutePath());
         break;
       }
     }
     res = null;
   }
 }
Example #3
0
 public void parse(
     IndexWriter writer, URL current, String[] extensions, boolean recurse, long timeout)
     throws IOException {
   translateExtension(extensions);
   if (ArrayUtil.isEmpty(extensions)) extensions = Index.EXTENSIONS;
   _parse(log, writer, null, current, new ArrayList(), extensions, recurse, 0, timeout);
 }
  /** @see railo.runtime.security.ISecurityManager#cloneSecurityManager() */
  public SecurityManager cloneSecurityManager() {
    SecurityManagerImpl sm = new SecurityManagerImpl();

    for (int i = 0; i < accesses.length; i++) {
      sm.accesses[i] = accesses[i];
    }
    if (customFileAccess != null)
      sm.customFileAccess =
          (Resource[]) ArrayUtil.clone(customFileAccess, new Resource[customFileAccess.length]);
    sm.rootDirectory = rootDirectory;
    return sm;
  }
  public void checkFileLocation(Config config, Resource res, String serverPassword)
      throws SecurityException {
    if (res == null || !(res.getResourceProvider() instanceof FileResourceProvider)) {
      return;
    }

    // All
    if (getAccess(TYPE_FILE) == VALUE_ALL) return;
    // Local
    if (getAccess(TYPE_FILE) == VALUE_LOCAL) {
      res = ResourceUtil.getCanonicalResourceEL(res);

      // local
      if (rootDirectory != null) if (ResourceUtil.isChildOf(res, rootDirectory)) return;
      // custom
      if (!ArrayUtil.isEmpty(customFileAccess)) {
        for (int i = 0; i < customFileAccess.length; i++) {
          if (ResourceUtil.isChildOf(res, customFileAccess[i])) return;
        }
      }
      if (isValid(config, serverPassword) || isAdminContext()) return;
      throw new SecurityException(
          createExceptionMessage(res, true), "access is prohibited by security manager");
    }
    // None
    if (isValid(config, serverPassword)) return;

    // custom
    if (!ArrayUtil.isEmpty(customFileAccess)) {
      res = ResourceUtil.getCanonicalResourceEL(res);

      for (int i = 0; i < customFileAccess.length; i++) {
        if (ResourceUtil.isChildOf(res, customFileAccess[i])) return;
      }
    }

    if (isAdminContext()) return;
    throw new SecurityException(
        createExceptionMessage(res, false), "access is prohibited by security manager");
  }
 public Resource[] getCustomFileAccess() {
   if (ArrayUtil.isEmpty(customFileAccess)) return EMPTY_RESOURCE_ARRAY;
   return (Resource[]) ArrayUtil.clone(customFileAccess, new Resource[customFileAccess.length]);
 }
Example #7
0
  private synchronized SessionFactory getSessionFactory(PageContext pc, boolean init)
      throws PageException {
    ApplicationContextPro appContext = ((ApplicationContextPro) pc.getApplicationContext());
    if (!appContext.isORMEnabled())
      throw new ORMException(this, "ORM is not enabled in application.cfc/cfapplication");

    this.hash = hash(appContext);

    // datasource
    String dsn = appContext.getORMDatasource();
    if (StringUtil.isEmpty(dsn))
      throw new ORMException(this, "missing datasource defintion in application.cfc/cfapplication");
    if (!dsn.equalsIgnoreCase(datasource)) {
      configuration = null;
      if (_factory != null) _factory.close();
      _factory = null;
      datasource = dsn.toLowerCase();
    }

    // config
    ormConf = appContext.getORMConfiguration();

    // List<Component> arr = null;
    arr = null;
    if (init) {
      if (ormConf.autogenmap()) {
        arr = HibernateSessionFactory.loadComponents(pc, this, ormConf);
        cfcs.clear();
      } else
        throw new HibernateException(this, "orm setting autogenmap=false is not supported yet");
    }

    // load entities
    if (!ArrayUtil.isEmpty(arr)) {
      loadNamingStrategy(ormConf);

      DatasourceConnectionPool pool =
          ((ConfigWebImpl) pc.getConfig()).getDatasourceConnectionPool();
      DatasourceConnection dc =
          pool.getDatasourceConnection(pc, pc.getConfig().getDataSource(dsn), null, null);
      // DataSourceManager manager = pc.getDataSourceManager();
      // DatasourceConnection dc=manager.getConnection(pc,dsn, null, null);
      this.ds = dc.getDatasource();
      try {
        Iterator<ComponentPro> it = arr.iterator();
        while (it.hasNext()) {
          createMapping(pc, it.next(), dc, ormConf);
        }
      } finally {
        pool.releaseDatasourceConnection(dc);
        // manager.releaseConnection(pc,dc);
      }
      if (arr.size() != cfcs.size()) {
        ComponentPro cfc;
        String name, lcName;
        Map<String, String> names = new HashMap<String, String>();
        Iterator<ComponentPro> it = arr.iterator();
        while (it.hasNext()) {
          cfc = it.next();
          name = HibernateCaster.getEntityName(cfc);
          lcName = name.toLowerCase();
          if (names.containsKey(lcName))
            throw new ORMException(
                this,
                "Entity Name ["
                    + name
                    + "] is ambigous, ["
                    + names.get(lcName)
                    + "] and ["
                    + cfc.getPageSource().getDisplayPath()
                    + "] use the same entity name.");
          names.put(lcName, cfc.getPageSource().getDisplayPath());
        }
      }
    }
    arr = null;
    if (configuration != null) return _factory;

    // MUST
    // cacheconfig
    // cacheprovider
    // ...

    String mappings = HibernateSessionFactory.createMappings(this, cfcs);

    DatasourceConnectionPool pool = ((ConfigWebImpl) pc.getConfig()).getDatasourceConnectionPool();
    DatasourceConnection dc =
        pool.getDatasourceConnection(pc, pc.getConfig().getDataSource(dsn), null, null);
    try {
      configuration = HibernateSessionFactory.createConfiguration(this, mappings, dc, ormConf);
    } catch (Exception e) {
      throw Caster.toPageException(e);
    } finally {
      pool.releaseDatasourceConnection(dc);
    }

    addEventListeners(pc, configuration, ormConf, cfcs);

    EntityTuplizerFactory tuplizerFactory = configuration.getEntityTuplizerFactory();
    // tuplizerFactory.registerDefaultTuplizerClass(EntityMode.MAP, CFCEntityTuplizer.class);
    // tuplizerFactory.registerDefaultTuplizerClass(EntityMode.MAP, MapEntityTuplizer.class);
    tuplizerFactory.registerDefaultTuplizerClass(EntityMode.MAP, AbstractEntityTuplizerImpl.class);
    tuplizerFactory.registerDefaultTuplizerClass(EntityMode.POJO, AbstractEntityTuplizerImpl.class);
    // tuplizerFactory.registerDefaultTuplizerClass(EntityMode.POJO,
    // AbstractEntityTuplizerImpl.class);

    // configuration.setEntityResolver(new CFCEntityResolver());
    // configuration.setEntityNotFoundDelegate(new EntityNotFoundDelegate());

    return _factory = configuration.buildSessionFactory();
  }
Example #8
0
 /** @see railo.runtime.type.Sizeable#sizeOf() */
 public long sizeOf() {
   return ArrayUtil.sizeOf((List) this);
 }