private Resource findUserProperties() throws IOException {
    GeoServerResourceLoader loader = GeoServerExtensions.bean(GeoServerResourceLoader.class);
    Resource propFile = loader.get("security/users.properties");

    InputStream is = null;
    OutputStream os = null;
    try {
      if (propFile.getType() == Type.RESOURCE) {
        // we're probably dealing with an old data dir, create
        // the file without
        // changing the username and password if possible
        Properties p = new Properties();
        GeoServerInfo global = GeoServerExtensions.bean(GeoServer.class).getGlobal();
        if ((global != null)
            && (global.getAdminUsername() != null)
            && !global.getAdminUsername().trim().equals("")) {
          p.put(global.getAdminUsername(), global.getAdminPassword() + ",ROLE_ADMINISTRATOR");
        } else {
          p.put("admin", "geoserver,ROLE_ADMINISTRATOR");
        }

        os = propFile.out();
        p.store(os, "Format: name=password,ROLE1,...,ROLEN");
        os.close();

        // setup a sample service.properties
        Resource serviceFile = loader.get("security/service.properties");
        os = serviceFile.out();
        is = GeoServerUserDao.class.getResourceAsStream("serviceTemplate.properties");
        byte[] buffer = new byte[1024];
        int count = 0;
        while ((count = is.read(buffer)) > 0) {
          os.write(buffer, 0, count);
        }
        return propFile;
      } else {
        throw new FileNotFoundException("Unable to find security/users.properties");
      }
    } finally {
      if (is != null) {
        try {
          is.close();
        } catch (IOException ei) {
          /* nothing to do */
        }
      }
      if (os != null) {
        try {
          os.close();
        } catch (IOException eo) {
          /* nothing to do */
        }
      }
    }
  }
Beispiel #2
0
 /**
  * Gets an SLD resource for the given style.
  *
  * @param style
  * @return
  */
 private Resource getStyleResource(StyleInfo style) {
   String[] prefix = new String[0];
   if (style.getWorkspace() != null) {
     prefix = new String[] {"workspaces", style.getWorkspace().getName()};
   }
   String fileName = style.getFilename();
   String[] pathParts = (String[]) ArrayUtils.addAll(prefix, new String[] {"styles", fileName});
   String path = Paths.path(pathParts);
   return loader.get(path);
 }
Beispiel #3
0
  public static boolean writeConfigToDisk(ProxyConfig pc) {
    Resource.Lock lock = null;
    try {
      GeoServerResourceLoader loader = GeoServerExtensions.bean(GeoServerResourceLoader.class);
      Resource configFile = loader.get("proxy/proxy.xml");

      XStream xs = new XStream();
      String xml = xs.toXML(pc);
      FileWriter fw = new FileWriter(configFile.file(), false); // false means overwrite old file
      // Take the write lock on the file & lock it
      lock = configFile.lock();
      fw.write(xml);
      fw.close();
      return true;
    } catch (Exception e) {
      LOG.warning("Failed to save configuration for Proxy module. Exception:" + e.toString());
      return false;
    } finally {
      if (lock != null) lock.release();
    }
  }
Beispiel #4
0
  /* this is pretty unappealingly hackish */
  public static ProxyConfig loadConfFromDisk() {
    ProxyConfig retval;
    Resource.Lock lock = null;
    try {
      GeoServerResourceLoader loader = GeoServerExtensions.bean(GeoServerResourceLoader.class);
      Resource configFile = loader.get("proxy/proxy.xml");
      lock = configFile.lock();

      InputStream proxyConfStream = configFile.in();
      XStream xs = new XStream();
      // Take the read lock, then read the file
      retval = (ProxyConfig) (xs.fromXML(proxyConfStream));
    } catch (Exception e) {
      LOG.warning(
          "Failed to open configuration for Proxy module. Using default. Exception:"
              + e.toString());
      // writeConfigToDisk(DEFAULT);
      retval = DEFAULT;
    } finally {
      if (lock != null) lock.release();
    }
    return retval;
  }
 public ResumableUploadResourceManager(String tmpFolder) {
   GeoServerResourceLoader loader = GeoServerExtensions.bean(GeoServerResourceLoader.class);
   tmpUploadFolder = loader.get(tmpFolder);
 }
Beispiel #6
0
  public static void initLogging(
      GeoServerResourceLoader resourceLoader,
      String configFileName,
      boolean suppressStdOutLogging,
      String logFileName)
      throws Exception {
    // to initialize logging we need to do a couple of things:
    // 1)  Figure out whether the user has 'overridden' some configuration settings
    // in the logging system (not using log4j in commons-logging.properties or perhaps
    // has set up their own 'custom' log4j.properties file.
    // 2)  If they *have*, then we don't worry about configuring logging
    // 3)  If they haven't, then we configure logging to use the log4j config file
    // specified, and remove console appenders if the suppressstdoutlogging is true.
    LoggingInitializer.LOGGER.fine("CONFIGURING GEOSERVER LOGGING -------------------------");

    if (configFileName == null) {
      configFileName = "DEFAULT_LOGGING.properties";
      LoggingInitializer.LOGGER.warning(
          "No log4jConfigFile defined in services.xml:  using 'DEFAULT_LOGGING.properties'");
    }
    Resource resource = resourceLoader.get(Paths.path("logs", configFileName));
    if (resource == null || resource.getType() == Type.UNDEFINED) {
      // hmm, well, we don't have a log4j config file and this could be due to the fact
      // that this is a data-dir upgrade.  We can count on the DEFAULT_LOGGING.properties file
      // being present on the classpath, so we'll upgrade their data_dir and then use the
      // default DEFAULT_LOGGING.properties configuration.
      LoggingInitializer.LOGGER.warning(
          "log4jConfigFile '"
              + configFileName
              + "' couldn't be found in the data dir, so GeoServer will "
              + "install the various logging config file into the data dir, and then try to find it again.");

      Resource logs = resourceLoader.get("logs");
      File lcdir = logs.dir();

      // now we copy in the various logging config files from the base repo location on the
      // classpath
      final String[] lcfiles =
          new String[] {
            "DEFAULT_LOGGING.properties",
            "GEOSERVER_DEVELOPER_LOGGING.properties",
            "GEOTOOLS_DEVELOPER_LOGGING.properties",
            "PRODUCTION_LOGGING.properties",
            "QUIET_LOGGING.properties",
            "TEST_LOGGING.properties",
            "VERBOSE_LOGGING.properties"
          };

      for (int i = 0; i < lcfiles.length; i++) {
        File target = new File(lcdir.getAbsolutePath(), lcfiles[i]);
        if (!target.exists()) {
          resourceLoader.copyFromClassPath(lcfiles[i], target);
        }
      }

      // ok, the possibly-new 'logs' directory is in-place, with all the various configs there.
      // Is the originally configured log4jconfigfile there now?
      if (resource.getType() != Type.RESOURCE) {
        LoggingInitializer.LOGGER.warning(
            "Still couldn't find log4jConfigFile '"
                + configFileName
                + "'.  Using DEFAULT_LOGGING.properties instead.");
      }

      resource = resourceLoader.get(Paths.path("logs", "DEFAULT_LOGGING.properties"));
    }

    if (resource == null || resource.getType() != Type.RESOURCE) {
      throw new ConfigurationException(
          "Unable to load logging configuration '"
              + configFileName
              + "'.  In addition, an attempt "
              + "was made to create the 'logs' directory in your data dir, and to use the DEFAULT_LOGGING configuration, but"
              + "this failed as well.  Is your data dir writeable?");
    }

    // reconfiguring log4j logger levels by resetting and loading a new set of configuration
    // properties
    InputStream loggingConfigStream = resource.in();
    if (loggingConfigStream == null) {
      LoggingInitializer.LOGGER.warning("Couldn't open Log4J configuration file '" + resource);
      return;
    } else {
      LoggingInitializer.LOGGER.fine(
          "GeoServer logging profile '" + resource.name() + "' enabled.");
    }

    configureGeoServerLogging(
        resourceLoader, loggingConfigStream, suppressStdOutLogging, false, logFileName);
  }