diff --git a/.env.tpl b/.env.tpl new file mode 100644 index 0000000..1d46bf3 --- /dev/null +++ b/.env.tpl @@ -0,0 +1,2 @@ +# https://developer.1password.com/docs/cli/secrets-config-files/ +LDAP_ADMIN_PASS="op://Professional-IT Projects/multi-cloud-WebApp-Attendance/password" \ No newline at end of file diff --git a/.gitignore b/.gitignore index 23491a9..df70f27 100644 --- a/.gitignore +++ b/.gitignore @@ -45,4 +45,9 @@ gradle-app.setting *.rar # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* \ No newline at end of file +hs_err_pid* + +# secrets 1Password locally generated auth +*.env +# avoid the jwt injected file +token_auth.properties \ No newline at end of file diff --git a/README.md b/README.md index 08a34f5..05531be 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ - [Attendance WebApp](#attendance-webapp) - [Introduction](#introduction) - - [Security warnings](#security-warnings) + - [GitHub Reports](#github-reports) + - [Security warnings](#security-warnings) + - [GitHub Vulnerability report](#github-vulnerability-report) - [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) @@ -10,15 +12,16 @@ - [Build WebApp](#build-webapp) - [Gradle Build Web Package](#gradle-build-web-package) - [Maven Build](#maven-build) - - [Package WebApp](#package-webapp) + - [Gradle Test suite](#gradle-test-suite) + - [Use 1Password CLI to inject the secrets](#use-1password-cli-to-inject-the-secrets) + - [Package/Run WebApp](#packagerun-webapp) - [Docker Image Build](#docker-image-build) - [Available Tomcat versions](#available-tomcat-versions) - - [Run WebApp](#run-webapp) + - [Execute WebApp](#execute-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 @@ -36,11 +39,14 @@ The idea is that you have a short timeframe to submit a random generated code by The application is a proof of concept for Service orientation and Service interoperability in the cloud -## Security warnings +## GitHub Reports +### 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) +### GitHub Vulnerability report +https://github.com/aleon1220/multi-cloud-WebApp-Attendance/security/dependabot ## Attendance WebApp Architecture (re-architected) @@ -98,7 +104,30 @@ gradle clean build --console plain --warning-mode all ### Maven Build > maven has been deprecated and moved to [maven](./maven) -## Package WebApp +### Gradle Test suite +#### Use 1Password CLI to inject the secrets +- as a pre-requisite you must have access to the shared vault +- login in the CLI +```bash +# Linux Ubuntu tested 2023-12-10 +op signin +``` +- inject the secrets for testing Authentication property file +```bash +op inject -i token_auth.properties.tpl -o token_auth.properties +``` + +- inject the secrets for Testing property file +```bash +op inject -i secrets.env.tpl -o secrets.env +``` + +- inject the secrets for Testing docker-compose +```bash +op inject -i .env.tpl -o .env +``` + +## Package/Run WebApp ### Docker Image Build - Build the app image with Docker. Deploy .WAR file in Tomcat refer to https://hub.docker.com/_/tomcat @@ -111,7 +140,7 @@ Use the tag latest or a particular version e.g. aleon1220/soa:v2 or aleon1220/so - 7.0.109 = `TOMCAT_VERSION_DOCKER_TAG="7.0.109-jdk8-openjdk"` - 9.0.78 = `TOMCAT_VERSION_DOCKER_TAG="9.0.78-jre8"` -## Run WebApp +## Execute WebApp ### Container Execution #### Docker execution @@ -131,15 +160,15 @@ Run the tomcat server with the pre-built WAR web Archive file ```bash docker run -itd --publish 8080:8080 aleon1220/soa:latest ``` -- get the name of the running container in port 8888 +- get the name of the running container ``` bash -CONTAINER_NAME=$(docker container ls --all --filter publish=8888 --format "{{.Names}}") +CONTAINER_NAME=$(docker container ls --all --filter publish=8080 --format "{{.Names}}") ``` - Access the Docker container via CLI ```bash 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) +- The URl is URL:8080/Attendance-0.0.1 [AttendanceWebApp](http://localhost:8080/AttendanceWebApp) - clean up docker container environment ``` bash docker stop $(docker ps --quiet) @@ -147,7 +176,11 @@ docker rm $(docker container ls --all --quiet) ``` #### Docker-compose - +- inject the secrets for Testing docker-compose +```bash +op inject -i .env.tpl -o .env +``` +- single variable ```bash export LDAP_ADMIN_PASS=$(op read "op://uqbpxejq7gifvi6mg3c7xxokre/jvuj7juvlxlg7delckucvidqhi/password") ``` @@ -156,6 +189,3 @@ export LDAP_ADMIN_PASS=$(op read "op://uqbpxejq7gifvi6mg3c7xxokre/jvuj7juvlxlg7d - 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 index 1440e67..77956b3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -81,7 +81,7 @@ tasks { } } -tasks.register("singleTest") { +tasks.register("singleTestQRFunctionality") { group = "Verification" description = "Runs a test to create a local QR code" filter { @@ -89,13 +89,21 @@ tasks.register("singleTest") { } } -tasks.register("openLDAP") { - description = "Runs openLDAP authentication testing" +tasks.register("mockOpenLDAP") { + description = "Runs openLDAP mock authentication testing" + group = "LDAP_Testing" filter { includeTestsMatching("TestLDAPAuthentication.testMockOpenLDAPAdminSearch") } } +tasks.register("searchOpenLDAP") { + description = "Runs openLDAP search" + group = "LDAP_Testing" + filter { + includeTestsMatching("TestLDAPAuthentication.testOpenLDAPAdminSearch_withOpenLDAP") + } +} // https://plugins.gradle.org/plugin/com.github.bjornvester.wsdl2java // https://www.w3schools.com/xml/tempconvert.asmx?WSDL wsdl2java { diff --git a/maven/pom.xml b/maven/pom.xml index 209ca25..fcf029f 100644 --- a/maven/pom.xml +++ b/maven/pom.xml @@ -1,17 +1,17 @@ - + 4.0.0 com.soa AttendWebApp war 0.0.1-SNAPSHOT Class Attendance WebApp - http://maven.apache.org + https://maven.apache.org prime-repo PrimeFaces Maven Repository - http://repository.primefaces.org + https://repository.primefaces.org default @@ -119,7 +119,7 @@ tomcat7-maven-plugin 2.2 - http://localhost:8080/manager/text + https://itlatinos.net:8080/manager/text TomcatServer /AttendWebApp diff --git a/secrets.env.tpl b/secrets.env.tpl new file mode 100644 index 0000000..b336d3d --- /dev/null +++ b/secrets.env.tpl @@ -0,0 +1,2 @@ +# General Secrets File +# https://developer.1password.com/docs/cli/secrets-config-files \ No newline at end of file diff --git a/src/main/java/entity/LoginReply.java b/src/main/java/entity/LoginReply.java index a8fe9b1..7a7f253 100644 --- a/src/main/java/entity/LoginReply.java +++ b/src/main/java/entity/LoginReply.java @@ -33,10 +33,9 @@ public void setAuthenticationResult(AuthenticationResult authenticationResult) { this.authenticationResult = authenticationResult; } - @Override public String toString() { //return getClass()+"challenge"+challengeParameters+"data in authent"+authenticationResult.getIdToken(); - return getClass()+" Not obtaining really much"; + return getClass()+" Overriding method"; } } diff --git a/src/main/java/service/UserService.java b/src/main/java/service/UserService.java index 3f79524..c0921dc 100644 --- a/src/main/java/service/UserService.java +++ b/src/main/java/service/UserService.java @@ -82,13 +82,9 @@ public String obtainIdToken(String id, String password) { conn.disconnect(); } catch (MalformedURLException e) { - e.printStackTrace(); } catch (IOException e) { - - //System.out.println("UserService: inside 2nd catch"); - e.printStackTrace(); } diff --git a/src/main/java/util/AuthenticateOpenLDAP.java b/src/main/java/util/AuthenticateOpenLDAP.java index 0757b3e..1d8572c 100644 --- a/src/main/java/util/AuthenticateOpenLDAP.java +++ b/src/main/java/util/AuthenticateOpenLDAP.java @@ -1,14 +1,16 @@ package util; -import com.unboundid.ldap.sdk.*; -import com.unboundid.util.ssl.SSLUtil; -import com.unboundid.util.ssl.TrustAllTrustManager; -import javax.net.ssl.SSLSocketFactory; +import com.unboundid.ldap.sdk.LDAPConnection; +import com.unboundid.ldap.sdk.LDAPException; +import com.unboundid.ldap.sdk.SearchResult; +import com.unboundid.ldap.sdk.SearchResultEntry; +import com.unboundid.ldap.sdk.SearchScope; public class AuthenticateOpenLDAP { public void openLDAPAdminSearch() { // LDAP connection parameters String ldapURL = "ldap://localhost"; + String ldapHost = "localhost"; String bindDN = "cn=admin,dc=my-company,dc=com"; String bindPassword = System.getenv("LDAP_ADMIN_PASS"); String baseDN = "dc=my-company,dc=com"; @@ -23,7 +25,7 @@ public void openLDAPAdminSearch() { // connection = new LDAPConnection(socketFactory, "localhost", 636); // For non-SSL connection - connection = new LDAPConnection("localhost", 389); + connection = new LDAPConnection(ldapHost, 389); connection.bind(bindDN, bindPassword); // Perform the search diff --git a/src/test/java/attendance/student/TestStudent.java b/src/test/java/attendance/student/TestStudent.java index be1a249..3127141 100644 --- a/src/test/java/attendance/student/TestStudent.java +++ b/src/test/java/attendance/student/TestStudent.java @@ -2,11 +2,13 @@ import javax.faces.bean.ManagedBean; -@ManagedBean +import org.junit.jupiter.api.Test; + public class TestStudent { private String name; + @Test public String sayHello() { if (name != null && !name.trim().equals("")) { return "Hello, " + name + "!"; diff --git a/src/test/java/auth/ldap/TestLDAPAuthentication.java b/src/test/java/auth/ldap/TestLDAPAuthentication.java index f486e57..2efb1ce 100644 --- a/src/test/java/auth/ldap/TestLDAPAuthentication.java +++ b/src/test/java/auth/ldap/TestLDAPAuthentication.java @@ -64,16 +64,17 @@ public void testMockOpenLDAPAdminSearch() throws LDAPSearchException { @Test public void testOpenLDAPAdminSearch_withOpenLDAP() { // Test parameters - String ldapURL = "ldap://localhost"; + String ldapURL = "ldap://localhost:389"; String ldapHost = "localhost"; int ldapPort = 389; String bindDN = "cn=admin,dc=my-company,dc=com"; - var bindPassword = "adminpassword"; + String bindPassword = System.getenv("LDAP_ADMIN_PASS"); + // var bindPassword = "adminpassword"; String baseDN = "dc=my-company,dc=com"; String searchFilter = "(objectClass=*)"; - // Connect to OpenLDAP - // Establishing a connection to the LDAP server + // Establish connection to OpenLDAP server + System.out.println("My variable value: " + bindPassword); try (LDAPConnection connection = new LDAPConnection(ldapHost, ldapPort, bindDN, bindPassword)) { System.out.println("Connected to the LDAP server."); @@ -96,7 +97,7 @@ public void testOpenLDAPAdminSearch_withOpenLDAP() { // Close connection connection.close(); } catch (LDAPException e) { - System.err.println("Error connecting to the LDAP server: " + e.getMessage()); + System.err.println("LDAP Error connecting: " + e.getMessage()); e.printStackTrace(); } diff --git a/src/test/java/json/TestConversionJSON2Object.java b/src/test/java/json/TestConversionJSON2Object.java index 6b9bc7a..575f5a4 100644 --- a/src/test/java/json/TestConversionJSON2Object.java +++ b/src/test/java/json/TestConversionJSON2Object.java @@ -1,21 +1,60 @@ package json; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; import com.google.gson.Gson; +import org.junit.jupiter.api.Test; import entity.LoginReply; public class TestConversionJSON2Object { - - public static void main(String[] args) { - String replyJson = "{\"ChallengeParameters\":{},\"AuthenticationResult\":{\"AccessToken\":\"eyJraWQiOiJ6M2pWR1lscDVsS2VHVzRXMkwrU3BtdjN4UzIwWGFCU1FvZFlvdWg1WkU4PSIsImFsZyI6IlJTMjU2In0.eyJzdWIiOiI2MWI5ZTI4NC1kMzVhLTQ0M2YtOTlhNy04MGY0OWE4YTI4NmQiLCJ0b2tlbl91c2UiOiJhY2Nlc3MiLCJzY29wZSI6ImF3cy5jb2duaXRvLnNpZ25pbi51c2VyLmFkbWluIiwiaXNzIjoiaHR0cHM6XC9cL2NvZ25pdG8taWRwLnVzLWVhc3QtMS5hbWF6b25hd3MuY29tXC91cy1lYXN0LTFfMEhkMUtvTTVhIiwiZXhwIjoxNTA1MTIwNzM1LCJpYXQiOjE1MDUxMTcxMzUsImp0aSI6ImNiMjdkZjJiLTIwOWQtNGU1MC05ZTI4LThjYTAyOGY1MTc5MyIsImNsaWVudF9pZCI6IjFlOHRlZm1sY2wyaDI5MHZuaDlyY2VmbnZyIiwidXNlcm5hbWUiOiIxMDI5NTc2NSJ9.ZGB_kC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CJhdWQiOiIxZTh0ZWZtbGNsMmgyOTB2bmg5cmNlZm52ciIsImNvZ25pdG86Z3JvdXBzIjpbImFkbWluaXN0cmF0b3IiXSwiZW1haWxfdmVyaWZpZWQiOmZhbHNlLCJ0b2tlbl91c2UiOiJpZCIsImF1dGhfdGltZSI6MTUwNTExNzEzNSwiaXNzIjoiaHR0cHM6XC9cL2NvZ25pdG8taWRwLnVzLWVhc3QtMS5hbWF6b25hd3MuY29tXC91cy1lYXN0LTFfMEhkMUtvTTVhIiwiY29nbml0bzp1c2VybmFtZSI6IjEwMjk1NzY1IiwiZXhwIjoxNTA1MTIwNzM1LCJpYXQiOjE1MDUxMTcxMzUsImVtYWlsIjoiam9uYXRoYW4udEB4dHJhLmNvLm56In0.gGcx2YYcjWzNvzlpPklry4Jt59GwDQuDRRIFfJGaf06hMKi0Cin31Ox7AD4CaRUmbUXzxh395Bb6bPS9cGdh5oa2hIveC27bwHpO7Eij6voEXdifS98_CTk_zKrAfH1U4qAHapemHA9eQqNnrGm0PtNHTo9Nh7ptrU_04Fc9askTjUnj3fOuDQTp1bLEJwwHbV7oBeQQlA6pYXvWvRwpj0col8N904w4QxoNNNEtYxIYbLtJkj3w-ZogJ9VPkKL_B3ayKTfle3nQ-PHrXyzYpBK89h39Hp2IiOddY-Ihl8iVuj8RziTUiMZ-0jTOToCAa8gQ813DGAtca0i4ffw3hg\"}}"; + /** + * examine JSON objects with gson + * + */ + @Test + public void testJWTOutputToken() { + var jwt_Token = readTokenFromProperties(); + System.out.println("Got the Token from readTokenFromProperties()"); + String replyJson = ""; + try { + // https://www.baeldung.com/java-text-blocks + replyJson = """ + { + "ChallengeParameters": {}, + "AuthenticationResult": { + "AccessToken": %s + } + } + """.formatted(jwt_Token); + } catch (Exception e) { + e.printStackTrace(); + } Gson gson = new Gson(); + // import com.google.gson.Gson; + // import com.google.gson.GsonBuilder; + // JSON Printing + System.out.println("Java Text Block FormattedJson " + replyJson); + String formattedJson = gson.toJson(replyJson); + System.out.println("gsonFormattedJson " + formattedJson); + } - // Restaurant restaurantObject = gson.fromJson(restaurantJson, - // Restaurant.class); - LoginReply loginReplyObject = gson.fromJson(replyJson, LoginReply.class); + public static String readTokenFromProperties() { + Properties prop = new Properties(); + var jwtToken = ""; - // Object loginReplyObject = gson.fromJson(replyJson, Object.class); - System.out.println("value " + loginReplyObject.getAuthenticationResult().getIdToken()); - // System.out.println("obtain token "+ loginReplyObject.authenticationResult); + try { + String propFileName = "token_auth.properties"; + FileInputStream fileInputStream = new FileInputStream(propFileName); + prop.load(fileInputStream); + // get the property value and print it out + jwtToken = prop.getProperty("jwt_Token"); + System.out.println("Got the Token from local property file "+ propFileName); + } catch (IOException ex) { + ex.printStackTrace(); + } + return jwtToken; } } diff --git a/src/test/java/json/TestConversionJson2Map.java b/src/test/java/json/TestConversionJson2Map.java index 3ac0ccb..8a3bca7 100644 --- a/src/test/java/json/TestConversionJson2Map.java +++ b/src/test/java/json/TestConversionJson2Map.java @@ -9,37 +9,31 @@ public class TestConversionJson2Map { public void convertJSON2Map() { - String jsonFromMS = "{\"ChallengeParameters\":{},\"AuthenticationResult\":{\"AccessToken\":\"eyJraWQiOiJ6M2pWR1lscDVsS2VHVzRXMkwrU3BtdjN4UzIwWGFCU1FvZFlvdWg1WkU4PSIsImFsZyI6IlJTMjU2In0.eyJzdWIiOiI2MWI5ZTI4NC1kMzVhLTQ0M2YtOTlhNy04MGY0OWE4YTI4NmQiLCJ0b2tlbl91c2UiOiJhY2Nlc3MiLCJzY29wZSI6ImF3cy5jb2duaXRvLnNpZ25pbi51c2VyLmFkbWluIiwiaXNzIjoiaHR0cHM6XC9cL2NvZ25pdG8taWRwLnVzLWVhc3QtMS5hbWF6b25hd3MuY29tXC91cy1lYXN0LTFfMEhkMUtvTTVhIiwiZXhwIjoxNTA1MDg5NDY5LCJpYXQiOjE1MDUwODU4NjksImp0aSI6ImI4MzY3ZjcwLTA5MDktNGI0Mi1hNDI2LWM2ZTYyY2M3ZTI0YSIsImNs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GciOiJSUzI1NiJ9.eyJzdWIiOiI2MWI5ZTI4NC1kMzVhLTQ0M2YtOTlhNy04MGY0OWE4YTI4NmQiLCJhdWQiOiIxZTh0ZWZtbGNsMmgyOTB2bmg5cmNlZm52ciIsImNvZ25pdG86Z3JvdXBzIjpbImFkbWluaXN0cmF0b3IiXSwiZW1haWxfdmVyaWZpZWQiOmZhbHNlLCJ0b2tlbl91c2UiOiJpZCIsImF1dGhfdGltZSI6MTUwNTA4NTg2OSwiaXNzIjoiaHR0cHM6XC9cL2NvZ25pdG8taWRwLnVzLWVhc3QtMS5hbWF6b25hd3MuY29tXC91cy1lYXN0LTFfMEhkMUtvTTVhIiwiY29nbml0bzp1c2VybmFtZSI6IjEwMjk1NzY1IiwiZXhwIjoxNTA1MDg5NDY5LCJpYXQiOjE1MDUwODU4NjksImVtYWlsIjoiam9uYXRoYW4udEB4dHJhLmNvLm56In0.N2vUTeKskoSGGnZNNQkoJrjqQSTwCRsAyoVzU8HoSESciE97PbHu_rsDBHdlIvExQgZOJUDH2fi2ZTVXL0qw_dw_1oy5PY0ss6iF9Ya8vNvwJ4QIg0nGLJEEWO6y9h81bUiy8WYOyC0uCy4FKPBzxu-VjO_ZkJwQZLlhkx56cPXhQI9JFbwQDeyxJDF9duOGiZkWYmiG842TeYpaNIiW46KtQ8kiZLGre9qUdPjQv9S-Ch9Cm8bDqVSunAVtTityUJMGJuxhM78hPAujGdeNfMX0qEx37MpKbQtkb_xJZaT1c0IXnu1tneqtGVxZtaZdQ4mUlBmdzamQaWhlSXvqyA\"}}"; - String jsonInString = "{'name' : 'Alejandra Rangel'}"; + var jwt_token = "op://Professional-IT Projects/JWT TestConversionJson2Map/credential"; + String jsonUser = "{'name' : 'Alejandra Rangel'}"; + String mockJSON_response = "{\"ChallengeParameters\":{},\"AuthenticationResult\":{\"AccessToken\":\"" + jwt_token +" \"}}"; Gson gson = new Gson(); Type authorization = new TypeToken>() { }.getType(); - Map authorizationMap = gson.fromJson(jsonFromMS, authorization); - - Map retMap = new Gson().fromJson(jsonFromMS, new TypeToken>() { + Map authorizationMap = gson.fromJson(mockJSON_response, authorization); + Map retMap = new Gson().fromJson(mockJSON_response, new TypeToken>() { }.getType()); - Map map = new Gson().fromJson(jsonFromMS, - new TypeToken>() { - }.getType()); - + Map map = new Gson().fromJson(mockJSON_response,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_AGQ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0b2tlbl91c2UiOiJpZCIsImF1dGhfdGltZSI6MTUwNTA4NTg2OSwiaXNzIjoiaHR0cHM6XC9cL2NvZ25pdG8taWRwLnVzLWVhc3QtMS5hbWF6b25hd3MuY29tXC91cy1lYXN0LTFfMEhkMUtvTTVhIiwiY29nbml0bzp1c2VybmFtZSI6IjEwMjk1NzY1IiwiZXhwIjoxNTA1MDg5NDY5LCJpYXQiOjE1MDUwODU4NjksImVtYWlsIjoiam9uYXRoYW4udEB4dHJhLmNvLm56In0.N2vUTeKskoSGGnZNNQkoJrjqQSTwCRsAyoVzU8HoSESciE97PbHu_rsDBHdlIvExQgZOJUDH2fi2ZTVXL0qw_dw_1oy5PY0ss6iF9Ya8vNvwJ4QIg0nGLJEEWO6y9h81bUiy8WYOyC0uCy4FKPBzxu-VjO_ZkJwQZLlhkx56cPXhQI9JFbwQDeyxJDF9duOGiZkWYmiG842TeYpaNIiW46KtQ8kiZLGre9qUdPjQv9S-Ch9Cm8bDqVSunAVtTityUJMGJuxhM78hPAujGdeNfMX0qEx37MpKbQtkb_xJZaT1c0IXnu1tneqtGVxZtaZdQ4mUlBmdzamQaWhlSXvqyA\"}}"; + var jwt_token = "op://Professional-IT Projects/convertJSONtoMapStructure/credential"; + String jsonFromMS = "{\"ChallengeParameters\":{},\"AuthenticationResult\":{\"AccessToken\":\"" + jwt_token +" \"}}"; Gson gson = new Gson(); - Type authorization = new TypeToken>() { }.getType(); diff --git a/src/test/java/json/TestJSONToken.java b/src/test/java/json/TestJSONToken.java index 0fd72b1..ef499a1 100644 --- a/src/test/java/json/TestJSONToken.java +++ b/src/test/java/json/TestJSONToken.java @@ -3,13 +3,10 @@ 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 auth.login.LoginReply; +import org.junit.jupiter.api.Test; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.OutputStream; @@ -22,19 +19,15 @@ public class TestJSONToken { @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\"}"; + var username = "op://Professional-IT Projects/multi-cloud-WebApp-Attendance/username"; + var password = "op://Professional-IT Projects/multi-cloud-WebApp-Attendance/password"; + String input = "{\"id\":\"" + username + "\",\"" + password + "\":\"\"}"; OutputStream os = conn.getOutputStream(); // 1.The client sends their credentials (username and password) to the server. @@ -68,15 +61,12 @@ public void testMalformedURL() throws MalformedURLException { } public void formatTokenJSONResponse() { - String replyJson = "{\"ChallengeParameters\":{},\"AuthenticationResult\":{\"AccessToken\":\"eyJraWQiOiJ6M2pWR1lscDVsS2VHVzRXMkwrU3BtdjN4UzIwWGFCU1FvZFlvdWg1WkU4PSIsImFsZyI6IlJTMjU2In0.eyJzdWIiOiI2MWI5ZTI4NC1kMzVhLTQ0M2YtOTlhNy04MGY0OWE4YTI4NmQiLCJ0b2tlbl91c2UiOiJhY2Nlc3MiLCJzY29wZSI6ImF3cy5jb2duaXRvLnNpZ25pbi51c2VyLmFkbWluIiwiaXNzIjoiaHR0cHM6XC9cL2NvZ25pdG8taWRwLnVzLWVhc3QtMS5hbWF6b25hd3MuY29tXC91cy1lYXN0LTFfMEhkMUtvTTVhIiwiZXhwIjoxNTA1MTIwNzM1LCJpYXQiOjE1MDUxMTcxMzUsImp0aSI6ImNiMjdkZjJiLTIwOWQtNGU1MC05ZTI4LThjYTAyOGY1MTc5MyIsImNsaWVudF9pZCI6IjFlOHRlZm1sY2wyaDI5MHZuaDlyY2VmbnZyIiwidXNlc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TQ0M2YtOTlhNy04MGY0OWE4YTI4NmQiLCJhdWQiOiIxZTh0ZWZtbGNsMmgyOTB2bmg5cmNlZm52ciIsImNvZ25pdG86Z3JvdXBzIjpbImFkbWluaXN0cmF0b3IiXSwiZW1haWxfdmVyaWZpZWQiOmZhbHNlLCJ0b2tlbl91c2UiOiJpZCIsImF1dGhfdGltZSI6MTUwNTExNzEzNSwiaXNzIjoiaHR0cHM6XC9cL2NvZ25pdG8taWRwLnVzLWVhc3QtMS5hbWF6b25hd3MuY29tXC91cy1lYXN0LTFfMEhkMUtvTTVhIiwiY29nbml0bzp1c2VybmFtZSI6IjEwMjk1NzY1IiwiZXhwIjoxNTA1MTIwNzM1LCJpYXQiOjE1MDUxMTcxMzUsImVtYWlsIjoiam9uYXRoYW4udEB4dHJhLmNvLm56In0.gGcx2YYcjWzNvzlpPklry4Jt59GwDQuDRRIFfJGaf06hMKi0Cin31Ox7AD4CaRUmbUXzxh395Bb6bPS9cGdh5oa2hIveC27bwHpO7Eij6voEXdifS98_CTk_zKrAfH1U4qAHapemHA9eQqNnrGm0PtNHTo9Nh7ptrU_04Fc9askTjUnj3fOuDQTp1bLEJwwHbV7oBeQQlA6pYXvWvRwpj0col8N904w4QxoNNNEtYxIYbLtJkj3w-ZogJ9VPkKL_B3ayKTfle3nQ-PHrXyzYpBK89h39Hp2IiOddY-Ihl8iVuj8RziTUiMZ-0jTOToCAa8gQ813DGAtca0i4ffw3hg\"}}"; + var token = ""; + String replyJson = "{\"ChallengeParameters\":{},\"AuthenticationResult\":{\"AccessToken\":\"" + token + "\"}}"; Gson gson = new Gson(); - - // Restaurant restaurantObject = gson.fromJson(restaurantJson, - // Restaurant.class); LoginReply loginReplyObject = gson.fromJson(replyJson, LoginReply.class); - // Object loginReplyObject = gson.fromJson(replyJson, Object.class); System.out.println("value " + loginReplyObject.getAuthenticationResult().getIdToken()); - System.out.println("obtain token "+ loginReplyObject.getAuthenticationResult().getAccessToken()); - } + System.out.println("obtain token " + loginReplyObject.getAuthenticationResult().getAccessToken()); + } } diff --git a/token_auth.properties.tpl b/token_auth.properties.tpl new file mode 100644 index 0000000..4191a86 --- /dev/null +++ b/token_auth.properties.tpl @@ -0,0 +1,3 @@ +# https://developer.1password.com/docs/secrets-automation +# https://developer.1password.com/docs/cli/secrets-config-files +jwt_Token = "op://Professional-IT Projects/AWS Cognito JWT Sample/credential"