@RunTestSetup @Test public void testGeoServerReload() throws Exception { Catalog cat = getCatalog(); FeatureTypeInfo lakes = cat.getFeatureTypeByName(MockData.LAKES.getNamespaceURI(), MockData.LAKES.getLocalPart()); assertFalse("foo".equals(lakes.getTitle())); GeoServerDataDirectory dd = new GeoServerDataDirectory(getResourceLoader()); File info = dd.findResourceFile(lakes); // File info = getResourceLoader().find("featureTypes", "cite_Lakes", "info.xml"); FileReader in = new FileReader(info); Element dom = ReaderUtils.parse(in); Element title = ReaderUtils.getChildElement(dom, "title"); title.getFirstChild().setNodeValue("foo"); OutputStream output = new FileOutputStream(info); try { TransformerFactory.newInstance() .newTransformer() .transform(new DOMSource(dom), new StreamResult(output)); } finally { output.close(); } getGeoServer().reload(); lakes = cat.getFeatureTypeByName(MockData.LAKES.getNamespaceURI(), MockData.LAKES.getLocalPart()); assertEquals("foo", lakes.getTitle()); }
public File findStyleFile(String name) { try { GeoServerDataDirectory datadir = new GeoServerDataDirectory(getCatalog().getResourceLoader()); File styleDir = datadir.findStyleDir(); return new File(styleDir, name); } catch (IOException ioe) { throw new WicketRuntimeException(ioe); } }
public String cssText2sldText(String css) { try { GeoServerDataDirectory datadir = new GeoServerDataDirectory(getCatalog().getResourceLoader()); File styleDir = datadir.findStyleDir(); scala.collection.Seq<org.geoscript.geocss.Rule> rules = CssParser.parse(css).get(); Translator translator = new Translator(scala.Option.apply(styleDir.toURI().toURL())); Style style = translator.css2sld(rules); SLDTransformer tx = new org.geotools.styling.SLDTransformer(); tx.setIndentation(2); StringWriter sldChars = new java.io.StringWriter(); System.out.println(sldChars.toString()); tx.transform(style, sldChars); return sldChars.toString(); } catch (Exception e) { throw new WicketRuntimeException("Error while parsing stylesheet [" + css + "] : " + e); } }
void initializeDataSource() throws Exception { Resource monitoringDir = dataDirectory.get("monitoring"); Resource dbprops = monitoringDir.get("db.properties"); if (Resources.exists(dbprops)) { LOGGER.info("Configuring monitoring database from: " + dbprops.path()); // attempt to configure try { configureDataSource(dbprops, monitoringDir); } catch (SQLException e) { // configure failed, try db1.properties dbprops = monitoringDir.get("db1.properties"); if (Resources.exists(dbprops)) { try { configureDataSource(dbprops, monitoringDir); // secondary file worked, return return; } catch (SQLException e1) { // secondary file failed as well, try for third dbprops = monitoringDir.get("db2.properties"); if (Resources.exists(dbprops)) { try { configureDataSource(dbprops, monitoringDir); // third file worked, return return; } catch (SQLException e2) { } } } } throw e; } } else { // no db.properties file, use internal default configureDataSource(null, monitoringDir); } }
/** Retrieves the GeoServer data directory */ private String getDataDirectory() { GeoServerDataDirectory dd = getGeoServerApplication().getBeanOfType(GeoServerDataDirectory.class); return dd.root().getAbsolutePath(); }
/** * @param ftpAuthRequest one of {@link org.apache.ftpserver.usermanager.AnonymousAuthentication} * or {@link org.apache.ftpserver.usermanager.UsernamePasswordAuthentication} * @throws AuthenticationFailedException if given an {@code AnonymousAuthentication}, or an * invalid/disabled user credentials * @see UserManager#authenticate(Authentication) */ public User authenticate(final Authentication ftpAuthRequest) throws AuthenticationFailedException { if (!(ftpAuthRequest instanceof UsernamePasswordAuthentication)) { throw new AuthenticationFailedException(); } final UsernamePasswordAuthentication upa = (UsernamePasswordAuthentication) ftpAuthRequest; final String principal = upa.getUsername(); final String credentials = upa.getPassword(); org.springframework.security.core.Authentication gsAuth = new UsernamePasswordAuthenticationToken(principal, credentials); try { gsAuth = authManager.authenticate(gsAuth); } catch (org.springframework.security.core.AuthenticationException authEx) { throw new AuthenticationFailedException(authEx); } try { // gather the user BaseUser user = getUserByName(principal); user.setPassword(credentials); // is the user enabled? if (!user.getEnabled()) { throw new AuthenticationFailedException(); } // scary message for admins if the username/password has not // been changed if (DEFAULT_USER.equals(user.getName()) && DEFAULT_PASSWORD.equals(credentials)) { LOGGER.log( Level.SEVERE, "The default admin/password combination has not been " + "modified, this makes the embedded FTP server an " + "open file host for everybody to use!!!"); } final File dataRoot = dataDir.findOrCreateDataRoot(); // enable only admins and non anonymous users boolean isGSAdmin = false; for (GrantedAuthority authority : gsAuth.getAuthorities()) { final String userRole = authority.getAuthority(); if (ADMIN_ROLE.equals(userRole)) { isGSAdmin = true; break; } } final File homeDirectory; if (isGSAdmin) { homeDirectory = dataRoot; } else { /* * This resolves the user's home directory to data/incoming/<user name> but does not * create the directory if it does not already exist. That is left to when the user * is authenticated, check the authenticate() method above. */ homeDirectory = new File(new File(dataRoot, "incoming"), user.getName()); } String normalizedPath = homeDirectory.getAbsolutePath(); normalizedPath = FilenameUtils.normalize(normalizedPath); user.setHomeDirectory(normalizedPath); if (!homeDirectory.exists()) { LOGGER.fine( "Creating FTP home directory for user " + user.getName() + " at " + normalizedPath); homeDirectory.mkdirs(); } return user; } catch (AuthenticationFailedException e) { throw e; } catch (Exception e) { LOGGER.log(Level.INFO, "FTP authentication failure", e); throw new AuthenticationFailedException(e); } }
String getURL(Properties db) { return db.getProperty("url") .replace("${GEOSERVER_DATA_DIR}", dataDirectory.root().getAbsolutePath()); }