diff --git a/README.md b/README.md new file mode 100644 index 0000000..d74ac48 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# Kimee's Blog + +This repository houses the code for Kimee's blog and website. +It's written using Java EE, primarily JSP, with a number of DAOs. + +To build follow the [building instructions](docs/building.md). + +To install follow the [installation instructions](docs/installation.md). + +## License + +It is licensed under the Apache 2.0 [license](license.txt). diff --git a/docs/building.md b/docs/building.md new file mode 100644 index 0000000..d99b13f --- /dev/null +++ b/docs/building.md @@ -0,0 +1,118 @@ +# Building Instructions + +Building this requires [maven](https://maven.apache.org/), [tomcat](https://tomcat.apache.org/), and [MariaDB](https://mariadb.org/). +Consult your Operating System Distribution's manual for installation instructions. +It also uses [git](https://git-scm.com/) for source control. + +## Database Configuration + +For developer testing, the project's ``context.xml`` is setup to expect a schema called ``blog`` with the following configuration: + + - Connection URL: localhost:3306/blog + - Username: blogger + - Password: bloggingit + +These credentials should be given minimal permissions to the rest of the database. +While possible to do so, it is recommended not to use these credentials in a production system. +Simply create a production user and edit ``context.xml`` after deploying to use different credentials. +See [installation](installation.md). + +These SQL commands will create the ``blog`` schema with the credentials as listed. this makes code-test-debug cycles easy, at minimal risk to the rest of the database. + +``` +CREATE SCHEMA blog; +USE SCHEMA blog; +SOURCE src/main/sql/setup.sql; +GRANT SELECT, INSERT, UPDATE, DELETE ON blog.* TO 'blogger'@'host' IDENTIFIED BY 'bloggingit'; +``` + +The project uses an additional schema called 'blogtest' for running unit tests. +The unit tests also have a testing user hard coded in, to facilitate testing queries. +The following credentials are used: + + - Connection URL: localhost:3306/blogtest + - Username: blogtester + - Password: bloggingit + +To install the schema in your database and create the ``blogtester`` user, run the following queries. +The project will automatically recreate the tables before each test run. + +``` +CREATE SCHEMA blogtest; +USE blogtest; +GRANT SELECT, INSERT, UPDATE, DELETE ON blog.* TO 'blogtester'@'host' IDENTIFIED BY 'testingit'; +``` + +Lastly the project requires a user account with full permissions to destroy and recreate the ``blogtest`` schema. +Run this query to create one, changing the username and password. + +``` +GRANT ALL PERMISSIONS ON blogtest.* TO 'username'@'localhost' IDENTIFIED BY 'password'; +``` + +This allows maven build to destroy and recreate the ``blogtest`` schema. + +Since this user has all permissions it is necessary to use unique credentials and protect them. +In Maven this can be done by hiding per-machine credentials in the ``.m2/settings.xml`` file. +Edit the file ``~/.m2/settings.xml`` to have the following. +Ensure the id is set to ``localhost-mariadb-tester`` so that the POM accesses the correct server. + +``` + + + localhost-mariadb-tester + username + password + + +``` + +## Tomcat Configuration + +There are two tomcat configuration items: the MariaDB JDBC driver jar, and the manager interface login. + +To configure the MariaDB driver change directory to ``${tomcat}/lib/`` (where ${tomcat} is the installation location of tomcat) and run the following maven command. + +``` +cd ${tomcat}/lib/ +mvn dependency:copy -Dartifact=org.mariadb.jdbc:mariadb-java-client:2.4.2:jar -DoutputDirectory=./ +``` + +To grant the project permission to deploy the blog.war application, you will need to edit ``${tomcat}/conf/tomcat-users.xml``. +Make sure you have the following lines. Changing passwords to protect your development environment. + +``` + + + + + +``` + +Again you should protect your server by hiding these credentials on the per-machine ``~/.m2/settings.xml`` file. +Make sure that this time the ``id`` is given as ``localhost-tomcat``. + +``` + + + localhost-tomcat + username + password + + +``` + +Now you should be ready to start developing. +To build the project, as usual run + +``` +mvn package +``` + +And to deploy, redeploy, or undeploy the project WAR file to the development tomcat instance, run the following commands. + +``` +mvn tomcat7:deploy +mvn tomcat7:redeploy +mvn tomcat7:undeploy +``` diff --git a/docs/installation.md b/docs/installation.md index 0e30f49..5f06903 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -30,7 +30,7 @@ - UPDATE - DELETE -To create such an account run the following statement, changing username, host to your web server's hostname or IP address and password to a unique password. +To create such an account run the following statement, changing username, host to the hostname or IP address of your database server and password to a unique password. ``` GRANT SELECT, INSERT, UPDATE, DELETE ON blog TO 'username'@'host' IDENTIFIED BY 'password'; diff --git a/pom.xml b/pom.xml index e09e755..167d590 100644 --- a/pom.xml +++ b/pom.xml @@ -161,6 +161,7 @@ org.mariadb.jdbc.Driver ${skipTests} + localhost-mariadb-tester @@ -169,8 +170,6 @@ process-test-sources jdbc:mariadb://localhost:3306 - tester - testingit true DROP SCHEMA IF EXISTS blogtest; continue @@ -182,8 +181,6 @@ generate-test-resources jdbc:mariadb://localhost:3306 - tester - testingit true CREATE SCHEMA blogtest; @@ -194,8 +191,6 @@ process-test-resources jdbc:mariadb://localhost:3306/blogtest - tester - testingit true src/main/sql/setup.sql diff --git a/src/main/webapp/style.css b/src/main/webapp/style.css index 761bec7..442cb91 100644 --- a/src/main/webapp/style.css +++ b/src/main/webapp/style.css @@ -410,6 +410,7 @@ div#contentcontainer img.floatleft { width: 40%; + max-width: 16em; float: left; margin: 0.5em; } diff --git a/src/test/java/kim/redbow/web/blog/TestUtil.java b/src/test/java/kim/redbow/web/blog/TestUtil.java index 39260c0..c8860a2 100644 --- a/src/test/java/kim/redbow/web/blog/TestUtil.java +++ b/src/test/java/kim/redbow/web/blog/TestUtil.java @@ -13,7 +13,7 @@ Class.forName("org.mariadb.jdbc.Driver"); return DriverManager .getConnection("jdbc:mariadb://localhost:3306/blogtest", - "tester", "testingit"); + "blogtester", "testingit"); } catch(SQLException | ClassNotFoundException e) { return null; } }