[DEBUG] missing some fiole for productions

This commit is contained in:
Edouard DUPIN 2023-05-28 22:18:09 +02:00
parent ec2f7d4a7f
commit 93f0915574
8 changed files with 118 additions and 8 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.kar</groupId> <groupId>org.kar</groupId>
<artifactId>karso</artifactId> <artifactId>karso</artifactId>
<version>0.4.2</version> <version>0.4.3</version>
<properties> <properties>
<!-- <!--
<jaxb.version>2.3.1</jaxb.version> <jaxb.version>2.3.1</jaxb.version>
@ -24,7 +24,7 @@
<dependency> <dependency>
<groupId>kangaroo-and-rabbit</groupId> <groupId>kangaroo-and-rabbit</groupId>
<artifactId>archidata</artifactId> <artifactId>archidata</artifactId>
<version>0.3.6</version> <version>0.3.7</version>
</dependency> </dependency>
<!-- testing --> <!-- testing -->
<dependency> <dependency>
@ -44,6 +44,11 @@
<sourceDirectory>src</sourceDirectory> <sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test/src</testSourceDirectory> <testSourceDirectory>test/src</testSourceDirectory>
<directory>${project.basedir}/out/maven/</directory> <directory>${project.basedir}/out/maven/</directory>
<resources>
<resource>
<directory>src/resources</directory>
</resource>
</resources>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>

View File

@ -23,7 +23,6 @@ import org.kar.archidata.catcher.FailException404API;
import org.kar.archidata.catcher.FailExceptionCatcher; import org.kar.archidata.catcher.FailExceptionCatcher;
import org.kar.archidata.catcher.InputExceptionCatcher; import org.kar.archidata.catcher.InputExceptionCatcher;
import org.kar.archidata.catcher.SystemExceptionCatcher; import org.kar.archidata.catcher.SystemExceptionCatcher;
import org.kar.archidata.db.DBEntry;
import org.kar.archidata.filter.CORSFilter; import org.kar.archidata.filter.CORSFilter;
import org.kar.archidata.util.ConfigBaseVariable; import org.kar.archidata.util.ConfigBaseVariable;
import org.kar.archidata.util.JWTWrapper; import org.kar.archidata.util.JWTWrapper;
@ -46,8 +45,11 @@ public class WebLauncher {
return UriBuilder.fromUri(ConfigBaseVariable.getlocalAddress()).build(); return UriBuilder.fromUri(ConfigBaseVariable.getlocalAddress()).build();
} }
public static void main(String[] args) throws InterruptedException { public static void main(String[] args) throws Exception {
WebLauncher.LOGGER.info("[START] application wake UP");
WebLauncher launcher = new WebLauncher(); WebLauncher launcher = new WebLauncher();
launcher.migrateDB();
launcher.process(); launcher.process();
WebLauncher.LOGGER.info("end-configure the server & wait finish process:"); WebLauncher.LOGGER.info("end-configure the server & wait finish process:");
Thread.currentThread().join(); Thread.currentThread().join();
@ -55,9 +57,15 @@ public class WebLauncher {
} }
public void migrateDB() throws Exception { public void migrateDB() throws Exception {
WebLauncher.LOGGER.info("Create migration engine");
MigrationEngine migrationEngine = new MigrationEngine(); MigrationEngine migrationEngine = new MigrationEngine();
WebLauncher.LOGGER.info("Add initialization");
migrationEngine.setInit(new Initialization()); migrationEngine.setInit(new Initialization());
WebLauncher.LOGGER.info("Add migration since last version");
// NOTHING for now
WebLauncher.LOGGER.info("Migrate the DB [START]");
migrationEngine.migrate(GlobalConfiguration.dbConfig); migrationEngine.migrate(GlobalConfiguration.dbConfig);
WebLauncher.LOGGER.info("Migrate the DB [STOP]");
} }
public void process() throws InterruptedException { public void process() throws InterruptedException {

View File

@ -10,7 +10,7 @@ public class WebLauncherEdgeLocal {
final Logger logger = LoggerFactory.getLogger(WebLauncherEdgeLocal.class); final Logger logger = LoggerFactory.getLogger(WebLauncherEdgeLocal.class);
private WebLauncherEdgeLocal() {} private WebLauncherEdgeLocal() {}
public static void main(String[] args) throws InterruptedException { public static void main(String[] args) throws Exception {
if (true) { if (true) {
// for local test: // for local test:
ConfigBaseVariable.apiAdress = "http://0.0.0.0:15080/karso/api/"; ConfigBaseVariable.apiAdress = "http://0.0.0.0:15080/karso/api/";

View File

@ -225,7 +225,8 @@ public class ApplicationResource {
@RolesAllowed(value= {"USER", "ADMIN"}) @RolesAllowed(value= {"USER", "ADMIN"})
public Response getClientToken(@Context SecurityContext sc, @QueryParam("application") String application) throws Exception { public Response getClientToken(@Context SecurityContext sc, @QueryParam("application") String application) throws Exception {
GenericContext gc = (GenericContext) sc.getUserPrincipal(); GenericContext gc = (GenericContext) sc.getUserPrincipal();
logger.debug("== USER ? {}", gc.userByToken); logger.info("get application TOKEN application name='{}'", application);
logger.debug("== USER ? {}", gc.userByToken.name);
if (application == null) { if (application == null) {
String result = "Input error missing parameter: 'application'"; String result = "Input error missing parameter: 'application'";
@ -285,7 +286,7 @@ public class ApplicationResource {
Map<String, Object> outRight = new HashMap<>(); Map<String, Object> outRight = new HashMap<>();
// we set the right in the under map to manage multiple application group right. and in some application user can see other user or all user of the application // we set the right in the under map to manage multiple application group right. and in some application user can see other user or all user of the application
outRight.put(applicationName, applicationRight); outRight.put(applicationName, applicationRight);
String ret = JWTWrapper.generateJWToken(gc.userByToken.id, gc.userByToken.name, "KarAuth", applicationName, outRight, appl.ttl); String ret = JWTWrapper.generateJWToken(gc.userByToken.id, gc.userByToken.name, "KarAuth", applicationName, outRight, -appl.ttl);
//logger.debug(" ==> generate token: {}", ret); //logger.debug(" ==> generate token: {}", ret);
String returnAdress = appl.redirect; String returnAdress = appl.redirect;
if (isDev) { if (isDev) {

View File

@ -109,10 +109,11 @@ public class ApplicationTokenResource {
@PathParam("applicationId") Long applicationId, @PathParam("applicationId") Long applicationId,
CreateRequest request CreateRequest request
) throws Exception { ) throws Exception {
logger.info("get user application TOKEN: app='{}' user='???'", applicationId);
// correct input string stream : // correct input string stream :
String name = multipartCorrection(request.name()); String name = multipartCorrection(request.name());
//validity = multipartCorrection(validity); //validity = multipartCorrection(validity);
logger.debug("create a nexw token..."); logger.debug("create a new token...");
if (applicationId == null) { if (applicationId == null) {
throw new InputException("applicationId", "can not be null"); throw new InputException("applicationId", "can not be null");
} }
@ -121,6 +122,7 @@ public class ApplicationTokenResource {
if (validity == null || validity < 0 || validity > maximum) { if (validity == null || validity < 0 || validity > maximum) {
validity = maximum; validity = maximum;
} }
logger.warn("validity= {}", validity);
// todo: set validity timestamp ... // todo: set validity timestamp ...
// TODO: check if application exist ... // TODO: check if application exist ...
ApplicationToken token = new ApplicationToken(); ApplicationToken token = new ApplicationToken();
@ -128,7 +130,9 @@ public class ApplicationTokenResource {
token.name = multipartCorrection(name); token.name = multipartCorrection(name);
token.parentId = applicationId; token.parentId = applicationId;
OffsetDateTime now = OffsetDateTime.now( ZoneOffset.UTC ); OffsetDateTime now = OffsetDateTime.now( ZoneOffset.UTC );
logger.warn("Check Timestamp now = {}", now);
token.endValidityTime = Timestamp.from(now.plusDays(validity).toInstant()); token.endValidityTime = Timestamp.from(now.plusDays(validity).toInstant());
logger.warn("token.endValidityTime = {}", token.endValidityTime);
// insert in the BDD // insert in the BDD
token = SqlWrapper.insert(token); token = SqlWrapper.insert(token);

View File

@ -306,6 +306,7 @@ public class UserResource {
@PermitAll @PermitAll
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public GetToken getToken(DataGetToken data) throws Exception { public GetToken getToken(DataGetToken data) throws Exception {
logger.info("User Authenticate: {}", data.login());
UserAuth user = checkAuthUser(data.method(), data.login(), data.time(), data.password()); UserAuth user = checkAuthUser(data.method(), data.login(), data.time(), data.password());
// at the point the user has been not deleted and not blocked. // at the point the user has been not deleted and not blocked.
// this authentication is valid only for Karso ==> not for the application // this authentication is valid only for Karso ==> not for the application
@ -322,6 +323,7 @@ public class UserResource {
String applicationName = "karso"; String applicationName = "karso";
// we set the right in the under map to manage multiple application group right. and in some application user can see other user or all user of the application // we set the right in the under map to manage multiple application group right. and in some application user can see other user or all user of the application
outRight.put(applicationName, ssoRight); outRight.put(applicationName, ssoRight);
// TODO: maybe correct this get of TTL...
String ret = JWTWrapper.generateJWToken(user.id, user.login, "KarAuth", applicationName, outRight, expirationTimeInMinutes); String ret = JWTWrapper.generateJWToken(user.id, user.login, "KarAuth", applicationName, outRight, expirationTimeInMinutes);
// Update last connection: // Update last connection:

View File

@ -0,0 +1,55 @@
package org.kar.karso.util;
public class Transform {
public static Object convertToType(String type, String value) {
if ("BOOLEAN".equals(type)) {
return Boolean.valueOf(value);
} else if ("STRING".equals(type)) {
return value;
} else if ("LONG".equals(type)) {
return Long.valueOf(value);
} else if ("NUMBER".equals(type)) {
return Double.valueOf(value);
} else {
return null;
}
}
public static String convertToStringCheck(String type, Object value) {
if ("BOOLEAN".equals(type)) {
if (value instanceof Boolean tmp) {
return String.valueOf(tmp);
}
} else if ("STRING".equals(type)) {
if (value instanceof String tmp) {
return tmp;
}
} else if ("LONG".equals(type)) {
if (value instanceof Long tmp) {
return String.valueOf(tmp);
} else if (value instanceof Integer tmp) {
return String.valueOf(tmp);
} else if (value instanceof Short tmp) {
return String.valueOf(tmp);
} else if (value instanceof Float tmp) {
return String.valueOf(Math.round(tmp));
} else if (value instanceof Double tmp) {
return String.valueOf(Math.round(tmp));
}
} else if ("NUMBER".equals(type)) {
if (value instanceof Long tmp) {
return String.valueOf(tmp);
} else if (value instanceof Integer tmp) {
return String.valueOf(tmp);
} else if (value instanceof Short tmp) {
return String.valueOf(tmp);
} else if (value instanceof Float tmp) {
return String.valueOf(tmp);
} else if (value instanceof Double tmp) {
return String.valueOf(tmp);
}
}
return null;
}
}

View File

@ -0,0 +1,35 @@
# SLF4J's SimpleLogger configuration file
# Simple implementation of Logger that sends all enabled log messages, for all defined loggers, to System.err.
# Default logging detail level for all instances of SimpleLogger.
# Must be one of ("trace", "debug", "info", "warn", or "error").
# If not specified, defaults to "info".
org.slf4j.simpleLogger.defaultLogLevel=trace
# Logging detail level for a SimpleLogger instance named "xxxxx".
# Must be one of ("trace", "debug", "info", "warn", or "error").
# If not specified, the default logging detail level is used.
#org.slf4j.simpleLogger.log.xxxxx=
# Set to true if you want the current date and time to be included in output messages.
# Default is false, and will output the number of milliseconds elapsed since startup.
#org.slf4j.simpleLogger.showDateTime=false
# The date and time format to be used in the output messages.
# The pattern describing the date and time format is the same that is used in java.text.SimpleDateFormat.
# If the format is not specified or is invalid, the default format is used.
# The default format is yyyy-MM-dd HH:mm:ss:SSS Z.
#org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss:SSS Z
# Set to true if you want to output the current thread name.
# Defaults to true.
org.slf4j.simpleLogger.showThreadName=true
# Set to true if you want the Logger instance name to be included in output messages.
# Defaults to true.
#org.slf4j.simpleLogger.showLogName=true
# Set to true if you want the last component of the name to be included in output messages.
# Defaults to false.
#org.slf4j.simpleLogger.showShortLogName=false