Beispiel #1
0
/** Web Context */
public final class ConfigWebImpl extends ConfigImpl implements ServletConfig, ConfigWeb {

  private final ServletConfig config;
  private final ConfigServerImpl configServer;
  private SecurityManager securityManager;
  private static final LockManager lockManager = LockManagerImpl.getInstance(false);
  private Resource rootDir;
  private final CFMLCompilerImpl compiler = new CFMLCompilerImpl();
  private CIPage baseComponentPageCFML;
  private CIPage baseComponentPageLucee;
  private MappingImpl serverTagMapping;
  private MappingImpl serverFunctionMapping;
  private KeyLock<String> contextLock;
  private GatewayEngineImpl gatewayEngine;
  private DebuggerPool debuggerPool;
  private final CFMLFactoryImpl factory;
  private CacheHandlerCollections cacheHandlerCollections;

  protected IdentificationWeb id;

  // private File deployDirectory;

  /**
   * constructor of the class
   *
   * @param configServer
   * @param config
   * @param configDir
   * @param configFile
   * @param cloneServer
   */
  ConfigWebImpl(
      CFMLFactoryImpl factory,
      ConfigServerImpl configServer,
      ServletConfig config,
      Resource configDir,
      Resource configFile) {
    super(configDir, configFile);
    this.configServer = configServer;
    this.config = config;
    this.factory = factory;
    factory.setConfig(this);
    ResourceProvider frp = ResourcesImpl.getFileResourceProvider();

    this.rootDir = frp.getResource(ReqRspUtil.getRootPath(config.getServletContext()));

    // Fix for tomcat
    if (this.rootDir.getName().equals(".") || this.rootDir.getName().equals(".."))
      this.rootDir = this.rootDir.getParentResource();
  }

  @Override
  public void reset() {
    super.reset();
    factory.resetPageContext();
    tagHandlerPool.reset();
    contextLock = null;
    baseComponentPageCFML = null;
    baseComponentPageLucee = null;
  }

  @Override
  public String getServletName() {
    return config.getServletName();
  }

  @Override
  public ServletContext getServletContext() {
    return config.getServletContext();
  }

  @Override
  public String getInitParameter(String name) {
    return config.getInitParameter(name);
  }

  @Override
  public Enumeration getInitParameterNames() {
    return config.getInitParameterNames();
  }

  protected ConfigServerImpl getConfigServerImpl() {
    return configServer;
  }

  @Override
  public ConfigServer getConfigServer(String password) throws ExpressionException {
    return getConfigServer(PasswordImpl.passwordToCompare(this, true, password));
  }

  @Override
  public ConfigServer getConfigServer(Password password) throws ExpressionException {
    configServer.checkAccess(password);
    return configServer;
  }

  @Override
  public ConfigServer getConfigServer(String key, long timeNonce) throws PageException {
    configServer.checkAccess(key, timeNonce);
    return configServer;
  }

  public Resource getServerConfigDir() {
    return configServer.getConfigDir();
  }

  /** @return Returns the accessor. */
  @Override
  public SecurityManager getSecurityManager() {
    return securityManager;
  }

  /** @param securityManager The accessor to set. */
  protected void setSecurityManager(SecurityManager securityManager) {
    ((SecurityManagerImpl) securityManager).setRootDirectory(getRootDirectory());
    this.securityManager = securityManager;
  }

  @Override
  public CFXTagPool getCFXTagPool() throws SecurityException {
    if (securityManager.getAccess(SecurityManager.TYPE_CFX_USAGE) == SecurityManager.VALUE_YES)
      return super.getCFXTagPool();
    throw new SecurityException("no access to cfx functionality", "disabled by security settings");
  }

  /** @return Returns the rootDir. */
  @Override
  public Resource getRootDirectory() {
    return rootDir;
  }

  @Override
  public String getUpdateType() {
    return configServer.getUpdateType();
  }

  @Override
  public URL getUpdateLocation() {
    return configServer.getUpdateLocation();
  }

  @Override
  public LockManager getLockManager() {
    return lockManager;
  }

  /** @return the compiler */
  public CFMLCompilerImpl getCompiler() {
    return compiler;
  }

  public CIPage getBaseComponentPage(int dialect, PageContext pc) throws PageException {
    // CFML
    if (dialect == CFMLEngine.DIALECT_CFML) {
      if (baseComponentPageCFML == null) {
        baseComponentPageCFML =
            (CIPage) getBaseComponentPageSource(dialect, pc).loadPage(pc, false);
      }
      return baseComponentPageCFML;
    }
    // Lucee
    if (baseComponentPageLucee == null) {
      baseComponentPageLucee = (CIPage) getBaseComponentPageSource(dialect, pc).loadPage(pc, false);
    }
    return baseComponentPageLucee;
  }

  public void resetBaseComponentPage() {
    baseComponentPageCFML = null;
    baseComponentPageLucee = null;
  }

  public Mapping getServerTagMapping() {
    if (serverTagMapping == null) {
      serverTagMapping = getConfigServerImpl().tagMapping.cloneReadOnly(this);
    }
    return serverTagMapping;
  }

  public Mapping getServerFunctionMapping() {
    if (serverFunctionMapping == null) {
      serverFunctionMapping = getConfigServerImpl().functionMapping.cloneReadOnly(this);
    }
    return serverFunctionMapping;
  }

  private Map<String, Mapping> applicationMappings = new ReferenceMap<String, Mapping>(SOFT, SOFT);

  private TagHandlerPool tagHandlerPool = new TagHandlerPool(this);
  private SearchEngine searchEngine;
  private AMFEngine amfEngine;

  // FYI used by Extensions, do not remove
  public Mapping getApplicationMapping(String virtual, String physical) {
    return getApplicationMapping("application", virtual, physical, null, true, false);
  }

  public Mapping getApplicationMapping(
      String type,
      String virtual,
      String physical,
      String archive,
      boolean physicalFirst,
      boolean ignoreVirtual) {
    String key =
        type
            + ":"
            + virtual.toLowerCase()
            + ":"
            + (physical == null ? "" : physical.toLowerCase())
            + ":"
            + (archive == null ? "" : archive.toLowerCase())
            + ":"
            + physicalFirst;
    key = Long.toString(HashUtil.create64BitHash(key), Character.MAX_RADIX);

    Mapping m = applicationMappings.get(key);

    if (m == null) {
      m =
          new MappingImpl(
              this,
              virtual,
              physical,
              archive,
              Config.INSPECT_UNDEFINED,
              physicalFirst,
              false,
              false,
              false,
              true,
              ignoreVirtual,
              null,
              -1,
              -1);
      applicationMappings.put(key, m);
    }

    return m;
  }

  public Mapping[] getApplicationMapping() {
    return applicationMappings.values().toArray(new Mapping[applicationMappings.size()]);
  }

  @Override
  public String getLabel() {
    String hash = getHash();
    String label = hash;
    Map<String, String> labels = configServer.getLabels();
    if (labels != null) {
      String l = labels.get(hash);
      if (!StringUtil.isEmpty(l)) {
        label = l;
      }
    }
    return label;
  }

  public String getHash() {
    return SystemUtil.hash(getServletContext());
  }

  public KeyLock<String> getContextLock() {
    if (contextLock == null) {
      contextLock = new KeyLockImpl<String>();
    }
    return contextLock;
  }

  protected void setGatewayEntries(Map<String, GatewayEntry> gatewayEntries) {
    try {
      getGatewayEngine().addEntries(this, gatewayEntries);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  public GatewayEngineImpl getGatewayEngine() {
    if (gatewayEngine == null) {
      gatewayEngine = new GatewayEngineImpl(this);
    }
    return gatewayEngine;
  }

  public void setGatewayEngine(GatewayEngineImpl gatewayEngine) {
    this.gatewayEngine = gatewayEngine;
  }

  public TagHandlerPool getTagHandlerPool() {
    return tagHandlerPool;
  }

  public DebuggerPool getDebuggerPool() {
    if (debuggerPool == null) {
      Resource dir = getConfigDir().getRealResource("debugger");
      dir.mkdirs();
      debuggerPool = new DebuggerPool(dir);
    }
    return debuggerPool;
  }

  @Override
  public ThreadQueue getThreadQueue() {
    return configServer.getThreadQueue();
  }

  @Override
  public int getLoginDelay() {
    return configServer.getLoginDelay();
  }

  @Override
  public boolean getLoginCaptcha() {
    return configServer.getLoginCaptcha();
  }

  @Override
  public boolean getRememberMe() {
    return configServer.getRememberMe();
  }

  @Override
  public Resource getSecurityDirectory() {
    return configServer.getSecurityDirectory();
  }

  @Override
  public boolean isMonitoringEnabled() {
    return configServer.isMonitoringEnabled();
  }

  @Override
  public RequestMonitor[] getRequestMonitors() {
    return configServer.getRequestMonitors();
  }

  @Override
  public RequestMonitor getRequestMonitor(String name) throws PageException {
    return configServer.getRequestMonitor(name);
  }

  @Override
  public IntervallMonitor[] getIntervallMonitors() {
    return configServer.getIntervallMonitors();
  }

  @Override
  public IntervallMonitor getIntervallMonitor(String name) throws PageException {
    return configServer.getIntervallMonitor(name);
  }

  @Override
  public void checkPermGenSpace(boolean check) {
    configServer.checkPermGenSpace(check);
  }

  @Override
  public Cluster createClusterScope() throws PageException {
    return configServer.createClusterScope();
  }

  @Override
  public boolean hasServerPassword() {
    return configServer.hasPassword();
  }

  public void updatePassword(boolean server, String passwordOld, String passwordNew)
      throws PageException, IOException, SAXException, BundleException {
    PasswordImpl.updatePassword(server ? configServer : this, passwordOld, passwordNew);
  }

  public void updatePassword(boolean server, Password passwordOld, Password passwordNew)
      throws PageException, IOException, SAXException, BundleException {
    PasswordImpl.updatePassword(server ? configServer : this, passwordOld, passwordNew);
  }

  public Password updatePasswordIfNecessary(boolean server, String passwordRaw) {
    ConfigImpl config = server ? configServer : this;
    return PasswordImpl.updatePasswordIfNecessary(config, config.password, passwordRaw);
  }

  @Override
  public Resource getConfigServerDir() {
    return configServer.getConfigDir();
  }

  public Map<String, String> getAllLabels() {
    return configServer.getLabels();
  }

  @Override
  public boolean allowRequestTimeout() {
    return configServer.allowRequestTimeout();
  }

  public CFMLWriter getCFMLWriter(PageContext pc, HttpServletRequest req, HttpServletResponse rsp) {
    if (writerType == CFML_WRITER_WS)
      return new CFMLWriterWS(
          pc, req, rsp, -1, false, closeConnection(), isShowVersion(), contentLength());
    else if (writerType == CFML_WRITER_REFULAR)
      return new CFMLWriterImpl(
          pc, req, rsp, -1, false, closeConnection(), isShowVersion(), contentLength());
    else
      return new CFMLWriterWSPref(
          pc, req, rsp, -1, false, closeConnection(), isShowVersion(), contentLength());
  }

  @Override
  public JspWriter getWriter(PageContext pc, HttpServletRequest req, HttpServletResponse rsp) {
    return getCFMLWriter(pc, req, rsp);
  }

  public ActionMonitorCollector getActionMonitorCollector() {
    return configServer.getActionMonitorCollector();
  }

  @Override
  public boolean getFullNullSupport() {
    return configServer.getFullNullSupport();
  }

  public boolean hasIndividualSecurityManager() {
    return configServer.hasIndividualSecurityManager(getIdentification().getId());
  }

  @Override
  public CFMLFactory getFactory() {
    return factory;
  }

  @Override
  public CacheHandlerCollection getCacheHandlerCollection(
      int type, CacheHandlerCollection defaultValue) {
    if (cacheHandlerCollections == null)
      cacheHandlerCollections = new CacheHandlerCollections(this);
    switch (type) {
      case Config.CACHE_TYPE_FILE:
        return cacheHandlerCollections.file;
      case Config.CACHE_TYPE_FUNCTION:
        return cacheHandlerCollections.function;
      case Config.CACHE_TYPE_HTTP:
        return cacheHandlerCollections.http;
      case Config.CACHE_TYPE_INCLUDE:
        return cacheHandlerCollections.include;
      case Config.CACHE_TYPE_QUERY:
        return cacheHandlerCollections.query;
      case Config.CACHE_TYPE_RESOURCE:
        return cacheHandlerCollections.resource;
      case Config.CACHE_TYPE_WEBSERVICE:
        return cacheHandlerCollections.webservice;
        // case Config.CACHE_TYPE_OBJECT: return cacheHandlerCollections.object;
        // case Config.CACHE_TYPE_TEMPLATE: return cacheHandlerCollections.template;
    }

    return defaultValue;
  }

  public void releaseCacheHandlers(PageContext pc) {
    if (cacheHandlerCollections == null) return;
    cacheHandlerCollections.releaseCacheHandlers(pc);
  }

  protected void setIdentification(IdentificationWeb id) {
    this.id = id;
  }

  @Override
  public IdentificationWeb getIdentification() {
    return id;
  }

  public int getServerPasswordType() {
    return configServer.getPasswordType();
  }

  public String getServerPasswordSalt() {
    return configServer.getPasswordSalt();
  }

  public int getServerPasswordOrigin() {
    return configServer.getPasswordOrigin();
  }

  public String getServerSalt() {
    return configServer.getSalt();
  }

  public Password isServerPasswordEqual(String password) {
    return configServer.isPasswordEqual(password);
  }

  public boolean isDefaultPassword() {
    if (password == null) return false;
    return password == configServer.defaultPassword;
  }

  @Override
  public Collection<BundleDefinition> getAllExtensionBundleDefintions() {
    return configServer.getAllExtensionBundleDefintions();
  }

  @Override
  public SearchEngine getSearchEngine(PageContext pc) throws PageException {
    if (searchEngine == null) {
      try {
        Object o = ClassUtil.loadInstance(getSearchEngineClassDefinition().getClazz());
        if (o instanceof SearchEngine) searchEngine = (SearchEngine) o;
        else
          throw new ApplicationException(
              "class ["
                  + o.getClass().getName()
                  + "] does not implement the interface SearchEngine");

        searchEngine.init(
            this,
            ConfigWebUtil.getFile(
                getConfigDir(),
                ConfigWebUtil.translateOldPath(getSearchEngineDirectory()),
                "search",
                getConfigDir(),
                FileUtil.TYPE_DIR,
                this));
      } catch (Exception e) {
        throw Caster.toPageException(e);
      }
    }
    return searchEngine;
  }

  @Override
  public ActionMonitor getActionMonitor(String name) {
    return configServer.getActionMonitor(name);
  }

  @Override
  public Resource getLocalExtensionProviderDirectory() {
    return configServer.getLocalExtensionProviderDirectory();
  }

  protected void setAMFEngine(AMFEngine engine) {
    amfEngine = engine;
  }

  @Override
  public AMFEngine getAMFEngine() {
    if (amfEngine == null) return AMFEngineDummy.getInstance();
    return amfEngine;
  }
}
Beispiel #2
0
  @Override
  public int doStartTag() throws PageException {
    // if(timeoutInMillis==0)timeoutInMillis=30000;
    // print.out("doStartTag");
    manager = pageContext.getConfig().getLockManager();
    // check attributes
    if (name != null && scope != SCOPE_NONE) {
      throw new LockException(
          LockException.OPERATION_CREATE,
          this.name,
          "invalid attribute combination",
          "attribute [name] and [scope] can't be used together");
    }
    if (name == null && scope == SCOPE_NONE) {
      name = "id-" + id;
    }

    String lockType = null;
    if (name == null) {
      String cid = pageContext.getConfig().getIdentification().getId();
      // Session
      if (scope == SCOPE_REQUEST) {
        lockType = "request";
        name = "__request_" + cid + "__" + ((RequestImpl) pageContext.requestScope())._getId();
      }
      // Session
      else if (scope == SCOPE_SESSION) {
        lockType = "session";
        name = "__session_" + cid + "__" + pageContext.sessionScope()._getId();
      }
      // Application
      else if (scope == SCOPE_APPLICATION) {
        lockType = "application";
        name =
            "__application_"
                + cid
                + "__"
                + ((ApplicationImpl) pageContext.applicationScope())._getId();
      }
      // Server
      else if (scope == SCOPE_SERVER) {
        lockType = "server";
        name = "__server_" + ((ServerImpl) pageContext.serverScope())._getId();
      }
    }
    Struct cflock = new StructImpl();
    cflock.set("succeeded", Boolean.TRUE);
    cflock.set("errortext", "");
    pageContext.variablesScope().set("cflock", cflock);
    start = System.nanoTime();
    try {
      ((PageContextImpl) pageContext)
          .setActiveLock(
              new ActiveLock(
                  type,
                  name,
                  timeoutInMillis)); // this has to be first, otherwise LockTimeoutException has
                                     // nothing to release
      data = manager.lock(type, name, timeoutInMillis, pageContext.getId());
    } catch (LockTimeoutException e) {
      LockManagerImpl mi = (LockManagerImpl) manager;
      Boolean hasReadLock = mi.isReadLocked(name);
      Boolean hasWriteLock = mi.isWriteLocked(name);
      String msg =
          LockTimeoutExceptionImpl.createMessage(
              type, name, lockType, timeoutInMillis, hasReadLock, hasWriteLock);

      _release(pageContext, System.nanoTime() - start);
      name = null;

      cflock.set("succeeded", Boolean.FALSE);
      cflock.set("errortext", msg);

      if (throwontimeout) throw new LockException(LockException.OPERATION_TIMEOUT, this.name, msg);

      return SKIP_BODY;
    } catch (InterruptedException e) {
      _release(pageContext, System.nanoTime() - start);
      cflock.set("succeeded", Boolean.FALSE);
      cflock.set("errortext", e.getMessage());

      if (throwontimeout) throw Caster.toPageException(e);

      return SKIP_BODY;
    }

    return EVAL_BODY_INCLUDE;
  }