diff --git a/README.md b/README.md index 5aaa319..aa0613b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,38 @@ # Accounting application for the LgHS + +## Devenv, compile and run + +1. create an alias for docker-compose +```bash +alias dcacc='docker-compose -p lghs-accounting -f path/to/accounting/dev-env/docker-compose.yml' +``` + +2. launch db and keycloak +```bash +dcacc up -d db keycloak +``` + +3. init db (only the first time you launch the db) +```bash +cat prepare_db.sql | dcacc exec -T db psql -Upostgres +``` + +4. generate jook tables +```bash +dcacc run --rm app gradle --stacktrace jooq +``` + +5. launch app +```bash +dcacc up -d +``` + +7. add entry to host `127.0.0.1 accounting.local` and connect to https://accounting.local or connect to http://localhost:8080 + + + + ## Dependencies You'll need a postgresql database and a compiled version of [coda-rs](https://github.com/bendem/coda-rs/tree/develop). diff --git a/dev-env/apache/Dockerfile b/dev-env/apache/Dockerfile new file mode 100644 index 0000000..2edcc9b --- /dev/null +++ b/dev-env/apache/Dockerfile @@ -0,0 +1,13 @@ +FROM httpd:2.4 + +RUN mkdir -p /usr/local/apache2/conf/sites/ /usr/local/apache2/htdocs/login +RUN echo 'IncludeOptional /conf/sites/*.conf' | tee -a /usr/local/apache2/conf/httpd.conf + +COPY resources/custom.conf /conf/sites/custom.conf +COPY resources/key /key +COPY resources/cert /cert + + + + + diff --git a/dev-env/apache/resources/cert b/dev-env/apache/resources/cert new file mode 100644 index 0000000..81a4afe --- /dev/null +++ b/dev-env/apache/resources/cert @@ -0,0 +1,21 @@ +-----BEGIN CERTIFICATE----- +MIIDczCCAlugAwIBAgIUaDm8Odr9Md37KJh+ddvLHtf+fn0wDQYJKoZIhvcNAQEL +BQAwSDELMAkGA1UEBhMCQkUxEzARBgNVBAgMClNvbWUtU3RhdGUxDTALBgNVBAoM +BGZyb2wxFTATBgNVBAMMDGNoYW1hbi5sb2NhbDAgFw0yMTExMjIyMTQ5MDBaGA8y +Mjk1MDkwNzIxNDkwMFowSDELMAkGA1UEBhMCQkUxEzARBgNVBAgMClNvbWUtU3Rh +dGUxDTALBgNVBAoMBGZyb2wxFTATBgNVBAMMDGNoYW1hbi5sb2NhbDCCASIwDQYJ +KoZIhvcNAQEBBQADggEPADCCAQoCggEBAMjT9okqxA20zrn78rEs+wmYlvmtZtQg +FGDQjRfLPfl8APYiKxkCR5BV6MAabX0b9JVIr4iyxUvn00Ln+8rgLIA1ZylwQ/aN +2qOAGgKSJrTysKDrPi+nBQBMRFrg+KmtKQadkBp960G+muZ4mlOn2KQiADsBUEXj +7C7g6zaFW+AucTxuB1/iGSIHN8JJuWeR+tWTnZKD9Cj9RW123iJm6MzF3mU8jEju ++3ymkr56guvtKI2DznARzKaoZA3SALFcL9HST766dlfnVJ9xBoXvFI9tbQr6jYI7 +pkdqWILVQ+6D4/nfYkzTdJBncV9sSkMC30KrD+T1YtePCZpJDGToaecCAwEAAaNT +MFEwHQYDVR0OBBYEFDQnyWPiMtOEjmS+VG8TBybCQQQiMB8GA1UdIwQYMBaAFDQn +yWPiMtOEjmS+VG8TBybCQQQiMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQEL +BQADggEBADn7Zpk3hGzV+FeppkJDVZOv5mXjZMDGtJq05ZnDrw52sQgSkOAYw1ed +EAzl08Bh5D48hbUiTAIZfIg0UciZB4ONwfggjirX+3HGx4i+rkxfLn/CTG4bDs0B +p+1a7y0VAw9C6KcL8+J2s7QYN/LvQ7rRmwAvpkNzcY2uNTldGsjDSFiprS62JfLu +NDVzAzLAUEt8yo6Nz+IMOrDqO/BLAkWiOaNt5fA7l8ZhhAb0gXScXJUqvKphuXVo +cXUL5MKgBWwCfZVqhtM2oa43163IdfxJZvBfInWBMXi2sZn2KsBxBkX0yicNbcDw +psN5uaKYHML7D5qwFdiIQByco7js8DQ= +-----END CERTIFICATE----- diff --git a/dev-env/apache/resources/custom.conf b/dev-env/apache/resources/custom.conf new file mode 100644 index 0000000..af47fd5 --- /dev/null +++ b/dev-env/apache/resources/custom.conf @@ -0,0 +1,27 @@ +Listen 443 + +ServerName accounting.local + + + + + LoadModule proxy_module modules/mod_proxy.so + LoadModule proxy_ajp_module modules/mod_proxy_ajp.so + LoadModule proxy_http_module modules/mod_proxy_http.so + LoadModule proxy_html_module modules/mod_proxy_html.so + LoadModule proxy_connect_module modules/mod_proxy_connect.so + LoadModule rewrite_module modules/mod_rewrite.so + LoadModule ssl_module modules/mod_ssl.so + + SSLEngine on + SSLCertificateFile "/cert" + SSLCertificateKeyFile "/key" + + + ProxyPreserveHost On + ProxyPass / http://app:8080/ + ProxyPassReverse / http://app:8080/ + + + + diff --git a/dev-env/apache/resources/key b/dev-env/apache/resources/key new file mode 100644 index 0000000..cde913c --- /dev/null +++ b/dev-env/apache/resources/key @@ -0,0 +1,28 @@ +-----BEGIN PRIVATE KEY----- +MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDI0/aJKsQNtM65 ++/KxLPsJmJb5rWbUIBRg0I0Xyz35fAD2IisZAkeQVejAGm19G/SVSK+IssVL59NC +5/vK4CyANWcpcEP2jdqjgBoCkia08rCg6z4vpwUATERa4PiprSkGnZAafetBvprm +eJpTp9ikIgA7AVBF4+wu4Os2hVvgLnE8bgdf4hkiBzfCSblnkfrVk52Sg/Qo/UVt +dt4iZujMxd5lPIxI7vt8ppK+eoLr7SiNg85wEcymqGQN0gCxXC/R0k++unZX51Sf +cQaF7xSPbW0K+o2CO6ZHaliC1UPug+P532JM03SQZ3FfbEpDAt9Cqw/k9WLXjwma +SQxk6GnnAgMBAAECggEAcHbrQEN3yWkwv8yNS5Ux/Fy8Z5Qo2rAgWVtRODr0OOut +qijWU8oIA5dooXPrTr3CCXvL+VSL0oc/st8xDZresOm3HOim1sL35soNRtVL4ddq +/KLgj1UMIu+S9AW6m2LCb9b65SsQ/R9dpaVyX1jGpJv53xFMP+d004fXkQ+7tN2v +NI/C9WAVwocNX/1nz/tiNgIYDqFpeS//cce89m/k1VtYQsPypIsIkVh9gBDMtJW2 +KTJoShd+hLUlYj5JYoyNHWQZKQ9YIN8p+GDhxL72Xxz3iq0XmsiQTOkqVuq+4Qw0 +GwMZLT1+HUCw5NmNYG61b3HDwPS+ABVvu6l1OOtwCQKBgQDpE124L/rJatLovBJH +BGYnTu0Y1tD9PsYW27HDVWXm9yKiDKss+5KnkZLecAKWUdvQejG8dwdsjCvz0O4v +L4B8esuuhvxoARmzHdKiPw3jwnrf8BokIz3j4smhGizb5M2n9zzSKPqOGaYbUy4Z +UNcfECyzLJbzgW3op1dysN3gGwKBgQDclKE8+w0vrkxW1+GcPk4xMcJUGLC5hzgQ +OLODyqW0rBIW82A8SjBssRynmcO7tZinBbxZaQQtVf6eGP9U3fQPgwR90SrTy0K2 +URmC75QuwZw6OiR0HSZ8ylTJ6B3dW1J3P/lpOPiCgLlpQs63sdZVE6IvlcZlF0k3 +ipBxQ9FyJQKBgHcIWu68IjpHghs2Iad/SaR9nHz5CJatPoFiBfEaZgaE5H0aNzmr +6YQGxpkvX0Lh338jSM9Vgsce9zt30ozql5X7KJajfbioBzYA3xfZWACfzB0eBFu8 +W9lMc2kBczOCML29eKRkJUH5O2ntGzf2n0bP/eQru5P03+rXu8NpLIdNAoGBAJ38 +5q+isQMhuBPLdBBQn/ikRyest4dqzkDwG8Oddao+RIajsp38FUsEYB27CHJ90uRu +O0Ve7lr6aPAbv2Wtw40IrkLfeelQgGvNEpSxvFTw31DlLA7ugg6HbMtgsWNGcX5w +F9fBslzmjeZSr3TqrzUoZtXmVL87OnnJiUNW68DxAoGAKSeg8xQRG26QBKVtrLja +TZpwkbEZIpOY8wMSeOYIVH6PiautbOcWKQo4UpIH2wIX7FM56kgPHitw7/5sZ7CE +pZZNbfS+dPQZp/SIvU3Sw3qxcu2dXcm0dMSS+Wz0HjBfhR0bF8lfF2/dQTLBhAko +fxOx5Y2q7R4hoVa4ysOmye8= +-----END PRIVATE KEY----- diff --git a/dev-env/docker-compose.yml b/dev-env/docker-compose.yml new file mode 100644 index 0000000..eca4893 --- /dev/null +++ b/dev-env/docker-compose.yml @@ -0,0 +1,27 @@ +version: "2" + +services: + + apache: + build: apache + ports: + - 80:80 + - 443:443 + + app: + image: registry.gitlab.com/lghs/accounting/accounting-build-docker + volumes: + - ..:/src + - $HOME/.gradle:/gradle/.gradle + user: $UID + working_dir: /src + command: ["gradle","--stacktrace","bootRun"] + ports: + - 8080:8080 + + db: + image: postgres:13 + environment: + - POSTGRES_HOST_AUTH_METHOD=trust + + diff --git a/gradle.properties b/gradle.properties index 38e4cf9..a45a1d8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ -database_url=jdbc:postgresql:lghs_accounting +database_url=jdbc:postgresql://db/lghs_accounting database_schema=accounting database_driver=org.postgresql.Driver database_user=lghs_accounting_root -database_password= +database_password=lghs_accounting_root_password diff --git a/prepare_db.sql b/prepare_db.sql new file mode 100644 index 0000000..d65fc1f --- /dev/null +++ b/prepare_db.sql @@ -0,0 +1,15 @@ +create user lghs_accounting_root with password 'lghs_accounting_root_password'; -- change it really +create database lghs_accounting owner lghs_accounting_root; + +\c lghs_accounting +revoke all on schema public from public; + +create user lghs_accounting_app with password 'lghs_accounting_app_password'; -- change it really +grant connect on database lghs_accounting to lghs_accounting_app; + +grant usage on schema public to lghs_accounting_root; +grant usage on schema public to lghs_accounting_app; + +create extension "uuid-ossp"; +create extension pgcrypto; +create extension btree_gist; diff --git a/src/main/java/be/lghs/accounting/configuration/WebConfiguration.java b/src/main/java/be/lghs/accounting/configuration/WebConfiguration.java index c66c283..b0bdf1e 100644 --- a/src/main/java/be/lghs/accounting/configuration/WebConfiguration.java +++ b/src/main/java/be/lghs/accounting/configuration/WebConfiguration.java @@ -1,7 +1,10 @@ package be.lghs.accounting.configuration; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.CacheControl; +import org.springframework.mail.javamail.JavaMailSender; +import org.springframework.mail.javamail.JavaMailSenderImpl; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @@ -28,4 +31,10 @@ public void addResourceHandlers(ResourceHandlerRegistry registry) { .addResourceLocations("classpath:/public/") .setCacheControl(staticCacheControl); } + + + @Bean + public JavaMailSender javaMailSender() { + return new JavaMailSenderImpl(); + } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 49b1d88..82c04db 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -7,21 +7,21 @@ logging.config: classpath:logback-spring.xml lghs.accounting: average-monthly-rent: 855 coda-rs: "../coda-rs" - deploy-url: "http://localhost:${server.port:8080}" + deploy-url: "https://accounting.local:${server.port:''}" spring: profiles: active: dev datasource: - url: jdbc:postgresql:lghs_accounting + url: jdbc:postgresql://db/lghs_accounting username: lghs_accounting_app - password: 'change-me' + password: 'lghs_accounting_app_password' flyway: url: ${spring.datasource.url} user: lghs_accounting_root - password: 'change-me' + password: 'lghs_accounting_root_password' schemas: accounting security: