initial commit
This commit is contained in:
13
src/main/java/zw/qantra/tm/TmApplication.java
Normal file
13
src/main/java/zw/qantra/tm/TmApplication.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package zw.qantra.tm;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class TmApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(TmApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
43
src/main/java/zw/qantra/tm/configs/CustomCorsFilter.java
Executable file
43
src/main/java/zw/qantra/tm/configs/CustomCorsFilter.java
Executable file
@@ -0,0 +1,43 @@
|
||||
package zw.qantra.tm.configs;
|
||||
|
||||
import jakarta.servlet.*;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Component
|
||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||
public class CustomCorsFilter implements Filter {
|
||||
|
||||
public CustomCorsFilter() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
|
||||
HttpServletResponse response = (HttpServletResponse) res;
|
||||
HttpServletRequest request = (HttpServletRequest) req;
|
||||
response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin"));
|
||||
response.setHeader("Access-Control-Allow-Methods", "*");
|
||||
response.setHeader("Access-Control-Allow-Credentials", "true");
|
||||
response.setHeader("Access-Control-Max-Age", "3600");
|
||||
response.setHeader("Access-Control-Allow-Headers", "*");
|
||||
|
||||
if ("OPTIONS".equalsIgnoreCase(request.getMethod())) {
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
} else {
|
||||
chain.doFilter(req, res);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package zw.qantra.tm.configs;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
import java.security.SecureRandom;
|
||||
import java.security.cert.X509Certificate;
|
||||
|
||||
@Configuration
|
||||
public class DisableSSLVerification {
|
||||
@PostConstruct
|
||||
public void disableSslVerification() {
|
||||
try {
|
||||
TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
|
||||
public X509Certificate[] getAcceptedIssuers() { return null; }
|
||||
public void checkClientTrusted(X509Certificate[] certs, String authType) { }
|
||||
public void checkServerTrusted(X509Certificate[] certs, String authType) { }
|
||||
}};
|
||||
SSLContext sc = SSLContext.getInstance("SSL");
|
||||
sc.init(null, trustAllCerts, new SecureRandom());
|
||||
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
|
||||
HttpsURLConnection.setDefaultHostnameVerifier((hostname, session) -> true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
33
src/main/java/zw/qantra/tm/utils/ContextUtils.java
Normal file
33
src/main/java/zw/qantra/tm/utils/ContextUtils.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package zw.qantra.tm.utils;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.databind.util.StdDateFormat;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ContextUtils {
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
public String getPrettyObject(Object object) {
|
||||
try {
|
||||
return this.mapper
|
||||
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
|
||||
.setDateFormat(new StdDateFormat().withColonInTimeZone(true))
|
||||
.registerModule(new JavaTimeModule())
|
||||
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
|
||||
.writerWithDefaultPrettyPrinter()
|
||||
.writeValueAsString(object);
|
||||
} catch (JsonProcessingException e) {
|
||||
System.out.print(e.getMessage());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
75
src/main/java/zw/qantra/tm/utils/Utils.java
Normal file
75
src/main/java/zw/qantra/tm/utils/Utils.java
Normal file
@@ -0,0 +1,75 @@
|
||||
package zw.qantra.tm.utils;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.databind.util.StdDateFormat;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Utils {
|
||||
public static String hashPassword(String password) {
|
||||
try {
|
||||
// Create a MessageDigest instance for SHA-256
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
||||
|
||||
// Perform the hashing
|
||||
byte[] hashedBytes = digest.digest(password.getBytes());
|
||||
|
||||
// Convert the hashed bytes to a hexadecimal string
|
||||
StringBuilder hexString = new StringBuilder();
|
||||
for (byte b : hashedBytes) {
|
||||
String hex = Integer.toHexString(0xff & b);
|
||||
if (hex.length() == 1) {
|
||||
hexString.append('0');
|
||||
}
|
||||
hexString.append(hex);
|
||||
}
|
||||
|
||||
return hexString.toString();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new RuntimeException("Error hashing password", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getUid(){
|
||||
return UUID.randomUUID().toString();
|
||||
}
|
||||
public static <T> T getJson(String json, Class<T> clazz){
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
mapper.setDateFormat(new StdDateFormat().withColonInTimeZone(true));
|
||||
mapper.registerModule(new JavaTimeModule());
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
|
||||
Object obj = null;
|
||||
try {
|
||||
obj = mapper.readValue(json, clazz);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return (T) obj;
|
||||
}
|
||||
|
||||
public static String setJson(Object obj){
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
mapper.setDateFormat(new StdDateFormat().withColonInTimeZone(true));
|
||||
mapper.registerModule(new JavaTimeModule());
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
|
||||
String json = "";
|
||||
try {
|
||||
json = mapper.writeValueAsString(obj);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
}
|
||||
14
src/main/resources/application-lab.properties
Normal file
14
src/main/resources/application-lab.properties
Normal file
@@ -0,0 +1,14 @@
|
||||
spring.application.name=tm
|
||||
debug=true
|
||||
logging.level.root=INFO
|
||||
logging.level.org.springframework.boot.autoconfigure=INFO
|
||||
|
||||
server.port=6950
|
||||
|
||||
spring.jpa.hibernate.ddl-auto=validate
|
||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
|
||||
|
||||
spring.datasource.url=jdbc:mysql://localhost:3306/qpay?useLegacyDatetimeCode=false
|
||||
spring.datasource.username=root
|
||||
spring.datasource.password=password
|
||||
14
src/main/resources/application.properties
Normal file
14
src/main/resources/application.properties
Normal file
@@ -0,0 +1,14 @@
|
||||
spring.application.name=tm
|
||||
debug=true
|
||||
logging.level.root=INFO
|
||||
logging.level.org.springframework.boot.autoconfigure=INFO
|
||||
|
||||
server.port=6950
|
||||
|
||||
spring.jpa.hibernate.ddl-auto=validate
|
||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
|
||||
|
||||
spring.datasource.url=jdbc:mysql://localhost:3306/qpay?useLegacyDatetimeCode=false
|
||||
spring.datasource.username=root
|
||||
spring.datasource.password=password
|
||||
9
src/main/resources/liquibase-lab.properties
Normal file
9
src/main/resources/liquibase-lab.properties
Normal file
@@ -0,0 +1,9 @@
|
||||
changeLogFile=src/main/resources/liquibase-diff-changeLog.xml
|
||||
url=jdbc:mysql://localhost:3306/qpay?serverTimezone=Africa/Harare&useLegacyDatetimeCode=false
|
||||
username=root
|
||||
password=password
|
||||
|
||||
driver=com.mysql.cj.jdbc.Driver
|
||||
referenceUrl=hibernate:spring:zw.qantra.tm.domain.models?dialect=org.hibernate.dialect.MySQL5Dialect&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy&hibernate.physical_naming_strategy=org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy
|
||||
diffChangeLogFile=src/main/resources/liquibase-diff-changeLog.xml
|
||||
outputChangeLogFile=src/main/resources/liquibase-changeLog.xml
|
||||
9
src/main/resources/liquibase.properties
Normal file
9
src/main/resources/liquibase.properties
Normal file
@@ -0,0 +1,9 @@
|
||||
changeLogFile=src/main/resources/liquibase-diff-changeLog.xml
|
||||
url=jdbc:mysql://localhost:3306/qpay?serverTimezone=Africa/Harare&useLegacyDatetimeCode=false
|
||||
username=root
|
||||
password=password
|
||||
|
||||
driver=com.mysql.cj.jdbc.Driver
|
||||
referenceUrl=hibernate:spring:zw.qantra.tm.domain.models?dialect=org.hibernate.dialect.MySQL5Dialect&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy&hibernate.physical_naming_strategy=org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy
|
||||
diffChangeLogFile=src/main/resources/liquibase-diff-changeLog.xml
|
||||
outputChangeLogFile=src/main/resources/liquibase-changeLog.xml
|
||||
Reference in New Issue
Block a user