Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added http-client, db-mysql, cryptoservice, cryptoserver modules #309

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ hibernate = '6.4.4.Final'
dom4j = '2.1.4'
jdbcPostgresql = '42.7.2'
agroal = '2.3'
flyway = '10.8.1'
flyway = '10.17.0'
h2 = '2.2.224'
testcontainers = '1.19.6'
httpAsyncClient = '4.1.5'
jdbcMysql = '9.0.0'

[libraries]
jpos = { module = "org.jpos:jpos", version.ref = "jpos" }
Expand Down Expand Up @@ -51,4 +53,5 @@ flywayPostgresql = { module = 'org.flywaydb:flyway-database-postgresql', version
flywayMysql = { module = 'org.flywaydb:flyway-mysql', version.ref='flyway' }
h2 = { module = 'com.h2database:h2', version.ref='h2' }
testcontainersPostgresql = { module = 'org.testcontainers:postgresql', version.ref='testcontainers' }

httpAsyncClient = { module = 'org.apache.httpcomponents:httpasyncclient', version.ref = 'httpAsyncClient' }
jdbcMysql = { module = 'com.mysql:mysql-connector-j', version.ref = 'jdbcMysql' }
6 changes: 2 additions & 4 deletions modules/cryptoserver/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
description = 'jPOS-EE :: Crypto Server'

dependencies {
testImplementation libraries.junit
testImplementation libraries.restAssured
testImplementation libs.junit
testImplementation testlibs.restAssured
api project(':modules:qrest')
api project(':modules:cryptoservice')
api project(':modules:db-mysql')
api project(':modules:logback')
}

apply from: "${rootProject.projectDir}/jpos-app.gradle"

test {
dependsOn('installApp')
workingDir = "build/install/cryptoserver"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public int prepare(long id, Serializable context) {
String jsonStr = request.content().toString(CharsetUtil.UTF_8);
ctx.log (jsonStr);
@SuppressWarnings("unchecked")
Map<String,String> m = (Map<String,String>) mapper.readValue(jsonStr, Map.class);
Map<String,String> m = mapper.readValue(jsonStr, Map.class);
UUID keyId = UUID.fromString(m.get("kid"));
byte[] encoded = decoder.decode(m.get("cryptogram"));
byte[] b = cs.aesDecrypt(jobId, keyId, encoded);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

package org.jpos.cryptoserver.participant;

import java.io.IOException;
import java.io.Serializable;
import java.util.*;

Expand Down Expand Up @@ -52,7 +51,7 @@ public int prepare(long id, Serializable context) {
String jsonStr = request.content().toString(CharsetUtil.UTF_8);
ctx.log (jsonStr);
@SuppressWarnings("unchecked")
Map<String,String> m = (Map<String,String>) mapper.readValue(jsonStr, Map.class);
Map<String,String> m = mapper.readValue(jsonStr, Map.class);

SecureData sd = cs.aesEncrypt(m.get("text").getBytes());

Expand Down
2 changes: 1 addition & 1 deletion modules/cryptoservice/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
description = 'jPOS-EE :: CryptoService'

dependencies {
api libraries.jpos
api libs.jpos
api project(':modules:sysconfig')
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package org.jpos.crypto;

import org.jpos.ee.DB;
import org.jpos.ee.SysConfigManager;
import org.jpos.sysconfig.SysConfigManager;

public class SysConfigCryptoServiceKeyStoreProvider implements CryptoServiceKeyStoreProvider {
@Override
Expand All @@ -30,7 +30,7 @@ public void put(String id, String value) throws CryptoServiceKeyStoreException {
if (mgr.get(id, null) != null)
throw new KeyAlreadyExistsException();

mgr.put(id, value, "security.read", "security.write");
mgr.put(id, value);
return true;
});
} catch (Exception e) {
Expand Down
3 changes: 2 additions & 1 deletion modules/db-mysql/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ description = 'jPOS-EE :: MySql support'

dependencies {
api project(':modules:dbsupport')
api libraries.jdbcMysql
api libs.jdbcMysql
api libs.flywayMysql
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ hibernate.connection.password=password
#
hibernate.connection.url=jdbc:mysql://localhost/jposee?autoReconnect=true
hibernate.connection.driver_class=com.mysql.cj.jdbc.Driver
hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
hibernate.dialect=org.hibernate.dialect.MySQLDialect
#
6 changes: 2 additions & 4 deletions modules/http-client/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
description = 'jPOS-EE :: QRest Client'

dependencies {
api libraries.jpos
api libraries.httpAsyncClient
api libs.jpos
api libs.httpAsyncClient
testImplementation project(':modules:qrest')
}

apply from: "${rootProject.projectDir}/jpos-app.gradle"

test {
dependsOn('installApp')
workingDir = "build/install/http-client"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,6 @@

package org.jpos.http.client;

import static org.jpos.util.Logger.log;

import java.io.IOException;
import java.io.Serializable;
import java.net.URI;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.*;
import java.util.function.Consumer;

import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
import javax.security.cert.CertificateExpiredException;

import org.apache.commons.codec.binary.StringUtils;
import org.apache.http.*;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
Expand All @@ -51,29 +29,44 @@
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.concurrent.FutureCallback;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.TrustAllStrategy;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;

import org.apache.http.impl.auth.BasicScheme;
import org.apache.http.impl.client.BasicAuthCache;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.DefaultRedirectStrategy;
import org.apache.http.impl.client.LaxRedirectStrategy;
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
import org.apache.http.impl.nio.client.HttpAsyncClients;
import org.apache.http.message.BasicHeader;
import org.apache.http.util.EntityUtils;

import org.jpos.core.Configurable;
import org.jpos.core.Configuration;
import org.jpos.core.ConfigurationException;
import org.jpos.transaction.AbortParticipant;
import org.jpos.transaction.Context;
import org.jpos.util.Destroyable;
import org.jpos.util.Log;
import org.jpos.util.LogEvent;
import org.jpos.core.Configurable;
import org.jpos.core.Configuration;
import org.jpos.transaction.Context;

import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.io.IOException;
import java.io.Serializable;
import java.net.URI;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;

import static org.jpos.util.Logger.log;


@SuppressWarnings("unused")
Expand Down Expand Up @@ -117,6 +110,7 @@ public HttpQuery () {
super();
}

@Override
public int prepare (long id, Serializable o) {
Context ctx = (Context) o;

Expand All @@ -130,7 +124,7 @@ public int prepare (long id, Serializable o) {
//config example <property name="httpVersionName" value="1.1"/>
HttpVersion definedVersion = null;
String httpVersion = getVersion(ctx);
if(httpVersion != null && httpVersion.length() > 0) {
if(httpVersion != null && !httpVersion.isEmpty()) {
String[] majmin = httpVersion.split("\\."); // split into major and minor version numbers
definedVersion = new HttpVersion(Integer.parseInt(majmin[0]),
majmin.length > 1 ? Integer.parseInt(majmin[1]) : 0); // default to minor 0 if it can't be split
Expand Down Expand Up @@ -187,7 +181,7 @@ public void completed(HttpResponse result) {
}

ctx.put (statusName, sc); // status has to be the last entry because client might be waiting on it
ctx.resume();
ctx.resume(PREPARED);
}

@Override
Expand All @@ -198,18 +192,19 @@ public void failed(Exception ex) {
// java.net.ConnectException: Timeout connecting to [mydomain.com/xxx.xxx.xxx.xxx:ppp]
// java.net.SocketTimeoutException: ... (when no HTTP response)
ctx.log(ex);
ctx.resume();
ctx.resume(ABORTED);
}

@Override
public void cancelled() {
ctx.resume();
ctx.resume(ABORTED);
}
});

return PREPARED | PAUSE | NO_JOIN | READONLY;
}

@Override
public int prepareForAbort (long id, Serializable o) {
if (cfg.getBoolean ("on-abort", false))
return prepare (id, o);
Expand Down Expand Up @@ -324,10 +319,11 @@ public java.security.cert.X509Certificate[] getAcceptedIssuers() {
}

public void checkClientTrusted(X509Certificate[] certs, String authType) {
// ignored
}

public void checkServerTrusted(X509Certificate[] certs, String authType) {
log(new LogEvent(certs.toString() + " " + authType));
log(new LogEvent(Arrays.toString(certs) + " " + authType));
}
}
};
Expand All @@ -350,7 +346,7 @@ private String getURL (Context ctx) {
ctx.getString (urlName, url)
);
String params = ctx.getString (paramsName, "");
if (params.length() > 0) {
if (!params.isEmpty()) {
sb.append ('?');
sb.append (params);
}
Expand Down
9 changes: 4 additions & 5 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ include ':modules:seqno'
include ':modules:binlog'
include ':modules:binlog-quartz'
include ':modules:server-simulator'

include ':modules:http-client'
include ':modules:db-mysql'
include ':modules:cryptoservice'
include ':modules:cryptoserver'
// include ':modules:dbtest'

dependencyResolutionManagement {
Expand All @@ -38,7 +41,6 @@ dependencyResolutionManagement {
// include ':modules:syslog'
// include ':modules:resultcode'
// include ':modules:txn'
// include ':modules:db-mysql'
// include ':modules:db-mssql'
// include ':modules:minigl'
// include ':modules:eeuser'
Expand All @@ -60,12 +62,9 @@ dependencyResolutionManagement {
// include ':modules:qi-eeuser'
// include ':modules:qi-sysconfig'
// include ':modules:qi-minigl'
// include ':modules:cryptoservice'
// include ':modules:cryptoserver'
// include ':modules:iso-http-client'
// include ':modules:iso-http-server'
// include ':modules:iso-http-servlet'
// include ':modules:http-client'
// include ':modules:elasticsearch'


Expand Down