diff --git a/MtdrSpring/backend/MyTodoList.iml b/MtdrSpring/backend/MyTodoList.iml new file mode 100644 index 0000000..c040de8 --- /dev/null +++ b/MtdrSpring/backend/MyTodoList.iml @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MtdrSpring/backend/build.sh b/MtdrSpring/backend/build.sh index 52ab827..b7019a3 100755 --- a/MtdrSpring/backend/build.sh +++ b/MtdrSpring/backend/build.sh @@ -13,8 +13,6 @@ if [ -z "$DOCKER_REGISTRY" ]; then echo "Error: DOCKER_REGISTRY env variable needs to be set!" exit 1 fi - - export IMAGE=${DOCKER_REGISTRY}/${IMAGE_NAME}:${IMAGE_VERSION} mvn clean package spring-boot:repackage diff --git a/MtdrSpring/backend/deploy.sh b/MtdrSpring/backend/deploy.sh index 29894c3..74dd5c7 100755 --- a/MtdrSpring/backend/deploy.sh +++ b/MtdrSpring/backend/deploy.sh @@ -16,6 +16,17 @@ if [ -z "$OCI_REGION" ]; then echo "Error: OCI_REGION env variable needs to be set!" exit 1 fi + +if [ -z "$UI_USERNAME" ]; then + echo "UI_USERNAME not set. Will get it with state_get" + export UI_USERNAME=$(state_get UI_USERNAME) +fi + +if [ -z "$UI_USERNAME" ]; then + echo "Error: UI_USERNAME env variable needs to be set!" + exit 1 +fi + echo "Creating springboot deplyoment and service" export CURRENTTIME=$( date '+%F_%H:%M:%S' ) echo CURRENTTIME is $CURRENTTIME ...this will be appended to generated deployment yaml @@ -29,7 +40,8 @@ sed -e "s|%TODO_PDB_NAME%|${TODO_PDB_NAME}|g" todolistapp-springboot-${CURRENTTI mv -- /tmp/todolistapp-springboot-$CURRENTTIME.yaml todolistapp-springboot-$CURRENTTIME.yaml sed -e "s|%OCI_REGION%|${OCI_REGION}|g" todolistapp-springboot-${CURRENTTIME}.yaml > /tmp/todolistapp-springboot-$CURRENTTIME.yaml mv -- /tmp/todolistapp-springboot-$CURRENTTIME.yaml todolistapp-springboot-$CURRENTTIME.yaml - +sed -e "s|%UI_USERNAME%|${UI_USERNAME}|g" todolistapp-springboot-${CURRENTTIME}.yaml > /tmp/todolistapp-springboot-$CURRENTTIME.yaml +mv -- /tmp/todolistapp-springboot-$CURRENTTIME.yaml todolistapp-springboot-$CURRENTTIME.yaml if [ -z "$1" ]; then kubectl apply -f $SCRIPT_DIR/todolistapp-springboot-$CURRENTTIME.yaml -n mtdrworkshop else diff --git a/MtdrSpring/backend/pom.xml b/MtdrSpring/backend/pom.xml index 2c5ef5f..52c75bd 100644 --- a/MtdrSpring/backend/pom.xml +++ b/MtdrSpring/backend/pom.xml @@ -16,6 +16,9 @@ 11 21.1.0.0 + ${project.basedir}/src/main/frontend + v16.13.2 + 8.1.2 @@ -58,6 +61,15 @@ spring-boot-starter-test test + + org.springframework.boot + spring-boot-starter-security + + + org.springframework.security + spring-security-test + test + @@ -65,26 +77,55 @@ com.github.eirslett frontend-maven-plugin - 1.9.1 + + ${node.version} + ${npm.version} + ${frontend-src-dir} + ${project.build.directory} + + + + + install-frontend-tools + + install-node-and-npm + + + + npm install + + npm + + + + npm run build + + npm + + + run build + + + org.apache.maven.plugins maven-resources-plugin + 3.2.0 - copy-resources - process-resources + position-react-build copy-resources + prepare-package - ${project.build.directory} + ${project.build.outputDirectory}/static - . - true + ${frontend-src-dir}/build + false diff --git a/MtdrSpring/frontend/package.json b/MtdrSpring/backend/src/main/frontend/package.json similarity index 100% rename from MtdrSpring/frontend/package.json rename to MtdrSpring/backend/src/main/frontend/package.json diff --git a/MtdrSpring/frontend/public/index.html b/MtdrSpring/backend/src/main/frontend/public/index.html similarity index 100% rename from MtdrSpring/frontend/public/index.html rename to MtdrSpring/backend/src/main/frontend/public/index.html diff --git a/MtdrSpring/frontend/public/manifest.json b/MtdrSpring/backend/src/main/frontend/public/manifest.json similarity index 100% rename from MtdrSpring/frontend/public/manifest.json rename to MtdrSpring/backend/src/main/frontend/public/manifest.json diff --git a/MtdrSpring/frontend/public/swagger_APIs_definition.json b/MtdrSpring/backend/src/main/frontend/public/swagger_APIs_definition.json similarity index 100% rename from MtdrSpring/frontend/public/swagger_APIs_definition.json rename to MtdrSpring/backend/src/main/frontend/public/swagger_APIs_definition.json diff --git a/MtdrSpring/frontend/public/swagger_APIs_definition.yaml b/MtdrSpring/backend/src/main/frontend/public/swagger_APIs_definition.yaml similarity index 100% rename from MtdrSpring/frontend/public/swagger_APIs_definition.yaml rename to MtdrSpring/backend/src/main/frontend/public/swagger_APIs_definition.yaml diff --git a/MtdrSpring/frontend/src/API.js b/MtdrSpring/backend/src/main/frontend/src/API.js similarity index 100% rename from MtdrSpring/frontend/src/API.js rename to MtdrSpring/backend/src/main/frontend/src/API.js diff --git a/MtdrSpring/frontend/src/App.js b/MtdrSpring/backend/src/main/frontend/src/App.js similarity index 100% rename from MtdrSpring/frontend/src/App.js rename to MtdrSpring/backend/src/main/frontend/src/App.js diff --git a/MtdrSpring/frontend/src/NewItem.js b/MtdrSpring/backend/src/main/frontend/src/NewItem.js similarity index 100% rename from MtdrSpring/frontend/src/NewItem.js rename to MtdrSpring/backend/src/main/frontend/src/NewItem.js diff --git a/MtdrSpring/frontend/src/index.css b/MtdrSpring/backend/src/main/frontend/src/index.css similarity index 100% rename from MtdrSpring/frontend/src/index.css rename to MtdrSpring/backend/src/main/frontend/src/index.css diff --git a/MtdrSpring/frontend/src/index.js b/MtdrSpring/backend/src/main/frontend/src/index.js similarity index 100% rename from MtdrSpring/frontend/src/index.js rename to MtdrSpring/backend/src/main/frontend/src/index.js diff --git a/MtdrSpring/backend/src/main/java/com/springboot/MyTodoList/security/WebSecurityConfiguration.java b/MtdrSpring/backend/src/main/java/com/springboot/MyTodoList/security/WebSecurityConfiguration.java new file mode 100644 index 0000000..fc0a1c5 --- /dev/null +++ b/MtdrSpring/backend/src/main/java/com/springboot/MyTodoList/security/WebSecurityConfiguration.java @@ -0,0 +1,18 @@ +package com.springboot.MyTodoList.security; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; + + +@Configuration +@EnableWebSecurity +public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter { + @Override + protected void configure(HttpSecurity httpSecurity) throws Exception { + httpSecurity.authorizeRequests().anyRequest().authenticated().and(). + formLogin().and().logout().permitAll(); + } +} diff --git a/MtdrSpring/backend/src/main/resources/application.properties b/MtdrSpring/backend/src/main/resources/application.properties index e93e221..80b15b5 100644 --- a/MtdrSpring/backend/src/main/resources/application.properties +++ b/MtdrSpring/backend/src/main/resources/application.properties @@ -1,9 +1,9 @@ #spring.jpa.database-platform=org.hibernate.dialect.Oracle12cDialect #oracle.jdbc.fanEnabled=false -###this is not used when deployed in kubernetes. Just for local testing -#spring.datasource.url=jdbc:oracle:thin:@petertestdb_medium?TNS_ADMIN=/Users/psong/Downloads/Wallet_petertestDB -#spring.datasource.username=TODOUSER -#spring.datasource.password=PeterSong123 +##this is not used when deployed in kubernetes. Just for local testing +#spring.datasource.url=jdbc:oracle:thin:@adbps_medium?TNS_ADMIN=/Users/psong/Downloads/Wallet_ADBPS +#spring.datasource.username=admin +#spring.datasource.password=WELcome__12345 ##Properties of UCP spring.datasource.driver-class-name=oracle.jdbc.OracleDriver @@ -18,4 +18,7 @@ spring.datasource.oracleucp.max-pool-size=30 ##Logging properties for UCP logging.level.root=trace logging.file.name=logs.log -logging.level.oracle.ucp=trace \ No newline at end of file +logging.level.oracle.ucp=trace + +#spring.security.user.name=psong +#spring.security.user.password=WELcome__12345 \ No newline at end of file diff --git a/MtdrSpring/backend/src/main/resources/application.yaml b/MtdrSpring/backend/src/main/resources/application.yaml index db7d406..8cae7ae 100644 --- a/MtdrSpring/backend/src/main/resources/application.yaml +++ b/MtdrSpring/backend/src/main/resources/application.yaml @@ -10,3 +10,7 @@ spring: hibernate: ddl-auto: none show-sql: true + security: + user: + name: ${ui_username} + password: ${ui_password} \ No newline at end of file diff --git a/MtdrSpring/backend/src/main/resources/todolistapp-springboot.yaml b/MtdrSpring/backend/src/main/resources/todolistapp-springboot.yaml index 6ced9b8..0475949 100644 --- a/MtdrSpring/backend/src/main/resources/todolistapp-springboot.yaml +++ b/MtdrSpring/backend/src/main/resources/todolistapp-springboot.yaml @@ -11,6 +11,19 @@ spec: selector: app: todolistapp-springboot --- +#this is new stuff for hosting on the load balancer +apiVersion: v1 +kind: Service +metadata: + name: todolistapp-backend-router +spec: + selector: + app: todolistapp-springboot + ports: + - protocol: TCP + port: 80 + targetPort: http +--- apiVersion: apps/v1 kind: Deployment metadata: @@ -47,6 +60,14 @@ spec: name: dbuser key: dbpassword optional: true + - name: ui_username + value: "%UI_USERNAME%" + - name: ui_password + valueFrom: + secretKeyRef: + name: frontendadmin + key: password + optional: true volumeMounts: - name: creds mountPath: /mtdrworkshop/creds diff --git a/MtdrSpring/backend/target/classes/application.properties b/MtdrSpring/backend/target/classes/application.properties index e93e221..228f63a 100644 --- a/MtdrSpring/backend/target/classes/application.properties +++ b/MtdrSpring/backend/target/classes/application.properties @@ -1,9 +1,9 @@ -#spring.jpa.database-platform=org.hibernate.dialect.Oracle12cDialect -#oracle.jdbc.fanEnabled=false -###this is not used when deployed in kubernetes. Just for local testing -#spring.datasource.url=jdbc:oracle:thin:@petertestdb_medium?TNS_ADMIN=/Users/psong/Downloads/Wallet_petertestDB -#spring.datasource.username=TODOUSER -#spring.datasource.password=PeterSong123 +spring.jpa.database-platform=org.hibernate.dialect.Oracle12cDialect +oracle.jdbc.fanEnabled=false +##this is not used when deployed in kubernetes. Just for local testing +spring.datasource.url=jdbc:oracle:thin:@adbps_medium?TNS_ADMIN=/Users/psong/Downloads/Wallet_ADBPS +spring.datasource.username=admin +spring.datasource.password=WELcome__12345 ##Properties of UCP spring.datasource.driver-class-name=oracle.jdbc.OracleDriver @@ -18,4 +18,7 @@ spring.datasource.oracleucp.max-pool-size=30 ##Logging properties for UCP logging.level.root=trace logging.file.name=logs.log -logging.level.oracle.ucp=trace \ No newline at end of file +logging.level.oracle.ucp=trace + +spring.security.user.name=psomg +spring.security.user.password=WELcome__12345 \ No newline at end of file diff --git a/MtdrSpring/backend/target/classes/todolistapp-springboot.yaml b/MtdrSpring/backend/target/classes/todolistapp-springboot.yaml index 6ced9b8..f4bc23f 100644 --- a/MtdrSpring/backend/target/classes/todolistapp-springboot.yaml +++ b/MtdrSpring/backend/target/classes/todolistapp-springboot.yaml @@ -11,6 +11,19 @@ spec: selector: app: todolistapp-springboot --- +#this is new stuff for hosting on the load balancer +apiVersion: v1 +kind: Service +metadata: + name: todolistapp-backend-router +spec: + selector: + app: todolistapp-springboot + ports: + - protocol: TCP + port: 80 + targetPort: http +--- apiVersion: apps/v1 kind: Deployment metadata: diff --git a/MtdrSpring/terraform/apigateway.tf b/MtdrSpring/terraform/apigateway.tf index c8999f0..db1222b 100644 --- a/MtdrSpring/terraform/apigateway.tf +++ b/MtdrSpring/terraform/apigateway.tf @@ -1,7 +1,9 @@ -resource "oci_apigateway_gateway" "todolist"{ - #required - compartment_id = var.ociCompartmentOcid - endpoint_type = "PUBLIC" - subnet_id = oci_core_subnet.svclb_Subnet.id - display_name = "todolist" -} \ No newline at end of file +#No longer creating API_gateway + +#resource "oci_apigateway_gateway" "todolist"{ +# #required +# compartment_id = var.ociCompartmentOcid +# endpoint_type = "PUBLIC" +# subnet_id = oci_core_subnet.svclb_Subnet.id +# display_name = "todolist" +#} \ No newline at end of file diff --git a/MtdrSpring/utils/main-setup.sh b/MtdrSpring/utils/main-setup.sh index 76b8f1d..6542f42 100755 --- a/MtdrSpring/utils/main-setup.sh +++ b/MtdrSpring/utils/main-setup.sh @@ -232,6 +232,39 @@ if ! state_done DB_PASSWORD; then BASE64_DB_PASSWORD=`echo -n "$PW" | base64` fi +# create UI username +if ! state_done UI_USERNAME; then + echo + echo 'Create a UI Username' + echo + read -s -r -p "Enter the username to be used for accessing the UI: " USERNAME + state_set UI_USERNAME "$USERNAME" + export UI_USERNAME="$(state_get UI_USERNAME)" + state_set_done UI_USERNAME +fi + +# Collect UI password and create secret +if ! state_done UI_PASSWORD; then + echo + echo 'UI passwords must be 8 to 30 characters' + echo + + while true; do + if test -z "$TEST_UI_PASSWORD"; then + read -s -r -p "Enter the password to be used for accessing the UI: " PW + else + PW="$TEST_UI_PASSWORD" + fi + if [[ ${#PW} -ge 8 && ${#PW} -le 30 ]]; then + echo + break + else + echo "Invalid Password, please retry" + fi + done + BASE64_UI_PASSWORD=`echo -n "$PW" | base64` +fi + # Wait for provisioning if ! state_done PROVISIONING; then echo "`date`: Waiting for terraform provisioning" @@ -314,6 +347,29 @@ while ! state_done OKE_SETUP; do sleep 2 done +# Create UI password secret +while ! state_done UI_PASSWORD; do + while true; do + if kubectl create -n mtdrworkshop -f -; then + state_set_done UI_PASSWORD + break + else + echo 'Error: Creating UI Password Secret Failed. Retrying...' + sleep 10 + fi <