Commit 370af334 by rndeguzman

Merge branch 'feature-WG-314' into feature-WG-320

parents c36164ce 1f0bf3b8
eclipse.preferences.version=1
org.eclipse.m2e.wtp.enabledProjectSpecificPrefs=false
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<runtime name="Payara Server 5 (5.2021.1)"/>
<fixed facet="jst.web"/>
<fixed facet="java"/>
<fixed facet="wst.jsdt.web"/>
<installed facet="java" version="1.8"/>
<installed facet="jst.web" version="3.1"/>
<installed facet="wst.jsdt.web" version="1.0"/>
<installed facet="jst.jaxrs" version="2.1"/>
<installed facet="jst.jsf" version="2.2"/>
</faceted-project>
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<runtime name="Payara Server 5 (5.2022.5)"/>
<fixed facet="jst.web"/>
<fixed facet="java"/>
<fixed facet="wst.jsdt.web"/>
<installed facet="java" version="1.8"/>
<installed facet="jst.web" version="3.1"/>
<installed facet="wst.jsdt.web" version="1.0"/>
<installed facet="jst.jaxrs" version="2.1"/>
<installed facet="jst.jsf" version="2.2"/>
</faceted-project>
......@@ -17,3 +17,9 @@ GET_ROLE_RIGHTS_URL=http://localhost:8080/gfs-explorer/svc/gfs-rest/rights/
CHECK_RIGHT_URL=http://localhost:8080/gfs-explorer/svc/gfs-rest/check-right/
GET_SUB_URL=http://localhost:8080/gfs-explorer/svc/gfs-rest/get-sub/
[MARIADB CONFIG]
JDBC_URL=jdbc:mariadb://localhost:3307/
DB_NAME=webgde_db
USERNAME=root
PASSWORD=p455w0rd
import { DB_URL } from "../config.js";
export const fetchOptionsDB = async (requestBody) => {
try {
const response = await fetch(DB_URL, {
method: 'POST',
body: JSON.stringify(requestBody),
headers: {
'Content-Type': 'application/json'
}
});
const data = await response.json();
return data.tableData || [];
} catch (error) {
throw error;
}
};
\ No newline at end of file
//Data Input Field Config
export var SCHEMA_FILE_PATH = "./WebGde-Widgets/sample_schema/HR Speed Test schema.json";
\ No newline at end of file
export var SCHEMA_FILE_PATH = "./WebGde-Widgets/sample_schema/HR Speed Test schema.json";
//DBLookup Webservice URL
export var DB_URL = "http://localhost:8080/WebGde/svc/gfs-rest/db-lookup"
\ No newline at end of file
import { generateFields } from "./generateFields.js";
import { clearForm, generateFields } from "./generateFields.js";
export class displayField {
constructor(schema, containerId) {
......@@ -10,6 +10,10 @@ export class displayField {
generateFields(this.schema, this.containerId);
}
clearForm(){
clearForm();
}
updateHeaderText(headerIndex, newText) {
let headers = document.getElementsByClassName("field-header");
if (headerIndex >= 0 && headerIndex < headers.length) {
......
{
"APPLICATION FORM": {
"SECTION1": {
"Date": {
"fieldLabel": "Date",
"aka": "field2",
"source": "p",
"validation": {
"fieldLength": 20,
"collection": "alphanumeric",
"invalidchar": "`~!@#&$%^*_={}[]:;/\"|\\<>",
"mandatory": true
}
},
"Position Applied For": {
"fieldLabel": "Pos Applied For",
"aka": "field3",
"source": "p",
"validation": {
"fieldLength": 30,
"collection": "alphanumeric",
"invalidchar": "`~!@#&$%^*={}[]:;/\"|\\<>",
"mandatory": true
}
},
"Surname": {
"fieldLabel": "Surname",
"aka": "field4",
"source": "p",
"validation": {
"fieldLength": 50,
"collection": "textarea",
"invalidchar": "`~!@#&$%^*={}[]:;/\"|\\<>",
"mandatory": true
}
},
"First Name": {
"fieldLabel": "First Name",
"aka": "field5",
"source": "p",
"validation": {
"fieldLength": 50,
"collection": "textarea",
"invalidchar": "`~!@#&$%^*={}[]:;/\"|\\<>",
"mandatory": true
}
},
"Middle Name": {
"fieldLabel": "Mid Name",
"aka": "field6",
"source": "p",
"validation": {
"fieldLength": 50,
"collection": "textarea",
"invalidchar": "`~!@#&$%^*={}[]:;/\"|\\<>",
"mandatory": true
}
},
"Mother's Maiden Name": {
"fieldLabel": "Mother's Maiden Name",
"aka": "field7",
"source": "p",
"validation": {
"fieldLength": 100,
"collection": "textarea",
"invalidchar": "`~!@#&$%^*={}[]:;/\"|\\<>",
"mandatory": true
}
},
"Date of Birth": {
"fieldLabel": "Date of Birth",
"aka": "field25",
"source": "p",
"validation": {
"fieldLength": 30,
"collection": "datepicker",
"mandatory": true
}
},
"Age": {
"fieldLabel": "Age",
"aka": "field26",
"source": "p",
"validation": {
"fieldLength": 3,
"collection": "numeric",
"mandatory": true
}
},
"Gender": {
"fieldLabel": "Gender",
"aka": "field27",
"source": "p",
"validation": {
"fieldLength": 10,
"collection": "dropdown",
"invalidchar": "`~!@#&$%^*={}[]:;/\"|\\<>",
"mandatory": true,
"options": ["Male","Female"]
}
},
"Civil Status": {
"fieldLabel": "Civil Status",
"aka": "field28",
"source": "s",
"validation": {
"fieldLength": 10,
"collection": "alphanumeric",
"invalidchar": "`~!@#&$%^*={}[]:;/\"|\\<>",
"mandatory": true,
"validvalues": ["Single", "Married", "Widowed"]
}
},
"Spouse Name": {
"fieldLabel": "Spouse Name",
"aka": "field29",
"source": "s",
"validation": {
"fieldLength": 100,
"collection": "textarea",
"invalidchar": "`~!@#&$%^*={}[]:;/\"|\\<>",
"mandatory": true
},
"childof": "Civil Status",
"parentvalue": ["Married", "Widowed"]
},
"Date of Marriage": {
"fieldLabel": "Date of Marriage",
"aka": "field30",
"source": "s",
"validation": {
"fieldLength": 30,
"collection": "alphanumeric",
"invalidchar": "`~!@#&$%^*={}[]:;/\"|\\<>",
"mandatory": true
},
"childof": "Civil Status",
"parentvalue": ["Married", "Widowed"]
},
"Mother's Name": {
"fieldLabel": "Mother's Name",
"aka": "field31",
"source": "s",
"validation": {
"fieldLength": 100,
"collection": "textarea",
"invalidchar": "`~!@#&$%^*={}[]:;/\"|\\<>",
"mandatory": true
},
"childof": "Civil Status",
"parentvalue": ["Single"]
},
"School": {
"fieldLabel": "School",
"aka": "field32",
"source": "p",
"validation": {
"fieldLength": 100,
"collection": "dblookup",
"mandatory": true,
"options": "TBLSchool~Name"
}
},
"TOR": {
"fieldLabel": "TOR",
"aka": "field33",
"source": "p",
"validation": {
"fieldLength": 100,
"collection": "alphanumeric",
"mandatory": true
},
"hidden": "y"
}
}
}
}
\ No newline at end of file
......@@ -111,7 +111,7 @@ async function createInputForm(){
// Instantiate widget and assign it to a container
const displayFieldClass = new displayField(schema, containerId);
// Call Function to generate fields with given schema to provided container
displayFieldClass.generateFields();
await displayFieldClass.generateFields();
// displayFieldClass.editHeader(element-id)
displayFieldClass.updateHeaderText(0, "User: " + sessionStorage.getItem("user_id"));
displayFieldClass.updateHeaderText(1, "Element ID: " + sessionStorage.getItem("element_id"));
......
......@@ -42,10 +42,11 @@
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client -->
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>JDBC 4.2</version>
<version>2.7.2</version>
</dependency>
</dependencies>
<build>
......
......@@ -22,7 +22,12 @@ public enum ApplicationConfig {
GET_SUBFOLDERS_URL("GET_SUBFOLDERS_URL"),
GET_SUBFILES_URL("GET_SUBFILES_URL"),
METRICS_DIR("METRICS_DIR");
METRICS_DIR("METRICS_DIR"),
JDBC_URL("JDBC_URL"),
DB_NAME("DB_NAME"),
USERNAME("USERNAME"),
PASSWORD("PASSWORD");
private String value = "";
private static Properties prop;
......
package com.svi.webgde.restservice.filters;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import javax.annotation.Priority;
import javax.ws.rs.Priorities;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.core.Cookie;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.Provider;
import org.apache.commons.lang3.StringUtils;
import com.svi.sso.jwt.utilities.JWTClaims;
import com.svi.sso.jwt.utilities.JWTUtility;
import com.svi.template.restservice.globals.AppConfig;
import com.svi.template.restservice.globals.GlobalConstants;
@Secured
@Provider
@Priority(Priorities.AUTHENTICATION)
public class SecuredFilter implements ContainerRequestFilter {
private static final GlobalConstants GLOBAL_CONSTANTS = GlobalConstants.getInstance();
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
if (AppConfig.IS_COOKIE.getValue().equalsIgnoreCase("Y")) {
if (!verifyCallerByCookie(requestContext)) {
try {
redirect(requestContext);
} catch (URISyntaxException e) {
System.out.println("SSO secured filter: " + e.getMessage());
}
}
}
else {
if (!verifyCallerByBearer(requestContext)) {
try {
redirect(requestContext);
} catch (URISyntaxException e) {
System.out.println("SSO secured filter: " + e.getMessage());
}
}
}
}
private boolean verifyCallerByCookie(ContainerRequestContext requestContext) {
Cookie cookie = requestContext.getCookies().get(AppConfig.ACCESS_TOKEN.getValue());
boolean callerVerified = false;
URI uri = requestContext.getUriInfo().getAbsolutePath();
if (cookie == null) {
callerVerified = false;
}
else {
try {
String token = cookie.getValue();
JWTClaims claims = JWTUtility.parseTokenSecure(token, AppConfig.ACCESS_SUBJECT.getValue());
if (claims == null) {
callerVerified = false;
}
else {
requestContext.setProperty(GLOBAL_CONSTANTS.getJwtClaimsText(), claims);
callerVerified = true;
}
} catch (Exception e) {
callerVerified = false;
}
}
return callerVerified;
}
private boolean verifyCallerByBearer(ContainerRequestContext requestContext) {
String bearer = requestContext.getHeaderString(GLOBAL_CONSTANTS.getAuthorizationHeaderText());
boolean validRequest = false;
if (StringUtils.isNoneBlank(bearer)) {
try {
String[] splittedBearer = bearer.split(" ");
String token = splittedBearer[1];
if (StringUtils.isNoneBlank(token)) {
JWTClaims claims = JWTUtility.parseTokenSecure(token, AppConfig.ACCESS_SUBJECT.getValue());
if (claims != null) {
requestContext.setProperty(GLOBAL_CONSTANTS.getJwtClaimsText(), claims);
validRequest = true;
}
}
} catch (Exception e) {
}
}
return validRequest;
}
private void redirect(ContainerRequestContext requestContext) throws URISyntaxException {
requestContext.abortWith(Response.serverError().entity(GLOBAL_CONSTANTS.getForbiddenText()).build());
}
}
package com.svi.webgde.restservice.filters;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import javax.annotation.Priority;
import javax.ws.rs.Priorities;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.core.Cookie;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.Provider;
import org.apache.commons.lang3.StringUtils;
import com.svi.sso.jwt.utilities.JWTClaims;
import com.svi.sso.jwt.utilities.JWTUtility;
import com.svi.template.restservice.globals.AppConfig;
import com.svi.template.restservice.globals.GlobalConstants;
@Secured
@Provider
@Priority(Priorities.AUTHENTICATION)
public class SecuredFilter implements ContainerRequestFilter {
private static final GlobalConstants GLOBAL_CONSTANTS = GlobalConstants.getInstance();
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
if (AppConfig.IS_COOKIE.getValue().equalsIgnoreCase("Y")) {
if (!verifyCallerByCookie(requestContext)) {
try {
redirect(requestContext);
} catch (URISyntaxException e) {
System.out.println("SSO secured filter: " + e.getMessage());
}
}
}
else {
if (!verifyCallerByBearer(requestContext)) {
try {
redirect(requestContext);
} catch (URISyntaxException e) {
System.out.println("SSO secured filter: " + e.getMessage());
}
}
}
}
private boolean verifyCallerByCookie(ContainerRequestContext requestContext) {
Cookie cookie = requestContext.getCookies().get(AppConfig.ACCESS_TOKEN.getValue());
boolean callerVerified = false;
URI uri = requestContext.getUriInfo().getAbsolutePath();
if (cookie == null) {
callerVerified = false;
}
else {
try {
String token = cookie.getValue();
JWTClaims claims = JWTUtility.parseTokenSecure(token, AppConfig.ACCESS_SUBJECT.getValue());
if (claims == null) {
callerVerified = false;
}
else {
requestContext.setProperty(GLOBAL_CONSTANTS.getJwtClaimsText(), claims);
callerVerified = true;
}
} catch (Exception e) {
callerVerified = false;
}
}
return callerVerified;
}
private boolean verifyCallerByBearer(ContainerRequestContext requestContext) {
String bearer = requestContext.getHeaderString(GLOBAL_CONSTANTS.getAuthorizationHeaderText());
boolean validRequest = false;
if (StringUtils.isNoneBlank(bearer)) {
try {
String[] splittedBearer = bearer.split(" ");
String token = splittedBearer[1];
if (StringUtils.isNoneBlank(token)) {
JWTClaims claims = JWTUtility.parseTokenSecure(token, AppConfig.ACCESS_SUBJECT.getValue());
if (claims != null) {
requestContext.setProperty(GLOBAL_CONSTANTS.getJwtClaimsText(), claims);
validRequest = true;
}
}
} catch (Exception e) {
}
}
return validRequest;
}
private void redirect(ContainerRequestContext requestContext) throws URISyntaxException {
requestContext.abortWith(Response.serverError().entity(GLOBAL_CONSTANTS.getForbiddenText()).build());
}
}
\ No newline at end of file
......@@ -23,12 +23,13 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.StreamingOutput;
import org.json.JSONObject;
import org.json.simple.JSONObject;
import com.opencsv.CSVReader;
import com.opencsv.CSVWriter;
import com.svi.webgde.restservice.object.Request;
import com.svi.webgde.restservice.object.XMLContents;
import com.svi.webgde.restservice.utils.DBUtil;
import com.svi.webgde.restservice.utils.XMLUtil;
@Path("/gfs-rest")
......@@ -39,6 +40,19 @@ public class GDEWebServices {
public Response testWebservice() {
return Response.ok("test webservice").build();
}
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_OCTET_STREAM)
@Path("/db-lookup")
public Response dbLookup(JsonObject jsonObject) {
JSONObject json = new JSONObject();
String string = jsonObject.getString("dbLookup");
json = DBUtil.dbLookup(string);
return Response.ok(json.toString()).build();
}
@POST
@Consumes(MediaType.APPLICATION_JSON)
......
package com.svi.webgde.restservice.utils;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import com.svi.webgde.restservice.config.ApplicationConfig;
public class DBUtil {
public static JSONObject dbLookup(String dbLookup) {
try {
Class.forName("org.mariadb.jdbc.Driver");
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String jdbcURL = ApplicationConfig.JDBC_URL.value() + ApplicationConfig.DB_NAME.value();
String username = ApplicationConfig.USERNAME.value();
String password = ApplicationConfig.PASSWORD.value();
System.out.println("url:"+jdbcURL);
String tableName = dbLookup.substring(0, dbLookup.indexOf("~"));
try (Connection connection = DriverManager.getConnection(jdbcURL, username, password)) {
String query = "SELECT * FROM " + tableName;
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(query);
JSONObject jsonObject = new JSONObject();
JSONArray jsonArray = new JSONArray();
ResultSetMetaData metaData = resultSet.getMetaData();
int columnCount = metaData.getColumnCount();
while (resultSet.next()) {
for (int i = 1; i <= columnCount; i++) {
String columnName = metaData.getColumnName(i);
String columnValue = resultSet.getString(i);
jsonArray.add(columnValue);
}
}
jsonObject.put("tableData", jsonArray);
return jsonObject;
} catch (SQLException e) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("error", "500");
e.printStackTrace();
return jsonObject;
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment