diff --git a/.gitignore b/.gitignore index 12924fc..23491a9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,27 @@ +# Gradle +.gradle/ +**/build/ +!src/**/build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Avoid ignore Gradle wrappper properties +!gradle-wrapper.properties + +# Cache of project +.gradletasknamecache + #.config file for eclipse projects .settings /.classpath /bin/ /.project -#target with generated objects +# Maven build files /target # Compiled class file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..d0874b5 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +AttendWebApp \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..b589d56 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..ce1c62c --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,16 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..6c68d51 --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..f5db0c5 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 629b2f7..f51d8c7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,8 @@ FROM tomcat:8-jdk8-corretto # https://hub.docker.com/layers/library/tomcat/7.0.109-jdk8-openjdk/images/sha256-489823486120d076cb576640c5819c6fa54948f470b46c54f02b48f462eb2c23 LABEL org.nz.itlatinos.image.authors="aleonrangel@outlook.co.nz" -ADD conf/tomcat-users.xml /usr/local/tomcat/conf +LABEL maintainer="andres.nz" +ENV APP_WAR_FILE="AttendanceApp-0.0.1.war" -COPY target/AttendanceWebApp.war /usr/local/tomcat/webapps/ -LABEL maintainer="andres.nz" \ No newline at end of file +# Tomcat Custom settings +COPY "build/libs/$APP_WAR_FILE" /usr/local/tomcat/webapps/ \ No newline at end of file diff --git a/README.md b/README.md index ba0f356..08a34f5 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,50 @@ +- [Attendance WebApp](#attendance-webapp) + - [Introduction](#introduction) + - [Security warnings](#security-warnings) + - [Attendance WebApp Architecture (re-architected)](#attendance-webapp-architecture-re-architected) + - [2018-Attendance WebApp high level Architecture](#2018-attendance-webapp-high-level-architecture) + - [Attendance WebApp UI](#attendance-webapp-ui) + - [Refer to the Wiki for details on the project](#refer-to-the-wiki-for-details-on-the-project) +- [Project general guidelines](#project-general-guidelines) +- [Setup](#setup) + - [Build WebApp](#build-webapp) + - [Gradle Build Web Package](#gradle-build-web-package) + - [Maven Build](#maven-build) + - [Package WebApp](#package-webapp) + - [Docker Image Build](#docker-image-build) + - [Available Tomcat versions](#available-tomcat-versions) + - [Run WebApp](#run-webapp) + - [Container Execution](#container-execution) + - [Docker execution](#docker-execution) + - [Docker-compose](#docker-compose) + - [Editing project diagrams](#editing-project-diagrams) + - [GitHub Vulnerability report](#github-vulnerability-report) + # Attendance WebApp -# Introduction +## Introduction Attendance WebApp is a proof of concept to improve the way attendance is managed at AUT university. The application uses maven, J2EE, primefaces, gson. +```kotlin + maven { + url = uri("https://repository.primefaces.org") + } +``` The idea is that you have a short timeframe to submit a random generated code by the lecturer so that attendance can be registered in the system. The application is a proof of concept for Service orientation and Service interoperability in the cloud -> ## Security Warning - +## Security warnings +> Security Warnings to check GitHub found 2 vulnerabilities on aleon1220/multi-cloud-WebApp-Attendance's default branch (2 moderate). To find out more, visit: [This project security report](https://github.com/aleon1220/multi-cloud-WebApp-Attendance/security) ## Attendance WebApp Architecture (re-architected) -since this is a 2018 project a lot of things need to change +2018 project with a lot of things to change * Simplification of used services * Streamline app to use 100% rest and deprecate SOAP and WSDL @@ -42,97 +69,93 @@ since this is a 2018 project a lot of things need to change # Project general guidelines -1. Installation process: project is Maven java project. Import in any IDE with the POM File. +1. Installation process: project a Java project JEE. Import in any IDE and build with gradle or maven. Build docker image and run 2. Software dependencies: dependencies are described in pom.xml file 3. Latest releases by using git tags 4. API references. API docs -# Build and Test +# Setup +> Tested in Win11 with WSL, Github codespaces and Linux Ubuntu 22 +- Clone repo HTTPS ```bash -git clone repo -# import in IDE Eclipse suggested or use online IDE -# execute some of the unit tests -# Generate the .WAR file -mvn package -# Deploy WebArchive file in tomcat. Docker apps info below -deploy .WAR in tomcat +git clone https://github.com/aleon1220/multi-cloud-WebApp-Attendance.git ``` - -## Maven - -### Run the maven build Locally - -- build the project locally with a locally installed maven client - -> Tested in Win11 with WSL - +- Clone Repo SSH ```bash -mvn verify +git clone git@github.com:aleon1220/multi-cloud-WebApp-Attendance.git ``` - -- Use a docker tag to select a target JDK - -> 8-jdk8-corretto - -```bash -TOMCAT_DOCKER_TAG="8-jdk8-corretto" +- open repo in chosen IDE +IDEs can be Eclipse, IntelliJ (suggested) or use online IDE (Github codespaces) + +## Build WebApp +### Gradle Build Web Package +- Pack the WebArchive file. Generate the .WAR file +``` bash +gradle clean build --console plain --warning-mode all ``` -- build the container to the latest version tag +### Maven Build +> maven has been deprecated and moved to [maven](./maven) +## Package WebApp +### Docker Image Build +- Build the app image with Docker. Deploy .WAR file in Tomcat +refer to https://hub.docker.com/_/tomcat ```bash docker build --tag aleon1220/soa:latest . ``` -- Run the tomcat server with the pre-built WAR web Archive file - Use the tag latest or a particular version e.g. aleon1220/soa:v2 or aleon1220/soa:latest - -```bash -docker run -itd --publish 8888:8080 --name attendance_webapp_container aleon1220/soa:latest -``` - -refer to https://hub.docker.com/_/tomcat +#### Available Tomcat versions +Use the tag latest or a particular version e.g. aleon1220/soa:v2 or aleon1220/soa:latest +- 7.0.109 = `TOMCAT_VERSION_DOCKER_TAG="7.0.109-jdk8-openjdk"` +- 9.0.78 = `TOMCAT_VERSION_DOCKER_TAG="9.0.78-jre8"` -- Access container +## Run WebApp +### Container Execution +#### Docker execution +##### Run from [Docker Hub](https://hub.docker.com/repository/docker/aleon1220/soa/general) +Test the immutable webapp from Docker ```bash -docker container exec -it aleon1220/soa /bin/bash +docker run -itd --publish 8080:8080 --name attendance_webapp_container aleon1220/soa:latest ``` -- The URl is localhost:8888/AttendanceWebApp | [AttendanceWebApp](http://localhost:8888/AttendanceWebApp) - ---- - -## Build using maven docker container - -Refer to maven docker official image https://hub.docker.com/_/maven -is best to have maven locally installed - -- Create a volume - +##### local build & Run +Test the container webapp after building the image locally ```bash -docker volume create --name maven-repo-volume +docker build --tag aleon1220/soa:latest . +docker run -itd --publish 8080:8080 --name attendance_webapp_container aleon1220/soa:latest ``` - -- Docker container build using the volume above - +Run the tomcat server with the pre-built WAR web Archive file ```bash -docker run -it -v maven-repo-volume:/root/.m2 maven mvn archetype:generate # will download artifacts +docker run -itd --publish 8080:8080 aleon1220/soa:latest ``` - -- Docker container run and build using the maven image - +- get the name of the running container in port 8888 +``` bash +CONTAINER_NAME=$(docker container ls --all --filter publish=8888 --format "{{.Names}}") +``` +- Access the Docker container via CLI ```bash -docker run -it --rm --name my-maven-project -v "$(pwd)":/usr/src/mymaven -w /usr/src/mymaven maven:3.3-jdk-8 mvn clean install +docker container exec -it $CONTAINER_NAME /bin/bash +``` +- The URl is URL:8888/Attendance-0.0.1 [AttendanceWebApp](http://localhost:8888/Attendance-0.0.1) +- clean up docker container environment +``` bash +docker stop $(docker ps --quiet) +docker rm $(docker container ls --all --quiet) ``` -- docker run build using bind volume mount +#### Docker-compose ```bash -docker run -it --name my-maven-project -v "$(pwd)":/usr/src/mymaven -w /usr/src/mymaven maven:3.3-jdk-8 mvn clean install +export LDAP_ADMIN_PASS=$(op read "op://uqbpxejq7gifvi6mg3c7xxokre/jvuj7juvlxlg7delckucvidqhi/password") ``` +## Editing project diagrams +- go to [diagrams.net](https://app.diagrams.net/?src=about) +- open the file [project-diagrams.drawio](./project-diagrams.drawio) XML file with the diagrams +- Explore > export images to convinience and update this README ## GitHub Vulnerability report https://github.com/aleon1220/multi-cloud-WebApp-Attendance/security/dependabot diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..1440e67 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,116 @@ +import org.gradle.api.tasks.testing.logging.TestLogEvent +/* + * file generated by Gradle 'init' task. @Incubating APIs subject to change + */ + +plugins { + java + // id ("com.adarshr.test-logger") version "3.0.0" + // https://docs.gradle.org/7.3/dsl/org.gradle.api.tasks.bundling.War.html + war + id ("jacoco") + id("com.github.bjornvester.wsdl2java") version "2.0.2" +} + +repositories { + gradlePluginPortal() + google() + mavenCentral() +} + +dependencies { + implementation("org.primefaces.extensions:primefaces-extensions:6.0.0") + implementation("org.primefaces:primefaces:6.0") + implementation("com.sun.faces:jsf-api:2.2.12") + implementation("com.sun.faces:jsf-impl:2.2.12") + implementation("javax.json:javax.json-api:1.1") + implementation("javax.ws.rs:javax.ws.rs-api:2.1") + implementation("com.sun.jersey:jersey-client:1.19.4") + implementation("com.google.code.gson:gson:2.8.9") + implementation("org.apache.httpcomponents:httpclient:4.5.3") + implementation("org.glassfish.jersey.core:jersey-common:2.22.2") + implementation("javax.servlet:javax.servlet-api:3.1.0") + // https://mvnrepository.com/artifact/com.google.zxing/javase + implementation("com.google.zxing:javase:3.5.1") + implementation("com.google.zxing:core:3.5.1") + testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.2") + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.2") + testImplementation("io.jsonwebtoken:jjwt:0.9.1") + // dependency below only needed if using the Java 8 version of @Generated (through "jdk8") on Java 9 or later + implementation("javax.annotation:javax.annotation-api:1.3.2") + implementation("io.github.threeten-jaxb:threeten-jaxb-core:2.1.0") // Use Java Date/Time API instead of clunky GregorianCalendar class + implementation("com.graphql-java-kickstart:graphql-webclient-spring-boot-starter:2.0.1") + implementation("com.graphql-java:graphql-java:20.7") + implementation("com.graphql-java-generator:graphql-java-runtime:1.18") + // JUnit 4 framework for unit testing + testImplementation("junit:junit:4.13.2") + // JUnit Jupiter API and Engine for unit testing + testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.0") + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.7.0") + // Mockito for mocking in tests + testImplementation("org.mockito:mockito-core:4.5.1") + // https://central.sonatype.com/artifact/com.unboundid/unboundid-ldapsdk + implementation("com.unboundid:unboundid-ldapsdk:6.0.11") + // https://github.com/google/gson library JSON serialization/deserialization + implementation("com.google.code.gson:gson:2.10.1") +} + +group = "soa.nz.aut" +version = "0.0.1" +description = "Student Attendance WebApp" +java.sourceCompatibility = JavaVersion.VERSION_17 + +tasks.war { + archiveBaseName.set("Attendance") + webAppDirectory.set(file("src/main/webapp")) + // from("src/rootContent") // adds a file-set to the root of the archive + // webInf { from("src/additionalWebInf") } // adds a file-set to the WEB-INF dir. + // classpath(fileTree("additionalLibs")) // adds a file-set to the WEB-INF/lib dir. + // classpath(moreLibs) // adds a configuration to the WEB-INF/lib dir. + // webXml = file("src/someWeb.xml") // copies a file to WEB-INF/web.xml +} + +tasks { + named("jacocoTestReport") { + reports { + } + } + test { + useJUnitPlatform() + testLogging.events = setOf(TestLogEvent.FAILED, TestLogEvent.PASSED, TestLogEvent.SKIPPED) + } +} + +tasks.register("singleTest") { + group = "Verification" + description = "Runs a test to create a local QR code" + filter { + includeTestsMatching("utilities.TestQRFunctions.createQRCodeLocally") + } +} + +tasks.register("openLDAP") { + description = "Runs openLDAP authentication testing" + filter { + includeTestsMatching("TestLDAPAuthentication.testMockOpenLDAPAdminSearch") + } +} + +// https://plugins.gradle.org/plugin/com.github.bjornvester.wsdl2java +// https://www.w3schools.com/xml/tempconvert.asmx?WSDL +wsdl2java { + // wsdlDir.set(layout.projectDirectory.dir("src/main/resources/wsdl")) + bindingFile.set(layout.projectDirectory.file("src/main/bindings/bindings.xjb")) + + includes.set( + listOf( + "src/main/resources/wsdl/NumberConversion.wsdl" + ) + ) + // includesWithOptions.set( + // mapOf( + // "**/ServiceTemp.wsdl" to listOf("-wsdlLocation", "https://www.w3schools.com/xml/tempconvert.asmx?WSDL") + // ) + // ) + // default output directory $buildDir/generated/sources/wsdl2java/java +} \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..313827f --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,20 @@ +version: '3' +services: + openldap: + # https://github.com/osixia/docker-openldap + # https://www.openldap.org + image: osixia/openldap:1.2.4 + environment: + LDAP_ORGANISATION: "IT Latinos NZ" + LDAP_DOMAIN: "latintech.org" + LDAP_ADMIN_PASSWORD: ${LDAP_ADMIN_PASS} + ports: + - 389:389 + - 636:636 + volumes: + - ./ldap:/var/lib/ldap + - ./ldap:/etc/ldap/slapd.d + webapp: + image: aleon1220/soa:latest + ports: + - 8080:8080 diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..eca1768 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,3 @@ +log4j_version = 1.2.17 +jaxb_version = 2.3.1 +junit_version = 5.5.1 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..1af9e09 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..1aa94a4 --- /dev/null +++ b/gradlew @@ -0,0 +1,249 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..6689b85 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/ldap/university.ldif b/ldap/university.ldif new file mode 100644 index 0000000..18de194 --- /dev/null +++ b/ldap/university.ldif @@ -0,0 +1,11 @@ +dn: ou=lecturers,dc=university,dc=nz,dc=andres +objectClass: organizationalUnit +ou: lecturers + +dn: ou=staff,dc=university,dc=nz,dc=andres +objectClass: organizationalUnit +ou: staff + +dn: ou=students,dc=university,dc=nz,dc=andres +objectClass: organizationalUnit +ou: students diff --git a/maven/Dockerfile b/maven/Dockerfile new file mode 100644 index 0000000..629b2f7 --- /dev/null +++ b/maven/Dockerfile @@ -0,0 +1,7 @@ +FROM tomcat:8-jdk8-corretto +# https://hub.docker.com/layers/library/tomcat/7.0.109-jdk8-openjdk/images/sha256-489823486120d076cb576640c5819c6fa54948f470b46c54f02b48f462eb2c23 +LABEL org.nz.itlatinos.image.authors="aleonrangel@outlook.co.nz" +ADD conf/tomcat-users.xml /usr/local/tomcat/conf + +COPY target/AttendanceWebApp.war /usr/local/tomcat/webapps/ +LABEL maintainer="andres.nz" \ No newline at end of file diff --git a/pom.xml b/maven/pom.xml similarity index 99% rename from pom.xml rename to maven/pom.xml index cce3041..209ca25 100644 --- a/pom.xml +++ b/maven/pom.xml @@ -86,7 +86,6 @@ gson 2.8.9 - org.apache.httpcomponents @@ -100,7 +99,6 @@ 2.22.2 compile - diff --git a/maven/readme.md b/maven/readme.md new file mode 100644 index 0000000..b1bb1eb --- /dev/null +++ b/maven/readme.md @@ -0,0 +1,42 @@ +# Maven Builds +--- +### Maven Stages +if you still want to build with maven +```bash +mvn package +``` + +- build the project locally with a locally installed maven client + +```bash +mvn verify +``` + +### Build using maven docker container +Refer to maven docker official image https://hub.docker.com/_/maven +is best to have maven locally installed + +- Create a volume + +```bash +docker volume create --name maven-repo-volume +``` + +- Docker container build using the volume above + +```bash +docker run -it -v maven-repo-volume:/root/.m2 maven mvn archetype:generate # will download artifacts +``` + +- Docker container run and build using the maven image + +```bash +docker run -it --rm --name my-maven-project -v "$(pwd)":/usr/src/mymaven -w /usr/src/mymaven maven:3.3-jdk-8 mvn clean install +``` + +- docker run build using bind volume mount + +```bash +docker run -it --name my-maven-project -v "$(pwd)":/usr/src/mymaven -w /usr/src/mymaven maven:3.3-jdk-8 mvn clean install +``` +--- \ No newline at end of file diff --git a/multi-cloud-WebApp-Attendance.code-workspace b/multi-cloud-WebApp-Attendance.code-workspace new file mode 100644 index 0000000..15c77e1 --- /dev/null +++ b/multi-cloud-WebApp-Attendance.code-workspace @@ -0,0 +1,10 @@ +{ + "folders": [ + { + "path": "." + } + ], + "settings": { + "java.configuration.updateBuildConfiguration": "automatic" + } +} \ No newline at end of file diff --git a/project-diagrams b/project-diagrams deleted file mode 100644 index 4c85eb3..0000000 --- a/project-diagrams +++ /dev/null @@ -1,103 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/project-diagrams.drawio b/project-diagrams.drawio new file mode 100644 index 0000000..abac217 --- /dev/null +++ b/project-diagrams.drawio @@ -0,0 +1,455 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..dbab213 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,7 @@ +/* + * This file was generated by the Gradle 'init' task. + * + * This project uses @Incubating APIs which are subject to change. + */ + +rootProject.name = "AttendWebApp" \ No newline at end of file diff --git a/src/main/bindings/bindings.xjb b/src/main/bindings/bindings.xjb new file mode 100644 index 0000000..6aee12d --- /dev/null +++ b/src/main/bindings/bindings.xjb @@ -0,0 +1,13 @@ + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/bean/AttendanceBean.java b/src/main/java/bean/AttendanceBean.java index 2224855..3e3d20e 100644 --- a/src/main/java/bean/AttendanceBean.java +++ b/src/main/java/bean/AttendanceBean.java @@ -28,7 +28,7 @@ public class AttendanceBean { public void init() { // invokes service class to populate classes classes = new ArrayList(); - classes.add("SOA"); + classes.add("Micro Services Architecture"); classes.add("Service Science"); classes.add("Service Based Design"); classes.add("Cloud Computing"); @@ -97,6 +97,5 @@ public void setRandomCode(String randomCode) { this.randomCode = randomCode; } } -/* - * End of AttendanceBean.java - */ +// End of AttendanceBean.java + diff --git a/src/main/java/bean/Main.java b/src/main/java/bean/Main.java deleted file mode 100644 index a4196b8..0000000 --- a/src/main/java/bean/Main.java +++ /dev/null @@ -1,63 +0,0 @@ - /** - * Class Main connects to main.xhtml - * calls Web services to obtain data from random Free services online - * obtains IP and Random Bible Verse - */ - -package bean; - -import javax.annotation.PostConstruct; -import javax.faces.bean.ManagedBean; -import javax.faces.bean.SessionScoped; - -import service.MainService; - -@ManagedBean(name = "main") -@SessionScoped - -public class Main{ - - private String bibleVerse; - private String linkedPage; - private String geoIpWS; - - @PostConstruct - public void init() { - MainService invoker = new MainService(); - //invoke services - setGeoIpWS(invoker.invokeWSDLForIP()); - setBibleVerse(invoker.invokeRestForBibleVerse()); - } - - public String getGeoIpWS() { - return geoIpWS; - } - - public void setGeoIpWS(String geoIpWS) { - this.geoIpWS = geoIpWS; - } - - public String getBibleVerse() { - return bibleVerse; - } - - public void setBibleVerse(String bibleVerse) { - this.bibleVerse = bibleVerse; - } - - public void setLinkedPage(String linkedPage) { - this.linkedPage = linkedPage; - } - - public String getlinkedPage() { - if (linkedPage=="1") { - - linkedPage = "attendance"; - System.out.println("this block page is-->"+linkedPage); - } else { - linkedPage = "registerAttendance"; - System.out.println("this else block page is-->"+linkedPage); - } - return linkedPage; - } -} \ No newline at end of file diff --git a/src/main/java/bean/MainMenu.java b/src/main/java/bean/MainMenu.java index 001e728..2f32d66 100644 --- a/src/main/java/bean/MainMenu.java +++ b/src/main/java/bean/MainMenu.java @@ -1,6 +1,6 @@ /** * Class MainMenu and controls main menu navigation - * links to mainMenu bean and .xhtml file. + * links to mainMenu bean and .xhtml file */ package bean; @@ -20,7 +20,6 @@ public void setLinkedPage(String linkedPage) { public String getlinkedPage() { if (linkedPage=="1") { - linkedPage = "attendance"; System.out.println("this page is-->"+linkedPage); } else { diff --git a/src/main/java/bean/Paper.java b/src/main/java/bean/Paper.java index 3fa70ff..78dd2c7 100644 --- a/src/main/java/bean/Paper.java +++ b/src/main/java/bean/Paper.java @@ -43,13 +43,11 @@ public class Paper { /** * No args constructor for use in serialization - * */ public Paper() { } /** - * * @param id * @param updatedAt * @param stream @@ -192,7 +190,6 @@ public Paper withRoom(String room) { } public String obtainLectureName() { - return "Lecturers Name String"; } } diff --git a/src/main/java/bean/Room.java b/src/main/java/bean/Room.java deleted file mode 100644 index 097d58e..0000000 --- a/src/main/java/bean/Room.java +++ /dev/null @@ -1,23 +0,0 @@ - /** - * Class Room reflects paper management UI for Lectures Rooms - * class template - */ - -package bean; - -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import javax.faces.bean.ManagedBean; - -@ManagedBean -// (name = "room") -public class Room { - - public String obtainSessionNumber() { - - DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"); - LocalDateTime now = LocalDateTime.now(); - - return dtf.format(now); - } -} diff --git a/src/main/java/bean/UserBean.java b/src/main/java/bean/UserBean.java index 9ac9a19..bfad57a 100644 --- a/src/main/java/bean/UserBean.java +++ b/src/main/java/bean/UserBean.java @@ -1,7 +1,7 @@ - /** - * Class UserBean performs specialized login - * contains attributes of user object and performs login calling service objects and functionalities - */ +/** + * Class UserBean performs specialized login + * contains attributes of user object and performs login calling service objects and functionalities + */ package bean; @@ -30,19 +30,18 @@ public class UserBean { private String idToken; private String refreshToken; private String tokenType; - + // Login Method public String login() { try { UserService userService = new UserService(); - //System.out.println("userBean: print the name to see if it got it: "+getId()); - + // System.out.println("userBean: print the name to see if it got it: "+getId()); String IdToken = userService.obtainIdToken(getId(), getPassword()); - //System.out.println("IdToken in UserBean: " + IdToken); - //System.out.println("UserBean checking value of response before if"); + // System.out.println("IdToken in UserBean: " + IdToken); + // System.out.println("UserBean checking value of response before if"); if (userService.createSession(IdToken).equals("ok")) { - + setAccessToken(userService.getAccessToken()); setExpiresIn(userService.getExpiresIn().toString()); setIdToken(userService.getIdToken()); @@ -62,7 +61,7 @@ public String login() { System.out.println("UserBean. inside exception catch."); return "loginError"; } - }// end of login method + }// end of login method public String getAccessToken() { return accessToken; diff --git a/src/main/java/entity/AuthenticationResult.java b/src/main/java/entity/AuthenticationResult.java index ce25292..7c15dbf 100644 --- a/src/main/java/entity/AuthenticationResult.java +++ b/src/main/java/entity/AuthenticationResult.java @@ -72,4 +72,4 @@ public String getIdToken() { public void setIdToken(String idToken) { this.idToken = idToken; } -} +} \ No newline at end of file diff --git a/src/main/java/service/AttendanceService.java b/src/main/java/service/AttendanceService.java index b47b937..b926217 100644 --- a/src/main/java/service/AttendanceService.java +++ b/src/main/java/service/AttendanceService.java @@ -5,7 +5,6 @@ package service; - //Class is used to show invokations to entities MS public class AttendanceService { diff --git a/src/main/java/service/GenerateQRCode.java b/src/main/java/service/GenerateQRCode.java new file mode 100644 index 0000000..c4ec2c7 --- /dev/null +++ b/src/main/java/service/GenerateQRCode.java @@ -0,0 +1,23 @@ +package service; + +import java.io.IOException; +import java.nio.file.Paths; + +import com.google.zxing.BarcodeFormat; +import com.google.zxing.MultiFormatWriter; +import com.google.zxing.WriterException; +import com.google.zxing.client.j2se.MatrixToImageWriter; +import com.google.zxing.common.BitMatrix; + +public class GenerateQRCode { + public boolean validateQR = false; + + public void createWebsiteQRCode() throws WriterException, IOException { + String qrData = "www.andres.nz"; + String localPath = "/home/aleonrangel"; + BitMatrix matrix = new MultiFormatWriter().encode(qrData, BarcodeFormat.QR_CODE, 500, 500, null); + MatrixToImageWriter.writeToPath(matrix, "png", Paths.get(localPath), null); + System.out.println("QR code created"); + validateQR = true; + } +} diff --git a/src/main/java/service/MainService.java b/src/main/java/service/MainService.java deleted file mode 100644 index 01b9d67..0000000 --- a/src/main/java/service/MainService.java +++ /dev/null @@ -1,37 +0,0 @@ - /** - * Class MainService - * invokes two external Web Services - */ - -package service; - -import javax.ws.rs.core.UriBuilder; - -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.config.ClientConfig; -import com.sun.jersey.api.client.config.DefaultClientConfig; - -public class MainService { - - public String invokeWSDLForIP() { - // GeoIPService service = new GeoIPService(); - // GeoIP ipService = service.getGeoIPServiceSoap().getGeoIPContext(); - String result = "WSDL and SOAP being deprecated"; - //String result = ipService.getCountryCode().concat(": ")+ipService.getCountryName().concat(", IP is: ")+ipService.getIP().concat(" the return code details are: ")+ipService.getReturnCodeDetails(); - // String wsdlResult = ipService.getCountryCode().concat(": ")+ipService.getCountryName().concat(", IP is: ")+ipService.getIP().concat(" the return code details are: ")+ipService.getReturnCodeDetails(); - return result; - } - - - public String invokeRestForBibleVerse() { - - ClientConfig config = new DefaultClientConfig(); - Client client = Client.create(config); - - WebResource service = client.resource(UriBuilder.fromUri("http://labs.bible.org/api/?passage=random").build()); - - return service.get(String.class); - } - -} diff --git a/src/main/java/util/AuthenticateAD.java b/src/main/java/util/AuthenticateAD.java new file mode 100644 index 0000000..f84dfca --- /dev/null +++ b/src/main/java/util/AuthenticateAD.java @@ -0,0 +1,135 @@ +// utility class authenticate LDAP call LdapAuth.authenticateUserAndGetInfo (username,password); +// Note: Configure ldapURI ,requiredAttributes ,ADSearchPaths,accountSuffex + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.*; + +import javax.naming.*; +import java.util.regex.*; +import javax.naming.directory.*; +import javax.naming.ldap.InitialLdapContext; +import javax.naming.ldap.LdapContext; + +public class AuthenticateAD { + /* + * you could use a secure connection such as LDAPS (LDAP over SSL/TLS) or + * StartTLS (LDAP over TLS) + * Use a secure password storage mechanism: Consider using a secure password + * storage mechanism such as a password hash or a secure encryption algorithm + * Handle errors and exceptions more robustly: The code currently catches and + * prints out errors and exceptions, but it does not provide specific error + * handling or recovery mechanisms. + * You could consider adding more robust error handling and recovery mechanisms + * to the code to ensure that it can handle a variety of error conditions and + * recover gracefully. + * Implement rate limiting: The code currently does not implement any rate + * limiting mechanisms, which could potentially allow an attacker to perform a + * brute force attack on the AD server. You could consider implementing rate + * limiting mechanisms such as sleeping between authentication attempts or + * limiting the number of authentication attempts per user. + * Use a more secure algorithm for searching the AD: The code currently uses the + * `objectClass=*` search filter, which can be inefficient and may return a + * large number of results. You could consider using a more specific search + * filter such as `(&(objectClass=user)(sAMAccountName=*))`, which only return user objects + * reduce the amount of data transferred over the network + * Use a more secure algorithm for binding to the AD: The code currently uses + * the `bind` method to authenticate the user, which can be vulnerable to replay + * attacks. You could consider using a more secure algorithm such as the + * `saslBind` method, which supports SASL (Simple Authentication and Security + * Layer) and is less vulnerable to replay attacks. + * Use a more secure algorithm for retrieving user information: The code + * currently uses the `search` method to retrieve user information, which can be + * inefficient and may return a large amount of data. You could consider using a + * more specific method such as `getAttribute` or `getAttributes` to retrieve + * only the specific user information that you need. + * Use a more secure algorithm for storing user information: The code currently + * stores user information in a `Map`, which is not secure. You could consider + * using a more secure storage mechanism such as a secure database or a secure + * file storage system to protect the user's information. + */ + + private static String ldapURI; + private static String[] requiredAttributes; + private static String[] ADSearchPaths; + private static String accountSuffex; + private final static String contextFactory = "com.sun.jndi.ldap.LdapCtxFactory"; + // private final static String ldapURI = + // "ldap://52.40.50.72:389/DC=corp,DC=local"; + // private static String[] requiredAttributes = { + // "cn","givenName","sn","userPrincipalName","sAMAccountName","objectSid" }; + // see you active directory user OU's hierarchy + // private static String[] ADSearchPaths = { + // "OU=O365 Synced Accounts,OU=ALL USERS", + // "OU=Users,OU=O365 Synced Accounts,OU=ALL USERS", + // "OU=In-House,OU=Users,OU=O365 Synced Accounts,OU=ALL USERS", + // "OU=Migrated Users + // }; + // private static String accountSuffex = "@corp.local"; // this will be used if + // user name is just provided + + public void readFromPropertiesFile() { + try (InputStream inputStream = AuthenticateAD.class.getClassLoader().getResourceAsStream("ad.properties")) { + Properties properties = new Properties(); + properties.load(inputStream); + ldapURI = properties.getProperty("ldapURI"); + requiredAttributes = properties.getProperty("requiredAttributes").split(","); + ADSearchPaths = properties.getProperty("ADSearchPaths").split(";"); + accountSuffex = properties.getProperty("accountSuffex"); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private static void authenticateUserAndGetInfo(String user, String password) throws Exception { + try { + Hashtable env = new Hashtable(); + env.put(Context.INITIAL_CONTEXT_FACTORY, contextFactory); + env.put(Context.PROVIDER_URL, ldapURI); + env.put(Context.SECURITY_AUTHENTICATION, "simple"); + env.put(Context.SECURITY_PRINCIPAL, user); + env.put(Context.SECURITY_CREDENTIALS, password); + + DirContext ctx = new InitialDirContext(env); + + String filter = "(sAMAccountName=" + user + ")"; // default for search filter username + + if (user.contains("@")) // if user name is a email then + { + // String parts[] = user.split("\\@"); + // use different filter for email + filter = "(userPrincipalName=" + user + ")"; + } + + SearchControls ctrl = new SearchControls(); + ctrl.setSearchScope(SearchControls.SUBTREE_SCOPE); + ctrl.setReturningAttributes(requiredAttributes); + + NamingEnumeration userInfo = null; + + Integer i = 0; + do { + userInfo = ctx.search(ADSearchPaths[i], filter, ctrl); + i++; + + } while (!userInfo.hasMore() && i < ADSearchPaths.length); + + if (userInfo.hasMore()) { + + SearchResult UserDetails = (SearchResult) userInfo.next(); + Attributes userAttr = UserDetails.getAttributes(); + System.out.println("adEmail = " + userAttr.get("userPrincipalName").get(0).toString()); + System.out.println("adFirstName = " + userAttr.get("givenName").get(0).toString()); + System.out.println("adLastName = " + userAttr.get("sn").get(0).toString()); + System.out.println("name = " + userAttr.get("cn").get(0).toString()); + System.out.println("AdFullName = " + userAttr.get("cn").get(0).toString()); + } + + userInfo.close(); + + } catch (javax.naming.AuthenticationException e) { + + } + } +} \ No newline at end of file diff --git a/src/main/java/util/AuthenticateOpenLDAP.java b/src/main/java/util/AuthenticateOpenLDAP.java new file mode 100644 index 0000000..0757b3e --- /dev/null +++ b/src/main/java/util/AuthenticateOpenLDAP.java @@ -0,0 +1,45 @@ +package util; + +import com.unboundid.ldap.sdk.*; +import com.unboundid.util.ssl.SSLUtil; +import com.unboundid.util.ssl.TrustAllTrustManager; +import javax.net.ssl.SSLSocketFactory; + +public class AuthenticateOpenLDAP { + public void openLDAPAdminSearch() { + // LDAP connection parameters + String ldapURL = "ldap://localhost"; + String bindDN = "cn=admin,dc=my-company,dc=com"; + String bindPassword = System.getenv("LDAP_ADMIN_PASS"); + String baseDN = "dc=my-company,dc=com"; + String searchFilter = "(objectClass=*)"; // Modify this filter as needed + + // Connect to the LDAP server + LDAPConnection connection = null; + try { + // If using SSL/TLS, initialize SSLSocketFactory (optional) + // SSLUtil sslUtil = new SSLUtil(new TrustAllTrustManager()); + // SSLSocketFactory socketFactory = sslUtil.createSSLSocketFactory(); + // connection = new LDAPConnection(socketFactory, "localhost", 636); + + // For non-SSL connection + connection = new LDAPConnection("localhost", 389); + connection.bind(bindDN, bindPassword); + + // Perform the search + SearchResult searchResult = connection.search(baseDN, SearchScope.SUB, searchFilter); + + // Process the search results + for (SearchResultEntry entry : searchResult.getSearchEntries()) { + System.out.println(entry.toLDIFString()); + } + } catch (LDAPException e) { + e.printStackTrace(); + } finally { + // Disconnect from the LDAP server + if (connection != null) { + connection.close(); + } + } + } +} \ No newline at end of file diff --git a/src/main/java/bean/AttendanceRegister.java b/src/main/java/util/AuthenticateToken.java similarity index 79% rename from src/main/java/bean/AttendanceRegister.java rename to src/main/java/util/AuthenticateToken.java index c5ae78f..76e86d6 100644 --- a/src/main/java/bean/AttendanceRegister.java +++ b/src/main/java/util/AuthenticateToken.java @@ -1,9 +1,9 @@ - /** - * Class AttendanceRegister - * sends invocation to webservice for confirmation of attendance. Includes prime faces UI functionality. - */ +/** + * Class AttendanceRegister + * sends invocation to webservice for confirmation of attendance. Includes prime faces UI functionality. + */ -package bean; +package util; import javax.faces.application.FacesMessage; import javax.faces.bean.ManagedBean; @@ -23,7 +23,7 @@ import service.UserService; @ManagedBean -public class AttendanceRegister { +public class AuthenticateToken { private String inputCode; private Integer progress; @@ -38,7 +38,8 @@ public String confirmAttendance() { ClientConfig config = new DefaultClientConfig(); Client client = Client.create(config); - WebResource webResource = client.resource(UriBuilder.fromUri("https://xgdeevdwh1.execute-api.us-east-1.amazonaws.com").path("addAttendance").build()); + WebResource webResource = client.resource(UriBuilder + .fromUri("https://xgdeevdwh1.execute-api.us-east-1.amazonaws.com").path("addAttendance").build()); // Passing parameters // {"studentId": "246810","paperId": "COMP101","status": "present"} @@ -52,11 +53,14 @@ public String confirmAttendance() { jsonPayLoad.addProperty("paperId", "COMP101"); jsonPayLoad.addProperty("status", "present"); - //ClientResponse response = webResource.accept(MediaType.APPLICATION_JSON).header("Authorization", token).post(ClientResponse.class, jsonPayLoad.toString()); - ClientResponse response = webResource.header("Authorization", token).post(ClientResponse.class, jsonPayLoad.toString()); - // + // ClientResponse response = + // webResource.accept(MediaType.APPLICATION_JSON).header("Authorization", + // token).post(ClientResponse.class, jsonPayLoad.toString()); + ClientResponse response = webResource.header("Authorization", token).post(ClientResponse.class, + jsonPayLoad.toString()); replyFromMS = response.getEntity(String.class); - //String replyFromMS = webResource.path("addAttendance").accept(MediaType.APPLICATION_JSON).header("Authorization", token).post(String.class, jsonPayLoad.toString()); + // webResource.path("addAttendance").accept(MediaType.APPLICATION_JSON).header("Authorization", + // token).post(String.class, jsonPayLoad.toString()); System.out.println("AttendanceRegisterResponse:" + response); diff --git a/src/main/resources/ad.properties b/src/main/resources/ad.properties new file mode 100644 index 0000000..bfefa90 --- /dev/null +++ b/src/main/resources/ad.properties @@ -0,0 +1,10 @@ +# Active Directory properties +ldapURI=ldap://20.200.200.200:389/DC=corp,DC=local +requiredAttributes=cn,givenName,sn,displayName,userPrincipalName,sAMAccountName,objectSid,userAccountControl +ADSearchPaths=OU=O365 Synced Accounts,OU=ALL USERS;OU=Users,OU=O365 Synced Accounts,OU=ALL USERS;OU=In-House,OU=Users,OU=O365 Synced Accounts,OU=ALL USERS;OU=Torbram Users,OU=Users,OU=O365 Synced Accounts,OU=ALL USERS;OU=Migrated Users,OU=TES-Users +accountSuffix=@corp.local + +# userPrincipalName: This attribute represents the user principal name (UPN) of the user. It is a unique identifier for the user within the Active Directory domain. +# sAMAccountName: This attribute represents the user's SAM account name. It is a legacy attribute used in older versions of Active Directory. +# objectSid: This attribute represents the security identifier (SID) of the user. It is a unique identifier for the user within the Active Directory domain. +# userAccountControl: This attribute represents the user account control (UAC) of the user. Specifies the user's permissions and access rights within the Active Directory domain. \ No newline at end of file diff --git a/src/main/resources/ldap.properties b/src/main/resources/ldap.properties new file mode 100644 index 0000000..97fa939 --- /dev/null +++ b/src/main/resources/ldap.properties @@ -0,0 +1,10 @@ +# ldap.properties +# https://www.openldap.org/ +ldapURI=ldap://localhost:389/DC=my-company,DC=com +# objectClass: attribute specifies the object class of the entry in the directory. Defines type of object that the entry represents. Active Directory, the object class is 'user', while in OpenLDAP, it is 'inetOrgPerson'. +# objectCategory: specifies the object category of the entry in the directory. Defines the purpose or role of the object. in Active Directory, the object category is 'person', while in OpenLDAP, it is 'top'. +# objectGUID: This attribute uniquely identifies the entry in the directory. It is generated automatically by OpenLDAP and should not be modified manually. +# givenName: This attribute represents the given name of the user. It is the first name of the user. +# sn: This attribute represents the surname (family name) of the user. +# displayName: This attribute represents the display name of the user. It is the name that the user wants to be displayed. +requiredAttributes=objectClass,objectCategory,objectGUID,givenName,sn,displayName diff --git a/src/main/resources/wsdl/NumberConversion.wsdl b/src/main/resources/wsdl/NumberConversion.wsdl new file mode 100644 index 0000000..8303c8a --- /dev/null +++ b/src/main/resources/wsdl/NumberConversion.wsdl @@ -0,0 +1,154 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/webapp/01-login.xhtml b/src/main/webapp/01-login.xhtml new file mode 100644 index 0000000..ce0f56c --- /dev/null +++ b/src/main/webapp/01-login.xhtml @@ -0,0 +1,63 @@ + + + + + Login Attendance System + + + + + + + + + + + + + + + + + + + + + + Login +

University Attendance System

+ + Attendance + +
+ + Username ID + + Passcode + + +
+ +
+
+ +
+
+
+
+
+

+ Info: - Enter Username - password +

+
+
+
+
+ + + diff --git a/src/main/webapp/02-studentHome.xhtml b/src/main/webapp/02-studentHome.xhtml new file mode 100644 index 0000000..ec07e08 --- /dev/null +++ b/src/main/webapp/02-studentHome.xhtml @@ -0,0 +1,106 @@ + + + + Generate Attendance System + + + + + + + Generate Attendance Code + + +

Attendance System Date

+

Time and Date

+ +
+
+
+
+ + + + + + + + +

+ Welcome + + to the session + + for Lecture. + + +
Generate a code to register attendance for this session. + Remember each student in the class has a time frame for 1 minute. +

+
+ + + + + + +
+ + + +
+ + + + + + + +
+ + + + +
+ +
+
+
+
+
+ +
+ +
+
+
+
+ + diff --git a/src/main/webapp/attendanceOK.xhtml b/src/main/webapp/03-attendanceOK.xhtml similarity index 100% rename from src/main/webapp/attendanceOK.xhtml rename to src/main/webapp/03-attendanceOK.xhtml diff --git a/src/main/webapp/attendanceRegister.xhtml b/src/main/webapp/04-lecturerHome.xhtml similarity index 100% rename from src/main/webapp/attendanceRegister.xhtml rename to src/main/webapp/04-lecturerHome.xhtml diff --git a/src/main/webapp/main.xhtml b/src/main/webapp/05-universityStaff.xhtml similarity index 100% rename from src/main/webapp/main.xhtml rename to src/main/webapp/05-universityStaff.xhtml diff --git a/src/main/webapp/sign.xhtml b/src/main/webapp/06-Reports.xhtml similarity index 100% rename from src/main/webapp/sign.xhtml rename to src/main/webapp/06-Reports.xhtml diff --git a/src/main/webapp/test2.xhtml b/src/main/webapp/07-StudentManagement.xhtml similarity index 100% rename from src/main/webapp/test2.xhtml rename to src/main/webapp/07-StudentManagement.xhtml diff --git a/src/main/webapp/testComponent.xhtml b/src/main/webapp/08-ClassManagement.xhtml similarity index 100% rename from src/main/webapp/testComponent.xhtml rename to src/main/webapp/08-ClassManagement.xhtml diff --git a/src/main/webapp/09-UserManagement.xhtml b/src/main/webapp/09-UserManagement.xhtml new file mode 100644 index 0000000..953aaf8 --- /dev/null +++ b/src/main/webapp/09-UserManagement.xhtml @@ -0,0 +1,47 @@ + + + + Main Menu Attendance System + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/webapp/10-CompositeServices.xhtml b/src/main/webapp/10-CompositeServices.xhtml new file mode 100644 index 0000000..5b5862c --- /dev/null +++ b/src/main/webapp/10-CompositeServices.xhtml @@ -0,0 +1,47 @@ + + + + Composite Services Integration + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/webapp/404-attendanceError.xhtml b/src/main/webapp/404-attendanceError.xhtml new file mode 100644 index 0000000..b59f635 --- /dev/null +++ b/src/main/webapp/404-attendanceError.xhtml @@ -0,0 +1,108 @@ + + + + + + + Error registering attendance + + + + +
+ +
+ + + + +
+

+ Se ha presentado un Error al publicar el aviso. Contacte a soporte + IT. +

+

+
+
+

+ Suba el archivo en formato xlsx de los horarios de los abogados + para las distintas semanas. +

+
+
+ + + +
+
+ + +
+ + +
+
+ +
+ This template downloaded from + free website templates +
+
+ diff --git a/src/main/webapp/loginError.xhtml b/src/main/webapp/404-loginError.xhtml similarity index 100% rename from src/main/webapp/loginError.xhtml rename to src/main/webapp/404-loginError.xhtml diff --git a/src/main/webapp/UserCreated.xhtml b/src/main/webapp/UserCreated.xhtml deleted file mode 100644 index 9f4bea4..0000000 --- a/src/main/webapp/UserCreated.xhtml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - Main Menu Attendance System - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 7570a92..7b5a5ad 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -1,9 +1,9 @@ - + - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" + version="3.1"> + AttendanceWebApp login.xhtml @@ -15,11 +15,11 @@ 1 - + Faces Servlet *.xhtml - + State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2 javax.faces.STATE_SAVING_METHOD client @@ -30,5 +30,5 @@ com.sun.faces.config.ConfigureListener - + \ No newline at end of file diff --git a/src/main/webapp/attendanceError.xhtml b/src/main/webapp/attendanceError.xhtml deleted file mode 100644 index c4c8ddb..0000000 --- a/src/main/webapp/attendanceError.xhtml +++ /dev/null @@ -1,82 +0,0 @@ - - - - - - - - Error registering attendance - - - - -
- -
- - - - -
- -

- Se - ha presentado un Error al publicar el aviso. Contacte a soporte IT.

-

-
-
-

Suba el archivo en formato xlsx de los horarios de los - abogados para las distintas semanas.

-
-
- - -
-
- - -
- - -
-
- -
- This template downloaded from free - website templates -
- -
- \ No newline at end of file diff --git a/src/main/webapp/attendanceGenerate.xhtml b/src/main/webapp/attendanceGenerate.xhtml deleted file mode 100644 index 5250a45..0000000 --- a/src/main/webapp/attendanceGenerate.xhtml +++ /dev/null @@ -1,91 +0,0 @@ - - - - - Generate Attendance System - - - - - - - - - - Generate Attendance Code - - -

Attendance System Date

-

Time and Date

- -
-
-
-
- - - - - - - - -

- Welcome - - to the session - - for Lecture. - - -
Generate a code to register attendance for this session. - Remember each student in the class has a time frame for 1 minute. -

-
- - - - - - -
- - - -
- - - - - - - -
- - - - -
- -
-
-
-
-
- -
- -
- -
- -
- -
- - - \ No newline at end of file diff --git a/src/main/webapp/attendanceNOK.xhtml b/src/main/webapp/attendanceNOK.xhtml deleted file mode 100644 index 95d0311..0000000 --- a/src/main/webapp/attendanceNOK.xhtml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - Class Attendance error - - - - - - - - - - - - attendance Error - -
-
-
-
-
- -
- -
- -
-
-
- - - - \ No newline at end of file diff --git a/src/main/webapp/dropdown.xhtml b/src/main/webapp/dropdown.xhtml deleted file mode 100644 index 43711d9..0000000 --- a/src/main/webapp/dropdown.xhtml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - -Insert title here - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/main/webapp/helloworld.xhtml b/src/main/webapp/helloworld.xhtml deleted file mode 100644 index ea2dd4c..0000000 --- a/src/main/webapp/helloworld.xhtml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - Hello World - - - - - - - -

- -
-
- \ No newline at end of file diff --git a/src/main/webapp/login.xhtml b/src/main/webapp/login.xhtml deleted file mode 100644 index fa27257..0000000 --- a/src/main/webapp/login.xhtml +++ /dev/null @@ -1,63 +0,0 @@ - - - - - Login Attendance System - - - - - - - - - - - - - - - - - - - - - Login -

Attendance System

- - AUT Attendance - -
- - Username ID - - Passcode - - -
- -
-
- -
-
-
-
-
-

- Info: - Enter Username and password -

-
-
-
- -
- - - diff --git a/src/test/attendance/Authorization.java b/src/test/attendance/Authorization.java deleted file mode 100644 index 069fc82..0000000 --- a/src/test/attendance/Authorization.java +++ /dev/null @@ -1,32 +0,0 @@ -/*-- com.leo.json.Authorization.java -- */ - -package com.leo.json; - -import com.google.gson.annotations.SerializedName; - -public class Authorization { - - // names have to be the same from JSON to Java Object so that it works fine. - - private ChallengeParameters challengeParameters; - // @SerializedName("AuthenticationResult") - // @Expose - private AuthenticationResult authenticationResult; - - public ChallengeParameters getChallengeParameters() { - return challengeParameters; - } - - public void setChallengeParameters(ChallengeParameters challengeParameters) { - this.challengeParameters = challengeParameters; - } - - public AuthenticationResult getAuthenticationResult() { - return authenticationResult; - } - - public void setAuthenticationResult(AuthenticationResult authenticationResult) { - this.authenticationResult = authenticationResult; - } - -} \ No newline at end of file diff --git a/src/test/attendance/student/StudentAuthenticationResult.java b/src/test/java/attendance/student/StudentAuthenticationResult.java similarity index 92% rename from src/test/attendance/student/StudentAuthenticationResult.java rename to src/test/java/attendance/student/StudentAuthenticationResult.java index 03b2f41..d2ff0c5 100644 --- a/src/test/attendance/student/StudentAuthenticationResult.java +++ b/src/test/java/attendance/student/StudentAuthenticationResult.java @@ -1,10 +1,11 @@ -package attendance.gson; +package attendance.student; import com.google.gson.annotations.SerializedName; public class StudentAuthenticationResult { - public StudentAuthenticationResult(String accessToken, Integer expiresIn, String tokenType, String refreshToken, String idToken) { + public StudentAuthenticationResult(String accessToken, Integer expiresIn, String tokenType, String refreshToken, + String idToken) { this.accessToken = accessToken; this.expiresIn = expiresIn; this.tokenType = tokenType; @@ -14,19 +15,19 @@ public StudentAuthenticationResult(String accessToken, Integer expiresIn, String @SerializedName("AccessToken") private String accessToken; - + @SerializedName("ExpiresIn") private Integer expiresIn; - + @SerializedName("TokenType") private String tokenType; - + @SerializedName("RefreshToken") private String refreshToken; - + @SerializedName("IdToken") private String idToken; - + // Setters and getters public String getAccessToken() { diff --git a/src/test/attendance/student/StudentAuthorization.java b/src/test/java/attendance/student/StudentAuthorization.java similarity index 87% rename from src/test/attendance/student/StudentAuthorization.java rename to src/test/java/attendance/student/StudentAuthorization.java index 01d3593..db768bf 100644 --- a/src/test/attendance/student/StudentAuthorization.java +++ b/src/test/java/attendance/student/StudentAuthorization.java @@ -1,6 +1,4 @@ -/*---------------------------------- com.leo.json.Authorization.java ---------------------------------- */ - -package attendance.gson; +package attendance.student; import com.google.gson.annotations.SerializedName; diff --git a/src/test/attendance/student/TestStudent.java b/src/test/java/attendance/student/TestStudent.java similarity index 100% rename from src/test/attendance/student/TestStudent.java rename to src/test/java/attendance/student/TestStudent.java diff --git a/src/test/java/auth/ldap/TestLDAPAuthentication.java b/src/test/java/auth/ldap/TestLDAPAuthentication.java new file mode 100644 index 0000000..f486e57 --- /dev/null +++ b/src/test/java/auth/ldap/TestLDAPAuthentication.java @@ -0,0 +1,104 @@ +package auth.ldap; + +import org.junit.Test; +import static org.junit.Assert.assertTrue; + +import java.util.Arrays; +import java.util.List; + +import org.mockito.Mockito; +import com.unboundid.ldap.sdk.LDAPConnection; +import com.unboundid.ldap.sdk.LDAPException; +import com.unboundid.ldap.sdk.LDAPSearchException; +import com.unboundid.ldap.sdk.SearchRequest; +import com.unboundid.ldap.sdk.SearchResult; +import com.unboundid.ldap.sdk.SearchResultEntry; +import com.unboundid.ldap.sdk.SearchScope; + +import util.AuthenticateOpenLDAP; + +public class TestLDAPAuthentication { + // - Mocks LDAPConnection to avoid real connection + // - Mocks search result and entries returned + // - Stubs the behavior for the mocks + // - Calls the method under test + // - Verifies expected methods are called on the mocks + + @Test + public void testMockOpenLDAPAdminSearch() throws LDAPSearchException { + // Mock LDAPConnection + LDAPConnection connectionMock = Mockito.mock(LDAPConnection.class); + + // Mock search result + SearchResult searchResultMock = Mockito.mock(SearchResult.class); + Mockito.when(connectionMock.search(Mockito.anyString(), Mockito.any(), Mockito.anyString())) + .thenReturn(searchResultMock); + + // Mock search result entries + SearchResultEntry entry1 = Mockito.mock(SearchResultEntry.class); + SearchResultEntry entry2 = Mockito.mock(SearchResultEntry.class); + SearchResultEntry[] ldapResult = new SearchResultEntry[] { entry1, entry2 }; + List resultList = Arrays.asList(ldapResult); + // Stub searchEntries to return mocked entries + Mockito.when(searchResultMock.getSearchEntries()).thenReturn(resultList); + + // Test the method + AuthenticateOpenLDAP ldapAuth = new AuthenticateOpenLDAP(); + ldapAuth.openLDAPAdminSearch(); + + // Verify search was called + try { + Mockito.verify(connectionMock).search(Mockito.anyString(), Mockito.any(), Mockito.anyString()); + } catch (LDAPSearchException e) { + e.printStackTrace(); + } + + // Verify entry processing + Mockito.verify(entry1).toLDIFString(); + Mockito.verify(entry2).toLDIFString(); + + // Verify connection closed + Mockito.verify(connectionMock).close(); + } + + @Test + public void testOpenLDAPAdminSearch_withOpenLDAP() { + // Test parameters + String ldapURL = "ldap://localhost"; + String ldapHost = "localhost"; + int ldapPort = 389; + String bindDN = "cn=admin,dc=my-company,dc=com"; + var bindPassword = "adminpassword"; + String baseDN = "dc=my-company,dc=com"; + String searchFilter = "(objectClass=*)"; + + // Connect to OpenLDAP + // Establishing a connection to the LDAP server + try (LDAPConnection connection = new LDAPConnection(ldapHost, ldapPort, bindDN, bindPassword)) { + System.out.println("Connected to the LDAP server."); + + SearchRequest searchRequest = new SearchRequest(baseDN, SearchScope.SUB, searchFilter); + // Performing the search + SearchResult result = connection.search(baseDN, SearchScope.SUB, "(objectClass=*)"); + + // Verify search returned results + assertTrue(result.getEntryCount() > 0); + + // Print entries + for (SearchResultEntry entry : result.getSearchEntries()) { + System.out.println(entry.toLDIFString()); + } + + SearchResult searchResult = connection.search(searchRequest); + System.out.println("Search returned " + searchResult.getEntryCount() + " entries."); + + // Process the search results as needed + // Close connection + connection.close(); + } catch (LDAPException e) { + System.err.println("Error connecting to the LDAP server: " + e.getMessage()); + e.printStackTrace(); + } + + } +} diff --git a/src/test/attendance/login/LoginReply.java b/src/test/java/auth/login/LoginReply.java similarity index 86% rename from src/test/attendance/login/LoginReply.java rename to src/test/java/auth/login/LoginReply.java index fe289ad..74142d4 100644 --- a/src/test/attendance/login/LoginReply.java +++ b/src/test/java/auth/login/LoginReply.java @@ -1,8 +1,11 @@ -package com.json; +package auth.login; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; +import entity.AuthenticationResult; +import entity.ChallengeParameters; + public class LoginReply { @SerializedName("ChallengeParameters") @@ -32,6 +35,6 @@ public void setAuthenticationResult(AuthenticationResult authenticationResult) { public String toString() { // return getClass()+"challenge"+challengeParameters+"data in // authent"+authenticationResult.getIdToken(); - return getClass() + " Not obtaining really much"; + return getClass() + "JSON Overriding functionality"; } } diff --git a/src/test/attendance/login/TestLogin.java b/src/test/java/auth/login/TestLogin.java similarity index 57% rename from src/test/attendance/login/TestLogin.java rename to src/test/java/auth/login/TestLogin.java index 7fb1c58..7e3b0da 100644 --- a/src/test/attendance/login/TestLogin.java +++ b/src/test/java/auth/login/TestLogin.java @@ -1,8 +1,8 @@ -package attendance.login; +package auth.login; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.Test; +import org.junit.jupiter.api.Test; import bean.UserBean; @@ -10,7 +10,7 @@ public class TestLogin { @Test public void GetToken() { - //fail("Not yet implemented"); + // fail("Not yet implemented"); } @Test @@ -18,8 +18,8 @@ public void loginGeneralUser() { UserBean user = new UserBean(); user.setId("10295765"); user.setPassword("Value!12"); - //System.out.println("assert result"+user.login()); - assertTrue(user.login()=="main"); + // System.out.println("assert result"+user.login()); + assertTrue(user.login() == "main"); } public void loginGeneralUserNOK() { diff --git a/src/test/restclient/PostAuthenticationToken.java b/src/test/java/auth/token/PostAuthenticationToken.java similarity index 99% rename from src/test/restclient/PostAuthenticationToken.java rename to src/test/java/auth/token/PostAuthenticationToken.java index b9d37a2..f6e3965 100644 --- a/src/test/restclient/PostAuthenticationToken.java +++ b/src/test/java/auth/token/PostAuthenticationToken.java @@ -1,4 +1,4 @@ -package rest; +package auth.token; import java.io.BufferedReader; import java.io.IOException; diff --git a/src/test/attendance/TestAuthenticationResult.java b/src/test/java/auth/token/TestTokenAuthentication.java similarity index 89% rename from src/test/attendance/TestAuthenticationResult.java rename to src/test/java/auth/token/TestTokenAuthentication.java index 3b9c801..ba48b04 100644 --- a/src/test/attendance/TestAuthenticationResult.java +++ b/src/test/java/auth/token/TestTokenAuthentication.java @@ -1,10 +1,10 @@ -package com.json; +package auth.token; import com.google.gson.annotations.SerializedName; -public class AuthenticationResult { +public class TestTokenAuthentication { - public AuthenticationResult(String accessToken, Integer expiresIn, String tokenType, String refreshToken, + public TestTokenAuthentication(String accessToken, Integer expiresIn, String tokenType, String refreshToken, String idToken) { this.accessToken = accessToken; this.expiresIn = expiresIn; @@ -69,4 +69,4 @@ public String getIdToken() { public void setIdToken(String idToken) { this.idToken = idToken; } -} +} \ No newline at end of file diff --git a/src/test/json/JSON2Object.java b/src/test/java/json/TestConversionJSON2Object.java similarity index 93% rename from src/test/json/JSON2Object.java rename to src/test/java/json/TestConversionJSON2Object.java index 2b50e7e..6b9bc7a 100644 --- a/src/test/json/JSON2Object.java +++ b/src/test/java/json/TestConversionJSON2Object.java @@ -1,16 +1,13 @@ -package com.leo.json; +package json; import com.google.gson.Gson; -public class JSON2Object { +import entity.LoginReply; - public static void main(String[] args) { - // TODO Auto-generated method stub +public class TestConversionJSON2Object { + public static void main(String[] args) { String replyJson = "{\"ChallengeParameters\":{},\"AuthenticationResult\":{\"AccessToken\":\"eyJraWQiOiJ6M2pWR1lscDVsS2VHVzRXMkwrU3BtdjN4UzIwWGFCU1FvZFlvdWg1WkU4PSIsImFsZyI6IlJTMjU2In0.eyJzdWIiOiI2MWI5ZTI4NC1kMzVhLTQ0M2YtOTlhNy04MGY0OWE4YTI4NmQiLCJ0b2tlbl91c2UiOiJhY2Nlc3MiLCJzY29wZSI6ImF3cy5jb2duaXRvLnNpZ25pbi51c2VyL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"{'name' : 'martina perumal'}"; - Gson gson = new Gson(); // Restaurant restaurantObject = gson.fromJson(restaurantJson, @@ -18,11 +15,7 @@ public static void main(String[] args) { LoginReply loginReplyObject = gson.fromJson(replyJson, LoginReply.class); // Object loginReplyObject = gson.fromJson(replyJson, Object.class); - - Girl girl = gson.fromJson(jsonInString, Girl.class); - System.out.println("value " + loginReplyObject.getAuthenticationResult().getIdToken()); - System.out.println("value of her name " + girl.getName()); // System.out.println("obtain token "+ loginReplyObject.authenticationResult); } } diff --git a/src/test/java/json/TestConversionJson2Map.java b/src/test/java/json/TestConversionJson2Map.java new file mode 100644 index 0000000..3ac0ccb --- /dev/null +++ b/src/test/java/json/TestConversionJson2Map.java @@ -0,0 +1,60 @@ +package json; + +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; +import entity.Authorization; +import java.lang.reflect.Type; +import java.util.HashMap; +import java.util.Map; + +public class TestConversionJson2Map { + public void convertJSON2Map() { + String jsonFromMS = "{\"ChallengeParameters\":{},\"AuthenticationResult\":{\"AccessToken\":\"eyJraWQiOiJ6M2pWR1lscDVsS2VHVzRXMkwrU3BtdjN4UzIwWGFCU1FvZFlvdWg1WkU4PSIsImFsZyI6IlJTMjU2In0.eyJzdWIiOiI2MWI5ZTI4NC1kMzVhLTQ0M2YtOTlhNy04MGY0OWE4YTI4NmQiLCJ0b2tlbl91c2UiOiJhY2Nlc3MiLCJzY29wZSI6ImF3cy5jb2duaXRvLnNpZ25pbi51c2VyLmFkbWluIiwiaXNzIjoiaHR0cHM6XC9cL2NvZ25pdG8taWRwLnVzLWVhc3QtMS5hbWF6b25hd3MuY29tXC91cy1lYXN0LTFfMEhkMUtvTTVhIiwiZXhwIjoxNTA1MDg5NDY5LCJpYXQiOjE1MDUwODU4NjksImp0aSI6ImI4MzY3ZjcwLTA5MDktNGI0Mi1hNDI2LWM2ZTYyY2M3ZTI0YSIsImNsaWVudF9pZCI6IjFlOHRlZm1sY2wyaDI5MHZuaDlyY2VmbnZyIiwidX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YtOTlhNy04MGY0OWE4YTI4NmQiLCJhdWQiOiIxZTh0ZWZtbGNsMmgyOTB2bmg5cmNlZm52ciIsImNvZ25pdG86Z3JvdXBzIjpbImFkbWluaXN0cmF0b3IiXSwiZW1haWxfdmVyaWZpZWQiOmZhbHNlLCJ0b2tlbl91c2UiOiJpZCIsImF1dGhfdGltZSI6MTUwNTA4NTg2OSwiaXNzIjoiaHR0cHM6XC9cL2NvZ25pdG8taWRwLnVzLWVhc3QtMS5hbWF6b25hd3MuY29tXC91cy1lYXN0LTFfMEhkMUtvTTVhIiwiY29nbml0bzp1c2VybmFtZSI6IjEwMjk1NzY1IiwiZXhwIjoxNTA1MDg5NDY5LCJpYXQiOjE1MDUwODU4NjksImVtYWlsIjoiam9uYXRoYW4udEB4dHJhLmNvLm56In0.N2vUTeKskoSGGnZNNQkoJrjqQSTwCRsAyoVzU8HoSESciE97PbHu_rsDBHdlIvExQgZOJUDH2fi2ZTVXL0qw_dw_1oy5PY0ss6iF9Ya8vNvwJ4QIg0nGLJEEWO6y9h81bUiy8WYOyC0uCy4FKPBzxu-VjO_ZkJwQZLlhkx56cPXhQI9JFbwQDeyxJDF9duOGiZkWYmiG842TeYpaNIiW46KtQ8kiZLGre9qUdPjQv9S-Ch9Cm8bDqVSunAVtTityUJMGJuxhM78hPAujGdeNfMX0qEx37MpKbQtkb_xJZaT1c0IXnu1tneqtGVxZtaZdQ4mUlBmdzamQaWhlSXvqyA\"}}"; + String jsonInString = "{'name' : 'Alejandra Rangel'}"; + + Gson gson = new Gson(); + Type authorization = new TypeToken>() { + }.getType(); + Map authorizationMap = gson.fromJson(jsonFromMS, authorization); + + Map retMap = new Gson().fromJson(jsonFromMS, new TypeToken>() { + }.getType()); + + Map map = new Gson().fromJson(jsonFromMS, + new TypeToken>() { + }.getType()); + + System.out.println("Printing Map object: " + authorizationMap.values().toString()); + + authorizationMap.keySet().iterator().forEachRemaining(System.out::println); + + System.out.println("Printing ret Map object this is bringing the values: " + retMap.values().toString()); + + map.keySet().iterator().forEachRemaining(System.out::println); + + System.out.println(retMap.get("IdToken")); + } + + public void convertJSONtoMapStructure() { + String jsonFromMS = "{\"ChallengeParameters\":{},\"AuthenticationResult\":{\"AccessToken\":\"eyJraWQiOiJ6M2pWR1lscDVsS2VHVzRXMkwrU3BtdjN4UzIwWGFCU1FvZFlvdWg1WkU4PSIsImFsZyI6IlJTMjU2In0.eyJzdWIiOiI2MWI5ZTI4NC1kMzVhLTQ0M2YtOTlhNy04MGY0OWE4YTI4NmQiLCJ0b2tlbl91c2UiOiJhY2Nlc3MiLCJzY29wZSI6ImF3cy5jb2duaXRvLnNpZ25pbi51c2VyLmFkbWluIiwiaXNzIjoiaHR0cHM6XC9cL2NvZ25pdG8taWRwLnVzLWVhc3QtMS5hbWF6b25hd3MuY29tXC91cy1lYXN0LTFfMEhkMUtvTTVhIiwiZXhwIjoxNTA1MDg5NDY5LCJpYXQiOjE1MDUwODU4NjksImp0aSI6ImI4MzY3ZjcwLTA5MDktNGI0Mi1hNDI2LWM2ZTYyY2M3ZTI0YSIsImNsaWVudF9pZCI6IjFlOHRlZm1sY2wyaDI5MHZuaDlyY2VmbnZyIiwidXNlcm5hbWUiOiIxMDI5NTc2NSJ9.jfGvw9FX5-XBcVVaY21wL7F7Y6KRzRdLweCybx819JdRES2f-m4qGeftAZdzoRuLDJ4QfbGqJdJ1V19MKcw070qdz_zd3JFMo3ev9-1yrzQ9vr9hQR6Utk7cBLs_AGQlXHt2wNimvW7mPj_yyyjLa5LTveX0W-hZ5ZG2FSuiAE6dTmmSZs-FEjwZRPTNbjDVKHHr8QRBFq43gg23PkRCAriLO02ymrVblKCx_kqKvYbvNed_RB0IeGZP_Ll27F34-xdZz6r_zAcgxvOqafa5wPAbOvgCubE_rWviCujhgIa4qe_nqkqMIJhm0B3xOkG6K7Ju2yOy0rNSOzYI5JzRaA\",\"ExpiresIn\":3600,\"TokenType\":\"Bearer\",\"RefreshToken\":\"eyJjdHkiOiJKV1QiLCJlbmM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oSGGnZNNQkoJrjqQSTwCRsAyoVzU8HoSESciE97PbHu_rsDBHdlIvExQgZOJUDH2fi2ZTVXL0qw_dw_1oy5PY0ss6iF9Ya8vNvwJ4QIg0nGLJEEWO6y9h81bUiy8WYOyC0uCy4FKPBzxu-VjO_ZkJwQZLlhkx56cPXhQI9JFbwQDeyxJDF9duOGiZkWYmiG842TeYpaNIiW46KtQ8kiZLGre9qUdPjQv9S-Ch9Cm8bDqVSunAVtTityUJMGJuxhM78hPAujGdeNfMX0qEx37MpKbQtkb_xJZaT1c0IXnu1tneqtGVxZtaZdQ4mUlBmdzamQaWhlSXvqyA\"}}"; + + Gson gson = new Gson(); + + Type authorization = new TypeToken>() { + }.getType(); + + Map authorizationMap = gson.fromJson(jsonFromMS, authorization); + + Map retMap = new Gson().fromJson(jsonFromMS, new TypeToken>() { + }.getType()); + + Map map = new Gson().fromJson(jsonFromMS, new TypeToken>() { + }.getType()); + + System.out.println("Printing Map object: " + authorizationMap.values().toString()); + authorizationMap.keySet().iterator().forEachRemaining(System.out::println); + System.out.println("Printing ret Map object this is bringing the values: " + retMap.values().toString()); + map.keySet().iterator().forEachRemaining(System.out::println); + System.out.println(retMap.get("IdToken")); + } +} diff --git a/src/test/java/json/TestJSON2YAML.java b/src/test/java/json/TestJSON2YAML.java new file mode 100644 index 0000000..cbd5d0f --- /dev/null +++ b/src/test/java/json/TestJSON2YAML.java @@ -0,0 +1,67 @@ +package json; + +import com.google.gson.Gson; +import org.yaml.snakeyaml.Yaml; +import org.junit.Test; +import static org.junit.Assert.*; + +import java.util.Map; + +public class TestJSON2YAML { + + // Test method to convert JSON to YAML + @Test + public void testJsonToYamlConversion() { + String jsonInput = "{\"name\":\"John\", \"age\":30}"; + Gson gson = new Gson(); + Yaml yaml = new Yaml(); + + // Convert JSON to a Map + Map map = gson.fromJson(jsonInput, Map.class); + + // Convert Map to YAML + String yamlOutput = yaml.dump(map); + + // Assert that YAML output is not null or empty + assertNotNull("YAML output should not be null", yamlOutput); + assertFalse("YAML output should not be empty", yamlOutput.isEmpty()); + } + + // Test method to convert YAML to JSON + @Test + public void testYamlToJsonConversion() { + String yamlInput = "name: John\nage: 30"; + Gson gson = new Gson(); + Yaml yaml = new Yaml(); + + // Convert YAML to a Map + Map map = yaml.load(yamlInput); + + // Convert Map to JSON + String jsonOutput = gson.toJson(map); + + // Assert that JSON output is not null or empty + assertNotNull("JSON output should not be null", jsonOutput); + assertFalse("JSON output should not be empty", jsonOutput.isEmpty()); + } + + // Test method to check if YAML output matches expected structure + @Test + public void testYamlStructure() { + String jsonInput = "{\"name\":\"John\", \"age\":30}"; + Gson gson = new Gson(); + Yaml yaml = new Yaml(); + + // Convert JSON to a Map + Map map = gson.fromJson(jsonInput, Map.class); + + // Convert Map to YAML + String yamlOutput = yaml.dump(map); + + // Expected YAML structure + String expectedYaml = "name: John\nage: 30\n"; + + // Assert that the YAML output matches the expected structure + assertEquals("YAML output should match the expected structure", expectedYaml, yamlOutput); + } +} diff --git a/src/test/json/ConversionJSON2Object.java b/src/test/java/json/TestJSONToken.java similarity index 61% rename from src/test/json/ConversionJSON2Object.java rename to src/test/java/json/TestJSONToken.java index d699a45..0fd72b1 100644 --- a/src/test/json/ConversionJSON2Object.java +++ b/src/test/java/json/TestJSONToken.java @@ -1,18 +1,74 @@ -package attendance.gson; +package json; + +import javax.json.Json; +import javax.json.stream.JsonParser; +import javax.json.stream.JsonParser.Event; + +import org.junit.Test; import com.google.gson.Gson; -import entity.LoginReply; +import auth.login.LoginReply; -public class ConversionJSON2Object { +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; - public static void main(String[] args) { - // TODO Auto-generated method stub: use a variable for the token +public class TestJSONToken { - String replyJson = "{\"ChallengeParameters\":{},\"AuthenticationResult\":{\"AccessToken\":\"eyJraWQiOiJ6M2pWR1lscDVsS2VHVzRXMkwrU3BtdjN4UzIwWGFCU1FvZFlvdWg1WkU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oBeQQlA6pYXvWvRwpj0col8N904w4QxoNNNEtYxIYbLtJkj3w-ZogJ9VPkKL_B3ayKTfle3nQ-PHrXyzYpBK89h39Hp2IiOddY-Ihl8iVuj8RziTUiMZ-0jTOToCAa8gQ813DGAtca0i4ffw3hg\"}}"; + @Test + public void testMalformedURL() throws MalformedURLException { + // URL url = new URL("https://graph.facebook.com/search?q=java&type=post"); + // URL url = new + // URL("https://ctpoixww04.execute-api.us-east-1.amazonaws.com/dev/login"); + + // try (InputStream is = url.openStream(); JsonParser parser = + // Json.createParser(is)) { + try { + URL url = new URL("https://ctpoixww04.execute-api.us-east-1.amazonaws.com/dev/login"); + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setDoOutput(true); + conn.setRequestMethod("POST"); + conn.setRequestProperty("Content-Type", "application/json"); + + String input = "{\"id\":\"10295765\",\"password\":\"Value!12\"}"; + + OutputStream os = conn.getOutputStream(); + // 1.The client sends their credentials (username and password) to the server. + os.write(input.getBytes()); + os.flush(); + + BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); - String jsonInString = "{'name' : 'martina perumal'}"; + JsonParser parser = (JsonParser) Json.createReader(br); + while (parser.hasNext()) { + Event e = parser.next(); + if (e == Event.KEY_NAME) { + switch (parser.getString()) { + case "RefreshToken": + parser.next(); + System.out.print(parser.getString()); + System.out.print(": "); + break; + case "IdToken": + parser.next(); + System.out.println(parser.getString()); + System.out.println("---------"); + break; + } + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void formatTokenJSONResponse() { + String replyJson = "{\"ChallengeParameters\":{},\"AuthenticationResult\":{\"AccessToken\":\"eyJraWQiOiJ6M2pWR1lscDVsS2VHVzRXMkwrU3BtdjN4UzIwWGFCU1FvZFlvdWg1WkU4PSIsImFsZyI6IlJTMjU2In0.eyJzdWIiOiI2MWI5ZTI4NC1kMzVhLTQ0M2YtOTlhNy04MGY0OWE4YTI4NmQiLCJ0b2tlbl91c2UiOiJhY2Nlc3MiLCJzY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CAa8gQ813DGAtca0i4ffw3hg\"}}"; Gson gson = new Gson(); // Restaurant restaurantObject = gson.fromJson(restaurantJson, @@ -20,11 +76,7 @@ public static void main(String[] args) { LoginReply loginReplyObject = gson.fromJson(replyJson, LoginReply.class); // Object loginReplyObject = gson.fromJson(replyJson, Object.class); - - Girl girl = gson.fromJson(jsonInString, Girl.class); - System.out.println("value " + loginReplyObject.getAuthenticationResult().getIdToken()); - System.out.println("value of her name " + girl.getName()); - // System.out.println("obtain token "+ loginReplyObject.authenticationResult); - } + System.out.println("obtain token "+ loginReplyObject.getAuthenticationResult().getAccessToken()); + } } diff --git a/src/test/ux/AttendanceGenerateTest.java b/src/test/java/ui/AttendanceGenerateTest.java similarity index 91% rename from src/test/ux/AttendanceGenerateTest.java rename to src/test/java/ui/AttendanceGenerateTest.java index 426478a..df73971 100644 --- a/src/test/ux/AttendanceGenerateTest.java +++ b/src/test/java/ui/AttendanceGenerateTest.java @@ -10,6 +10,5 @@ public class AttendanceGenerateTest { public void testRandomCode() { AttendanceBean at = new AttendanceBean(); assertNotNull("data", at.generateAttendanceCode()); - } - + } // testRandomCode() } diff --git a/src/test/java/utilities/TestCodeGeneration.java b/src/test/java/utilities/TestCodeGeneration.java new file mode 100644 index 0000000..d670b91 --- /dev/null +++ b/src/test/java/utilities/TestCodeGeneration.java @@ -0,0 +1,15 @@ +package utilities; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import org.junit.jupiter.api.Test; + +import bean.AttendanceBean; + +public class TestCodeGeneration { + + @Test + public void testRandomCode() { + AttendanceBean at = new AttendanceBean(); + assertNotNull("data", at.generateAttendanceCode()); + } // testRandomCode() +} diff --git a/src/test/java/utilities/TestQRFunctions.java b/src/test/java/utilities/TestQRFunctions.java new file mode 100644 index 0000000..c984d83 --- /dev/null +++ b/src/test/java/utilities/TestQRFunctions.java @@ -0,0 +1,24 @@ +package utilities; + +import static org.junit.Assert.assertTrue; + +import java.io.IOException; + +import org.junit.Test; + +import com.google.zxing.WriterException; + +import service.GenerateQRCode; + +public class TestQRFunctions { + @Test + public void createQRCodeLocally() { + GenerateQRCode qrCode = new GenerateQRCode(); + try { + qrCode.createWebsiteQRCode(); + } catch (WriterException | IOException e) { + e.printStackTrace(); + } + assertTrue(qrCode.validateQR); + } // End of createQRCodeLocally() +} // End of Class Declaration diff --git a/src/test/json/ConversionJson2Map.java b/src/test/json/ConversionJson2Map.java deleted file mode 100644 index 106862d..0000000 --- a/src/test/json/ConversionJson2Map.java +++ /dev/null @@ -1,38 +0,0 @@ -package attendance.gson; - -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import java.lang.reflect.Type; -import java.util.HashMap; -import java.util.Map; - -public class ConversionJson2Map { - - public static void main(String[] args) { - String jsonFromMS = "{\"ChallengeParameters\":{},\"AuthenticationResult\":{\"AccessToken\":\"eyJraWQiOiJ6M2pWR1lscDVsS2VHVzRXMkwrU3BtdjN4UzIwWGFCU1FvZFlvdWg1WkU4PSIsImFsZyI6IlJTMjU2In0.eyJzdWIiOiI2MWI5ZTI4NC1kMzVhLTQ0M2YtOTlhNy04MGY0OWE4YTI4NmQiLCJ0b2tlbl91c2UiOiJhY2Nlc3MiLCJzY29wZSI6ImF3cy5jb2duaXRvLnNpZ25pbi51c2VyLmFkbWluIiwiaXNzIjoiaHR0cHM6XC9cL2NvZ25pdG8taWRwLnVzLWVhc3QtMS5hbWF6b25hd3MuY29tXC91cy1lYXN0LTFfMEhkMUtvTTVhIiwiZXhwIjoxNTA1MDg5NDY5LCJpYXQiOjE1MDUwODU4NjksImp0aSI6ImI4MzY3ZjcwLTA5MDktNGI0Mi1hNDI2LWM2ZTYyY2M3ZTI0YSIsImNsaWVudF9pZCI6IjFlOHRlZm1sY2wyaDI5MHZuaDlyY2VmbnZyIiwidXNlcm5hbWUiOiIxMDI5NTc2NSJ9.jfGvw9FX5-XBcVVaY21wL7F7Y6KRzRdLweCybx819JdRES2f-m4qGeftAZdzoRuLDJ4QfbGqJdJ1V19MKcw070qdz_zd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iXSwiZW1haWxfdmVyaWZpZWQiOmZhbHNlLCJ0b2tlbl91c2UiOiJpZCIsImF1dGhfdGltZSI6MTUwNTA4NTg2OSwiaXNzIjoiaHR0cHM6XC9cL2NvZ25pdG8taWRwLnVzLWVhc3QtMS5hbWF6b25hd3MuY29tXC91cy1lYXN0LTFfMEhkMUtvTTVhIiwiY29nbml0bzp1c2VybmFtZSI6IjEwMjk1NzY1IiwiZXhwIjoxNTA1MDg5NDY5LCJpYXQiOjE1MDUwODU4NjksImVtYWlsIjoiam9uYXRoYW4udEB4dHJhLmNvLm56In0.N2vUTeKskoSGGnZNNQkoJrjqQSTwCRsAyoVzU8HoSESciE97PbHu_rsDBHdlIvExQgZOJUDH2fi2ZTVXL0qw_dw_1oy5PY0ss6iF9Ya8vNvwJ4QIg0nGLJEEWO6y9h81bUiy8WYOyC0uCy4FKPBzxu-VjO_ZkJwQZLlhkx56cPXhQI9JFbwQDeyxJDF9duOGiZkWYmiG842TeYpaNIiW46KtQ8kiZLGre9qUdPjQv9S-Ch9Cm8bDqVSunAVtTityUJMGJuxhM78hPAujGdeNfMX0qEx37MpKbQtkb_xJZaT1c0IXnu1tneqtGVxZtaZdQ4mUlBmdzamQaWhlSXvqyA\"}}"; - - Gson gson = new Gson(); - - Type authorization = new TypeToken>() { - }.getType(); - // TODO Auto-generated method stub - - Map authorizationMap = gson.fromJson(jsonFromMS, authorization); - - Map retMap = new Gson().fromJson(jsonFromMS, new TypeToken>() { - }.getType()); - - Map map = new Gson().fromJson(jsonFromMS, new TypeToken>() { - }.getType()); - - System.out.println("Printing Map object: " + authorizationMap.values().toString()); - - authorizationMap.keySet().iterator().forEachRemaining(System.out::println); - - System.out.println("Printing ret Map object this is bringing the values: " + retMap.values().toString()); - - map.keySet().iterator().forEachRemaining(System.out::println); - - System.out.println(retMap.get("IdToken")); - } -} diff --git a/src/test/json/Json2Map.java b/src/test/json/Json2Map.java deleted file mode 100644 index cf80674..0000000 --- a/src/test/json/Json2Map.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.json; - -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import java.lang.reflect.Type; -import java.util.HashMap; -import java.util.Map; - -public class Json2Map { - - public static void main(String[] args) { - String jsonFromMS = "{\"ChallengeParameters\":{},\"AuthenticationResult\":{\"AccessToken\":\"eyJraWQiOiJ6M2pWR1lscDVsS2VHVzRXMkwrU3BtdjN4UzIwWGFCU1FvZFlvdWg1WkU4PSIsImFsZyI6IlJTMjU2In0.eyJzdWIiOiI2MWI5ZTI4NC1kMzVhLTQ0M2YtOTlhNy04MGY0OWE4YTI4NmQiLCJ0b2tlbl91c2UiOiJhY2Nlc3MiLCJzY29wZSI6ImF3cy5jb2duaXRvLnNpZ25pbi51c2VyLmFkbWluIiwiaXNzIjoiaHR0cHM6XC9cL2NvZ25pdG8taWRwLnVzLWVhc3QtMS5hbWF6b25hd3MuY29tXC91cy1lYXN0LTFfMEhkMUtvTTVhIiwiZXhwIjoxNTA1MDg5NDY5LCJpYXQiOjE1MDUwODU4NjksImp0aSI6ImI4MzY3ZjcwLTA5MDktNGI0Mi1hNDI2LWM2ZTYyY2M3ZTI0YSIsImNsaWVudF9pZCI6IjFlOHRlZm1sY2wyaDI5MHZuaDlyY2VmbnZyIiwidXNlcm5hbWUiOiIxMDI5NTc2NSJ9.jfGvw9FX5-XBcVVaY21wL7F7Y6KRzRdLweCybx819JdRES2f-m4qGeftAZdzoRuLDJ4QfbGqJdJ1V19MKcw070qdz_zd3JFMo3ev9-1yrzQ9vr9hQR6Utk7cBLs_AGQlXHt2wNimvW7mPj_yyyjLa5LTveX0W-hZ5ZG2FSuiAE6dTmmSZs-FEjwZRPTNbjDVKHHr8QRBFq43gg23PkRCAriLO02ymrVblKCx_kqKvYbvNed_RB0IeGZP_Ll27F34-xdZz6r_zAcgxvOqafa5wPAbOvgCubE_rWviCujhgIa4qe_nqkqMIJhm0B3xOkG6K7Ju2yOy0rNSOzYI5JzRaA\",\"ExpiresIn\":3600,\"T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ksImVtYWlsIjoiam9uYXRoYW4udEB4dHJhLmNvLm56In0.N2vUTeKskoSGGnZNNQkoJrjqQSTwCRsAyoVzU8HoSESciE97PbHu_rsDBHdlIvExQgZOJUDH2fi2ZTVXL0qw_dw_1oy5PY0ss6iF9Ya8vNvwJ4QIg0nGLJEEWO6y9h81bUiy8WYOyC0uCy4FKPBzxu-VjO_ZkJwQZLlhkx56cPXhQI9JFbwQDeyxJDF9duOGiZkWYmiG842TeYpaNIiW46KtQ8kiZLGre9qUdPjQv9S-Ch9Cm8bDqVSunAVtTityUJMGJuxhM78hPAujGdeNfMX0qEx37MpKbQtkb_xJZaT1c0IXnu1tneqtGVxZtaZdQ4mUlBmdzamQaWhlSXvqyA\"}}"; - - Gson gson = new Gson(); - - Type authorization = new TypeToken>() { - }.getType(); - // TODO Auto-generated method stub - - Map authorizationMap = gson.fromJson(jsonFromMS, authorization); - - Map retMap = new Gson().fromJson(jsonFromMS, new TypeToken>() { - }.getType()); - - Map map = new Gson().fromJson(jsonFromMS, new TypeToken>() { - }.getType()); - - System.out.println("Printing Map object: " + authorizationMap.values().toString()); - - authorizationMap.keySet().iterator().forEachRemaining(System.out::println); - - System.out.println("Printing ret Map object this is bringing the values: " + retMap.values().toString()); - - map.keySet().iterator().forEachRemaining(System.out::println); - - System.out.println(retMap.get("IdToken")); - - } - -} diff --git a/src/test/restclient/JerseyClient.java b/src/test/restclient/JerseyClient.java deleted file mode 100644 index eb99c52..0000000 --- a/src/test/restclient/JerseyClient.java +++ /dev/null @@ -1,42 +0,0 @@ -package testing.rest; - -import java.io.IOException; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.UriBuilder; -import org.apache.http.client.ClientProtocolException; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.config.ClientConfig; -import com.sun.jersey.api.client.config.DefaultClientConfig; - -public class JerseyClient { - - /** - * @param args - * @throws ClientProtocolException - * @throws IOException - */ - - public void obtainJSONResponse() throws ClientProtocolException, IOException { - - // invoking REST service with GET Method - - ClientConfig config = new DefaultClientConfig(); - Client client = Client.create(config); - - WebResource service = client - .resource(UriBuilder.fromUri("https://ctpoixww04.execute-api.us-east-1.amazonaws.com").build()); - - // getting JSON data - System.out.println("With JSON" + service.path("dev").path("session").accept(MediaType.APPLICATION_JSON).header( - "Authorization", - "eyJraWQiOiJKQWJRaHNlTTVldFRBMk1vMlpoNGs5Mlp2ZmFHaU5zWWtVQlFNbG1cL1Mybz0iLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiI2MWI5ZTI4NC1kMzVhLTQ0M2YtOTlhNy04MGY0OWE4YTI4NmQiLCJhdWQiOiIxZTh0ZWZtbGNsMmgyOTB2bmg5cmNlZm52ciIsImNvZ25pdG86Z3JvdXBzIjpbImFkbWluaXN0cmF0b3IiXSwiZW1haWxfdmVyaWZpZWQiOmZhbHNlLCJ0b2tlbl91c2UiOiJpZCIsImF1dGhfdGltZSI6MTUwNTAyMTU0OSwiaXNzIjoiaHR0cHM6XC9cL2NvZ25pdG8taWRwLnVzLWVhc3QtMS5hbWF6b25hd3MuY29tXC91cy1lYXN0LTFfMEhkMUtvTTVhIiwiY29nbml0bzp1c2VybmFtZSI6IjEwMjk1NzY1IiwiZXhwIjoxNTA1MDI1MTQ5LCJpYXQiOjE1MDUwMjE1NDksImVtYWlsIjoiam9uYXRoYW4udEB4dHJhLmNvLm56In0.pL9EmmsbB-pxTCXRmDmAAnfMBhLgEY39tbNf0LMhHWF_sSFTB6gYELxnfNa3ITMEEV_wwgvJ-9USb3nHh1G8JkNDxDVCS0S0q4U81GZDqA8USGzA4mklTg1qROlHQkKFipaKQia8U9oLZSIGp6HrpvtQN7wOm9S_0Z5ePXN2REgYsWKobfkLI3dHICACt0RANRBLlXNlQC1F8Hj7dl7UbeQkCZqgj_J_GcxHHLHBRRERO4Koz09gYBhpVrWZZlbUJpwAk3OVCesj7Wz73xjpE2ckm9x6SLkzxC8W5FLvyH5rbiD7Dif9xIVB6jV1pz9GIwMGqzcSWT0LIujw90hoNg") - .get(String.class)); - } - - public void obtainXMLResponse() throws ClientProtocolException, IOException { - // getting XML data - // System.out.println("with - // XML"+service.path("dev").path("session").accept(MediaType.APPLICATION_XML).get(String.class)); - } -} \ No newline at end of file diff --git a/src/test/restclient/JerseyClientPost.java b/src/test/restclient/JerseyClientPost.java deleted file mode 100644 index 8c36562..0000000 --- a/src/test/restclient/JerseyClientPost.java +++ /dev/null @@ -1,34 +0,0 @@ -package jersey; - -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.WebResource; - -public class JerseyClientPost { - - public static void main(String[] args) { - - try { - - Client client = Client.create(); - WebResource webResource = client - .resource("https://ctpoixww04.execute-api.us-east-1.amazonaws.com/dev/login"); - String input = "{\"id\":\"10295765\",\"password\":\"Value!12\"}"; - ClientResponse response = webResource.type("application/json").post(ClientResponse.class, input); - - if (response.getStatus() != 201) { - throw new RuntimeException("Failed : HTTP error code : " - + response.getStatus()); - } - - System.out.println("Output from Server .... \n"); - String output = response.getEntity(String.class); - System.out.println(output); - - } catch (Exception e) { - - e.printStackTrace(); - - } - } -} \ No newline at end of file diff --git a/src/test/restclient/JerseyGet.java b/src/test/restclient/JerseyGet.java deleted file mode 100644 index e04c856..0000000 --- a/src/test/restclient/JerseyGet.java +++ /dev/null @@ -1,37 +0,0 @@ -package jersey; - -import java.io.IOException; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.UriBuilder; -import org.apache.http.client.ClientProtocolException; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.config.ClientConfig; -import com.sun.jersey.api.client.config.DefaultClientConfig; - -public class JerseyGet { - - /** - * @param args - * @throws ClientProtocolException - * @throws IOException - */ - public static void main(String[] args) throws ClientProtocolException, IOException { - - ClientConfig config = new DefaultClientConfig(); - Client client = Client.create(config); - - WebResource service = client - .resource(UriBuilder.fromUri("https://ctpoixww04.execute-api.us-east-1.amazonaws.com").build()); - - // getting JSON data - System.out.println("With JSON" + service.path("dev").path("session").accept(MediaType.APPLICATION_JSON).header( - "Authorization", - "eyJraWQiOiJKQWJRaHNlTTVldFRBMk1vMlpoNGs5Mlp2ZmFHaU5zWWtVQlFNbG1cL1Mybz0iLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiI2MWI5ZTI4NC1kMzVhLTQ0M2YtOTlhNy04MGY0OWE4YTI4NmQiLCJhdWQiOiIxZTh0ZWZtbGNsMmgyOTB2bmg5cmNlZm52ciIsImNvZ25pdG86Z3JvdXBzIjpbImFkbWluaXN0cmF0b3IiXSwiZW1haWxfdmVyaWZpZWQiOmZhbHNlLCJ0b2tlbl91c2UiOiJpZCIsImF1dGhfdGltZSI6MTUwNTAyMTU0OSwiaXNzIjoiaHR0cHM6XC9cL2NvZ25pdG8taWRwLnVzLWVhc3QtMS5hbWF6b25hd3MuY29tXC91cy1lYXN0LTFfMEhkMUtvTTVhIiwiY29nbml0bzp1c2VybmFtZSI6IjEwMjk1NzY1IiwiZXhwIjoxNTA1MDI1MTQ5LCJpYXQiOjE1MDUwMjE1NDksImVtYWlsIjoiam9uYXRoYW4udEB4dHJhLmNvLm56In0.pL9EmmsbB-pxTCXRmDmAAnfMBhLgEY39tbNf0LMhHWF_sSFTB6gYELxnfNa3ITMEEV_wwgvJ-9USb3nHh1G8JkNDxDVCS0S0q4U81GZDqA8USGzA4mklTg1qROlHQkKFipaKQia8U9oLZSIGp6HrpvtQN7wOm9S_0Z5ePXN2REgYsWKobfkLI3dHICACt0RANRBLlXNlQC1F8Hj7dl7UbeQkCZqgj_J_GcxHHLHBRRERO4Koz09gYBhpVrWZZlbUJpwAk3OVCesj7Wz73xjpE2ckm9x6SLkzxC8W5FLvyH5rbiD7Dif9xIVB6jV1pz9GIwMGqzcSWT0LIujw90hoNg") - .get(String.class)); - - // getting XML data - // System.out.println("with - // XML"+service.path("dev").path("session").accept(MediaType.APPLICATION_XML).get(String.class)); - } -} \ No newline at end of file diff --git a/src/test/restclient/JerseyJsonResponse.java b/src/test/restclient/JerseyJsonResponse.java deleted file mode 100644 index f04a585..0000000 --- a/src/test/restclient/JerseyJsonResponse.java +++ /dev/null @@ -1,39 +0,0 @@ -package jersey; - -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.WebResource; - -public class JerseyJsonResponse { - - public static void main(String[] args) { - - try { - String baseuri = "https://ctpoixww04.execute-api.us-east-1.amazonaws.com/dev/login/"; - Client client = Client.create(); - - WebResource webResource = client.resource(baseuri); - - String input = "{\"id\":\"10295765\",\"password\":\"Value!12\"}"; - - // POST method - ClientResponse response = webResource.accept("application/json").type("application/json").post(ClientResponse.class, input); - - // check response status code - if (response.getStatus() != 200) { - throw new RuntimeException("Failed : HTTP error code : "+ response.getStatus()); - } - - // display response - String output = response.getEntity(String.class); - System.out.println("Output from Server .... "); - System.out.println(output + "\n"); - } catch (Exception e) { - e.printStackTrace(); - } - - } - -} - - diff --git a/src/test/restclient/JerseyJsonSimpler.java b/src/test/restclient/JerseyJsonSimpler.java deleted file mode 100644 index 8941a7e..0000000 --- a/src/test/restclient/JerseyJsonSimpler.java +++ /dev/null @@ -1,28 +0,0 @@ -package testing.rest; - -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.representation.Form; - -public class JerseyJsonSimpler { - - public static void main(String[] args) { - - try { - Client client = (Client) ClientBuilder.newClient(); - WebTarget target = ((javax.ws.rs.client.Client) client).target("http://localhost:9998").path("resource"); - - Form form = new Form(); - form.add("id", "10295765"); - form.add("password", "Value!12"); - // ClientResponse response = - // WebResource.class.type(MediaType.TEXT_PLAIN).post(ClientResponse.class, - // form); - } catch (Exception e) { - e.printStackTrace(); - } - - } -} \ No newline at end of file diff --git a/src/test/restclient/JerseyPost.java b/src/test/restclient/JerseyPost.java deleted file mode 100644 index ddbac2a..0000000 --- a/src/test/restclient/JerseyPost.java +++ /dev/null @@ -1,36 +0,0 @@ -package testing.rest; - -import java.io.IOException; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.MultivaluedMap; -import javax.ws.rs.core.UriBuilder; -import org.apache.http.client.ClientProtocolException; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.config.ClientConfig; -import com.sun.jersey.api.client.config.DefaultClientConfig; -import com.sun.jersey.core.util.MultivaluedMapImpl; - -public class JerseyPost { - - public static void main(String[] args) throws ClientProtocolException, IOException { - - ClientConfig config = new DefaultClientConfig(); - - Client client = Client.create(config); - - WebResource webResource = client - .resource(UriBuilder.fromUri("https://ctpoixww04.execute-api.us-east-1.amazonaws.com/").build()); - - MultivaluedMap formData = new MultivaluedMapImpl(); - - formData.add("id", "10295765"); - formData.add("password", "Value!12"); - - ClientResponse response = webResource.path("dev").path("login").type(MediaType.APPLICATION_FORM_URLENCODED) - .post(ClientResponse.class, formData); - - System.out.println("Response " + response.getEntity(String.class)); - } -} diff --git a/src/test/restclient/JerseyPostHeader.java b/src/test/restclient/JerseyPostHeader.java deleted file mode 100644 index ae8f69e..0000000 --- a/src/test/restclient/JerseyPostHeader.java +++ /dev/null @@ -1,24 +0,0 @@ -package testing.rest; - -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; - -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.representation.Form; - -public class JerseyPostHeader { - - Client client = (Client) ClientBuilder.newClient(); - WebTarget target = ((javax.ws.rs.client.Client) client).target("http://localhost:9998").path("resource"); - - Form form = new Form(); - // form.param("x", "foo"); - // form.param("y", "bar"); - - // String bean = - // target.request(MediaType.APPLICATION_JSON_TYPE).post(MediaType.APPLICATION_FORM_URLENCODED_TYPE, - // String.class); -} diff --git a/src/test/restclient/JerseyTest.java b/src/test/restclient/JerseyTest.java deleted file mode 100644 index a474dc2..0000000 --- a/src/test/restclient/JerseyTest.java +++ /dev/null @@ -1,36 +0,0 @@ -package testing.rest; - -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.Response; - -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.WebResource; - -import bean.AttendanceRegister; - -public class JerseyTest { - - public static void main(String[] args) { - testAttendanceRegister(); - // responseREST(); - } - - String responseREST() { - // Client client =(Client) ClientBuilder.newClient(); - Client client = Client.create(); - WebResource target = client.resource("https://ctpoixww04.execute-api.us-east-1.amazonaws.com/dev/login"); - String input = "{\"id\":\"10295765\",\"password\":\"Value!12\"}"; - - Response response = ((WebTarget) target).request("application/json").post(Entity.json(input)); - // System.out.println(response.toString()); - - return response.toString(); - } - - static void testAttendanceRegister() { - AttendanceRegister att = new AttendanceRegister(); - att.confirmAttendance(); - } - -} diff --git a/src/test/restclient/NetClientPost.java b/src/test/restclient/NetClientPost.java deleted file mode 100644 index 213b3af..0000000 --- a/src/test/restclient/NetClientPost.java +++ /dev/null @@ -1,56 +0,0 @@ -package testing.rest; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.net.HttpURLConnection; -import java.net.MalformedURLException; -import java.net.URL; - -public class NetClientPost { - - // http://localhost:8080/RESTfulExample/json/product/post - public static void main(String[] args) { - - try { - URL url = new URL("https://fahze41owc.execute-api.us-east-1.amazonaws.com/dev/user"); - HttpURLConnection conn = (HttpURLConnection) url.openConnection(); - conn.setDoOutput(true); - conn.setRequestMethod("POST"); - conn.setRequestProperty("Content-Type", "application/json"); - - String input = "{\r\n" + - " \"id\": \"102030\",\r\n" + - " \"firstName\": \"Julito\",\r\n" + - " \"lastName\": \"Schwartzenegger\",\r\n" + - " \"type\": \"administrator\"\r\n" + - "}"; - - OutputStream os = conn.getOutputStream(); - os.write(input.getBytes()); - os.flush(); - - if (conn.getResponseCode() != HttpURLConnection.HTTP_CREATED) { - throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode()); - } - - BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); - - String output; - System.out.println("Output from Server .... \n"); - while ((output = br.readLine()) != null) { - System.out.println(output); - } - - conn.disconnect(); - - } catch (MalformedURLException e) { - - e.printStackTrace(); - - } catch (IOException e) { - e.printStackTrace(); - } - } -} \ No newline at end of file diff --git a/src/test/restclient/TestJSONResponse.java b/src/test/restclient/TestJSONResponse.java deleted file mode 100644 index 46de1f6..0000000 --- a/src/test/restclient/TestJSONResponse.java +++ /dev/null @@ -1,61 +0,0 @@ -package jersey; - -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.net.HttpURLConnection; -import java.net.MalformedURLException; -import java.net.URL; -import javax.json.Json; -import javax.json.stream.JsonParser; -import javax.json.stream.JsonParser.Event; - -public class TestJSONResponse { - - public static void main(String[] args) throws MalformedURLException { - //URL url = new URL("https://graph.facebook.com/search?q=java&type=post"); - //URL url = new URL("https://ctpoixww04.execute-api.us-east-1.amazonaws.com/dev/login"); - - //try (InputStream is = url.openStream(); JsonParser parser = Json.createParser(is)) { - try { - URL url = new URL("https://ctpoixww04.execute-api.us-east-1.amazonaws.com/dev/login"); - HttpURLConnection conn = (HttpURLConnection) url.openConnection(); - conn.setDoOutput(true); - conn.setRequestMethod("POST"); - conn.setRequestProperty("Content-Type", "application/json"); - - String input = "{\"id\":\"10295765\",\"password\":\"Value!12\"}"; - - OutputStream os = conn.getOutputStream(); - // 1.The client sends their credentials (username and password) to the server. - os.write(input.getBytes()); - os.flush(); - - BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); - - JsonParser parser = (JsonParser) Json.createReader(br); - - while (parser.hasNext()) { - Event e = parser.next(); - if (e == Event.KEY_NAME) { - switch (parser.getString()) { - case "RefreshToken": - parser.next(); - System.out.print(parser.getString()); - System.out.print(": "); - break; - case "IdToken": - parser.next(); - System.out.println(parser.getString()); - System.out.println("---------"); - break; - } - } - } - } catch (Exception e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - } -} diff --git a/src/test/restclient/TestRestClient.java b/src/test/restclient/TestRestClient.java deleted file mode 100644 index db047ad..0000000 --- a/src/test/restclient/TestRestClient.java +++ /dev/null @@ -1,38 +0,0 @@ -package rest; - -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.WebResource; - -public class TestRestClient { - string AWS_URL="https://ctpoixww04.execute-api.us-east-1.amazonaws.com/dev/login"; - - public void cheackServerAvailable(){ - - } - - public void testAWSConnectAPI() { - - try { - - Client client = Client.create(); - WebResource webResource = client.resource(+ AWS_URL); - String input = "{\"id\":\"10295765\",\"password\":\"TestPassword!12\"}"; - ClientResponse response = webResource.type("application/json").post(ClientResponse.class, input); - - if (response.getStatus() != 201) { - throw new RuntimeException("Failed : HTTP error code : " - + response.getStatus()); - } - - System.out.println("Output from Server .... \n"); - String output = response.getEntity(String.class); - System.out.println(output); - - } catch (Exception e) { - - e.printStackTrace(); - - } - } -} diff --git a/src/test/wsclient/GeoIP.java b/src/test/wsclient/GeoIP.java deleted file mode 100644 index 0e9bf9a..0000000 --- a/src/test/wsclient/GeoIP.java +++ /dev/null @@ -1,170 +0,0 @@ - /** - * Class GeoIP imported from WSDL with java tool - * replicates WSDL to invoke External Web service - */ - -package wsclient; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlType; - - -/** - *

Java class for GeoIP complex type. - * - *

The following schema fragment specifies the expected content contained within this class. - * - *

- * <complexType name="GeoIP">
- *   <complexContent>
- *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *       <sequence>
- *         <element name="ReturnCode" type="{http://www.w3.org/2001/XMLSchema}int"/>
- *         <element name="IP" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
- *         <element name="ReturnCodeDetails" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
- *         <element name="CountryName" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
- *         <element name="CountryCode" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
- *       </sequence>
- *     </restriction>
- *   </complexContent>
- * </complexType>
- * 
- * - * - */ -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "GeoIP", propOrder = { - "returnCode", - "ip", - "returnCodeDetails", - "countryName", - "countryCode" -}) -public class GeoIP { - - @XmlElement(name = "ReturnCode") - protected int returnCode; - @XmlElement(name = "IP") - protected String ip; - @XmlElement(name = "ReturnCodeDetails") - protected String returnCodeDetails; - @XmlElement(name = "CountryName") - protected String countryName; - @XmlElement(name = "CountryCode") - protected String countryCode; - - /** - * Gets the value of the returnCode property. - * - */ - public int getReturnCode() { - return returnCode; - } - - /** - * Sets the value of the returnCode property. - * - */ - public void setReturnCode(int value) { - this.returnCode = value; - } - - /** - * Gets the value of the ip property. - * - * @return - * possible object is - * {@link String } - * - */ - public String getIP() { - return ip; - } - - /** - * Sets the value of the ip property. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setIP(String value) { - this.ip = value; - } - - /** - * Gets the value of the returnCodeDetails property. - * - * @return - * possible object is - * {@link String } - * - */ - public String getReturnCodeDetails() { - return returnCodeDetails; - } - - /** - * Sets the value of the returnCodeDetails property. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setReturnCodeDetails(String value) { - this.returnCodeDetails = value; - } - - /** - * Gets the value of the countryName property. - * - * @return - * possible object is - * {@link String } - * - */ - public String getCountryName() { - return countryName; - } - - /** - * Sets the value of the countryName property. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setCountryName(String value) { - this.countryName = value; - } - - /** - * Gets the value of the countryCode property. - * - * @return - * possible object is - * {@link String } - * - */ - public String getCountryCode() { - return countryCode; - } - - /** - * Sets the value of the countryCode property. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setCountryCode(String value) { - this.countryCode = value; - } - -} diff --git a/src/test/wsclient/GeoIPService.java b/src/test/wsclient/GeoIPService.java deleted file mode 100644 index b3eecd0..0000000 --- a/src/test/wsclient/GeoIPService.java +++ /dev/null @@ -1,98 +0,0 @@ - /** - * Class GeoIPService imported from WSDL with java tool - * replicates WSDL to invoke External Web service - */ - -package wsclient; - -import java.net.MalformedURLException; -import java.net.URL; -import javax.xml.namespace.QName; -import javax.xml.ws.Service; -import javax.xml.ws.WebEndpoint; -import javax.xml.ws.WebServiceClient; -import javax.xml.ws.WebServiceException; -import javax.xml.ws.WebServiceFeature; - - -/** - * This class was generated by the JAX-WS RI. - * JAX-WS RI 2.2.9-b130926.1035 - * Generated source version: 2.2 - * - */ -@WebServiceClient(name = "GeoIPService", targetNamespace = "http://www.webservicex.net/", wsdlLocation = "http://www.webservicex.net/geoipservice.asmx?WSDL") -public class GeoIPService - extends Service -{ - - private final static URL GEOIPSERVICE_WSDL_LOCATION; - private final static WebServiceException GEOIPSERVICE_EXCEPTION; - private final static QName GEOIPSERVICE_QNAME = new QName("http://www.webservicex.net/", "GeoIPService"); - - static { - URL url = null; - WebServiceException e = null; - try { - url = new URL("http://www.webservicex.net/geoipservice.asmx?WSDL"); - } catch (MalformedURLException ex) { - e = new WebServiceException(ex); - } - GEOIPSERVICE_WSDL_LOCATION = url; - GEOIPSERVICE_EXCEPTION = e; - } - - public GeoIPService() { - super(__getWsdlLocation(), GEOIPSERVICE_QNAME); - } - - public GeoIPService(WebServiceFeature... features) { - super(__getWsdlLocation(), GEOIPSERVICE_QNAME, features); - } - - public GeoIPService(URL wsdlLocation) { - super(wsdlLocation, GEOIPSERVICE_QNAME); - } - - public GeoIPService(URL wsdlLocation, WebServiceFeature... features) { - super(wsdlLocation, GEOIPSERVICE_QNAME, features); - } - - public GeoIPService(URL wsdlLocation, QName serviceName) { - super(wsdlLocation, serviceName); - } - - public GeoIPService(URL wsdlLocation, QName serviceName, WebServiceFeature... features) { - super(wsdlLocation, serviceName, features); - } - - /** - * - * @return - * returns GeoIPServiceSoap - */ - @WebEndpoint(name = "GeoIPServiceSoap") - public GeoIPServiceSoap getGeoIPServiceSoap() { - return super.getPort(new QName("http://www.webservicex.net/", "GeoIPServiceSoap"), GeoIPServiceSoap.class); - } - - /** - * - * @param features - * A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy. Supported features not in the features parameter will have their default values. - * @return - * returns GeoIPServiceSoap - */ - @WebEndpoint(name = "GeoIPServiceSoap") - public GeoIPServiceSoap getGeoIPServiceSoap(WebServiceFeature... features) { - return super.getPort(new QName("http://www.webservicex.net/", "GeoIPServiceSoap"), GeoIPServiceSoap.class, features); - } - - private static URL __getWsdlLocation() { - if (GEOIPSERVICE_EXCEPTION!= null) { - throw GEOIPSERVICE_EXCEPTION; - } - return GEOIPSERVICE_WSDL_LOCATION; - } - -} diff --git a/src/test/wsclient/GeoIPServiceSoap.java b/src/test/wsclient/GeoIPServiceSoap.java deleted file mode 100644 index af50614..0000000 --- a/src/test/wsclient/GeoIPServiceSoap.java +++ /dev/null @@ -1,56 +0,0 @@ - /** - * Class GeoIPServiceSoap imported from WSDL with java tool - * replicates WSDL to invoke External Web service - */ - -package wsclient; - -import javax.jws.WebMethod; -import javax.jws.WebParam; -import javax.jws.WebResult; -import javax.jws.WebService; -import javax.xml.bind.annotation.XmlSeeAlso; -import javax.xml.ws.RequestWrapper; -import javax.xml.ws.ResponseWrapper; - - -/** - * This class was generated by the JAX-WS RI. - * JAX-WS RI 2.2.9-b130926.1035 - * Generated source version: 2.2 - * - */ -@WebService(name = "GeoIPServiceSoap", targetNamespace = "http://www.webservicex.net/") -@XmlSeeAlso({ - ObjectFactory.class -}) -public interface GeoIPServiceSoap { - - /** - * GeoIPService - GetGeoIP enables you to easily look up countries by IP addresses - * - * @param ipAddress - * @return - * returns wsclient.GeoIP - */ - @WebMethod(operationName = "GetGeoIP", action = "http://www.webservicex.net/GetGeoIP") - @WebResult(name = "GetGeoIPResult", targetNamespace = "http://www.webservicex.net/") - @RequestWrapper(localName = "GetGeoIP", targetNamespace = "http://www.webservicex.net/", className = "wsclient.GetGeoIP") - @ResponseWrapper(localName = "GetGeoIPResponse", targetNamespace = "http://www.webservicex.net/", className = "wsclient.GetGeoIPResponse") - public GeoIP getGeoIP( - @WebParam(name = "IPAddress", targetNamespace = "http://www.webservicex.net/") - String ipAddress); - - /** - * GeoIPService - GetGeoIPContext enables you to easily look up countries by Context - * - * @return - * returns wsclient.GeoIP - */ - @WebMethod(operationName = "GetGeoIPContext", action = "http://www.webservicex.net/GetGeoIPContext") - @WebResult(name = "GetGeoIPContextResult", targetNamespace = "http://www.webservicex.net/") - @RequestWrapper(localName = "GetGeoIPContext", targetNamespace = "http://www.webservicex.net/", className = "wsclient.GetGeoIPContext") - @ResponseWrapper(localName = "GetGeoIPContextResponse", targetNamespace = "http://www.webservicex.net/", className = "wsclient.GetGeoIPContextResponse") - public GeoIP getGeoIPContext(); - -} diff --git a/src/test/wsclient/GetGeoIP.java b/src/test/wsclient/GetGeoIP.java deleted file mode 100644 index fcb0571..0000000 --- a/src/test/wsclient/GetGeoIP.java +++ /dev/null @@ -1,68 +0,0 @@ - /** - * Class GetGeoIP imported from WSDL with java tool - * replicates WSDL to invoke External Web service - */ - -package wsclient; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - - -/** - *

Java class for anonymous complex type. - * - *

The following schema fragment specifies the expected content contained within this class. - * - *

- * <complexType>
- *   <complexContent>
- *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *       <sequence>
- *         <element name="IPAddress" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
- *       </sequence>
- *     </restriction>
- *   </complexContent>
- * </complexType>
- * 
- * - * - */ - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "", propOrder = { - "ipAddress" -}) -@XmlRootElement(name = "GetGeoIP") -public class GetGeoIP { - - @XmlElement(name = "IPAddress") - protected String ipAddress; - - /** - * Gets the value of the ipAddress property. - * - * @return - * possible object is - * {@link String } - * - */ - public String getIPAddress() { - return ipAddress; - } - - /** - * Sets the value of the ipAddress property. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setIPAddress(String value) { - this.ipAddress = value; - } -} diff --git a/src/test/wsclient/GetGeoIPContext.java b/src/test/wsclient/GetGeoIPContext.java deleted file mode 100644 index 5a9adbc..0000000 --- a/src/test/wsclient/GetGeoIPContext.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Class GetGeoIPContext imported from WSDL with java tool - * replicates WSDL to invoke External Web service - */ - -package wsclient; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -/** - *

- * Java class for anonymous complex type. - * - *

- * The following schema fragment specifies the expected content contained within - * this class. - * - *

- * <complexType>
- *   <complexContent>
- *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *     </restriction>
- *   </complexContent>
- * </complexType>
- * 
- * - * - */ -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "") -@XmlRootElement(name = "GetGeoIPContext") -public class GetGeoIPContext { - -} diff --git a/src/test/wsclient/GetGeoIPContextResponse.java b/src/test/wsclient/GetGeoIPContextResponse.java deleted file mode 100644 index 0fbb17b..0000000 --- a/src/test/wsclient/GetGeoIPContextResponse.java +++ /dev/null @@ -1,68 +0,0 @@ - /** - * Class getGeoIPContextResult imported from WSDL with java tool - * replicates WSDL to invoke External Web service - */ - -package wsclient; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - - -/** - *

Java class for anonymous complex type. - * - *

The following schema fragment specifies the expected content contained within this class. - * - *

- * <complexType>
- *   <complexContent>
- *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *       <sequence>
- *         <element name="GetGeoIPContextResult" type="{http://www.webservicex.net/}GeoIP" minOccurs="0"/>
- *       </sequence>
- *     </restriction>
- *   </complexContent>
- * </complexType>
- * 
- * - * - */ -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "", propOrder = { - "getGeoIPContextResult" -}) -@XmlRootElement(name = "GetGeoIPContextResponse") -public class GetGeoIPContextResponse { - - @XmlElement(name = "GetGeoIPContextResult") - protected GeoIP getGeoIPContextResult; - - /** - * Gets the value of the getGeoIPContextResult property. - * - * @return - * possible object is - * {@link GeoIP } - * - */ - public GeoIP getGetGeoIPContextResult() { - return getGeoIPContextResult; - } - - /** - * Sets the value of the getGeoIPContextResult property. - * - * @param value - * allowed object is - * {@link GeoIP } - * - */ - public void setGetGeoIPContextResult(GeoIP value) { - this.getGeoIPContextResult = value; - } - -} diff --git a/src/test/wsclient/GetGeoIPResponse.java b/src/test/wsclient/GetGeoIPResponse.java deleted file mode 100644 index e5e621e..0000000 --- a/src/test/wsclient/GetGeoIPResponse.java +++ /dev/null @@ -1,67 +0,0 @@ - /** - * Class getGeoIPResult imported from WSDL with java tool - * replicates WSDL to invoke External Web service - */ - -package wsclient; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -/** - *

Java class for anonymous complex type. - * - *

The following schema fragment specifies the expected content contained within this class. - * - *

- * <complexType>
- *   <complexContent>
- *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *       <sequence>
- *         <element name="GetGeoIPResult" type="{http://www.webservicex.net/}GeoIP" minOccurs="0"/>
- *       </sequence>
- *     </restriction>
- *   </complexContent>
- * </complexType>
- * 
- * - * - */ -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "", propOrder = { - "getGeoIPResult" -}) -@XmlRootElement(name = "GetGeoIPResponse") -public class GetGeoIPResponse { - - @XmlElement(name = "GetGeoIPResult") - protected GeoIP getGeoIPResult; - - /** - * Gets the value of the getGeoIPResult property. - * - * @return - * possible object is - * {@link GeoIP } - * - */ - public GeoIP getGetGeoIPResult() { - return getGeoIPResult; - } - - /** - * Sets the value of the getGeoIPResult property. - * - * @param value - * allowed object is - * {@link GeoIP } - * - */ - public void setGetGeoIPResult(GeoIP value) { - this.getGeoIPResult = value; - } - -} diff --git a/src/test/wsclient/ObjectFactory.java b/src/test/wsclient/ObjectFactory.java deleted file mode 100644 index 0c8da64..0000000 --- a/src/test/wsclient/ObjectFactory.java +++ /dev/null @@ -1,89 +0,0 @@ - /** - * Class ObjectFactory imported from WSDL with java tool - * replicates WSDL to invoke External Web service - */ - -package wsclient; - -import javax.xml.bind.JAXBElement; -import javax.xml.bind.annotation.XmlElementDecl; -import javax.xml.bind.annotation.XmlRegistry; -import javax.xml.namespace.QName; - - -/** - * This object contains factory methods for each - * Java content interface and Java element interface - * generated in the wsclient package. - *

An ObjectFactory allows you to programatically - * construct new instances of the Java representation - * for XML content. The Java representation of XML - * content can consist of schema derived interfaces - * and classes representing the binding of schema - * type definitions, element declarations and model - * groups. Factory methods for each of these are - * provided in this class. - * - */ -@XmlRegistry -public class ObjectFactory { - - private final static QName _GeoIP_QNAME = new QName("http://www.webservicex.net/", "GeoIP"); - - /** - * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: wsclient - * - */ - public ObjectFactory() { - } - - /** - * Create an instance of {@link GeoIP } - * - */ - public GeoIP createGeoIP() { - return new GeoIP(); - } - - /** - * Create an instance of {@link GetGeoIP } - * - */ - public GetGeoIP createGetGeoIP() { - return new GetGeoIP(); - } - - /** - * Create an instance of {@link GetGeoIPResponse } - * - */ - public GetGeoIPResponse createGetGeoIPResponse() { - return new GetGeoIPResponse(); - } - - /** - * Create an instance of {@link GetGeoIPContextResponse } - * - */ - public GetGeoIPContextResponse createGetGeoIPContextResponse() { - return new GetGeoIPContextResponse(); - } - - /** - * Create an instance of {@link GetGeoIPContext } - * - */ - public GetGeoIPContext createGetGeoIPContext() { - return new GetGeoIPContext(); - } - - /** - * Create an instance of {@link JAXBElement }{@code <}{@link GeoIP }{@code >}} - * - */ - @XmlElementDecl(namespace = "http://www.webservicex.net/", name = "GeoIP") - public JAXBElement createGeoIP(GeoIP value) { - return new JAXBElement(_GeoIP_QNAME, GeoIP.class, null, value); - } - -} diff --git a/src/test/wsclient/package-info.java b/src/test/wsclient/package-info.java deleted file mode 100644 index 485323c..0000000 --- a/src/test/wsclient/package-info.java +++ /dev/null @@ -1,6 +0,0 @@ -/** - * injects annotation for java tool to work and invoke the WSDL - */ - -@javax.xml.bind.annotation.XmlSchema(namespace = "http://www.webservicex.net/", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) -package wsclient; diff --git a/src/test/wsdl/ServiceInvokationTest.java b/src/test/wsdl/ServiceInvokationTest.java deleted file mode 100644 index ff82ba3..0000000 --- a/src/test/wsdl/ServiceInvokationTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package attendance.wsdl; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import bean.AttendanceRegister; -import service.MainService; - -public class ServiceInvokationTest { - - MainService testService = new MainService(); - AttendanceRegister attend = new AttendanceRegister(); - - @Test - public void testWSDLSuccess() { - - assertTrue(testService.invokeWSDLForIP().length()>2); - //System.out.println(testService.invokeWSDLForIP()); - } - - @Test - public void testRestBibleSuccess() { - assertTrue(testService.invokeRestForBibleVerse().length()>2); - //System.out.println(testService.invokeRestForBibleVerse()); - } -}