From 0970968f11f20cb1af018a99d37989d759de6f31 Mon Sep 17 00:00:00 2001 From: buddhika Date: Wed, 24 Sep 2025 08:03:06 +0530 Subject: [PATCH 1/4] Signed-off-by: buddhika --- src/main/setup/glassfish-resources.xml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/setup/glassfish-resources.xml b/src/main/setup/glassfish-resources.xml index 740fbe0..488b82e 100644 --- a/src/main/setup/glassfish-resources.xml +++ b/src/main/setup/glassfish-resources.xml @@ -3,11 +3,13 @@ - - - - - + + + + + + + From fdca16a66ee8b49095c419470cad2f013e40703a Mon Sep 17 00:00:00 2001 From: Chinthaka Date: Thu, 9 Oct 2025 12:20:42 +0530 Subject: [PATCH 2/4] Signed-off-by: Chinthaka --- .github/workflows/drawer_prod_ci_cd.yml | 180 ++++++++++++------------ 1 file changed, 90 insertions(+), 90 deletions(-) diff --git a/.github/workflows/drawer_prod_ci_cd.yml b/.github/workflows/drawer_prod_ci_cd.yml index 8c4b4ba..47f7157 100644 --- a/.github/workflows/drawer_prod_ci_cd.yml +++ b/.github/workflows/drawer_prod_ci_cd.yml @@ -49,93 +49,93 @@ jobs: # - name: Run Tests # run: mvn test - # deploy: - # needs: build - # runs-on: ubuntu-latest - - # steps: - # - name: Checkout Code - # uses: actions/checkout@v4 - - # - name: Download Build Artifact - # uses: actions/download-artifact@v4 - # with: - # name: build-artifacts - # path: ./ - - # - name: Deploy to Payara - # env: - # SERVER_IP: ${{ secrets.RUHUNU_DRAWER_IP }} - # SERVER_USER: ${{ secrets.RUHUNU_DRAWER_USER }} - # SSH_PRIVATE_KEY: ${{ secrets.RUHUNU_DRAWER_SSH_PRIVATE_KEY }} - # PAYARA_ADMIN_PASS: ${{ secrets.RUHUNU_DRAWER_PAYARA_ADMIN_PASSWORD }} - # run: | - # # Add SSH private key to the SSH agent - # echo "$SSH_PRIVATE_KEY" > private_key.pem - # chmod 600 private_key.pem - - # # Variables - # WAR_NAME="drawer.war" - # WAR_DIR="/home/appuser/app/latest" - # APP_NAME="drawer" - # SUBDOMAIN="rhdrawer" - - # # Ensure deployment directory exists - # ssh -i private_key.pem -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP " - # mkdir -p $WAR_DIR - # chown -R appuser:appuser $WAR_DIR - # cd $WAR_DIR - - # # Remove old backup if it exists - # if [ -f $WAR_NAME.old ]; then - # rm $WAR_NAME.old - # fi - - # # If the current WAR file exists, back it up - # if [ -f $WAR_NAME ]; then - # mv $WAR_NAME $WAR_NAME.old - # fi - # " - - # # Copy new WAR file to the server - # rsync -aL --progress -e "ssh -i private_key.pem" ./*.war $SERVER_USER@$SERVER_IP:$WAR_DIR/$WAR_NAME - - # # Set the WAR file permission - # ssh -i private_key.pem -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP " - # chown appuser:appuser $WAR_DIR/$WAR_NAME - # " - - # # Deploy the WAR using asadmin - # ssh -i private_key.pem -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP " - # echo 'AS_ADMIN_PASSWORD=$PAYARA_ADMIN_PASS' > /tmp/payara-admin-pass.txt - # /opt/payara5/bin/asadmin --user admin --passwordfile /tmp/payara-admin-pass.txt undeploy $APP_NAME || true - # /opt/payara5/bin/asadmin --user admin --passwordfile /tmp/payara-admin-pass.txt deploy --force=true --contextroot $APP_NAME $WAR_DIR/$WAR_NAME - # rm /tmp/payara-admin-pass.txt - # " - - # # Validate if the application is running - # ssh -i private_key.pem -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP " - # echo 'AS_ADMIN_PASSWORD=$PAYARA_ADMIN_PASS' > /tmp/payara-admin-pass.txt - # if /opt/payara5/bin/asadmin --user admin --passwordfile /tmp/payara-admin-pass.txt list-applications | grep -q '$APP_NAME'; then - # echo 'Application is running.' - # else - # echo 'Application failed to start.' - # fi - # rm /tmp/payara-admin-pass.txt - # " - - # # Check if the application is reachable - # for i in {1..5}; do - # RESPONSE_CODE=$(curl -s -o /dev/null -w "%{http_code}" https://$SUBDOMAIN.carecode.org/$APP_NAME/) - # if [ "$RESPONSE_CODE" == "200" ]; then - # echo "Application is reachable and healthy." - # break - # elif [ "$i" == "5" ]; then - # echo "Application is not reachable or unhealthy at https://$SUBDOMAIN.carecode.org/$APP_NAME (HTTP $RESPONSE_CODE)" - # break - # fi - # sleep 10 - # done - - # # Cleanup - # rm -f private_key.pem + deploy: + needs: build + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Download Build Artifact + uses: actions/download-artifact@v4 + with: + name: build-artifacts + path: ./ + + - name: Deploy to Payara + env: + SERVER_IP: ${{ secrets.RUHUNU_DRAWER_IP }} + SERVER_USER: ${{ secrets.RUHUNU_DRAWER_USER }} + SSH_PRIVATE_KEY: ${{ secrets.RUHUNU_DRAWER_SSH_PRIVATE_KEY }} + PAYARA_ADMIN_PASS: ${{ secrets.RUHUNU_DRAWER_PAYARA_ADMIN_PASSWORD }} + run: | + # Add SSH private key to the SSH agent + echo "$SSH_PRIVATE_KEY" > private_key.pem + chmod 600 private_key.pem + + # Variables + WAR_NAME="drawer.war" + WAR_DIR="/home/appuser/app/latest" + APP_NAME="drawer" + SUBDOMAIN="rhdrawer" + + # Ensure deployment directory exists + ssh -i private_key.pem -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP " + mkdir -p $WAR_DIR + chown -R appuser:appuser $WAR_DIR + cd $WAR_DIR + + # Remove old backup if it exists + if [ -f $WAR_NAME.old ]; then + rm $WAR_NAME.old + fi + + # If the current WAR file exists, back it up + if [ -f $WAR_NAME ]; then + mv $WAR_NAME $WAR_NAME.old + fi + " + + # Copy new WAR file to the server + rsync -aL --progress -e "ssh -i private_key.pem" ./*.war $SERVER_USER@$SERVER_IP:$WAR_DIR/$WAR_NAME + + # Set the WAR file permission + ssh -i private_key.pem -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP " + chown appuser:appuser $WAR_DIR/$WAR_NAME + " + + # Deploy the WAR using asadmin + ssh -i private_key.pem -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP " + echo 'AS_ADMIN_PASSWORD=$PAYARA_ADMIN_PASS' > /tmp/payara-admin-pass.txt + /opt/payara5/bin/asadmin --user admin --passwordfile /tmp/payara-admin-pass.txt undeploy $APP_NAME || true + /opt/payara5/bin/asadmin --user admin --passwordfile /tmp/payara-admin-pass.txt deploy --force=true --contextroot $APP_NAME $WAR_DIR/$WAR_NAME + rm /tmp/payara-admin-pass.txt + " + + # Validate if the application is running + ssh -i private_key.pem -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP " + echo 'AS_ADMIN_PASSWORD=$PAYARA_ADMIN_PASS' > /tmp/payara-admin-pass.txt + if /opt/payara5/bin/asadmin --user admin --passwordfile /tmp/payara-admin-pass.txt list-applications | grep -q '$APP_NAME'; then + echo 'Application is running.' + else + echo 'Application failed to start.' + fi + rm /tmp/payara-admin-pass.txt + " + + # Check if the application is reachable + for i in {1..5}; do + RESPONSE_CODE=$(curl -s -o /dev/null -w "%{http_code}" https://$SUBDOMAIN.carecode.org/$APP_NAME/) + if [ "$RESPONSE_CODE" == "200" ]; then + echo "Application is reachable and healthy." + break + elif [ "$i" == "5" ]; then + echo "Application is not reachable or unhealthy at https://$SUBDOMAIN.carecode.org/$APP_NAME (HTTP $RESPONSE_CODE)" + break + fi + sleep 10 + done + + # Cleanup + rm -f private_key.pem From d11e2261ab222f3bc5ca02a159aa03f502ce9d52 Mon Sep 17 00:00:00 2001 From: buddhika Date: Wed, 29 Oct 2025 20:11:38 +0530 Subject: [PATCH 3/4] Signed-off-by: buddhika --- .claude/settings.local.json | 26 +++++++++++++++++++ src/main/resources/META-INF/persistence.xml | 2 +- src/main/setup/glassfish-resources.xml | 4 +-- src/main/webapp/admin_manage_users.xhtml | 2 +- .../webapp/resources/template/template.xhtml | 16 ++++++------ 5 files changed, 38 insertions(+), 12 deletions(-) create mode 100644 .claude/settings.local.json diff --git a/.claude/settings.local.json b/.claude/settings.local.json new file mode 100644 index 0000000..e40e6ce --- /dev/null +++ b/.claude/settings.local.json @@ -0,0 +1,26 @@ +{ + "permissions": { + "allow": [ + "Read(//d/tmp/**)", + "Bash(D:\\Payara\\bin\\asadmin.bat list-connection-pools:*)", + "Bash(D:\\Payara\\bin\\asadmin.bat list-jdbc-resources:*)", + "Read(//d/Payara/bin/**)", + "Read(//d/Payara/glassfish/bin/**)", + "Bash(asadmin.bat list-jdbc-resources:*)", + "Bash(\"D:\\Payara\\glassfish\\bin\\asadmin.bat\" list-connection-pools)", + "Bash(\"D:\\Payara\\glassfish\\bin\\asadmin.bat\" list-jdbc-resources)", + "Bash(\"D:\\Payara\\glassfish\\bin\\asadmin.bat\" list-jdbc-connection-pools)", + "Bash(\"D:\\Payara\\glassfish\\bin\\asadmin.bat\" ping-connection-pool mysql_drawer_rootPool)", + "Bash(\"D:\\Payara\\glassfish\\bin\\asadmin.bat\" ping-connection-pool coopAzure)", + "Bash(\"D:\\Payara\\glassfish\\bin\\asadmin.bat\" get-property domain1.resources.jdbc-connection-pool.coopAzure.datasource-classname)", + "Bash(\"D:\\Payara\\glassfish\\bin\\asadmin.bat\" get domain1.resources.jdbc-connection-pool.coopAzure.datasource-classname)", + "Bash(\"D:\\Payara\\glassfish\\bin\\asadmin.bat\" get domain1.resources.jdbc-connection-pool.mysql_drawer_rootPool.datasource-classname)", + "Bash(\"D:\\Payara\\glassfish\\bin\\asadmin.bat\" get domain1.resources.jdbc-connection-pool.coopAzure.property.driverClass)", + "Bash(\"D:\\Payara\\glassfish\\bin\\asadmin.bat\" create-jdbc-connection-pool --datasourceclassname com.mysql.cj.jdbc.MysqlDataSource --restype javax.sql.DataSource --property user=hmis_admin:password=DHyMGgy7RRl8EPe:databaseName=rhdrawer:serverName=localhost:port=3336:useSSL=false:allowPublicKeyRetrieval=true:zeroDateTimeBehavior=CONVERT_TO_NULL rhdrawerPool)", + "Bash(\"D:\\Payara\\glassfish\\bin\\asadmin.bat\" create-jdbc-resource --connectionpoolid rhdrawerPool jdbc/rhdrawer)", + "Bash(\"D:\\Payara\\glassfish\\bin\\asadmin.bat\" ping-connection-pool rhdrawerPool)" + ], + "deny": [], + "ask": [] + } +} \ No newline at end of file diff --git a/src/main/resources/META-INF/persistence.xml b/src/main/resources/META-INF/persistence.xml index 8825bb1..6a837ad 100644 --- a/src/main/resources/META-INF/persistence.xml +++ b/src/main/resources/META-INF/persistence.xml @@ -2,7 +2,7 @@ org.eclipse.persistence.jpa.PersistenceProvider - jdbc/drawer + jdbc/rhdrawer false diff --git a/src/main/setup/glassfish-resources.xml b/src/main/setup/glassfish-resources.xml index 488b82e..1a18610 100644 --- a/src/main/setup/glassfish-resources.xml +++ b/src/main/setup/glassfish-resources.xml @@ -1,7 +1,7 @@ - + @@ -10,7 +10,7 @@ - + diff --git a/src/main/webapp/admin_manage_users.xhtml b/src/main/webapp/admin_manage_users.xhtml index 38eed71..8126ad5 100644 --- a/src/main/webapp/admin_manage_users.xhtml +++ b/src/main/webapp/admin_manage_users.xhtml @@ -10,7 +10,7 @@ - + diff --git a/src/main/webapp/resources/template/template.xhtml b/src/main/webapp/resources/template/template.xhtml index 43ad7cb..2de746e 100644 --- a/src/main/webapp/resources/template/template.xhtml +++ b/src/main/webapp/resources/template/template.xhtml @@ -34,7 +34,7 @@ - + @@ -68,12 +68,12 @@ - - - - - - + + + + + + @@ -93,7 +93,7 @@ - +
From 2272972a889ad4c1cb3cc8903e82007a1f6d0612 Mon Sep 17 00:00:00 2001 From: buddhika Date: Wed, 29 Oct 2025 22:44:03 +0530 Subject: [PATCH 4/4] Signed-off-by: buddhika --- .../com/divudi/bean/SecurityController.java | 20 +++++++++- .../com/divudi/bean/SessionController.java | 40 +++++++++++++++++-- .../com/divudi/bean/WebUserController.java | 36 ++++++++++++++--- .../webapp/resources/template/template.xhtml | 16 ++++---- 4 files changed, 93 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/divudi/bean/SecurityController.java b/src/main/java/com/divudi/bean/SecurityController.java index a80b231..aff06e9 100644 --- a/src/main/java/com/divudi/bean/SecurityController.java +++ b/src/main/java/com/divudi/bean/SecurityController.java @@ -30,6 +30,9 @@ public SecurityController() { } public String encrypt(String word) { + if (word == null) { + return null; + } BasicTextEncryptor en = new BasicTextEncryptor(); en.setPassword("health"); try { @@ -40,6 +43,9 @@ public String encrypt(String word) { } public String hash(String word) { + if (word == null) { + return null; + } try { BasicPasswordEncryptor en = new BasicPasswordEncryptor(); return en.encryptPassword(word); @@ -49,11 +55,21 @@ public String hash(String word) { } public boolean matchPassword(String planePassword, String encryptedPassword) { - BasicPasswordEncryptor en = new BasicPasswordEncryptor(); - return en.checkPassword(planePassword, encryptedPassword); + if (planePassword == null || encryptedPassword == null) { + return false; + } + try { + BasicPasswordEncryptor en = new BasicPasswordEncryptor(); + return en.checkPassword(planePassword, encryptedPassword); + } catch (Exception e) { + return false; + } } public String decrypt(String word) { + if (word == null) { + return null; + } BasicTextEncryptor en = new BasicTextEncryptor(); en.setPassword("health"); try { diff --git a/src/main/java/com/divudi/bean/SessionController.java b/src/main/java/com/divudi/bean/SessionController.java index e6f7971..72b2eed 100644 --- a/src/main/java/com/divudi/bean/SessionController.java +++ b/src/main/java/com/divudi/bean/SessionController.java @@ -304,8 +304,22 @@ public void changeCurrentUserPassword() { public Boolean userNameAvailable(String userName) { Boolean available = true; List allUsers = getFacede().findAll(); + + if (getSecurityController() == null || userName == null) { + return available; + } + for (WebUser w : allUsers) { - if (userName.toLowerCase().equals(getSecurityController().decrypt(w.getName()).toLowerCase())) { + if (w.getName() == null) { + continue; + } + + String decryptedName = getSecurityController().decrypt(w.getName()); + if (decryptedName == null) { + continue; + } + + if (userName.toLowerCase().equals(decryptedName.toLowerCase())) { available = false; } } @@ -336,13 +350,29 @@ private boolean checkUsers() { String temSQL; temSQL = "SELECT u FROM WebUser u WHERE u.retired = false"; List allUsers = getFacede().findBySQL(temSQL); + + if (getSecurityController() == null) { + UtilityController.addErrorMessage("Security controller not initialized"); + return false; + } + for (WebUser u : allUsers) { // System.out.println("u = " + u); // System.out.println("u.getId() = " + u.getId()); // System.out.println("u.getId() = " + u.getCode()); // System.out.println("u.getName() = " + u.getName()); // System.out.println("userName = " + userName); - if (getSecurityController().decrypt(u.getName()).equalsIgnoreCase(userName)) { + + if (u.getName() == null) { + continue; + } + + String decryptedName = getSecurityController().decrypt(u.getName()); + if (decryptedName == null) { + continue; + } + + if (decryptedName.equalsIgnoreCase(userName)) { boolean passwordMatch = getSecurityController().matchPassword(passord, u.getWebUserPassword()); @@ -556,7 +586,11 @@ public void setrFacade(WebUserRoleFacade rFacade) { } public String getDisplayName() { - return getSecurityController().decrypt(getLoggedUser().getName()); + if (getSecurityController() == null || getLoggedUser() == null || getLoggedUser().getName() == null) { + return ""; + } + String decryptedName = getSecurityController().decrypt(getLoggedUser().getName()); + return decryptedName != null ? decryptedName : ""; } /** diff --git a/src/main/java/com/divudi/bean/WebUserController.java b/src/main/java/com/divudi/bean/WebUserController.java index b4a9ab0..7defa9d 100644 --- a/src/main/java/com/divudi/bean/WebUserController.java +++ b/src/main/java/com/divudi/bean/WebUserController.java @@ -143,8 +143,18 @@ public void removeUser() { } public void updateUser(WebUser wu) { + if (wu == null) { + UtilityController.addErrorMessage("No user to update"); + return; + } + System.out.println("wu.getName() = " + wu.getName()); - wu.setName(getSecurityController().encrypt(wu.getName())); + if (getSecurityController() != null && wu.getName() != null) { + String encryptedName = getSecurityController().encrypt(wu.getName()); + if (encryptedName != null) { + wu.setName(encryptedName); + } + } System.out.println("wu.getName() = " + wu.getName()); getPersonFacade().edit(wu.getWebUserPerson()); getFacade().edit(wu); @@ -301,10 +311,19 @@ public List getItems() { private void dycryptName() { List temp = items; + if (getSecurityController() == null) { + return; + } + for (int i = 0; i < temp.size(); i++) { WebUser w = temp.get(i); - w.setName(getSecurityController().decrypt(w.getName()).toLowerCase()); - temp.set(i, w); + if (w != null && w.getName() != null) { + String decryptedName = getSecurityController().decrypt(w.getName()); + if (decryptedName != null) { + w.setName(decryptedName.toLowerCase()); + temp.set(i, w); + } + } } items = temp; @@ -379,10 +398,15 @@ public Boolean userNameAvailable(String userName) { if (allUsers == null) { return false; } - for (WebUser w : allUsers) { - if (userName != null && w != null && w.getName() != null) { - if (userName.toLowerCase().equals(getSecurityController().decrypt(w.getName()).toLowerCase())) { + if (getSecurityController() == null || userName == null) { + return false; + } + + for (WebUser w : allUsers) { + if (w != null && w.getName() != null) { + String decryptedName = getSecurityController().decrypt(w.getName()); + if (decryptedName != null && userName.toLowerCase().equals(decryptedName.toLowerCase())) { //////System.out.println("Ift"); available = true; return available;// ok. that is may be the issue. we will try with it ok diff --git a/src/main/webapp/resources/template/template.xhtml b/src/main/webapp/resources/template/template.xhtml index 2de746e..43ad7cb 100644 --- a/src/main/webapp/resources/template/template.xhtml +++ b/src/main/webapp/resources/template/template.xhtml @@ -34,7 +34,7 @@ - + @@ -68,12 +68,12 @@ - - - - - - + + + + + + @@ -93,7 +93,7 @@ - +