/** * Logs the user in if the login and password match. * * @param login * @param password * @return */ public boolean doLogin(final String login, final String password) { if (serverConfig.getAttribute("admin.login").equals(login) && serverConfig.getAttribute("admin.password").equals(password)) { session.setAttribute(ATTR_LOGGEDIN, "1"); return true; } else { LOGGER.fine("Not logging in - wrong password"); } return false; } }
@Test public void shouldPreferSystemPropertiesOverFileDefinedOnes() throws IOException { writeFiles(DEFAULT_CONFIG_DATA); ServerConfig serverConfig = ServerConfigImpl.createFromPath(workingDirectory, tempDirectory); assertThat(serverConfig.getAttribute(ADDITIONAL_ATTRIBUTE_NAME), is(ORIGINAL_VALUE)); System.setProperty(ADDITIONAL_ATTRIBUTE_NAME, OVERWRITTEN_VALUE); assertThat(serverConfig.getAttribute(ADDITIONAL_ATTRIBUTE_NAME), is(OVERWRITTEN_VALUE)); System.clearProperty(ADDITIONAL_ATTRIBUTE_NAME); assertThat(serverConfig.getAttribute(ADDITIONAL_ATTRIBUTE_NAME), is(ORIGINAL_VALUE)); }
/** * {@inheritDoc} */ @Override public void service(final HttpServletRequest request, final HttpServletResponse response) throws ServletException { ServerConfig serverConfig = (ServerConfig) getServletContext().getAttribute(ServerConfig.class.getName()); if (!serverConfig.getAttribute(ATTR_ADMIN_DRIVE_ACCESS_ENABLED).equals(ServerConfigImpl.TRUE)) { response.getWriter().println("Option disabled in configuration."); return; } boolean fileExists = false; if (!request.getQueryString().equals("")) { File f = new File(getPathname(request)); if (f.exists() && f.isFile()) { fileExists = true; try { serveFile(f, response); } catch (IOException e) { throw new ServletException(e); } } } if (!fileExists) { response.setStatus(HttpServletResponse.STATUS_NOT_FOUND); response.getWriter().print("File does not exist."); } }
/** * {@inheritDoc} */ @Override public void service(final HttpServletRequest request, final HttpServletResponse response) throws ServletException { ServerConfig serverConfig = (ServerConfig) getServletContext().getAttribute(ServerConfig.class.getName()); HTMLDocument doc = new HTMLDocument("Drive Access"); doc.setOwnerClass(getClass().getSimpleName()); doc.writeln("<div class=\"page-header\"><h1>Drive Access</h1></div>"); if (!serverConfig.getAttribute(ADMIN_DRIVE_ACCESS_ENABLED).equals(ServerConfigImpl.TRUE)) { renderFunctionDisabled(response, doc); return; } String path = StringUtilities.urlDecode(request.getQueryString()); if ("".equals(path)) { path = "/"; } renderBreadcrubms(doc, path); File file = new File(Environment.getExternalStorageDirectory() + path); if (file.exists() && file.isDirectory()) { renderDirectoryList(doc, path, file); } else { renderPathNotAvailable(doc); } response.getWriter().print(doc.toString()); }
@Test public void shouldReadSystemPropertiesWhenNoFileIsPresent() throws IOException { System.setProperty("server.port", "9090"); System.setProperty("server.static.path", "path"); System.setProperty("server.static.directoryIndex", "i.php,i.html"); System.setProperty("server.maxThreads", "66"); System.setProperty("server.keepAlive.enabled", "false"); System.setProperty("server.errorDocument.404", "ERROR404.html"); System.setProperty("server.errorDocument.403", "ERROR403.html"); System.setProperty(ADDITIONAL_ATTRIBUTE_NAME, "YET_ANOTHER_VALUE"); ServerConfig serverConfig = new ServerConfigImpl("/tmp/", "/tmp/", new Properties()); assertThat(serverConfig.getDocumentRootPath(), is("/tmp/path")); assertThat(serverConfig.getDirectoryIndex(), hasItem("i.php")); assertThat(serverConfig.getDirectoryIndex(), hasItem("i.html")); assertThat(serverConfig.getDirectoryIndex().size(), is(2)); assertThat(serverConfig.getErrorDocument403Path(), is("/tmp/ERROR403.html")); assertThat(serverConfig.getErrorDocument404Path(), is("/tmp/ERROR404.html")); assertThat(serverConfig.getListenPort(), is(9090)); assertThat(serverConfig.getMaxServerThreads(), is(66)); assertThat(serverConfig.isKeepAlive(), is(false)); // assertThat(serverConfig.getMimeTypeMapping().getMimeTypeByExtension("ANY"), is("mime/text")); assertThat(serverConfig.getAttribute(ADDITIONAL_ATTRIBUTE_NAME), is("YET_ANOTHER_VALUE")); } }
@Test public void shouldCreateFromPath() throws IOException { writeFiles(DEFAULT_CONFIG_DATA + "DefaultMimeType mime/text\n"); ServerConfig serverConfig = ServerConfigImpl.createFromPath(workingDirectory, tempDirectory); assertThat(serverConfig.getTempPath(), is(tempDirectory)); assertThat(serverConfig.getBasePath(), is(workingDirectory)); assertThat(serverConfig.getDocumentRootPath(), is(workingDirectory + "wwwx")); assertThat(serverConfig.getDirectoryIndex(), hasItem("index.php")); assertThat(serverConfig.getDirectoryIndex(), hasItem("index.html")); assertThat(serverConfig.getDirectoryIndex().size(), is(2)); assertThat(serverConfig.getErrorDocument403Path(), is(workingDirectory + "error403.html")); assertThat(serverConfig.getErrorDocument404Path(), is(workingDirectory + "error404.html")); assertThat(serverConfig.getListenPort(), is(8090)); assertThat(serverConfig.getMaxServerThreads(), is(3)); assertThat(serverConfig.isKeepAlive(), is(true)); assertThat(serverConfig.getMimeTypeMapping().getMimeTypeByExtension("ANY"), is("mime/text")); assertThat(serverConfig.getAttribute(ADDITIONAL_ATTRIBUTE_NAME), is(ORIGINAL_VALUE)); }