diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..edf8a303d --- /dev/null +++ b/.gitignore @@ -0,0 +1,50 @@ +# These are some examples of commonly ignored file patterns. +# You should customize this list as applicable to your project. +# Learn more about .gitignore: +# https://www.atlassian.com/git/tutorials/saving-changes/gitignore + +# Node artifact files +node_modules/ +dist/ + +# Compiled Java class files +*.class + +# Compiled Python bytecode +#*.py[cod] + +# Log files +*.log + +# Package files +*.jar + +# Maven +target/ +dist/ + +# JetBrains IDE +.idea/ + +# Unit test reports +TEST*.xml + +# Generated by MacOS +.DS_Store + +# Generated by Windows +Thumbs.db + +# Applications +*.app +#*.exe +*.war + +# Large media files +*.mp4 +*.tiff +*.avi +*.flv +*.mov +*.wmv + diff --git a/Jenkinsfile b/Jenkinsfile deleted file mode 100644 index be7508be5..000000000 --- a/Jenkinsfile +++ /dev/null @@ -1,121 +0,0 @@ -pipeline { - - agent any -/* - tools { - maven "maven3" - } -*/ - environment { - NEXUS_VERSION = "nexus3" - NEXUS_PROTOCOL = "http" - NEXUS_URL = "172.31.40.209:8081" - NEXUS_REPOSITORY = "vprofile-release" - NEXUS_REPO_ID = "vprofile-release" - NEXUS_CREDENTIAL_ID = "nexuslogin" - ARTVERSION = "${env.BUILD_ID}" - } - - stages{ - - stage('BUILD'){ - steps { - sh 'mvn clean install -DskipTests' - } - post { - success { - echo 'Now Archiving...' - archiveArtifacts artifacts: '**/target/*.war' - } - } - } - - stage('UNIT TEST'){ - steps { - sh 'mvn test' - } - } - - stage('INTEGRATION TEST'){ - steps { - sh 'mvn verify -DskipUnitTests' - } - } - - stage ('CODE ANALYSIS WITH CHECKSTYLE'){ - steps { - sh 'mvn checkstyle:checkstyle' - } - post { - success { - echo 'Generated Analysis Result' - } - } - } - - stage('CODE ANALYSIS with SONARQUBE') { - - environment { - scannerHome = tool 'sonarscanner4' - } - - steps { - withSonarQubeEnv('sonar-pro') { - sh '''${scannerHome}/bin/sonar-scanner -Dsonar.projectKey=vprofile \ - -Dsonar.projectName=vprofile-repo \ - -Dsonar.projectVersion=1.0 \ - -Dsonar.sources=src/ \ - -Dsonar.java.binaries=target/test-classes/com/visualpathit/account/controllerTest/ \ - -Dsonar.junit.reportsPath=target/surefire-reports/ \ - -Dsonar.jacoco.reportsPath=target/jacoco.exec \ - -Dsonar.java.checkstyle.reportPaths=target/checkstyle-result.xml''' - } - - timeout(time: 10, unit: 'MINUTES') { - waitForQualityGate abortPipeline: true - } - } - } - - stage("Publish to Nexus Repository Manager") { - steps { - script { - pom = readMavenPom file: "pom.xml"; - filesByGlob = findFiles(glob: "target/*.${pom.packaging}"); - echo "${filesByGlob[0].name} ${filesByGlob[0].path} ${filesByGlob[0].directory} ${filesByGlob[0].length} ${filesByGlob[0].lastModified}" - artifactPath = filesByGlob[0].path; - artifactExists = fileExists artifactPath; - if(artifactExists) { - echo "*** File: ${artifactPath}, group: ${pom.groupId}, packaging: ${pom.packaging}, version ${pom.version} ARTVERSION"; - nexusArtifactUploader( - nexusVersion: NEXUS_VERSION, - protocol: NEXUS_PROTOCOL, - nexusUrl: NEXUS_URL, - groupId: pom.groupId, - version: ARTVERSION, - repository: NEXUS_REPOSITORY, - credentialsId: NEXUS_CREDENTIAL_ID, - artifacts: [ - [artifactId: pom.artifactId, - classifier: '', - file: artifactPath, - type: pom.packaging], - [artifactId: pom.artifactId, - classifier: '', - file: "pom.xml", - type: "pom"] - ] - ); - } - else { - error "*** File: ${artifactPath}, could not be found"; - } - } - } - } - - - } - - -} diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF new file mode 100644 index 000000000..59499bce4 --- /dev/null +++ b/META-INF/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 + diff --git a/README.md b/README.md index 88fd3cbba..268549b37 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Prerequisites # -- JDK 11 -- Maven 3 +- JDK 17 +- Maven 3.9 - MySQL 8 # Technologies diff --git a/ansible/ansible.cfg b/ansible/ansible.cfg deleted file mode 100644 index 6d2dcd6a9..000000000 --- a/ansible/ansible.cfg +++ /dev/null @@ -1,3 +0,0 @@ -[defaults] -host_key_checking = False -timeout = 30 diff --git a/ansible/site.yml b/ansible/site.yml deleted file mode 100644 index 59aebc9bf..000000000 --- a/ansible/site.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- -- import_playbook: tomcat_setup.yml -- import_playbook: vpro-app-setup.yml - -#### diff --git a/ansible/templates/application.j2 b/ansible/templates/application.j2 deleted file mode 100644 index d930446bb..000000000 --- a/ansible/templates/application.j2 +++ /dev/null @@ -1,25 +0,0 @@ -#JDBC Configutation for Database Connection -jdbc.driverClassName=com.mysql.jdbc.Driver -jdbc.url=jdbc:mysql://dbhost:3306/accounts?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull -jdbc.username=db_user -jdbc.password=db_password - -#Memcached Configuration For Active and StandBy Host -#For Active Host -memcached.active.host=127.0.0.1 -memcached.active.port=11211 -#For StandBy Host -memcached.standBy.host=127.0.0.2 -memcached.standBy.port=11211 - -#RabbitMq Configuration -rabbitmq.address=18.220.62.126 -rabbitmq.port=5672 -rabbitmq.username=test -rabbitmq.password=test - -#Elasticesearch Configuration -elasticsearch.host =192.168.1.85 -elasticsearch.port =9300 -elasticsearch.cluster=vprofile -elasticsearch.node=vprofilenode diff --git a/ansible/templates/epel6-svcfile.j2 b/ansible/templates/epel6-svcfile.j2 deleted file mode 100644 index 379d55164..000000000 --- a/ansible/templates/epel6-svcfile.j2 +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash - -### BEGIN INIT INFO -# Provides: tomcat7 -# Required-Start: $network -# Required-Stop: $network -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: Start/Stop Tomcat server -### END INIT INFO - -PATH=/sbin:/bin:/usr/sbin:/usr/bin - -start() { -sh /usr/local/tomcat8/bin/startup.sh -} - -stop() { -sh /usr/local/tomcat8/bin/shutdown.sh -} - -status() { -pid=$(ps -fe | grep '/usr/local/tomcat8' | grep -v grep | tr -s " " | cut -d" " -f2) - if [ -n "$pid" ]; then - echo -e "\e[00;32mTomcat is running with pid: $pid\e[00m" - else - echo -e "\e[00;31mTomcat is not running\e[00m" - fi -} - -case $1 in -start|stop|status) $1;; -restart) stop; start;; -*) echo "Run as $0 "; exit 1;; -esac -exit 0 - - diff --git a/ansible/templates/epel7-svcfile.j2 b/ansible/templates/epel7-svcfile.j2 deleted file mode 100644 index feb317ccd..000000000 --- a/ansible/templates/epel7-svcfile.j2 +++ /dev/null @@ -1,18 +0,0 @@ -[Unit] -Description=Tomcat -After=network.target - -[Service] -User=tomcat -WorkingDirectory=/usr/local/tomcat8 -Environment=JRE_HOME=/usr/lib/jvm/jre -Environment=JAVA_HOME=/usr/lib/jvm/jre -Environment=CATALINA_HOME=/usr/local/tomcat8 -Environment=CATALINE_BASE=/usr/local/tomcat8 -ExecStart=/usr/local/tomcat8/bin/catalina.sh run -ExecStop=/usr/local/tomcat8/bin/shutdown.sh -SyslogIdentifier=tomcat-%i - -[Install] -WantedBy=multi-user.target - diff --git a/ansible/templates/ubuntu14_15-svcfile.j2 b/ansible/templates/ubuntu14_15-svcfile.j2 deleted file mode 100644 index 379d55164..000000000 --- a/ansible/templates/ubuntu14_15-svcfile.j2 +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash - -### BEGIN INIT INFO -# Provides: tomcat7 -# Required-Start: $network -# Required-Stop: $network -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: Start/Stop Tomcat server -### END INIT INFO - -PATH=/sbin:/bin:/usr/sbin:/usr/bin - -start() { -sh /usr/local/tomcat8/bin/startup.sh -} - -stop() { -sh /usr/local/tomcat8/bin/shutdown.sh -} - -status() { -pid=$(ps -fe | grep '/usr/local/tomcat8' | grep -v grep | tr -s " " | cut -d" " -f2) - if [ -n "$pid" ]; then - echo -e "\e[00;32mTomcat is running with pid: $pid\e[00m" - else - echo -e "\e[00;31mTomcat is not running\e[00m" - fi -} - -case $1 in -start|stop|status) $1;; -restart) stop; start;; -*) echo "Run as $0 "; exit 1;; -esac -exit 0 - - diff --git a/ansible/templates/ubuntu16-svcfile.j2 b/ansible/templates/ubuntu16-svcfile.j2 deleted file mode 100644 index 423b00d60..000000000 --- a/ansible/templates/ubuntu16-svcfile.j2 +++ /dev/null @@ -1,18 +0,0 @@ -[Unit] -Description=Tomcat -After=network.target - -[Service] -User=tomcat -WorkingDirectory=/usr/local/tomcat8 -Environment=JRE_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre -Environment=JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre -Environment=CATALINA_HOME=/usr/local/tomcat8 -Environment=CATALINE_BASE=/usr/local/tomcat8 -ExecStart=/usr/local/tomcat8/bin/catalina.sh run -ExecStop=/usr/local/tomcat8/bin/shutdown.sh -SyslogIdentifier=tomcat-%i - -[Install] -WantedBy=multi-user.target - diff --git a/ansible/tomcat_setup.yml b/ansible/tomcat_setup.yml deleted file mode 100644 index 66dff8904..000000000 --- a/ansible/tomcat_setup.yml +++ /dev/null @@ -1,113 +0,0 @@ -- name: Common tool setup on all the servers - hosts: appsrvgrp - become: yes - vars: - tom_url: https://archive.apache.org/dist/tomcat/tomcat-8/v8.5.37/bin/apache-tomcat-8.5.37.tar.gz - - tasks: - - name: Install JDK on Centos 6/7 - yum: - name: java-1.8.0-openjdk.x86_64 - state: present - when: ansible_distribution == 'CentOS' - - - name: Install JDK on Ubuntu 14/15/16/18 - apt: - name: openjdk-8-jdk - state: present - update_cache: yes - when: ansible_distribution == 'Ubuntu' - - - name: Download Tomcat Tar Ball/Binaries - get_url: - url: "{{tom_url}}" - dest: /tmp/tomcat-8.tar.gz - - - name: Add tomcat group - group: - name: tomcat - state: present - - - name: Add tomcat user - user: - name: tomcat - group: tomcat - shell: /bin/nologin - home: /usr/local/tomcat8 - - - file: - path: /tmp/tomcat8 - state: directory - - - name: Extract tomcat - unarchive: - src: /tmp/tomcat-8.tar.gz - dest: /tmp/tomcat8/ - remote_src: yes - list_files: yes - register: unarchive_info - - - debug: - msg: "{{unarchive_info.files[0].split('/')[0]}}" - - - name: Synchronize /tmp/tomcat8/tomcat_cont /usr/local/tomcat8. - synchronize: - src: "/tmp/tomcat8/{{unarchive_info.files[0].split('/')[0]}}/" - dest: /usr/local/tomcat8/ - delegate_to: "{{ inventory_hostname }}" - - - name: Change ownership of /usr/local/tomcat8 - file: - path: /usr/local/tomcat8 - owner: tomcat - group: tomcat - recurse: yes - - - name: Setup tomcat SVC file on Centos 7 - template: - src: templates/epel7-svcfile.j2 - dest: /etc/systemd/system/tomcat.service - mode: "a+x" - when: ansible_distribution == 'CentOS' and ansible_distribution_major_version == '7' - - - name: Setup tomcat SVC file on Centos 6 - template: - src: templates/epel6-svcfile.j2 - dest: /etc/init.d/tomcat - mode: "a+x" - when: ansible_distribution == 'CentOS' and ansible_distribution_major_version == '6' - - - name: Setup tomcat SVC file on ubuntu 14/15 - template: - src: templates/ubuntu14_15-svcfile.j2 - dest: /etc/init.d/tomcat - mode: "a+x" - when: ansible_distribution == 'Ubuntu' and ansible_distribution_major_version < '16' - - - name: Setup tomcat SVC file on ubuntu 16 and 18 - template: - src: templates/ubuntu16-svcfile.j2 - dest: /etc/systemd/system/tomcat.service - mode: "a+x" - when: ansible_distribution == 'Ubuntu' and ansible_distribution_major_version >= '16' - - - name: Reload tomcat svc config in ubuntu 14/15 - command: update-rc.d tomcat defaults - when: ansible_distribution == 'Ubuntu' and ansible_distribution_major_version < '16' - - - name: Reload tomcat svc config in Centos 6 - command: chkconfig --add tomcat - when: ansible_distribution == 'CentOS' and ansible_distribution_major_version == '6' - - - name: just force systemd to reread configs (2.4 and above) - systemd: - daemon_reload: yes - when: ansible_distribution_major_version > '6' or ansible_distribution_major_version > '15' - - - name: Start & Enable TOmcat 8 - service: - name: tomcat - state: started - enabled: yes - - diff --git a/ansible/vpro-app-setup.yml b/ansible/vpro-app-setup.yml deleted file mode 100644 index 0c3f5d4a5..000000000 --- a/ansible/vpro-app-setup.yml +++ /dev/null @@ -1,105 +0,0 @@ - -- name: Setup Tomcat8 & Deploy Artifact - hosts: appsrvgrp - become: yes - vars: - timestamp: "{{ansible_date_time.date}}_{{ansible_date_time.hour}}_{{ansible_date_time.minute}}" - tasks: - - name: Download latest VProfile.war from nexus - get_url: - url: "http://{{USER}}:{{PASS}}@{{nexusip}}:8081/repository/{{reponame}}/{{groupid}}/{{time}}/{{build}}/{{vprofile_version}}" - dest: "/tmp/vproapp-{{vprofile_version}}" - register: wardeploy - tags: - - deploy - - - stat: - path: /usr/local/tomcat8/webapps/ROOT - register: artifact_stat - tags: - - deploy - - - name: Stop tomcat svc - service: - name: tomcat - state: stopped - tags: - - deploy - - - name: Try Backup and Deploy - block: - - name: Archive ROOT dir with timestamp - archive: - path: /usr/local/tomcat8/webapps/ROOT - dest: "/opt/ROOT_{{timestamp}}.tgz" - when: artifact_stat.stat.exists - register: archive_info - tags: - - deploy - - - name: copy ROOT dir with old_ROOT name - shell: cp -r ROOT old_ROOT - args: - chdir: /usr/local/tomcat8/webapps/ - - - name: Delete current artifact - file: - path: "{{item}}" - state: absent - when: archive_info.changed - loop: - - /usr/local/tomcat8/webapps/ROOT - - /usr/local/tomcat8/webapps/ROOT.war - tags: - - deploy - - - name: Try deploy artifact else restore from previos old_ROOT - block: - - name: Deploy vprofile artifact - copy: - src: "/tmp/vproapp-{{vprofile_version}}" - dest: /usr/local/tomcat8/webapps/ROOT.war - remote_src: yes - register: deploy_info - tags: - - deploy - rescue: - - shell: cp -r old_ROOT ROOT - args: - chdir: /usr/local/tomcat8/webapps/ - - rescue: - - name: Start tomcat svc - service: - name: tomcat - state: started - - - name: Start tomcat svc - service: - name: tomcat - state: started - when: deploy_info.changed - tags: - - deploy - - - name: Wait until ROOT.war is extracted to ROOT directory - wait_for: - path: /usr/local/tomcat8/webapps/ROOT - tags: - - deploy - -# - name: Deploy web configuration file -# template: -# src: templates/application.j2 -# dest: /usr/local/tomcat8/webapps/ROOT/WEB-INF/classes/application.properties -# force: yes -# notify: -# - Restart Tomcat -# tags: -# - deploy - - handlers: - - name: Restart Tomcat - service: - name: tomcat - state: restarted diff --git a/aws-files/artifact_buildspec.yml b/aws-files/artifact_buildspec.yml new file mode 100644 index 000000000..f41738861 --- /dev/null +++ b/aws-files/artifact_buildspec.yml @@ -0,0 +1,30 @@ +version: 0.2 # Buildspec version + +#env: # Environment variables (commented) + #parameter-store: # AWS Parameter Store variables (commented) + #CODEARTIFACT_AUTH_TOKEN: CODEARTIFACT_AUTH_TOKEN # Token reference (commented) + +phases: + install: + runtime-versions: + java: corretto17 # Set Java runtime to Amazon Corretto 17 + commands: + - cp ./settings.xml /root/.m2/settings.xml # Copy Maven settings to user folder + - export CODEARTIFACT_AUTH_TOKEN=`aws codeartifact get-authorization-token --domain ArtifactDomain --domain-owner ID --region REGION --query authorizationToken --output text` # Get CodeArtifact auth token + + pre_build: + commands: + - apt-get update # Update package list + - apt-get install -y jq # Install jq JSON processor + - wget https://dlcdn.apache.org/maven/maven-3/3.9.4/binaries/apache-maven-3.9.4-bin.tar.gz # Download Maven 3.9.4 + - tar xzvf apache-maven-3.9.4-bin.tar.gz # Extract Maven archive + - ln -s apache-maven-3.9.4 maven # Create Maven symlink + build: + commands: + - mvn clean install -DskipTests # Maven build without tests +artifacts: + files: + - target/**/*.war # Collect all WAR files from target + discard-paths: yes # Remove directory paths from artifacts + + diff --git a/aws-files/buildspec.yml b/aws-files/buildspec.yml new file mode 100644 index 000000000..7977afd5f --- /dev/null +++ b/aws-files/buildspec.yml @@ -0,0 +1,34 @@ +version: 0.2 + +#env: + #variables: + # key: "value" + # key: "value" + #parameter-store: + # key: "value" + # key: "value" + +phases: + install:l + runtime-versions: + java: corretto17 + pre_build: + commands: + - apt-get update + - apt-get install -y jq + - wget https://archive.apache.org/dist/maven/maven-3/3.9.8/binaries/apache-maven-3.9.8-bin.tar.gz + - tar xzf apache-maven-3.9.8-bin.tar.gz + - ln -s apache-maven-3.9.8 maven + - sed -i 's/jdbc.password=admin123/jdbc.password=nr1mTWY6OvlLBovvmZpD/' src/main/resources/application.properties + - sed -i 's/jdbc.username=admin/jdbc.username=admin/' src/main/resources/application.properties + - sed -i 's/db01:3306/vprodb.c50sgqqusvnr.us-east-1.rds.amazonaws.com:3306/' src/main/resources/application.properties + build: + commands: + - mvn install + post_build: + commands: + - mvn package +artifacts: + files: + - '**/*' + base-directory: 'target/vprofile-v2' \ No newline at end of file diff --git a/aws-files/sonar_buildspec.yml b/aws-files/sonar_buildspec.yml new file mode 100644 index 000000000..b98a67cb1 --- /dev/null +++ b/aws-files/sonar_buildspec.yml @@ -0,0 +1,38 @@ +version: 0.2 # AWS CodeBuild buildspec version 0.2 + +env: # Environment variables section + parameter-store: # Variables retrieved from AWS Systems Manager Parameter Store + LOGIN: LOGIN # SonarQube login token stored in parameter store + HOST: HOST # SonarQube host URL stored in parameter store + Organization: Organization # SonarQube organization name stored in parameter store + Project: Project # SonarQube project key stored in parameter store + #CODEARTIFACT_AUTH_TOKEN: CODEARTIFACT_AUTH_TOKEN # Commented out - token generated dynamically instead + +phases: # Build phases definition + install: # Install phase - runtime setup + runtime-versions: # Specify runtime versions to install + java: corretto17 # Use Amazon Corretto 17 Java runtime (updated from 11) + commands: # Commands executed in install phase + - cp ./settings.xml /root/.m2/settings.xml # Copy Maven settings file to default Maven directory + - export CODEARTIFACT_AUTH_TOKEN=`aws codeartifact get-authorization-token --domain ArtifactDomain --domain-owner ID --region REGION --query authorizationToken --output text` # Generate CodeArtifact authentication token for Maven dependencies + + pre_build: # Pre-build phase - install tools and dependencies + commands: # Commands executed before main build + - apt-get update # Update Ubuntu package repository lists + - apt-get install -y jq checkstyle # Install jq (JSON processor) and checkstyle tool + - wget https://dlcdn.apache.org/maven/maven-3/3.9.4/binaries/apache-maven-3.9.4-bin.tar.gz # Download Maven 3.9.4 binary + - tar xzvf apache-maven-3.9.4-bin.tar.gz # Extract Maven archive (x=extract, z=gunzip, v=verbose, f=file) + - ln -s apache-maven-3.9.4 maven # Create symbolic link 'maven' pointing to extracted directory + - wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-3.3.0.1492-linux.zip # Download SonarQube scanner CLI + - unzip ./sonar-scanner-cli-3.3.0.1492-linux.zip # Extract SonarQube scanner archive + - export PATH=$PATH:/sonar-scanner-3.3.0.1492-linux/bin/ # Add SonarQube scanner to system PATH + + build: # Build phase - main build and analysis + commands: # Commands executed in build phase + - mvn test # Run Maven unit tests + - mvn checkstyle:checkstyle # Run checkstyle static code analysis + - mvn sonar:sonar -Dsonar.login=$LOGIN -Dsonar.host.url=$HOST -Dsonar.projectKey=$Project -Dsonar.organization=$Organization -Dsonar.java.binaries=target/test-classes/com/visualpathit/account/controllerTest/ -Dsonar.junit.reportsPath=target/surefire-reports/ -Dsonar.jacoco.reportsPath=target/jacoco.exec -Dsonar.java.checkstyle.reportPaths=target/checkstyle-result.xml # Run SonarQube analysis with comprehensive parameters + - sleep 5 # Wait 5 seconds for SonarQube to process analysis + - curl https://sonarcloud.io/api/qualitygates/project_status?projectKey=$Project >result.json # Fetch quality gate status from SonarCloud API and save to file + - cat result.json # Display quality gate result in build logs + - if [ $(jq -r '.projectStatus.status' result.json) = ERROR ] ; then $CODEBUILD_BUILD_SUCCEEDING -eq 0 ;fi # Parse JSON result and fail build if quality gate status is ERROR diff --git a/aws-files/ssh_config_file b/aws-files/ssh_config_file new file mode 100644 index 000000000..02fa3733f --- /dev/null +++ b/aws-files/ssh_config_file @@ -0,0 +1,4 @@ +Host git-codecommit.*.amazonaws.com + User APKAXIXFJTQEW2ZCTWED + IdentityFile ~/.ssh/vpro-codecommit_rsa + diff --git a/pom.xml b/pom.xml index 03bba333b..767786a10 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,7 @@ - + + 4.0.0 com.visualpathit vprofile @@ -7,82 +9,148 @@ v2 Visualpathit VProfile Webapp http://maven.apache.org + - 4.2.0.RELEASE - 4.0.2.RELEASE - 1.8.2.RELEASE - 4.3.11.Final - 5.2.1.Final - 8.0.32 - 1.4 - 1.2 - 4.10 - 1.1.3 - 1.8 - 1.8 + 6.0.11 + 3.1.3 + 6.1.2 + 3.1.2 + 7.0.0.Alpha3 + 6.2.0.Final + 8.0.33 + 2.12.0 + + 4.13.2 + 1.5.6 + 17 + 17 + + org.springframework spring-web ${spring.version} - org.springframework spring-webmvc ${spring.version} - + org.springframework.security spring-security-web ${spring-security.version} - org.springframework.security spring-security-config ${spring-security.version} - - - org.hibernate - hibernate-validator - ${hibernate-validator.version} - - org.springframework.data spring-data-jpa ${spring-data-jpa.version} - org.hibernate - hibernate-entitymanager + hibernate-validator + ${hibernate-validator.version} + + + org.hibernate.orm + hibernate-core ${hibernate.version} + + org.springframework + spring-orm + ${spring.version} + + + org.springframework + spring-tx + ${spring.version} + + + org.springframework + spring-context + ${spring.version} + + + org.elasticsearch.client + elasticsearch-rest-high-level-client + 7.10.2 + + + org.elasticsearch + elasticsearch + 7.10.2 + + + org.springframework.amqp + spring-rabbit + 3.1.6 + + + com.rabbitmq + amqp-client + 5.21.0 + + + net.spy + spymemcached + 2.12.3 + + mysql mysql-connector-java ${mysql-connector.version} + - commons-dbcp - commons-dbcp - ${commons-dbcp.version} + jakarta.servlet + jakarta.servlet-api + 6.1.0 + provided - - javax.servlet - jstl - ${jstl.version} + jakarta.persistence + jakarta.persistence-api + 3.2.0 + + + jakarta.platform + jakarta.jakartaee-api + 10.0.0 + provided + + + org.springframework.boot + spring-boot-starter-test + ${spring-boot.version} + test + + + org.mockito + mockito-core + 5.5.0 + test + + + org.mockito + mockito-junit-jupiter + 5.5.0 + test + junit junit @@ -90,122 +158,149 @@ test - org.mockito - mockito-core - 1.9.5 + org.junit.jupiter + junit-jupiter-engine + 5.10.0 test - - - org.springframework - spring-test - 3.2.3.RELEASE - test - - - javax.servlet - javax.servlet-api - 3.1.0 - provided - + + + org.junit.jupiter + junit-jupiter-api + 5.10.0 + test + + + org.springframework + spring-test + ${spring.version} + test + ch.qos.logback logback-classic ${logback.version} - org.hamcrest - hamcrest-all - 1.3 - test - - - commons-fileupload - commons-fileupload - 1.3.1 - - - - net.spy - spymemcached - 2.12.3 - - - commons-io - commons-io - 2.4 - - - - org.springframework.amqp - spring-rabbit - 1.7.1.RELEASE - - - - com.rabbitmq - amqp-client - 4.0.2 - - - - org.elasticsearch - elasticsearch - 5.6.4 - - - - org.elasticsearch.client - transport - 5.6.4 - - - - com.google.code.gson - gson - 2.8.2 - + org.hamcrest + hamcrest-all + 1.3 + test + + + + + org.apache.logging.log4j + log4j-api + 2.23.1 + + + org.apache.logging.log4j + log4j-core + 2.20.0 + + + org.apache.logging.log4j + log4j-slf4j-impl + 2.20.0 + + + + commons-fileupload + commons-fileupload + 1.4 + + + commons-io + commons-io + 2.11.0 + + + org.apache.commons + commons-dbcp2 + 2.12.0 + + + org.elasticsearch.plugin + aggs-matrix-stats-client + 7.10.2 + + + com.fasterxml.jackson.core + jackson-databind + 2.13.0 + + + + org.springframework + spring-messaging + ${spring.version} + + + + jakarta.servlet.jsp.jstl + jakarta.servlet.jsp.jstl-api + 2.0.0 + + + + + org.glassfish.web + jakarta.servlet.jsp.jstl + 2.0.0 + + - + + + + org.eclipse.jetty jetty-maven-plugin - 9.2.11.v20150529 + 11.0.15 - 10 / - - - org.apache.maven.plugins - maven-war-plugin - 3.2.2 - - - org.jacoco - jacoco-maven-plugin - 0.8.4 - - - jacoco-initialize - process-resources - - prepare-agent - - - - jacoco-site - post-integration-test - - report - - - - - + + + + org.apache.maven.plugins + maven-war-plugin + 3.4.0 + + + + org.jacoco + jacoco-maven-plugin + 0.8.10 + + + jacoco-initialize + process-resources + + prepare-agent + + + + jacoco-site + post-integration-test + + report + + + + - + + + codeartifact + codeartifact + https://domainame-accountid.d.codeartifact.regioncode.amazonaws.com/maven/maven-central-store/ + + + \ No newline at end of file diff --git a/settings.xml b/settings.xml new file mode 100644 index 000000000..e55239acd --- /dev/null +++ b/settings.xml @@ -0,0 +1,34 @@ + + + + + codeartifact + aws + ${env.CODEARTIFACT_AUTH_TOKEN} + + + + + default + + + codeartifact + https://domain-accountid.d.codeartifact.region.amazonaws.com/maven/maven-central-store/ + + + + + + default + + + + codeartifact + domainname--maven-central-store + https://domain-accountdid.d.codeartifact.region.amazonaws.com/maven/maven-central-store/ + * + + + \ No newline at end of file diff --git a/src/main/java/com/visualpathit/account/controller/ElasticSearchController.java b/src/main/java/com/visualpathit/account/controller/ElasticSearchController.java index 6fe7f4104..bb321cb7f 100644 --- a/src/main/java/com/visualpathit/account/controller/ElasticSearchController.java +++ b/src/main/java/com/visualpathit/account/controller/ElasticSearchController.java @@ -2,137 +2,105 @@ import java.io.IOException; import java.util.List; -import java.util.Map; -import java.util.concurrent.ExecutionException; -import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; +import org.apache.http.HttpHost; +import org.elasticsearch.action.delete.DeleteRequest; import org.elasticsearch.action.delete.DeleteResponse; +import org.elasticsearch.action.get.GetRequest; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.action.update.UpdateRequest; import org.elasticsearch.action.update.UpdateResponse; +import org.elasticsearch.client.RequestOptions; +import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseBody; -import com.google.gson.Gson; import com.visualpathit.account.model.User; import com.visualpathit.account.service.UserService; import com.visualpathit.account.utils.ElasticsearchUtil; -import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; - @Controller public class ElasticSearchController { - @Autowired + + @Autowired private UserService userService; - - @RequestMapping(value="/user/elasticsearch", method=RequestMethod.GET) + + @RequestMapping(value = "/user/elasticsearch", method = RequestMethod.GET) public String insert(final Model model) throws IOException { - List users = userService.getList(); - //contextMapping(); - - /* for (User user : users) { - //IndexRequest indexRequest = new IndexRequest("users","user", String.valueOf(user.getId())); - //indexRequest.source(new Gson().toJson(user)); - //IndexResponse response = ElasticsearchUtil.trannsportClient().index(indexRequest).actionGet(); - System.out.println("User" +new Gson().toJson(user)); - }*/ - String result =""; - for (User user : users) { - IndexResponse response = ElasticsearchUtil.trannsportClient().prepareIndex("users","user", String.valueOf(user.getId())) - .setSource(jsonBuilder() - .startObject() - .field("name", user.getUsername()) - .field("DOB",user.getDateOfBirth()) - .field("fatherName",user.getFatherName()) - .field("motherName",user.getMotherName()) - .field("gender",user.getGender()) - .field("nationality",user.getNationality()) - .field("phoneNumber", user.getPhoneNumber()) - .endObject() - ) - .get(); - String res =response.getResult().toString(); - System.out.println(res); - result="Users"; - } - model.addAttribute(result); + List users = userService.getList(); + + try (RestHighLevelClient client = ElasticsearchUtil.getRestHighLevelClient()) { + for (User user : users) { + IndexRequest indexRequest = new IndexRequest("users", "_doc", String.valueOf(user.getId())) + .source(XContentFactory.jsonBuilder() + .startObject() + .field("name", user.getUsername()) + .field("DOB", user.getDateOfBirth()) + .field("fatherName", user.getFatherName()) + .field("motherName", user.getMotherName()) + .field("gender", user.getGender()) + .field("nationality", user.getNationality()) + .field("phoneNumber", user.getPhoneNumber()) + .endObject()); + + IndexResponse response = client.index(indexRequest, RequestOptions.DEFAULT); + String res = response.getResult().toString(); + System.out.println(res); + } + } + + model.addAttribute("result", "Users indexed successfully"); return "elasticeSearchRes"; - } - @RequestMapping(value="/rest/users/view/{id}", method=RequestMethod.GET) - public String view(@PathVariable final String id,final Model model) { - GetResponse getResponse = ElasticsearchUtil.trannsportClient().prepareGet("users", "user", id).get(); - System.out.println(getResponse.getSource()); - - model.addAttribute("res", getResponse.getSource().get("name")); - + @RequestMapping(value = "/rest/users/view/{id}", method = RequestMethod.GET) + public String view(@PathVariable final String id, final Model model) throws IOException { + try (RestHighLevelClient client = ElasticsearchUtil.getRestHighLevelClient()) { + GetRequest getRequest = new GetRequest("users", "_doc", id); + GetResponse getResponse = client.get(getRequest, RequestOptions.DEFAULT); + + System.out.println(getResponse.getSourceAsString()); + model.addAttribute("res", getResponse.getSource().get("name")); + } + return "elasticeSearchRes"; } - /*@RequestMapping(value = "/get_user_list", method = RequestMethod.GET) - public @ResponseBody List getTagList(@RequestParam("term") String query) { - List users = userService.getList(); - List tagList = null; - for (User user : users) { - GetResponse getResponse = ElasticsearchUtil.trannsportClient().prepareGet("users", "user" ,String.valueOf(user.getId())).get(); - System.out.println(getResponse.getSource()); - - tagList.add(getResponse.getSource()); - } - return tagList; - }*/ - - @RequestMapping(value="/rest/users/update/{id}", method=RequestMethod.GET) - public String update(@PathVariable final String id,final Model model) throws IOException { - - UpdateRequest updateRequest = new UpdateRequest(); - updateRequest.index("employee") - .type("id") - .id(id) - .doc(jsonBuilder() - .startObject() - .field("gender", "male") - .endObject()); - try { - UpdateResponse updateResponse = ElasticsearchUtil.trannsportClient().update(updateRequest).get(); + + @RequestMapping(value = "/rest/users/update/{id}", method = RequestMethod.GET) + public String update(@PathVariable final String id, final Model model) throws IOException { + try (RestHighLevelClient client = ElasticsearchUtil.getRestHighLevelClient()) { + UpdateRequest updateRequest = new UpdateRequest("users", "_doc", id) + .doc(XContentFactory.jsonBuilder() + .startObject() + .field("gender", "male") + .endObject()); + + UpdateResponse updateResponse = client.update(updateRequest, RequestOptions.DEFAULT); System.out.println(updateResponse.status()); model.addAttribute("res", updateResponse.status()); - return "elasticeSearchRes"; - } catch (InterruptedException | ExecutionException e) { - System.out.println(e); } + return "elasticeSearchRes"; } - @RequestMapping(value="/rest/users/delete/{id}", method=RequestMethod.GET) - public String delete(@PathVariable final String id,final Model model) { - DeleteResponse deleteResponse =ElasticsearchUtil.trannsportClient().prepareDelete("employee", "id", id).get(); - System.out.println(deleteResponse.getResult().toString()); - model.addAttribute("res", deleteResponse.getResult().toString()); + @RequestMapping(value = "/rest/users/delete/{id}", method = RequestMethod.GET) + public String delete(@PathVariable final String id, final Model model) throws IOException { + try (RestHighLevelClient client = ElasticsearchUtil.getRestHighLevelClient()) { + DeleteRequest deleteRequest = new DeleteRequest("users", "_doc", id); + DeleteResponse deleteResponse = client.delete(deleteRequest, RequestOptions.DEFAULT); + + System.out.println(deleteResponse.getResult().toString()); + model.addAttribute("res", deleteResponse.getResult().toString()); + } + return "elasticeSearchRes"; } - /*public void contextMapping() throws IOException{ - String json ="{" - + "\"mappings\":{" - + "\"users\":\" {" - + "\"properties\" : {" - + "\"name\" : { \"type\" : \"string\" }," - + " \"city\" : { \"type\" : \"string\" }," - + "\"name_suggest\" : {" - + "\"type\" : \"completion\"" - + "}}" - + "}"; - IndexResponse response = ElasticsearchUtil.trannsportClient().prepareIndex("users", "data") - .setSource(json).execute().actionGet(); - - }*/ } diff --git a/src/main/java/com/visualpathit/account/controller/UserController.java b/src/main/java/com/visualpathit/account/controller/UserController.java index c370682e2..d5d6ac2fa 100644 --- a/src/main/java/com/visualpathit/account/controller/UserController.java +++ b/src/main/java/com/visualpathit/account/controller/UserController.java @@ -6,21 +6,19 @@ import com.visualpathit.account.service.UserService; import com.visualpathit.account.utils.MemcachedUtils; import com.visualpathit.account.validator.UserValidator; - -import java.util.List; -import java.util.UUID; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -/**{@author imrant}*/ +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import java.util.List; +import java.util.UUID; + @Controller public class UserController { + @Autowired private UserService userService; @@ -29,146 +27,139 @@ public class UserController { @Autowired private UserValidator userValidator; - + @Autowired private ProducerService producerService; - - /** {@inheritDoc} */ - @RequestMapping(value = "/registration", method = RequestMethod.GET) - public final String registration(final Model model) { + + @GetMapping("/registration") + public String registration(Model model) { model.addAttribute("userForm", new User()); - return "registration"; - } - /** {@inheritDoc} */ - @RequestMapping(value = "/registration", method = RequestMethod.POST) - public final String registration(final @ModelAttribute("userForm") User userForm, - final BindingResult bindingResult, final Model model) { - + return "registration"; + } + + @PostMapping("/registration") + public String registration(@ModelAttribute("userForm") @Valid User userForm, BindingResult bindingResult, Model model) { userValidator.validate(userForm, bindingResult); + if (bindingResult.hasErrors()) { return "registration"; } - System.out.println("User PWD:"+userForm.getPassword()); - userService.save(userForm); - securityService.autologin(userForm.getUsername(), userForm.getPasswordConfirm()); + userService.save(userForm); + boolean loginSuccessful = securityService.autologin(userForm.getUsername(), userForm.getPasswordConfirm()); + if (!loginSuccessful) { + return "redirect:/login?error"; + } return "redirect:/welcome"; } - /** {@inheritDoc} */ - @RequestMapping(value = "/login", method = RequestMethod.GET) - public final String login(final Model model, final String error, final String logout) { - System.out.println("Model data"+model.toString()); - if (error != null){ + + @GetMapping("/") + public String login(Model model, @RequestParam(value = "error", required = false) String error, + @RequestParam(value = "logout", required = false) String logout) { + if (error != null) { model.addAttribute("error", "Your username and password is invalid."); } - if (logout != null){ + if (logout != null) { model.addAttribute("message", "You have been logged out successfully."); } return "login"; } - /** {@inheritDoc} */ - @RequestMapping(value = { "/", "/welcome"}, method = RequestMethod.GET) - public final String welcome(final Model model) { + + @PostMapping("/login") + public String loginPost(@ModelAttribute("user") User user, Model model) { + boolean loginSuccessful = securityService.autologin(user.getUsername(), user.getPassword()); + if (!loginSuccessful) { + model.addAttribute("error", "Your username and password is invalid."); + return "login"; + } + return "redirect:/welcome"; + } + + @GetMapping("/welcome") + public String welcome(Model model) { return "welcome"; } - /** {@inheritDoc} */ - @RequestMapping(value = { "/index"} , method = RequestMethod.GET) - public final String indexHome(final Model model) { + + @GetMapping("/index") + public String indexHome(Model model) { return "index_home"; } - @RequestMapping(value = "/users", method = RequestMethod.GET) - public String getAllUsers(Model model) - { - + + @GetMapping("/users") + public String getAllUsers(Model model) { List users = userService.getList(); - //JSONObject jsonObject - System.out.println("All User Data:::" + users); model.addAttribute("users", users); return "userList"; } - - @RequestMapping(value = "/users/{id}", method = RequestMethod.GET) - public String getOneUser(@PathVariable(value="id") String id,Model model) - { - String Result =""; - try{ - if( id != null && MemcachedUtils.memcachedGetData(id)!= null){ - User userData = MemcachedUtils.memcachedGetData(id); - Result ="Data is From Cache"; - System.out.println("--------------------------------------------"); - System.out.println("Data is From Cache !!"); - System.out.println("--------------------------------------------"); - System.out.println("Father ::: "+userData.getFatherName()); - model.addAttribute("user", userData); - model.addAttribute("Result", Result); - } - else{ - User user = userService.findById(Long.parseLong(id)); - Result = MemcachedUtils.memcachedSetData(user,id); - if(Result == null ){ - Result ="Memcached Connection Failure !!"; - } - System.out.println("--------------------------------------------"); - System.out.println("Data is From Database"); - System.out.println("--------------------------------------------"); - System.out.println("Result ::: "+ Result); - model.addAttribute("user", user); - model.addAttribute("Result", Result); - } - } catch (Exception e) { - System.out.println( e.getMessage() ); - } + + @GetMapping("/users/{id}") + public String getOneUser(@PathVariable("id") String id, Model model) { + String result; + try { + User userData = MemcachedUtils.memcachedGetData(id); + if (userData != null) { + result = "Data is From Cache"; + model.addAttribute("user", userData); + } else { + User user = userService.findById(Long.parseLong(id)); + result = MemcachedUtils.memcachedSetData(user, id); + if (result == null) { + result = "Memcached Connection Failure !!"; + } + model.addAttribute("user", user); + } + model.addAttribute("Result", result); + } catch (Exception e) { + e.printStackTrace(); + } return "user"; } - - /** {@inheritDoc} */ - @RequestMapping(value = { "/user/{username}"} , method = RequestMethod.GET) - public final String userUpdate(@PathVariable(value="username") String username,final Model model) { - User user = userService.findByUsername(username); - System.out.println("User Data:::" + user); - model.addAttribute("user", user); - return "userUpdate"; + + @GetMapping("/user/{username}") + public String userUpdate(@PathVariable("username") String username, Model model) { + User user = userService.findByUsername(username); + model.addAttribute("user", user); + return "userUpdate"; } - @RequestMapping(value = { "/user/{username}"} , method = RequestMethod.POST) - public final String userUpdateProfile(@PathVariable(value="username") String username,final @ModelAttribute("user") User userForm,final Model model) { - User user = userService.findByUsername(username); - user.setUsername(userForm.getUsername()); - user.setUserEmail(userForm.getUserEmail()); - user.setDateOfBirth(userForm.getDateOfBirth()); - user.setFatherName(userForm.getFatherName()); - user.setMotherName(userForm.getMotherName()); - user.setGender(userForm.getGender()); - user.setLanguage(userForm.getLanguage()); - user.setMaritalStatus(userForm.getMaritalStatus()); - user.setNationality(userForm.getNationality()); - user.setPermanentAddress(userForm.getPermanentAddress()); - user.setTempAddress(userForm.getTempAddress()); - user.setPhoneNumber(userForm.getPhoneNumber()); - user.setSecondaryPhoneNumber(userForm.getSecondaryPhoneNumber()); - user.setPrimaryOccupation(userForm.getPrimaryOccupation()); - user.setSecondaryOccupation(userForm.getSecondaryOccupation()); - user.setSkills(userForm.getSkills()); - user.setWorkingExperience(userForm.getWorkingExperience()); - userService.save(user); - /*model.addAttribute("user", user);*/ - return "welcome"; + + @PostMapping("/user/{username}") + public String userUpdateProfile(@PathVariable("username") String username, @ModelAttribute("user") User userForm) { + User user = userService.findByUsername(username); + updateUserDetails(user, userForm); + userService.save(user); + return "welcome"; } - - @RequestMapping(value={"/user/rabbit"}, method={RequestMethod.GET}) - public String rabbitmqSetUp() { - System.out.println("Rabbit mq method is callled!!!"); - for (int i = 0; i < 20; i++) { - producerService.produceMessage(generateString()); - } - return "rabbitmq"; + + @GetMapping("/user/rabbit") + public String rabbitmqSetUp() { + for (int i = 0; i < 20; i++) { + producerService.produceMessage(generateString()); + } + return "rabbitmq"; } - - private static String generateString() { - String uuid = UUID.randomUUID().toString(); - return "uuid = " + uuid; + + private void updateUserDetails(User user, User userForm) { + user.setUsername(userForm.getUsername()); + user.setUserEmail(userForm.getUserEmail()); + user.setDateOfBirth(userForm.getDateOfBirth()); + user.setFatherName(userForm.getFatherName()); + user.setMotherName(userForm.getMotherName()); + user.setGender(userForm.getGender()); + user.setLanguage(userForm.getLanguage()); + user.setMaritalStatus(userForm.getMaritalStatus()); + user.setNationality(userForm.getNationality()); + user.setPermanentAddress(userForm.getPermanentAddress()); + user.setTempAddress(userForm.getTempAddress()); + user.setPhoneNumber(userForm.getPhoneNumber()); + user.setSecondaryPhoneNumber(userForm.getSecondaryPhoneNumber()); + user.setPrimaryOccupation(userForm.getPrimaryOccupation()); + user.setSecondaryOccupation(userForm.getSecondaryOccupation()); + user.setSkills(userForm.getSkills()); + user.setWorkingExperience(userForm.getWorkingExperience()); } - - + private static String generateString() { + return "uuid = " + UUID.randomUUID().toString(); + } } diff --git a/src/main/java/com/visualpathit/account/model/Role.java b/src/main/java/com/visualpathit/account/model/Role.java index af821ad0e..1914f2149 100644 --- a/src/main/java/com/visualpathit/account/model/Role.java +++ b/src/main/java/com/visualpathit/account/model/Role.java @@ -1,6 +1,7 @@ package com.visualpathit.account.model; -import javax.persistence.*; +import jakarta.persistence.*; + import java.util.Set; /**{@author imrant} !*/ @Entity @@ -14,7 +15,7 @@ public class Role { private Set users; /** {@inheritDoc}} !*/ @Id - @GeneratedValue(strategy = GenerationType.AUTO) + @GeneratedValue(strategy = GenerationType.IDENTITY) /** * {@link Role#id} !*/ diff --git a/src/main/java/com/visualpathit/account/model/User.java b/src/main/java/com/visualpathit/account/model/User.java index 23050ce94..ffe522abc 100644 --- a/src/main/java/com/visualpathit/account/model/User.java +++ b/src/main/java/com/visualpathit/account/model/User.java @@ -1,7 +1,7 @@ package com.visualpathit.account.model; -import javax.persistence.*; +import jakarta.persistence.*; import java.io.Serializable; import java.util.Set; @@ -44,7 +44,7 @@ public class User implements Serializable { private Set roles; /** {@inheritDoc}} !*/ @Id - @GeneratedValue(strategy = GenerationType.AUTO) + @GeneratedValue(strategy = GenerationType.IDENTITY) /** {@link User#id} */ public Long getId() { return id; diff --git a/src/main/java/com/visualpathit/account/service/SecurityService.java b/src/main/java/com/visualpathit/account/service/SecurityService.java index dbd4d9bc5..534171f90 100644 --- a/src/main/java/com/visualpathit/account/service/SecurityService.java +++ b/src/main/java/com/visualpathit/account/service/SecurityService.java @@ -5,5 +5,5 @@ public interface SecurityService { /** {@inheritDoc}} !*/ String findLoggedInUsername(); - void autologin(String username, String password); + boolean autologin(String username, String password); } diff --git a/src/main/java/com/visualpathit/account/service/SecurityServiceImpl.java b/src/main/java/com/visualpathit/account/service/SecurityServiceImpl.java index 14fee640d..5c826f066 100644 --- a/src/main/java/com/visualpathit/account/service/SecurityServiceImpl.java +++ b/src/main/java/com/visualpathit/account/service/SecurityServiceImpl.java @@ -4,49 +4,45 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.authentication.AuthenticationManager; -import org.springframework.security.authentication - .UsernamePasswordAuthenticationToken; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.stereotype.Service; -/** {@author imrant} !*/ + @Service public class SecurityServiceImpl implements SecurityService { - /** authenticationManager !*/ - @Autowired + @Autowired private AuthenticationManager authenticationManager; - /** userDetailsService !*/ + @Autowired private UserDetailsService userDetailsService; - /** Logger creation !*/ - private static final Logger logger = LoggerFactory - .getLogger(SecurityServiceImpl.class); + private static final Logger logger = LoggerFactory.getLogger(SecurityServiceImpl.class); @Override public String findLoggedInUsername() { - Object userDetails = SecurityContextHolder.getContext() - .getAuthentication().getDetails(); + Object userDetails = SecurityContextHolder.getContext().getAuthentication().getDetails(); if (userDetails instanceof UserDetails) { return ((UserDetails) userDetails).getUsername(); } - return null; } @Override - public void autologin(final String username, final String password) { + public boolean autologin(final String username, final String password) { UserDetails userDetails = userDetailsService.loadUserByUsername(username); - UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken = - new UsernamePasswordAuthenticationToken(userDetails, password, userDetails.getAuthorities()); + UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken = + new UsernamePasswordAuthenticationToken(userDetails, password, userDetails.getAuthorities()); authenticationManager.authenticate(usernamePasswordAuthenticationToken); if (usernamePasswordAuthenticationToken.isAuthenticated()) { - SecurityContextHolder.getContext() - .setAuthentication(usernamePasswordAuthenticationToken); + SecurityContextHolder.getContext().setAuthentication(usernamePasswordAuthenticationToken); logger.debug(String.format("Auto login %s successfully!", username)); + return true; } + logger.debug(String.format("Auto login %s failed!", username)); + return false; } } diff --git a/src/main/java/com/visualpathit/account/service/UserDetailsServiceImpl.java b/src/main/java/com/visualpathit/account/service/UserDetailsServiceImpl.java index 04c68ae80..f2bbb1bad 100644 --- a/src/main/java/com/visualpathit/account/service/UserDetailsServiceImpl.java +++ b/src/main/java/com/visualpathit/account/service/UserDetailsServiceImpl.java @@ -3,18 +3,20 @@ import com.visualpathit.account.model.Role; import com.visualpathit.account.model.User; import com.visualpathit.account.repository.UserRepository; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.HashSet; import java.util.Set; + /** {@author imrant} !*/ +@Service public class UserDetailsServiceImpl implements UserDetailsService { @Autowired /** userRepository !*/ @@ -22,16 +24,18 @@ public class UserDetailsServiceImpl implements UserDetailsService { @Override @Transactional(readOnly = true) - public UserDetails loadUserByUsername(final String username) - throws UsernameNotFoundException { + public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException { User user = userRepository.findByUsername(username); + if (user == null) { + throw new UsernameNotFoundException("User not found with username: " + username); + } + Set grantedAuthorities = new HashSet<>(); for (Role role : user.getRoles()) { grantedAuthorities.add(new SimpleGrantedAuthority(role.getName())); } - return new org.springframework.security.core - .userdetails.User(user.getUsername(), user.getPassword(), grantedAuthorities); + return new org.springframework.security.core.userdetails.User(user.getUsername(), user.getPassword(), grantedAuthorities); } } diff --git a/src/main/java/com/visualpathit/account/service/UserServiceImpl.java b/src/main/java/com/visualpathit/account/service/UserServiceImpl.java index 2426b853f..fd48cd3c7 100644 --- a/src/main/java/com/visualpathit/account/service/UserServiceImpl.java +++ b/src/main/java/com/visualpathit/account/service/UserServiceImpl.java @@ -42,6 +42,6 @@ public List getList() { } @Override public User findById(long id){ - return userRepository.findOne(id); + return userRepository.findById(id); } } diff --git a/src/main/java/com/visualpathit/account/utils/ElasticsearchUtil.java b/src/main/java/com/visualpathit/account/utils/ElasticsearchUtil.java index 838fa536e..b4d08685a 100644 --- a/src/main/java/com/visualpathit/account/utils/ElasticsearchUtil.java +++ b/src/main/java/com/visualpathit/account/utils/ElasticsearchUtil.java @@ -1,48 +1,45 @@ package com.visualpathit.account.utils; +import java.io.IOException; import java.net.InetSocketAddress; -import org.elasticsearch.client.transport.TransportClient; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.InetSocketTransportAddress; -import org.elasticsearch.transport.client.PreBuiltTransportClient; +import org.apache.http.HttpHost; +import org.elasticsearch.client.RequestOptions; +import org.elasticsearch.client.RestClient; +import org.elasticsearch.client.RestHighLevelClient; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.visualpathit.account.beans.Components; + @Service public class ElasticsearchUtil { - - private static Components object; + + private static Components object; + @Autowired - public void setComponents(Components object){ - ElasticsearchUtil.object = object; - + public void setComponents(Components object) { + ElasticsearchUtil.object = object; } - public static TransportClient trannsportClient() { - System.out.println(" elasticsearch client"); - String elasticsearchHost =object.getElasticsearchHost(); - String elasticsearchPort =object.getElasticsearchPort(); - String elasticsearchCluster =object.getElasticsearchCluster(); - String elasticsearchNode =object.getElasticsearchNode(); - System.out.println(" elasticsearchHost ........"+ elasticsearchHost); - System.out.println(" elasticsearchHost ........"+ elasticsearchPort); - TransportClient client = null; - try { - Settings settings = Settings.builder() - .put("cluster.name",elasticsearchCluster) - .put("node.name",elasticsearchNode) - .build(); - client = new PreBuiltTransportClient(settings) - .addTransportAddress( - new InetSocketTransportAddress( - new InetSocketAddress(elasticsearchHost, Integer.parseInt(elasticsearchPort)))); + public static RestHighLevelClient getRestHighLevelClient() { + System.out.println("Creating Elasticsearch client..."); + String elasticsearchHost = object.getElasticsearchHost(); + String elasticsearchPort = object.getElasticsearchPort(); - } - catch (Exception e) { - e.printStackTrace(); - } - return client; - } + System.out.println("Elasticsearch Host: " + elasticsearchHost); + System.out.println("Elasticsearch Port: " + elasticsearchPort); + + RestHighLevelClient client = null; + try { + client = new RestHighLevelClient( + RestClient.builder( + new HttpHost(elasticsearchHost, Integer.parseInt(elasticsearchPort), "http") + ) + ); + } catch (Exception e) { + e.printStackTrace(); + } + return client; + } } diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index 35b81df4d..b84b4e88d 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -1,24 +1,25 @@ - + - - - %date{HH:mm:ss.SSS} [%thread] %-5level %logger{15}#%line %msg\n - - + + + %date{HH:mm:ss.SSS} [%thread] %-5level %logger{15}#%line + %msg\n + + - - - + + + - - - + + + - - - - + + + + \ No newline at end of file diff --git a/src/main/webapp/META-INF/MANIFEST.MF b/src/main/webapp/META-INF/MANIFEST.MF new file mode 100644 index 000000000..59499bce4 --- /dev/null +++ b/src/main/webapp/META-INF/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 + diff --git a/src/main/webapp/WEB-INF/appconfig-data.xml b/src/main/webapp/WEB-INF/appconfig-data.xml index 7be0032b5..18d9dbafd 100644 --- a/src/main/webapp/WEB-INF/appconfig-data.xml +++ b/src/main/webapp/WEB-INF/appconfig-data.xml @@ -1,54 +1,45 @@ - - - + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd + http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> - - - - - + + + + + - - + + - + - org.hibernate.dialect.MySQL5Dialect + org.hibernate.dialect.MySQLDialect true - - + + - - - - + + - - + + + diff --git a/src/main/webapp/WEB-INF/appconfig-mvc.xml b/src/main/webapp/WEB-INF/appconfig-mvc.xml index 58f404dc5..c8efd8bda 100644 --- a/src/main/webapp/WEB-INF/appconfig-mvc.xml +++ b/src/main/webapp/WEB-INF/appconfig-mvc.xml @@ -1,32 +1,32 @@ + xmlns:mvc="http://www.springframework.org/schema/mvc" + xmlns="http://www.springframework.org/schema/beans" + xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> - + - - - - - - classpath:validation - - - - - - /WEB-INF/views/ - - - .jsp - - - - - + + + + + classpath:validation + + + + + + /WEB-INF/views/ + + + .jsp + + + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/appconfig-rabbitmq.xml b/src/main/webapp/WEB-INF/appconfig-rabbitmq.xml index 989faec37..2fadbead6 100644 --- a/src/main/webapp/WEB-INF/appconfig-rabbitmq.xml +++ b/src/main/webapp/WEB-INF/appconfig-rabbitmq.xml @@ -1,28 +1,30 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:beans="http://www.springframework.org/schema/beans" + xmlns:context="http://www.springframework.org/schema/context" + xmlns:mvc="http://www.springframework.org/schema/mvc" + xmlns:rabbit="http://www.springframework.org/schema/rabbit" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd + http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd + http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit.xsd"> - + - + - + - + - - - - - + + + + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/appconfig-root.xml b/src/main/webapp/WEB-INF/appconfig-root.xml index 064cc5e7a..aa7ae8728 100644 --- a/src/main/webapp/WEB-INF/appconfig-root.xml +++ b/src/main/webapp/WEB-INF/appconfig-root.xml @@ -1,20 +1,19 @@ - http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> + - + + + - - - - - - - - + + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/appconfig-security.xml b/src/main/webapp/WEB-INF/appconfig-security.xml index 5e2acf137..797eff774 100644 --- a/src/main/webapp/WEB-INF/appconfig-security.xml +++ b/src/main/webapp/WEB-INF/appconfig-security.xml @@ -1,30 +1,31 @@ + xmlns:beans="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd + http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd"> - - - - - - - + + + + + + + - - - - - + + + + + - + - - - + + + diff --git a/src/main/webapp/WEB-INF/views/index_home.jsp b/src/main/webapp/WEB-INF/views/index_home.jsp index 4579f61fe..b0d981839 100644 --- a/src/main/webapp/WEB-INF/views/index_home.jsp +++ b/src/main/webapp/WEB-INF/views/index_home.jsp @@ -10,53 +10,41 @@ -
-
-
- Architecture -
-

DevOps

-
+ Architecture

Keep Learning ..

-

Learning is a Treasure that will follow it's Owner Everywhere..

+

Learning is a Treasure that will follow it's Owner Everywhere..

@@ -69,8 +57,8 @@
- DevOps -
+ DevOps +
@@ -97,7 +85,7 @@
- DevOps + DevOps
@@ -115,20 +103,32 @@

ABOUT

-
-

VisualPath is an IT Educational Institute.Established in 2001,and Institute offers world class quality of education and wide range of courses.VisualPath Institute has a dedicated placement team to help students get job placement in various IT job roles with major companies. -

-

Address: Flat no: 205, 2nd Floor,NILGIRI Block,Aditya Encalve,Ameerpet, Hyderabad-16

-

Ph No: +91-9704455959,9618245689

-

E-Mail ID : visualpath999@gmail.com

+
+

+ HKH Infotech is a dynamic software company dedicated to delivering innovative technology solutions. Founded with a mission to leverage cutting-edge technology and unparalleled expertise, we specialize in creating high-quality software solutions that drive business success. +

+

+ Our team is led by seasoned DevOps experts with many years of industry experience. They bring a wealth of knowledge in automating and optimizing the software development lifecycle, ensuring that our projects are efficient, reliable, and scalable. +

+

+ At HKH Infotech, we focus on understanding our clients' unique needs and providing tailored solutions that meet their objectives. Whether it's custom software development, system integration, or ongoing support, we are committed to excellence and client satisfaction. +

+

+ With a commitment to staying ahead of technological trends and a passion for innovation, HKH Infotech is your trusted partner in navigating the digital landscape and achieving your business goals. +

+

Address: Punjagutta Colony Ameerpet, Hyderabad

+

Phone: +91-8001234567

+

Email: contact@hkhinfotech.com

- +
+

CONTACT

+

Lets get in touch and talk about your and our next project.

-
+ @@ -137,16 +137,12 @@ SEND MESSAGE
+
- + -
- - diff --git a/src/main/webapp/WEB-INF/views/login.jsp b/src/main/webapp/WEB-INF/views/login.jsp index 0a41ac1c4..4b3b06ce8 100644 --- a/src/main/webapp/WEB-INF/views/login.jsp +++ b/src/main/webapp/WEB-INF/views/login.jsp @@ -7,89 +7,154 @@ - - + Login + - - - - - LOGIN - - - - - - - - Welcome - - - - + + + + + + + + + + + + + + + + + + + + + + + + + +
-
- - +
+
+
+
+ + Login + + +
+ Username + + +
+ +
+ Password + + +
+ + + + +
+
+
+ +
+
+ +
+ + Don't have an account? + + + + Sign Up + +
+
+
+
- - - + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/webapp/WEB-INF/views/registration.jsp b/src/main/webapp/WEB-INF/views/registration.jsp index be726ccd9..936cd5f8f 100644 --- a/src/main/webapp/WEB-INF/views/registration.jsp +++ b/src/main/webapp/WEB-INF/views/registration.jsp @@ -1,14 +1,14 @@ +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> -<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> - - + Login + @@ -18,94 +18,83 @@ - - - + + + - + + -
-
+
+
-
- +
-
- + diff --git a/src/main/webapp/WEB-INF/views/user.jsp b/src/main/webapp/WEB-INF/views/user.jsp index 480bf6e24..e07388835 100644 --- a/src/main/webapp/WEB-INF/views/user.jsp +++ b/src/main/webapp/WEB-INF/views/user.jsp @@ -1,163 +1,172 @@ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> - <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> - - +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> + + UserData - + + - - - - - - + + + + + + - -
-
-