diff --git a/back/.classpath b/back/.classpath index bc0f9ef..3b18167 100644 --- a/back/.classpath +++ b/back/.classpath @@ -27,7 +27,6 @@ - diff --git a/back/.project b/back/.project index 3c43e57..182e0e3 100644 --- a/back/.project +++ b/back/.project @@ -10,16 +10,6 @@ - - org.eclipse.ui.externaltools.ExternalToolBuilder - full,incremental, - - - LaunchConfigHandle - <project>/.externalToolBuilders/org.eclipse.jdt.core.javabuilder.launch - - - org.eclipse.m2e.core.maven2Builder diff --git a/back/README.md b/back/README.md index ee2ee59..f50d714 100644 --- a/back/README.md +++ b/back/README.md @@ -11,7 +11,7 @@ mvn package // download all dependency in out/maven/dependency mvn dependency:copy-dependencies -java -cp out/maven/scenarium-karso-0.1.0.jar org.kar.oauth.WebLauncher +java -cp out/maven/kar-karso-0.1.0.jar org.kar.karso.WebLauncher // create a single package jar @@ -19,7 +19,7 @@ mvn clean compile assembly:single -java -cp out/maven/karso-0.1.0-jar-with-dependencies.jar org.kar.karso.WebLauncher +java -cp out/maven/karso-0.1.0-jar-with-dependencies.jar org.kar.karso.WebLauncher diff --git a/back/pom.xml b/back/pom.xml index f8be67b..61472ce 100644 --- a/back/pom.xml +++ b/back/pom.xml @@ -121,21 +121,13 @@ prepare-agent - report test report - + jacoco-check @@ -186,8 +178,49 @@ org.kar.karso.WebLauncher + + - @@ -202,4 +235,4 @@ - \ No newline at end of file + diff --git a/back/src/org/kar/karso/WebLauncher.java b/back/src/org/kar/karso/WebLauncher.java index 03363a0..99aba1c 100755 --- a/back/src/org/kar/karso/WebLauncher.java +++ b/back/src/org/kar/karso/WebLauncher.java @@ -19,7 +19,7 @@ import org.kar.archidata.catcher.SystemExceptionCatcher; import org.kar.archidata.filter.CORSFilter; import org.kar.archidata.filter.OptionFilter; import org.kar.archidata.migration.MigrationEngine; -import org.kar.archidata.migration.MigrationModel; +import org.kar.archidata.migration.model.Migration; import org.kar.archidata.util.ConfigBaseVariable; import org.kar.archidata.util.JWTWrapper; import org.kar.karso.api.ApplicationResource; @@ -54,13 +54,13 @@ public class WebLauncher { public WebLauncher() { ConfigBaseVariable.bdDatabase = "karso"; - backupEngine.addClass(MigrationModel.class); - backupEngine.addClass(Settings.class); - backupEngine.addClass(UserAuth.class); - backupEngine.addClass(Application.class); - backupEngine.addClass(ApplicationToken.class); - backupEngine.addClass(RightDescription.class); - backupEngine.addClass(Right.class); + this.backupEngine.addClass(Migration.class); + this.backupEngine.addClass(Settings.class); + this.backupEngine.addClass(UserAuth.class); + this.backupEngine.addClass(Application.class); + this.backupEngine.addClass(ApplicationToken.class); + this.backupEngine.addClass(RightDescription.class); + this.backupEngine.addClass(Right.class); } @@ -132,11 +132,12 @@ public class WebLauncher { //rc.property(LoggingFeature.LOGGING_FEATURE_LOGGER_LEVEL_SERVER, Level.WARNING.getName()); this.server = GrizzlyHttpServerFactory.createHttpServer(getBaseURI(), this.rc); + final HttpServer serverLink = this.server; Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { LOGGER.info("Stopping server.."); - WebLauncher.this.server.shutdownNow(); + serverLink.shutdownNow(); } }, "shutdownHook")); @@ -151,4 +152,11 @@ public class WebLauncher { e.printStackTrace(); } } + + public void stop() { + if (this.server != null) { + this.server.shutdownNow(); + this.server = null; + } + } } diff --git a/back/src/org/kar/karso/api/ApplicationResource.java b/back/src/org/kar/karso/api/ApplicationResource.java index fa456e9..1c9819d 100755 --- a/back/src/org/kar/karso/api/ApplicationResource.java +++ b/back/src/org/kar/karso/api/ApplicationResource.java @@ -5,13 +5,12 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.kar.archidata.annotation.security.RolesAllowed; +import org.kar.archidata.dataAccess.DataAccess; +import org.kar.archidata.dataAccess.QueryAnd; +import org.kar.archidata.dataAccess.QueryCondition; +import org.kar.archidata.dataAccess.addOn.AddOnManyToMany; import org.kar.archidata.exception.InputException; import org.kar.archidata.filter.GenericContext; -import org.kar.archidata.sqlWrapper.QuerryAnd; -import org.kar.archidata.sqlWrapper.QuerryCondition; -import org.kar.archidata.sqlWrapper.SqlWrapper; -import org.kar.archidata.sqlWrapper.addOn.AddOnManyToMany; import org.kar.archidata.util.JWTWrapper; import org.kar.karso.model.Application; import org.kar.karso.model.ApplicationSmall; @@ -21,6 +20,7 @@ import org.kar.karso.model.UserLinkApplication; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import jakarta.annotation.security.RolesAllowed; import jakarta.ws.rs.Consumes; import jakarta.ws.rs.DELETE; import jakarta.ws.rs.GET; @@ -39,14 +39,14 @@ import jakarta.ws.rs.core.SecurityContext; @Produces(MediaType.APPLICATION_JSON) public class ApplicationResource { final Logger logger = LoggerFactory.getLogger(ApplicationResource.class); - + public ApplicationResource() {} - + public List getUserListOfApplication(final Long userId) { final List out = new ArrayList<>(); List links = null; try { - links = SqlWrapper.getsWhere(UserLinkApplication.class, new QuerryCondition("user_id", "=", userId)); + links = DataAccess.getsWhere(UserLinkApplication.class, new QueryCondition("user_id", "=", userId)); } catch (final Exception e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -64,7 +64,7 @@ public class ApplicationResource { final List out = new ArrayList<>(); List links = null; try { - links = SqlWrapper.getsWhere(UserLinkApplication.class, new QuerryCondition("application_id", "=", applicationId)); + links = DataAccess.getsWhere(UserLinkApplication.class, new QueryCondition("application_id", "=", applicationId)); } catch (final Exception e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -83,14 +83,14 @@ public class ApplicationResource { // Generic /application/ // //////////////////////////////////////////////////////////////////////////////////////// - + @GET @RolesAllowed(value = { "USER", "ADMIN" }) public List getApplications(@Context final SecurityContext sc) throws Exception { final GenericContext gc = (GenericContext) sc.getUserPrincipal(); this.logger.debug("getApplications"); // TODO filter with the list of element available in his authorizations ... - final List tmp = SqlWrapper.gets(Application.class); + final List tmp = DataAccess.gets(Application.class); if (gc.userByToken.hasRight("ADMIN", true)) { return tmp; } @@ -103,7 +103,7 @@ public class ApplicationResource { } return out; } - + @POST @RolesAllowed("ADMIN") public Application create(final Application application) throws Exception { @@ -119,68 +119,68 @@ public class ApplicationResource { application.createdAt = null; application.deleted = null; application.updatedAt = null; - return SqlWrapper.insert(application); + return DataAccess.insert(application); } - + //////////////////////////////////////////////////////////////////////////////////////// // // Generic /application/{id} // //////////////////////////////////////////////////////////////////////////////////////// - + @GET @Path("{id}") @RolesAllowed("ADMIN") public Application get(@PathParam("id") final Long id) throws Exception { - return SqlWrapper.get(Application.class, id); + return DataAccess.get(Application.class, id); } - + @PUT @Path("{id}") @RolesAllowed("ADMIN") @Consumes(MediaType.APPLICATION_JSON) public Application put(@PathParam("id") final Long id, final String jsonRequest) throws Exception { - SqlWrapper.update(Application.class, id, jsonRequest); - return SqlWrapper.get(Application.class, id); + DataAccess.updateWithJson(Application.class, id, jsonRequest); + return DataAccess.get(Application.class, id); } - + @DELETE @Path("{id}") @RolesAllowed("ADMIN") @Produces(value = MediaType.TEXT_PLAIN) public void remove(@Context final SecurityContext sc, @PathParam("id") final long applicationId) throws Exception { - SqlWrapper.delete(Application.class, applicationId); + DataAccess.delete(Application.class, applicationId); } - + //////////////////////////////////////////////////////////////////////////////////////// // // Generic /{id}/* // //////////////////////////////////////////////////////////////////////////////////////// - + @GET @Path("{id}/users") @RolesAllowed(value = { "ADMIN" }) public List getApplicationUsers(@PathParam("id") final Long applicationId) throws Exception { // special case for SSO: (all user have access on the SSO...). - + this.logger.debug("Request list of user for an applciation: {}", applicationId); return getListOfUsers(applicationId); } - + //////////////////////////////////////////////////////////////////////////////////////// // // Generic /application/* // //////////////////////////////////////////////////////////////////////////////////////// - + @GET @Path("small") @RolesAllowed(value = { "USER", "ADMIN" }) public List getApplicationsSmall(@Context final SecurityContext sc) throws Exception { final GenericContext gc = (GenericContext) sc.getUserPrincipal(); this.logger.debug("getApplications"); - final List tmp = SqlWrapper.gets(Application.class); + final List tmp = DataAccess.gets(Application.class); final List regular = getUserListOfApplication(gc.userByToken.id); final List out = new ArrayList<>(); for (final Application app : tmp) { @@ -190,10 +190,10 @@ public class ApplicationResource { } return out; } - + public record AddUserData( long userId) {}; - + // TODO : review the function to correct admin only access... @POST @Path("{id}/users") @@ -203,7 +203,7 @@ public class ApplicationResource { AddOnManyToMany.addLink(UserAuth.class, data.userId, "application", applicationId); return true; } - + // TODO : review the function to correct admin only access... @DELETE @Path("{id}/users") @@ -213,16 +213,16 @@ public class ApplicationResource { AddOnManyToMany.removeLink(UserAuth.class, data.userId, "application", applicationId); return true; } - + // TODO : review the function to correct admin only access... @GET @Path("{id}/rights") @RolesAllowed(value = { "ADMIN" }) public List getRightsDescription(@PathParam("id") final Long applicationId) throws Exception { this.logger.debug("getApplications rights"); - return SqlWrapper.getsWhere(RightDescription.class, new QuerryCondition("applicationId", "=", applicationId)); + return DataAccess.getsWhere(RightDescription.class, new QueryCondition("applicationId", "=", applicationId)); } - + @GET @Path("get_token") @RolesAllowed(value = { "USER", "ADMIN" }) @@ -230,7 +230,7 @@ public class ApplicationResource { final GenericContext gc = (GenericContext) sc.getUserPrincipal(); this.logger.info("get application TOKEN application name='{}'", application); this.logger.debug("== USER ? {}", gc.userByToken.name); - + if (application == null) { final String result = "Input error missing parameter: 'application'"; this.logger.debug(" result: {}", result); @@ -243,10 +243,10 @@ public class ApplicationResource { isDev = true; } this.logger.debug("Search for '{}' base of '{}'", applicationName, application); - + Application appl = null; try { - appl = SqlWrapper.getWhere(Application.class, new QuerryCondition("name", "=", applicationName)); + appl = DataAccess.getWhere(Application.class, new QueryCondition("name", "=", applicationName)); } catch (final Exception e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -254,7 +254,7 @@ public class ApplicationResource { this.logger.debug(" result: {}", result); return Response.status(500).entity(result).build(); } - + if (appl == null) { final String result = "Authentiocate-wrong email/login '" + applicationName + "')"; this.logger.error(" result: {}", result); @@ -262,8 +262,8 @@ public class ApplicationResource { } UserLinkApplication links = null; try { - links = SqlWrapper.getWhere(UserLinkApplication.class, - new QuerryAnd(new QuerryCondition("user_id", "=", gc.userByToken.id), new QuerryCondition("deleted", "=", 0), new QuerryCondition("application_id", "=", appl.id))); + links = DataAccess.getWhere(UserLinkApplication.class, + new QueryAnd(new QueryCondition("user_id", "=", gc.userByToken.id), new QueryCondition("deleted", "=", 0), new QueryCondition("application_id", "=", appl.id))); } catch (final Exception e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -293,7 +293,7 @@ public class ApplicationResource { } return Response.status(201).entity("{ \"url\":\"" + returnAdress + "\", \"jwt\":\"" + ret + "\"}").build(); } - + @GET @Path("return") @RolesAllowed(value = { "USER", "ADMIN" }) @@ -303,7 +303,7 @@ public class ApplicationResource { this.logger.debug("====================================="); final GenericContext gc = (GenericContext) sc.getUserPrincipal(); this.logger.debug("== USER ? {}", gc.userByToken); - + if (application == null) { final String result = "Input error missing parameter: 'application'"; this.logger.error(" result: {}", result); @@ -316,10 +316,10 @@ public class ApplicationResource { isDev = true; } this.logger.debug("Search for '{}' base of '{}'", applicationName, application); - + Application appl = null; try { - appl = SqlWrapper.getWhere(Application.class, new QuerryCondition("name", "=", applicationName)); + appl = DataAccess.getWhere(Application.class, new QueryCondition("name", "=", applicationName)); } catch (final Exception e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -327,7 +327,7 @@ public class ApplicationResource { this.logger.error(" result: {}", result); return Response.status(500).entity(result).build(); } - + if (appl == null) { final String result = "Authentiocate-wrong email/login '" + applicationName + "')"; this.logger.error(" result: {}", result); @@ -339,5 +339,5 @@ public class ApplicationResource { } return Response.status(201).entity("{ \"url\":\"" + returnAdress + "\"}").build(); } - + } diff --git a/back/src/org/kar/karso/api/ApplicationTokenResource.java b/back/src/org/kar/karso/api/ApplicationTokenResource.java index a0856c8..be09ca2 100755 --- a/back/src/org/kar/karso/api/ApplicationTokenResource.java +++ b/back/src/org/kar/karso/api/ApplicationTokenResource.java @@ -5,15 +5,15 @@ import java.time.OffsetDateTime; import java.time.ZoneOffset; import java.util.List; -import org.kar.archidata.annotation.security.RolesAllowed; +import org.kar.archidata.dataAccess.DataAccess; +import org.kar.archidata.dataAccess.QueryAnd; +import org.kar.archidata.dataAccess.QueryCondition; import org.kar.archidata.exception.InputException; -import org.kar.archidata.sqlWrapper.QuerryAnd; -import org.kar.archidata.sqlWrapper.QuerryCondition; -import org.kar.archidata.sqlWrapper.SqlWrapper; import org.kar.karso.model.ApplicationToken; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import jakarta.annotation.security.RolesAllowed; import jakarta.ws.rs.DELETE; import jakarta.ws.rs.GET; import jakarta.ws.rs.POST; @@ -29,32 +29,32 @@ import jakarta.ws.rs.core.SecurityContext; @Produces(MediaType.APPLICATION_JSON) public class ApplicationTokenResource { final Logger logger = LoggerFactory.getLogger(ApplicationTokenResource.class); - + public ApplicationTokenResource() {} - + //////////////////////////////////////////////////////////////////////////////////////// // // Generic /application_token/{applicationId} // //////////////////////////////////////////////////////////////////////////////////////// - + @GET @Path("{applicationId}") @RolesAllowed(value = { "ADMIN" }) public List gets(@Context final SecurityContext sc, @PathParam("applicationId") final Long applicationId) throws Exception { - final List values = SqlWrapper.getsWhere(ApplicationToken.class, new QuerryCondition("parentId", "=", applicationId)); + final List values = DataAccess.getsWhere(ApplicationToken.class, new QueryCondition("parentId", "=", applicationId)); // clean all tokens this is a secret: for (final ApplicationToken elem : values) { elem.token = null; } return values; } - + @DELETE @Path("{applicationId}/{tokenId}") @RolesAllowed(value = { "ADMIN" }) public Response delete(@Context final SecurityContext sc, @PathParam("applicationId") final Long applicationId, @PathParam("tokenId") final Integer tokenId) throws Exception { - final int nbRemoved = SqlWrapper.setDeleteWhere(ApplicationToken.class, new QuerryAnd(new QuerryCondition("parentId", "=", applicationId), new QuerryCondition("id", "=", tokenId))); + final int nbRemoved = DataAccess.deleteWhere(ApplicationToken.class, new QueryAnd(new QueryCondition("parentId", "=", applicationId), new QueryCondition("id", "=", tokenId)), null); if (nbRemoved == 0) { return Response.notModified("{}").build(); } @@ -76,7 +76,7 @@ public class ApplicationTokenResource { } return data; } - + static String randomToken() { final int len = 48; final String valid_element = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvxyz0123456789#_@-~*!?"; @@ -91,11 +91,11 @@ public class ApplicationTokenResource { } return out.toString(); } - + public record CreateRequest( String name, Integer validity) {}; - + @POST @Path("/{applicationId}/create") @RolesAllowed("ADMIN") @@ -124,9 +124,9 @@ public class ApplicationTokenResource { this.logger.warn("Check Timestamp now = {}", now); token.endValidityTime = Timestamp.from(now.plusDays(validity).toInstant()); this.logger.warn("token.endValidityTime = {}", token.endValidityTime); - + // insert in the BDD - token = SqlWrapper.insert(token); + token = DataAccess.insert(token); // here we return the token to permit to the user to see it to set it in the application. return token; } diff --git a/back/src/org/kar/karso/api/HealthCheck.java b/back/src/org/kar/karso/api/HealthCheck.java index 3702b71..a024028 100644 --- a/back/src/org/kar/karso/api/HealthCheck.java +++ b/back/src/org/kar/karso/api/HealthCheck.java @@ -1,20 +1,32 @@ package org.kar.karso.api; -import org.kar.archidata.annotation.security.PermitAll; +import org.kar.archidata.exception.FailException; +import org.kar.archidata.util.ConfigBaseVariable; +import org.kar.archidata.util.JWTWrapper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import jakarta.ws.rs.*; +import jakarta.annotation.security.PermitAll; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; @Path("/health_check") @Produces(MediaType.APPLICATION_JSON) public class HealthCheck { final static Logger LOGGER = LoggerFactory.getLogger(HealthCheck.class); - public record HealthResult(String value) {}; - @GET - @PermitAll - public HealthResult getHealth() { - return new HealthResult("alive and kicking"); - } + + public record HealthResult( + String value) {}; + + @GET + @PermitAll + public HealthResult getHealth() throws FailException { + if (JWTWrapper.getPublicKeyJson() == null && !ConfigBaseVariable.getTestMode()) { + throw new FailException(Response.Status.INTERNAL_SERVER_ERROR, "Missing Jwt public token"); + } + return new HealthResult("alive and kicking"); + } } diff --git a/back/src/org/kar/karso/api/PublicKeyResource.java b/back/src/org/kar/karso/api/PublicKeyResource.java index fb306a5..b0d7c9b 100755 --- a/back/src/org/kar/karso/api/PublicKeyResource.java +++ b/back/src/org/kar/karso/api/PublicKeyResource.java @@ -1,5 +1,8 @@ package org.kar.karso.api; +import java.security.interfaces.RSAPublicKey; +import java.util.Base64; + import org.kar.archidata.util.JWTWrapper; import org.kar.archidata.util.JWTWrapper.PublicKey; import org.slf4j.Logger; @@ -7,26 +10,25 @@ import org.slf4j.LoggerFactory; import com.nimbusds.jose.JOSEException; -import org.kar.archidata.annotation.security.RolesAllowed; - -import java.security.interfaces.RSAPublicKey; -import java.util.Base64; - -import jakarta.ws.rs.*; +import jakarta.annotation.security.RolesAllowed; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; import jakarta.ws.rs.core.MediaType; @Path("/public_key") @Produces(MediaType.APPLICATION_JSON) public class PublicKeyResource { final Logger logger = LoggerFactory.getLogger(PublicKeyResource.class); - + public PublicKeyResource() { - + } + // This is for java server that use the same implementation // curl http://localhost:9993/public_key @GET - @RolesAllowed(value= {"APPLICATION"}) + @RolesAllowed(value = { "APPLICATION" }) public PublicKey getKey() { return new PublicKey(JWTWrapper.getPublicKeyJson()); } @@ -34,13 +36,12 @@ public class PublicKeyResource { // This is for common other interface that support public PEM stream. // curl http://localhost:9993/public_key/pem @GET - @Path("/pem") - @RolesAllowed(value= {"APPLICATION"}) + @Path("/pem") + @RolesAllowed(value = { "APPLICATION" }) public String getKeyPem() throws JOSEException { - RSAPublicKey keyPub = JWTWrapper.getPublicKeyJava(); - byte[] data = keyPub.getEncoded(); - String base64encoded = new String(Base64.getEncoder().encode(data)); + final RSAPublicKey keyPub = JWTWrapper.getPublicKeyJava(); + final byte[] data = keyPub.getEncoded(); + final String base64encoded = new String(Base64.getEncoder().encode(data)); return "-----BEGIN PUBLIC KEY-----\n" + base64encoded + "\n-----END PUBLIC KEY-----\n"; } } - diff --git a/back/src/org/kar/karso/api/RightResource.java b/back/src/org/kar/karso/api/RightResource.java index a073671..fa811c9 100644 --- a/back/src/org/kar/karso/api/RightResource.java +++ b/back/src/org/kar/karso/api/RightResource.java @@ -4,16 +4,16 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.kar.archidata.annotation.security.RolesAllowed; -import org.kar.archidata.sqlWrapper.QuerryAnd; -import org.kar.archidata.sqlWrapper.QuerryCondition; -import org.kar.archidata.sqlWrapper.SqlWrapper; +import org.kar.archidata.dataAccess.DataAccess; +import org.kar.archidata.dataAccess.QueryAnd; +import org.kar.archidata.dataAccess.QueryCondition; import org.kar.karso.model.Right; import org.kar.karso.model.RightDescription; import org.kar.karso.util.Transform; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import jakarta.annotation.security.RolesAllowed; import jakarta.ws.rs.Consumes; import jakarta.ws.rs.DELETE; import jakarta.ws.rs.GET; @@ -29,13 +29,13 @@ import jakarta.ws.rs.core.Response; @Produces({ MediaType.APPLICATION_JSON }) public class RightResource { final static Logger logger = LoggerFactory.getLogger(RightResource.class); - + public static List getApplicationRightDecription(final long applicationId) throws Exception { - return SqlWrapper.getsWhere(RightDescription.class, new QuerryCondition("applicationId", "=", applicationId)); + return DataAccess.getsWhere(RightDescription.class, new QueryCondition("applicationId", "=", applicationId)); } - + public static List getRawUserRight(final long userId, final long applicationId) throws Exception { - return SqlWrapper.getsWhere(Right.class, new QuerryAnd(new QuerryCondition("applicationId", "=", applicationId), new QuerryCondition("userId", "=", userId))); + return DataAccess.getsWhere(Right.class, new QueryAnd(new QueryCondition("applicationId", "=", applicationId), new QueryCondition("userId", "=", userId))); } public static Map getUserRight(final long userId, final long applicationId) throws Exception { @@ -54,7 +54,7 @@ public class RightResource { logger.debug(" - id={} key={} type={} default={}", elem.id, elem.key, elem.type, elem.defaultValue); } for (final RightDescription description : rightsDescriptions) { - + if (description == null) { // TODO: this is a really strange case to manage later... continue; @@ -74,7 +74,7 @@ public class RightResource { } return out; } - + public static void updateUserRight(final long userId, final long applicationId, final Map delta) throws Exception { final List rightsDescriptions = getApplicationRightDecription(applicationId); logger.debug("Get some descriptions: {} applicationId={}", rightsDescriptions.size(), applicationId); @@ -102,7 +102,7 @@ public class RightResource { // The value exist, we need to update it logger.debug("Request update a knonwn parameter: {} with {}", description.key, newValue); right.value = convertedValue; - SqlWrapper.update(right, right.id, List.of("value")); + DataAccess.update(right, right.id, List.of("value")); } else { // we need to create it logger.debug("Request create parameter: {} with {}", description.key, newValue); @@ -111,46 +111,46 @@ public class RightResource { right.userId = userId; right.rightDescriptionId = description.id; right.value = convertedValue; - SqlWrapper.insert(right); + DataAccess.insert(right); } } } - + @GET @RolesAllowed("ADMIN") public List get() throws Exception { - return SqlWrapper.gets(Right.class); + return DataAccess.gets(Right.class); } - + @POST @RolesAllowed("ADMIN") @Consumes(MediaType.APPLICATION_JSON) public Right post(final String jsonRequest) throws Exception { - return SqlWrapper.insertWithJson(Right.class, jsonRequest); + return DataAccess.insertWithJson(Right.class, jsonRequest); } - + @GET @Path("{id}") @RolesAllowed("ADMIN") public static Right getWithId(@PathParam("id") final Long id) throws Exception { - return SqlWrapper.get(Right.class, id); + return DataAccess.get(Right.class, id); } - + @PUT @Path("{id}") @RolesAllowed("ADMIN") @Consumes(MediaType.APPLICATION_JSON) public Right put(@PathParam("id") final Long id, final String jsonRequest) throws Exception { - SqlWrapper.update(Right.class, id, jsonRequest); - return SqlWrapper.get(Right.class, id); + DataAccess.updateWithJson(Right.class, id, jsonRequest); + return DataAccess.get(Right.class, id); } - + @DELETE @Path("{id}") @RolesAllowed("ADMIN") public Response delete(@PathParam("id") final Long id) throws Exception { - SqlWrapper.delete(Right.class, id); + DataAccess.delete(Right.class, id); return Response.ok().build(); } - + } diff --git a/back/src/org/kar/karso/api/SystemConfigResource.java b/back/src/org/kar/karso/api/SystemConfigResource.java index af5a29a..6fedf68 100755 --- a/back/src/org/kar/karso/api/SystemConfigResource.java +++ b/back/src/org/kar/karso/api/SystemConfigResource.java @@ -2,11 +2,9 @@ package org.kar.karso.api; import java.util.List; -import org.kar.archidata.annotation.security.PermitAll; -import org.kar.archidata.annotation.security.RolesAllowed; +import org.kar.archidata.dataAccess.DataAccess; +import org.kar.archidata.dataAccess.QueryCondition; import org.kar.archidata.exception.NotFoundException; -import org.kar.archidata.sqlWrapper.QuerryCondition; -import org.kar.archidata.sqlWrapper.SqlWrapper; import org.kar.karso.model.Settings; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -14,6 +12,8 @@ import org.slf4j.LoggerFactory; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import jakarta.annotation.security.PermitAll; +import jakarta.annotation.security.RolesAllowed; import jakarta.ws.rs.Consumes; import jakarta.ws.rs.GET; import jakarta.ws.rs.PUT; @@ -40,7 +40,6 @@ public class SystemConfigResource { public GetSignUpAvaillable() { this.signup = false; } - } public SystemConfigResource() {} @@ -49,7 +48,7 @@ public class SystemConfigResource { @Path("is_sign_up_availlable") @PermitAll public GetSignUpAvaillable isSignUpAvaillable() throws Exception { - final Settings set = SqlWrapper.getWhere(Settings.class, new QuerryCondition("key", "=", "SIGN_UP_ENABLE")); + final Settings set = DataAccess.getWhere(Settings.class, new QueryCondition("key", "=", "SIGN_UP_ENABLE")); if (set == null) { throw new NotFoundException("Value does not exist"); } @@ -63,7 +62,7 @@ public class SystemConfigResource { @Path("key/{key}") @RolesAllowed(value = { "USER", "ADMIN" }) public Response getKey(@Context final SecurityContext sc, @PathParam("key") final String key) throws Exception { - final Settings set = SqlWrapper.getWhere(Settings.class, new QuerryCondition("key", "=", key)); + final Settings set = DataAccess.getWhere(Settings.class, new QueryCondition("key", "=", key)); if (set == null) { throw new NotFoundException("Value does not exist"); } @@ -85,7 +84,7 @@ public class SystemConfigResource { public Response setKey(@Context final SecurityContext sc, @PathParam("key") final String key, final String jsonRequest) throws Exception { Settings res = null; try { - res = SqlWrapper.getWhere(Settings.class, new QuerryCondition("key", "=", key)); + res = DataAccess.getWhere(Settings.class, new QueryCondition("key", "=", key)); } catch (final Exception e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -99,7 +98,7 @@ public class SystemConfigResource { res.value = value.asText(); this.logger.debug("Update value : {}", res.value); - SqlWrapper.update(res, res.id, List.of("value")); + DataAccess.update(res, res.id, List.of("value")); return Response.status(201).entity("{ \"value\":\"" + res.value + "\"}").build(); } diff --git a/back/src/org/kar/karso/api/UserResource.java b/back/src/org/kar/karso/api/UserResource.java index a1f9040..2d1c772 100755 --- a/back/src/org/kar/karso/api/UserResource.java +++ b/back/src/org/kar/karso/api/UserResource.java @@ -9,16 +9,14 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.kar.archidata.annotation.security.PermitAll; -import org.kar.archidata.annotation.security.RolesAllowed; +import org.kar.archidata.dataAccess.DataAccess; +import org.kar.archidata.dataAccess.QueryCondition; +import org.kar.archidata.dataAccess.addOn.AddOnManyToMany; import org.kar.archidata.exception.FailException; import org.kar.archidata.exception.InputException; import org.kar.archidata.exception.SystemException; import org.kar.archidata.filter.GenericContext; import org.kar.archidata.model.GetToken; -import org.kar.archidata.sqlWrapper.QuerryCondition; -import org.kar.archidata.sqlWrapper.SqlWrapper; -import org.kar.archidata.sqlWrapper.addOn.AddOnManyToMany; import org.kar.archidata.util.JWTWrapper; import org.kar.karso.migration.Initialization; import org.kar.karso.model.ChangePassword; @@ -32,6 +30,8 @@ import org.slf4j.LoggerFactory; import com.fasterxml.jackson.annotation.JsonInclude; +import jakarta.annotation.security.PermitAll; +import jakarta.annotation.security.RolesAllowed; import jakarta.ws.rs.Consumes; import jakarta.ws.rs.GET; import jakarta.ws.rs.NotFoundException; @@ -60,15 +60,14 @@ public class UserResource { this.id = id; this.login = login; } - } - + public UserResource() {} @GET @RolesAllowed("ADMIN") public List getUsers() throws Exception { - return SqlWrapper.gets(UserAuthGet.class); + return DataAccess.gets(UserAuthGet.class); } @GET @@ -76,7 +75,7 @@ public class UserResource { @RolesAllowed("ADMIN") public UserAuthGet getUser(@Context final SecurityContext sc, @PathParam("id") final long userId) throws Exception { //GenericContext gc = (GenericContext) sc.getUserPrincipal(); - return SqlWrapper.get(UserAuthGet.class, userId); + return DataAccess.get(UserAuthGet.class, userId); } @POST @@ -90,7 +89,7 @@ public class UserResource { } else { AddOnManyToMany.removeLink(UserAuth.class, userId, "application", applicationId); } - return SqlWrapper.get(UserAuth.class, userId); + return DataAccess.get(UserAuth.class, userId); } @GET @@ -117,7 +116,7 @@ public class UserResource { public Response setAdmin(@Context final SecurityContext sc, @PathParam("id") final long userId, final boolean data) throws Exception { final UserAuth user = new UserAuth(); user.admin = data; - final int ret = SqlWrapper.update(user, userId, List.of("admin")); + final int ret = DataAccess.update(user, userId, List.of("admin")); if (ret == 0) { return Response.notModified("{}").build(); } @@ -130,7 +129,7 @@ public class UserResource { public Response setBlocked(@Context final SecurityContext sc, @PathParam("id") final long userId, final boolean data) throws Exception { final UserAuth user = new UserAuth(); user.blocked = data; - final int ret = SqlWrapper.update(user, userId, List.of("blocked")); + final int ret = DataAccess.update(user, userId, List.of("blocked")); if (ret == 0) { return Response.notModified("{}").build(); } @@ -159,12 +158,12 @@ public class UserResource { // TODO: verify if the data are a hash ... // Check login does not exist - List out = SqlWrapper.getsWhere(UserAuth.class, new QuerryCondition("login", "=", user.login)); + List out = DataAccess.getsWhere(UserAuth.class, new QueryCondition("login", "=", user.login)); if (out.size() >= 1) { throw new FailException(Response.Status.BAD_REQUEST, "Login already used !!!"); } // Check email does not exist - out = SqlWrapper.getsWhere(UserAuth.class, new QuerryCondition("email", "=", user.email)); + out = DataAccess.getsWhere(UserAuth.class, new QueryCondition("email", "=", user.email)); if (out.size() >= 1) { throw new FailException(Response.Status.BAD_REQUEST, "e-mail already used !!!"); } @@ -179,9 +178,9 @@ public class UserResource { newUser.password = user.password; newUser.email = user.email; newUser.lastConnection = Timestamp.valueOf(LocalDateTime.now()); - final UserAuth tmp = SqlWrapper.insert(newUser); + final UserAuth tmp = DataAccess.insert(newUser); this.logger.debug("create new user done with id=={}", tmp.id); - return SqlWrapper.get(UserAuthGet.class, tmp.id); + return DataAccess.get(UserAuthGet.class, tmp.id); } @GET @@ -214,7 +213,7 @@ public class UserResource { } // Process the update: user.password = data.newPassword; - SqlWrapper.update(user, user.id, List.of("password")); + DataAccess.update(user, user.id, List.of("password")); return Response.status(Response.Status.OK).build(); } @@ -240,7 +239,7 @@ public class UserResource { @PermitAll public Response checkLogin(@QueryParam("login") final String login) throws Exception { this.logger.debug("checkLogin: '{}'", login); - final List out = SqlWrapper.getsWhere(UserAuth.class, new QuerryCondition("login", "=", login)); + final List out = DataAccess.getsWhere(UserAuth.class, new QueryCondition("login", "=", login)); if (out.size() >= 1) { return Response.ok().build(); } @@ -253,7 +252,7 @@ public class UserResource { @PermitAll public Response checkEmail(@QueryParam("email") final String email) throws Exception { this.logger.debug("checkEmail: {}", email); - final List out = SqlWrapper.getsWhere(UserAuth.class, new QuerryCondition("email", "=", email)); + final List out = DataAccess.getsWhere(UserAuth.class, new QueryCondition("email", "=", email)); if (out.size() >= 1) { return Response.ok().build(); } @@ -277,7 +276,7 @@ public class UserResource { if (login.contains("@")) { query = "email"; } - final UserAuth user = SqlWrapper.getWhere(UserAuth.class, new QuerryCondition(query, "=", login)); + final UserAuth user = DataAccess.getWhere(UserAuth.class, new QueryCondition(query, "=", login)); if (user == null) { throw new FailException(Response.Status.PRECONDITION_FAILED, "FAIL Authentiocate-wrong email/login '" + login + "')"); @@ -322,7 +321,7 @@ public class UserResource { // Update last connection: final UserAuth newUser = new UserAuth(); newUser.lastConnection = Timestamp.valueOf(LocalDateTime.now()); - SqlWrapper.update(newUser, user.id, List.of("lastConnection")); + DataAccess.update(newUser, user.id, List.of("lastConnection")); //logger.debug(" ==> generate token: {}", ret); return new GetToken(ret); diff --git a/back/src/org/kar/karso/filter/KarsoAuthenticationFilter.java b/back/src/org/kar/karso/filter/KarsoAuthenticationFilter.java index f70db67..74994c4 100644 --- a/back/src/org/kar/karso/filter/KarsoAuthenticationFilter.java +++ b/back/src/org/kar/karso/filter/KarsoAuthenticationFilter.java @@ -3,9 +3,9 @@ package org.kar.karso.filter; import java.sql.Timestamp; import java.time.Instant; +import org.kar.archidata.dataAccess.DataAccess; import org.kar.archidata.filter.AuthenticationFilter; import org.kar.archidata.model.UserByToken; -import org.kar.archidata.sqlWrapper.SqlWrapper; import org.kar.karso.model.ApplicationToken; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,7 +39,7 @@ public class KarsoAuthenticationFilter extends AuthenticationFilter { } final Long indexToken = Long.parseLong(elems[0]); - final ApplicationToken value = SqlWrapper.get(ApplicationToken.class, indexToken); + final ApplicationToken value = DataAccess.get(ApplicationToken.class, indexToken); if (value == null) { System.out.println("Application authentication can not find id '" + authorization + "'"); return null; diff --git a/back/src/org/kar/karso/migration/Initialization.java b/back/src/org/kar/karso/migration/Initialization.java index 21ff299..5d1b1f2 100644 --- a/back/src/org/kar/karso/migration/Initialization.java +++ b/back/src/org/kar/karso/migration/Initialization.java @@ -9,14 +9,14 @@ import org.kar.karso.model.Settings; import org.kar.karso.model.UserAuth; public class Initialization extends MigrationSqlStep { - + public static final int KARSO_INITIALISATION_ID = 1; - + @Override public String getName() { return "Initialization"; } - + public Initialization() throws Exception { addClass(Settings.class); addClass(UserAuth.class); @@ -24,7 +24,7 @@ public class Initialization extends MigrationSqlStep { addClass(ApplicationToken.class); addClass(RightDescription.class); addClass(Right.class); - + addAction(""" INSERT INTO `application` (`id`, `name`, `description`, `redirect`, `redirectDev`, `notification`, `ttl`) VALUES (1, 'karso', 'Root SSO interface', 'http://atria-soft/karso', '', '', 666); @@ -36,7 +36,7 @@ public class Initialization extends MigrationSqlStep { 'admin@admin.ZZZ', 1); """); addAction(""" - INSERT INTO `user_link_application` (`user_id`, `application_id`) + INSERT INTO `user_link_application` (`object1Id`, `object2Id`) VALUES ('1', '1'); """); addAction(""" @@ -72,5 +72,5 @@ public class Initialization extends MigrationSqlStep { """, "mysql"); display(); } - + } diff --git a/back/src/org/kar/karso/model/Application.java b/back/src/org/kar/karso/model/Application.java index 57492d6..36963bd 100644 --- a/back/src/org/kar/karso/model/Application.java +++ b/back/src/org/kar/karso/model/Application.java @@ -10,10 +10,10 @@ CREATE TABLE `application` ( */ -import org.kar.archidata.annotation.SQLComment; -import org.kar.archidata.annotation.SQLDefault; -import org.kar.archidata.annotation.SQLIfNotExists; -import org.kar.archidata.model.GenericTableSoftDelete; +import org.kar.archidata.annotation.DataComment; +import org.kar.archidata.annotation.DataDefault; +import org.kar.archidata.annotation.DataIfNotExists; +import org.kar.archidata.model.GenericDataSoftDelete; import com.fasterxml.jackson.annotation.JsonInclude; @@ -21,9 +21,9 @@ import jakarta.persistence.Column; import jakarta.persistence.Table; @Table(name = "application") -@SQLIfNotExists +@DataIfNotExists @JsonInclude(JsonInclude.Include.NON_NULL) -public class Application extends GenericTableSoftDelete { +public class Application extends GenericDataSoftDelete { @Column(length = 256) public String name; @Column(length = 2048) @@ -31,22 +31,22 @@ public class Application extends GenericTableSoftDelete { @Column(length = 2048, nullable = false) public String redirect; @Column(length = 2048) - @SQLDefault("'http://localhost:4200/sso/'") + @DataDefault("'http://localhost:4200/sso/'") public String redirectDev; @Column(length = 2048) - @SQLDefault("'http://localhost:4200/sso/notification'") + @DataDefault("'http://localhost:4200/sso/notification'") public String notification; @Column(nullable = false) - @SQLComment("Expiration time ") - @SQLDefault("666") + @DataComment("Expiration time ") + @DataDefault("666") public Integer ttl; @Column(nullable = false) - @SQLComment("Right is manage with Karso") - @SQLDefault("0") + @DataComment("Right is manage with Karso") + @DataDefault("0") public Boolean manageRight; - + public Application() {} - + @Override public String toString() { return "Application{" + "id=" + this.id + ", description='" + this.description + '\'' + ", redirect='" + this.redirect + '\'' + ", redirectDev='" + this.redirectDev + '\'' + ", notification='" diff --git a/back/src/org/kar/karso/model/ApplicationToken.java b/back/src/org/kar/karso/model/ApplicationToken.java index afcfeb6..871f8dd 100644 --- a/back/src/org/kar/karso/model/ApplicationToken.java +++ b/back/src/org/kar/karso/model/ApplicationToken.java @@ -1,6 +1,6 @@ package org.kar.karso.model; -import org.kar.archidata.annotation.SQLIfNotExists; +import org.kar.archidata.annotation.DataIfNotExists; import org.kar.archidata.model.GenericToken; import com.fasterxml.jackson.annotation.JsonInclude; @@ -8,7 +8,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import jakarta.persistence.Table; @Table(name = "applicationToken") -@SQLIfNotExists +@DataIfNotExists @JsonInclude(JsonInclude.Include.NON_NULL) public class ApplicationToken extends GenericToken { diff --git a/back/src/org/kar/karso/model/Right.java b/back/src/org/kar/karso/model/Right.java index f809b0d..48a169d 100644 --- a/back/src/org/kar/karso/model/Right.java +++ b/back/src/org/kar/karso/model/Right.java @@ -1,8 +1,8 @@ package org.kar.karso.model; -import org.kar.archidata.annotation.SQLComment; -import org.kar.archidata.annotation.SQLIfNotExists; -import org.kar.archidata.model.GenericTableSoftDelete; +import org.kar.archidata.annotation.DataComment; +import org.kar.archidata.annotation.DataIfNotExists; +import org.kar.archidata.model.GenericDataSoftDelete; import com.fasterxml.jackson.annotation.JsonInclude; @@ -12,23 +12,23 @@ import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; @Table(name = "right") -@SQLIfNotExists +@DataIfNotExists @JsonInclude(JsonInclude.Include.NON_NULL) -public class Right extends GenericTableSoftDelete { +public class Right extends GenericDataSoftDelete { @Column(nullable = false) - @SQLComment("application-ID that have the reference of the right") + @DataComment("application-ID that have the reference of the right") @ManyToOne(fetch = FetchType.LAZY, targetEntity = Application.class) - public long applicationId; + public Long applicationId; @Column(nullable = false) - @SQLComment("user-ID ") + @DataComment("user-ID ") @ManyToOne(fetch = FetchType.LAZY, targetEntity = UserAuth.class) - public long userId; + public Long userId; @Column(nullable = false) - @SQLComment("rightDescription-ID of the right description") + @DataComment("rightDescription-ID of the right description") @ManyToOne(fetch = FetchType.LAZY, targetEntity = RightDescription.class) - public long rightDescriptionId; + public Long rightDescriptionId; @Column(length = 1024, nullable = false) - @SQLComment("Value of the right") + @DataComment("Value of the right") public String value; } diff --git a/back/src/org/kar/karso/model/RightDescription.java b/back/src/org/kar/karso/model/RightDescription.java index 6b3e0d4..7d1ef97 100644 --- a/back/src/org/kar/karso/model/RightDescription.java +++ b/back/src/org/kar/karso/model/RightDescription.java @@ -1,9 +1,9 @@ package org.kar.karso.model; -import org.kar.archidata.annotation.SQLComment; -import org.kar.archidata.annotation.SQLDefault; -import org.kar.archidata.annotation.SQLIfNotExists; -import org.kar.archidata.model.GenericTableSoftDelete; +import org.kar.archidata.annotation.DataComment; +import org.kar.archidata.annotation.DataDefault; +import org.kar.archidata.annotation.DataIfNotExists; +import org.kar.archidata.model.GenericDataSoftDelete; import com.fasterxml.jackson.annotation.JsonInclude; @@ -13,27 +13,27 @@ import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; @Table(name = "rightDescription") -@SQLIfNotExists +@DataIfNotExists @JsonInclude(JsonInclude.Include.NON_NULL) -public class RightDescription extends GenericTableSoftDelete { +public class RightDescription extends GenericDataSoftDelete { @Column(nullable = false) - @SQLComment("Application id that have the reference of the right") + @DataComment("Application id that have the reference of the right") @ManyToOne(fetch = FetchType.LAZY, targetEntity = Application.class) - public long applicationId; + public Long applicationId; @Column(length = 64, nullable = false) - @SQLComment("Key of the property") + @DataComment("Key of the property") public String key; @Column(length = 1024, nullable = false) - @SQLComment("Title of the right") + @DataComment("Title of the right") public String title; @Column(length = 1024, nullable = false) - @SQLComment("Description of the right") + @DataComment("Description of the right") public String description; @Column(length = 1024) - @SQLComment("default value if Never set") + @DataComment("default value if Never set") public String defaultValue; @Column(length = 16, nullable = false) - @SQLComment("Type of the property") - @SQLDefault("\"BOOLEAN\"") + @DataComment("Type of the property") + @DataDefault("\"BOOLEAN\"") public String type = "BOOLEAN"; // this is a place-holder (current type supported BOOLEAN) } \ No newline at end of file diff --git a/back/src/org/kar/karso/model/Settings.java b/back/src/org/kar/karso/model/Settings.java index 1b2f6c4..74a38de 100644 --- a/back/src/org/kar/karso/model/Settings.java +++ b/back/src/org/kar/karso/model/Settings.java @@ -10,10 +10,10 @@ CREATE TABLE `application` ( */ -import org.kar.archidata.annotation.SQLComment; -import org.kar.archidata.annotation.SQLDefault; -import org.kar.archidata.annotation.SQLIfNotExists; -import org.kar.archidata.model.GenericTableSoftDelete; +import org.kar.archidata.annotation.DataComment; +import org.kar.archidata.annotation.DataDefault; +import org.kar.archidata.annotation.DataIfNotExists; +import org.kar.archidata.model.GenericDataSoftDelete; import com.fasterxml.jackson.annotation.JsonInclude; @@ -25,25 +25,25 @@ enum PropertyType { } @Table(name = "settings") -@SQLIfNotExists +@DataIfNotExists @JsonInclude(JsonInclude.Include.NON_NULL) -public class Settings extends GenericTableSoftDelete { +public class Settings extends GenericDataSoftDelete { @Column(length = 512, nullable = false) public String key; - @SQLComment("Right for the specific element(ADMIN [rw] USER [rw] other [rw])") + @DataComment("Right for the specific element(ADMIN [rw] USER [rw] other [rw])") @Column(length = 6, nullable = false) - @SQLDefault("\"rw----\"") + @DataDefault("\"rw----\"") public String right; - @SQLComment("Type Of the data") + @DataComment("Type Of the data") @Column(length = 10, nullable = false) public String type; - @SQLComment("Value of the configuration") + @DataComment("Value of the configuration") @Column(nullable = false) public String value; - + @Override public String toString() { return "Settings [key=" + this.key + ", value=" + this.value + ", id=" + this.id + ", deleted=" + this.deleted + "]"; } - + } diff --git a/back/src/org/kar/karso/model/UserAuth.java b/back/src/org/kar/karso/model/UserAuth.java index ac7ae4c..bb05c26 100644 --- a/back/src/org/kar/karso/model/UserAuth.java +++ b/back/src/org/kar/karso/model/UserAuth.java @@ -3,9 +3,9 @@ package org.kar.karso.model; import java.sql.Timestamp; import java.util.List; -import org.kar.archidata.annotation.SQLComment; -import org.kar.archidata.annotation.SQLDefault; -import org.kar.archidata.annotation.SQLIfNotExists; +import org.kar.archidata.annotation.DataComment; +import org.kar.archidata.annotation.DataDefault; +import org.kar.archidata.annotation.DataIfNotExists; import org.kar.archidata.model.User; import com.fasterxml.jackson.annotation.JsonInclude; @@ -15,7 +15,7 @@ import jakarta.persistence.ManyToMany; import jakarta.persistence.Table; @Table(name = "user") -@SQLIfNotExists +@DataIfNotExists @JsonInclude(JsonInclude.Include.NON_NULL) public class UserAuth extends User { @Column(length = 128, nullable = false) @@ -31,11 +31,11 @@ public class UserAuth extends User { public Timestamp emailValidate; // time of validation @Column(length = 512) public String newEmail; - @SQLDefault("'0'") + @DataDefault("'0'") @Column(nullable = false) - public boolean avatar = false; - @SQLComment("List of accessible application (if not set the application is not available)") + public Boolean avatar = false; + @DataComment("List of accessible application (if not set the application is not available)") @ManyToMany(targetEntity = Application.class) public List applications = null; - + } diff --git a/back/src/org/kar/karso/model/UserAuthGet.java b/back/src/org/kar/karso/model/UserAuthGet.java index 5e2a29c..c740277 100644 --- a/back/src/org/kar/karso/model/UserAuthGet.java +++ b/back/src/org/kar/karso/model/UserAuthGet.java @@ -1,7 +1,7 @@ package org.kar.karso.model; -import org.kar.archidata.annotation.SQLDefault; -import org.kar.archidata.annotation.SQLIfNotExists; +import org.kar.archidata.annotation.DataDefault; +import org.kar.archidata.annotation.DataIfNotExists; import org.kar.archidata.model.User; import com.fasterxml.jackson.annotation.JsonInclude; @@ -10,12 +10,12 @@ import jakarta.persistence.Column; import jakarta.persistence.Table; @Table(name = "user") -@SQLIfNotExists +@DataIfNotExists @JsonInclude(JsonInclude.Include.NON_NULL) public class UserAuthGet extends User { @Column(length = 512, nullable = false) public String email; - @SQLDefault("'0'") + @DataDefault("'0'") @Column(nullable = false) - public boolean avatar = false; + public Boolean avatar = false; } diff --git a/back/src/org/kar/karso/model/UserLinkApplication.java b/back/src/org/kar/karso/model/UserLinkApplication.java index a55557b..a27c127 100644 --- a/back/src/org/kar/karso/model/UserLinkApplication.java +++ b/back/src/org/kar/karso/model/UserLinkApplication.java @@ -10,18 +10,18 @@ CREATE TABLE `application` ( */ -import org.kar.archidata.annotation.SQLIfNotExists; -import org.kar.archidata.model.GenericTableSoftDelete; +import org.kar.archidata.annotation.DataIfNotExists; +import org.kar.archidata.model.GenericDataSoftDelete; import com.fasterxml.jackson.annotation.JsonInclude; import jakarta.persistence.Table; -// TODO: reùmove this, it must be generated instead of manually create /// +// TODO: remove this, it must be generated instead of manually create /// @Table(name = "user_link_application") -@SQLIfNotExists +@DataIfNotExists @JsonInclude(JsonInclude.Include.NON_NULL) -public class UserLinkApplication extends GenericTableSoftDelete { - public long user_id; - public long application_id; +public class UserLinkApplication extends GenericDataSoftDelete { + public Long user_id; + public Long application_id; } diff --git a/back/test/resources/simplelogger.properties b/back/test/resources/simplelogger.properties index 4314b58..54b58f4 100644 --- a/back/test/resources/simplelogger.properties +++ b/back/test/resources/simplelogger.properties @@ -3,7 +3,7 @@ # 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 +org.slf4j.simpleLogger.defaultLogLevel=debug # Logging detail level for a SimpleLogger instance named "xxxxx". # Must be one of ("trace", "debug", "info", "warn", or "error"). diff --git a/back/test/src/test/kar/karso/StepwiseExtension.java b/back/test/src/test/kar/karso/StepwiseExtension.java new file mode 100644 index 0000000..549bb01 --- /dev/null +++ b/back/test/src/test/kar/karso/StepwiseExtension.java @@ -0,0 +1,33 @@ +package test.kar.karso; + +import org.junit.jupiter.api.extension.ConditionEvaluationResult; +import org.junit.jupiter.api.extension.ExecutionCondition; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.TestExecutionExceptionHandler; + +class StepwiseExtension implements ExecutionCondition, TestExecutionExceptionHandler { + @Override + public ConditionEvaluationResult evaluateExecutionCondition(final ExtensionContext extensionContext) { + final ExtensionContext.Namespace namespace = namespaceFor(extensionContext); + final ExtensionContext.Store store = storeFor(extensionContext, namespace); + final String value = store.get(StepwiseExtension.class, String.class); + return value == null ? ConditionEvaluationResult.enabled("No test failures in stepwise tests") + : ConditionEvaluationResult.disabled(String.format("Stepwise test disabled due to previous failure in '%s'", value)); + } + + @Override + public void handleTestExecutionException(final ExtensionContext extensionContext, final Throwable throwable) throws Throwable { + final ExtensionContext.Namespace namespace = namespaceFor(extensionContext); + final ExtensionContext.Store store = storeFor(extensionContext, namespace); + store.put(StepwiseExtension.class, extensionContext.getDisplayName()); + throw throwable; + } + + private ExtensionContext.Namespace namespaceFor(final ExtensionContext extensionContext) { + return ExtensionContext.Namespace.create(StepwiseExtension.class, extensionContext.getParent()); + } + + private ExtensionContext.Store storeFor(final ExtensionContext extensionContext, final ExtensionContext.Namespace namespace) { + return extensionContext.getParent().get().getStore(namespace); + } +} \ No newline at end of file diff --git a/back/test/src/test/kar/karso/TestBase.java b/back/test/src/test/kar/karso/TestBase.java index 4d387e6..009bce6 100644 --- a/back/test/src/test/kar/karso/TestBase.java +++ b/back/test/src/test/kar/karso/TestBase.java @@ -1,5 +1,6 @@ package test.kar.karso; +import java.io.IOException; import java.util.Map; import org.junit.jupiter.api.AfterAll; @@ -9,17 +10,12 @@ import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; -import org.junit.jupiter.api.extension.ConditionEvaluationResult; -import org.junit.jupiter.api.extension.ExecutionCondition; import org.junit.jupiter.api.extension.ExtendWith; -import org.junit.jupiter.api.extension.ExtensionContext; -import org.junit.jupiter.api.extension.TestExecutionExceptionHandler; -import org.kar.archidata.exception.RESTErrorResponseExeption; +import org.kar.archidata.db.DBEntry; import org.kar.archidata.model.GetToken; import org.kar.archidata.util.ConfigBaseVariable; import org.kar.archidata.util.JWTWrapper; import org.kar.archidata.util.RESTApi; -import org.kar.karso.api.HealthCheck.HealthResult; import org.kar.karso.model.DataGetToken; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -30,10 +26,10 @@ import com.nimbusds.jwt.JWTClaimsSet; @TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class TestBase { private final static Logger LOGGER = LoggerFactory.getLogger(TestBase.class); - + static WebLauncherTest webInterface = null; static RESTApi api = null; - + public void login(final String login, final String password) { try { final GetToken token = api.post(GetToken.class, "users/get_token", DataGetToken.generate(login, "v1", "202515252", password)); @@ -42,11 +38,11 @@ public class TestBase { Assertions.fail("Can not get Authentication for '" + login + "' ==> " + ex.getMessage()); } } - + public void loginAdmin() { login("karadmin", "adminA@666"); } - + @BeforeAll public static void configureWebServer() throws Exception { LOGGER.info("configure server ..."); @@ -63,28 +59,18 @@ public class TestBase { LOGGER.info("Start REST (DONE)"); api = new RESTApi(ConfigBaseVariable.apiAdress); } - + @AfterAll - public static void stopWebServer() throws InterruptedException { + public static void stopWebServer() throws InterruptedException, IOException { LOGGER.info("Kill the web server"); + webInterface.stop(); webInterface = null; - // TODO: do it better... + LOGGER.info("Remove the test db"); + DBEntry.closeAllForceMode(); + ConfigBaseVariable.clearAllValue(); + Thread.sleep(1000); } - - @Order(1) - @Test - //@RepeatedTest(10) - public void checkHealthCheck() throws Exception { - final HealthResult result = api.get(HealthResult.class, "health_check"); - Assertions.assertEquals(result.value(), "alive and kicking"); - } - - @Order(2) - @Test - public void checkHealthCheckWrongAPI() throws Exception { - Assertions.assertThrows(RESTErrorResponseExeption.class, () -> api.get(HealthResult.class, "health_checks")); - } - + @Order(3) @Test public void firstUserConnect() throws Exception { @@ -103,7 +89,7 @@ public class TestBase { Assertions.assertEquals(1, id); final String name = (String) ret.getClaim("login"); Assertions.assertEquals("karadmin", name); - + final Object rowRight = ret.getClaim("right"); Assertions.assertNotNull(rowRight); final Map> rights = (Map>) ret.getClaim("right"); @@ -117,166 +103,21 @@ public class TestBase { Assertions.assertEquals(true, applRight.get("ADMIN")); Assertions.assertTrue(applRight.containsKey("USER")); Assertions.assertEquals(true, applRight.get("USER")); - + //logger.debug("request user: '{}' right: '{}' row='{}'", userUID, applRight, rowRight); - + //Assertions.assertEquals("eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9", splitted[0]); //Assertions.assertEquals("eyJzdWIiOiIwIiwiYXBwbGljYXRpb24iOiJrYXJzbyIsImlzcyI6IkthckF1dGgiLCJyaWdodCI6eyJrYXJzbyI6eyJBRE1JTiI6dHJ1ZSwiVVNFUiI6dHJ1ZX19LCJsb2dpbiI6ImthcmFkbWluIiwiZXhwIjoxNjg0MTk5MTkzLCJpYXQiOjE2ODI3NTU0MjV9", splitted[1]); // TODO ... Assertions.assertEquals("????", splitted[2]); } - public void checkFail(final String type, final String urlOffset, final int errorStatus) { - checkFail(type, urlOffset, errorStatus, null); - } - - public void checkFail(final String type, final String urlOffset, final int errorStatus, final String data) { - LOGGER.info("Test API: url={} urlOffset={}", type, urlOffset); - try { - if ("GET".equals(type)) { - api.get(String.class, urlOffset); - } else if ("POST".equals(type)) { - api.post(String.class, urlOffset, data); - } else if ("PUT".equals(type)) { - api.put(String.class, urlOffset, data); - } else if ("DELETE".equals(type)) { - api.delete(String.class, urlOffset); - } - Assertions.fail("Request on URL does not fail as expected: '" + type + "' url='" + urlOffset + "'"); - } catch (final RESTErrorResponseExeption ex) { - if (errorStatus != ex.status) { - LOGGER.error("Fail in test with the wrong return errors: {}", ex.toString()); - } - Assertions.assertEquals(errorStatus, ex.status); - } catch (final Exception ex) { - LOGGER.error("Unexpected throw error: {}", ex); - Assertions.fail("Unexpected throws..."); - } - - } - - public void checkWork(final String type, final String urlOffset) { - checkWork(type, urlOffset, null); - } - - public void checkWork(final String type, final String urlOffset, final String data) { - LOGGER.info("Test API: url={} urlOffset={}", type, urlOffset); - try { - if ("GET".equals(type)) { - api.get(String.class, urlOffset); - } else if ("POST".equals(type)) { - api.post(String.class, urlOffset, data); - } else if ("PUT".equals(type)) { - api.put(String.class, urlOffset, data); - } else if ("DELETE".equals(type)) { - api.delete(String.class, urlOffset); - } - //Assertions.fail("Request on URL does not fail as expected: '" + type + "' url='" + urlOffset + "'"); - } catch (final RESTErrorResponseExeption ex) { - Assertions.fail("Must not fail ... " + ex.toString()); - } catch (final Exception ex) { - LOGGER.error("Unexpected throw error: {}", ex); - Assertions.fail("Unexpected throws..."); - } - - } - - @Order(4) - @Test - public void checkUnAuthorizedAPI() throws Exception { - // /application/ - checkFail("GET", "application/", 401); - checkFail("POST", "application/", 401, "{}"); - checkFail("PUT", "application/", 405, "{}"); // does not exist - checkFail("DELETE", "application/", 405); // does not exist - // /application/{id} - checkFail("GET", "application/0", 401); - checkFail("PUT", "application/0", 401, "{}"); - checkFail("POST", "application/0", 405, "{}"); - checkFail("DELETE", "application/0", 401); - // /application/{id}/* - checkFail("GET", "application/0/users", 401); - // /application/* - checkFail("GET", "application/small", 401); - checkFail("GET", "application/get_token", 401); - checkFail("GET", "application/return", 401); - - // /application_token/ section: - checkFail("GET", "application_token/0", 401); - checkFail("DELETE", "application_token/0/5", 401); - checkFail("DELETE", "application_token/0/create", 401); - - // /front/* - checkFail("GET", "front", 404); // no index in test section - // health check - checkWork("GET", "health_check"); - - // public_key (only application) - checkFail("GET", "public_key", 401); - checkFail("GET", "public_key/pem", 401); - - // /right - checkFail("GET", "right", 401); - checkFail("POST", "right", 401, "{}"); - checkFail("GET", "right/0", 401); - checkFail("PUT", "right/0", 401, "{}"); - checkFail("DELETE", "right/0", 401); - - // /system_config - checkWork("GET", "system_config/is_sign_up_availlable"); - checkFail("GET", "system_config/key/skjdfhkjsdhfkjsh", 401); - checkFail("PUT", "system_config/key/skjdfhkjsdhfkjsh", 401, "{}"); - - // /users - checkFail("GET", "users", 401); - checkFail("GET", "users/0", 401); - checkFail("POST", "users/0/application/0/link", 401, "{}"); - checkFail("POST", "users/0/set_admin", 401, "{}"); - checkFail("POST", "users/0/set_blocked", 401, "{}"); - checkFail("POST", "users/create_new_user", 401, "{}"); - checkFail("GET", "users/me", 401, "{}"); - checkFail("POST", "users/password", 401, "{}"); - checkWork("GET", "users/check_login?login=karadmin"); - checkFail("GET", "users/check_login?login=jhkjhkjh", 404); - checkWork("GET", "users/check_email?email=admin@admin.ZZZ"); - checkFail("GET", "users/check_email?email=ksjhdkjfhskjdh", 404); - // not testable : get_token - - } - @Order(5) @Test public void testMeWithToken() throws Exception { loginAdmin(); final String result = api.get(String.class, "users/me"); Assertions.assertEquals("{\"id\":1,\"login\":\"karadmin\"}", result); - - } - -} -class StepwiseExtension implements ExecutionCondition, TestExecutionExceptionHandler { - @Override - public ConditionEvaluationResult evaluateExecutionCondition(final ExtensionContext extensionContext) { - final ExtensionContext.Namespace namespace = namespaceFor(extensionContext); - final ExtensionContext.Store store = storeFor(extensionContext, namespace); - final String value = store.get(StepwiseExtension.class, String.class); - return value == null ? ConditionEvaluationResult.enabled("No test failures in stepwise tests") - : ConditionEvaluationResult.disabled(String.format("Stepwise test disabled due to previous failure in '%s'", value)); - } - - @Override - public void handleTestExecutionException(final ExtensionContext extensionContext, final Throwable throwable) throws Throwable { - final ExtensionContext.Namespace namespace = namespaceFor(extensionContext); - final ExtensionContext.Store store = storeFor(extensionContext, namespace); - store.put(StepwiseExtension.class, extensionContext.getDisplayName()); - throw throwable; - } - - private ExtensionContext.Namespace namespaceFor(final ExtensionContext extensionContext) { - return ExtensionContext.Namespace.create(StepwiseExtension.class, extensionContext.getParent()); - } - - private ExtensionContext.Store storeFor(final ExtensionContext extensionContext, final ExtensionContext.Namespace namespace) { - return extensionContext.getParent().get().getStore(namespace); } + } diff --git a/back/test/src/test/kar/karso/TestHealthCheck.java b/back/test/src/test/kar/karso/TestHealthCheck.java new file mode 100644 index 0000000..76c723c --- /dev/null +++ b/back/test/src/test/kar/karso/TestHealthCheck.java @@ -0,0 +1,71 @@ +package test.kar.karso; + +import java.io.IOException; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; +import org.junit.jupiter.api.extension.ExtendWith; +import org.kar.archidata.db.DBEntry; +import org.kar.archidata.exception.RESTErrorResponseExeption; +import org.kar.archidata.util.ConfigBaseVariable; +import org.kar.archidata.util.RESTApi; +import org.kar.karso.api.HealthCheck.HealthResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@ExtendWith(StepwiseExtension.class) +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +public class TestHealthCheck { + private final static Logger LOGGER = LoggerFactory.getLogger(TestHealthCheck.class); + + static WebLauncherTest webInterface = null; + static RESTApi api = null; + + @BeforeAll + public static void configureWebServer() throws Exception { + LOGGER.info("configure server ..."); + webInterface = new WebLauncherTest(); + LOGGER.info("Create DB"); + try { + webInterface.migrateDB(); + } catch (final Exception ex) { + ex.printStackTrace(); + LOGGER.error("Detect an error: {}", ex.getMessage()); + } + LOGGER.info("Start REST (BEGIN)"); + webInterface.process(); + LOGGER.info("Start REST (DONE)"); + api = new RESTApi(ConfigBaseVariable.apiAdress); + } + + @AfterAll + public static void stopWebServer() throws InterruptedException, IOException { + LOGGER.info("Kill the web server"); + webInterface.stop(); + webInterface = null; + LOGGER.info("Remove the test db"); + DBEntry.closeAllForceMode(); + ConfigBaseVariable.clearAllValue(); + Thread.sleep(1000); + } + + @Order(1) + @Test + //@RepeatedTest(10) + public void checkHealthCheck() throws Exception { + final HealthResult result = api.get(HealthResult.class, "health_check"); + Assertions.assertEquals(result.value(), "alive and kicking"); + } + + @Order(2) + @Test + public void checkHealthCheckWrongAPI() throws Exception { + Assertions.assertThrows(RESTErrorResponseExeption.class, () -> api.get(HealthResult.class, "health_checks")); + } + +} diff --git a/back/test/src/test/kar/karso/TestUnAuthorizedAPI.java b/back/test/src/test/kar/karso/TestUnAuthorizedAPI.java new file mode 100644 index 0000000..064a56e --- /dev/null +++ b/back/test/src/test/kar/karso/TestUnAuthorizedAPI.java @@ -0,0 +1,187 @@ +package test.kar.karso; + +import java.io.IOException; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; +import org.kar.archidata.db.DBEntry; +import org.kar.archidata.exception.RESTErrorResponseExeption; +import org.kar.archidata.model.GetToken; +import org.kar.archidata.util.ConfigBaseVariable; +import org.kar.archidata.util.RESTApi; +import org.kar.karso.model.DataGetToken; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +public class TestUnAuthorizedAPI { + private final static Logger LOGGER = LoggerFactory.getLogger(TestUnAuthorizedAPI.class); + + static WebLauncherTest webInterface = null; + static RESTApi api = null; + + public void login(final String login, final String password) { + try { + final GetToken token = api.post(GetToken.class, "users/get_token", DataGetToken.generate(login, "v1", "202515252", password)); + api.setToken(token.jwt()); + } catch (final Exception ex) { + Assertions.fail("Can not get Authentication for '" + login + "' ==> " + ex.getMessage()); + } + } + + public void loginAdmin() { + login("karadmin", "adminA@666"); + } + + @BeforeAll + public static void configureWebServer() throws Exception { + LOGGER.info("configure server ..."); + webInterface = new WebLauncherTest(); + LOGGER.info("Create DB"); + try { + webInterface.migrateDB(); + } catch (final Exception ex) { + ex.printStackTrace(); + LOGGER.error("Detect an error: {}", ex.getMessage()); + } + LOGGER.info("Start REST (BEGIN)"); + webInterface.process(); + LOGGER.info("Start REST (DONE)"); + api = new RESTApi(ConfigBaseVariable.apiAdress); + } + + @AfterAll + public static void stopWebServer() throws InterruptedException, IOException { + LOGGER.info("Kill the web server"); + webInterface.stop(); + webInterface = null; + LOGGER.info("Remove the test db"); + DBEntry.closeAllForceMode(); + ConfigBaseVariable.clearAllValue(); + Thread.sleep(1000); + } + + public void checkFail(final String type, final String urlOffset, final int errorStatus) { + checkFail(type, urlOffset, errorStatus, null); + } + + public void checkFail(final String type, final String urlOffset, final int errorStatus, final String data) { + LOGGER.info("Test API: url={} urlOffset={}", type, urlOffset); + try { + if ("GET".equals(type)) { + api.get(String.class, urlOffset); + } else if ("POST".equals(type)) { + api.post(String.class, urlOffset, data); + } else if ("PUT".equals(type)) { + api.put(String.class, urlOffset, data); + } else if ("DELETE".equals(type)) { + api.delete(String.class, urlOffset); + } + Assertions.fail("Request on URL does not fail as expected: '" + type + "' url='" + urlOffset + "'"); + } catch (final RESTErrorResponseExeption ex) { + if (errorStatus != ex.status) { + LOGGER.error("Fail in test with the wrong return errors: {}", ex.toString()); + } + Assertions.assertEquals(errorStatus, ex.status); + } catch (final Exception ex) { + LOGGER.error("Unexpected throw error: {}", ex); + Assertions.fail("Unexpected throws..."); + } + + } + + public void checkWork(final String type, final String urlOffset) { + checkWork(type, urlOffset, null); + } + + public void checkWork(final String type, final String urlOffset, final String data) { + LOGGER.info("Test API: url={} urlOffset={}", type, urlOffset); + try { + if ("GET".equals(type)) { + api.get(String.class, urlOffset); + } else if ("POST".equals(type)) { + api.post(String.class, urlOffset, data); + } else if ("PUT".equals(type)) { + api.put(String.class, urlOffset, data); + } else if ("DELETE".equals(type)) { + api.delete(String.class, urlOffset); + } + //Assertions.fail("Request on URL does not fail as expected: '" + type + "' url='" + urlOffset + "'"); + } catch (final RESTErrorResponseExeption ex) { + Assertions.fail("Must not fail ... " + ex.toString()); + } catch (final Exception ex) { + LOGGER.error("Unexpected throw error: {}", ex); + Assertions.fail("Unexpected throws..."); + } + + } + + @Order(1) + @Test + public void checkUnAuthorizedAPI() throws Exception { + // /application/ + checkFail("GET", "application/", 401); + checkFail("POST", "application/", 401, "{}"); + checkFail("PUT", "application/", 405, "{}"); // does not exist + checkFail("DELETE", "application/", 405); // does not exist + // /application/{id} + checkFail("GET", "application/0", 401); + checkFail("PUT", "application/0", 401, "{}"); + checkFail("POST", "application/0", 405, "{}"); + checkFail("DELETE", "application/0", 401); + // /application/{id}/* + checkFail("GET", "application/0/users", 401); + // /application/* + checkFail("GET", "application/small", 401); + checkFail("GET", "application/get_token", 401); + checkFail("GET", "application/return", 401); + + // /application_token/ section: + checkFail("GET", "application_token/0", 401); + checkFail("DELETE", "application_token/0/5", 401); + checkFail("DELETE", "application_token/0/create", 401); + + // /front/* + checkFail("GET", "front", 404); // no index in test section + // health check + checkWork("GET", "health_check"); + + // public_key (only application) + checkFail("GET", "public_key", 401); + checkFail("GET", "public_key/pem", 401); + + // /right + checkFail("GET", "right", 401); + checkFail("POST", "right", 401, "{}"); + checkFail("GET", "right/0", 401); + checkFail("PUT", "right/0", 401, "{}"); + checkFail("DELETE", "right/0", 401); + + // /system_config + checkWork("GET", "system_config/is_sign_up_availlable"); + checkFail("GET", "system_config/key/skjdfhkjsdhfkjsh", 401); + checkFail("PUT", "system_config/key/skjdfhkjsdhfkjsh", 401, "{}"); + + // /users + checkFail("GET", "users", 401); + checkFail("GET", "users/0", 401); + checkFail("POST", "users/0/application/0/link", 401, "{}"); + checkFail("POST", "users/0/set_admin", 401, "{}"); + checkFail("POST", "users/0/set_blocked", 401, "{}"); + checkFail("POST", "users/create_new_user", 401, "{}"); + checkFail("GET", "users/me", 401, "{}"); + checkFail("POST", "users/password", 401, "{}"); + checkWork("GET", "users/check_login?login=karadmin"); + checkFail("GET", "users/check_login?login=jhkjhkjh", 404); + checkWork("GET", "users/check_email?email=admin@admin.ZZZ"); + checkFail("GET", "users/check_email?email=ksjhdkjfhskjdh", 404); + // not testable : get_token + + } + +} diff --git a/back/test/src/test/kar/karso/WebLauncherTest.java b/back/test/src/test/kar/karso/WebLauncherTest.java index 2b16985..5cece21 100755 --- a/back/test/src/test/kar/karso/WebLauncherTest.java +++ b/back/test/src/test/kar/karso/WebLauncherTest.java @@ -8,14 +8,14 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class WebLauncherTest extends WebLauncher { - final Logger logger = LoggerFactory.getLogger(WebLauncherTest.class); - + final private static Logger LOGGER = LoggerFactory.getLogger(WebLauncherTest.class); + public WebLauncherTest() { - this.logger.debug("Configure REST system"); + LOGGER.debug("Configure REST system"); // for local test: ConfigBaseVariable.apiAdress = "http://127.0.0.1:12345/test/api/"; - - ConfigBaseVariable.dbPort = "3306"; + + //ConfigBaseVariable.dbPort = "3306"; // create a unique key for test ==> not retrieve the token every load... ConfigVariable.uuid_for_key_generation = "lkjlkjlkjlmkjqmwlsdkjqfsdlkf,nmQLSDK,NFMQLKSdjmlKQJSDMLQK,S;ndmLQKZNERMA,ÉL"; // for the test we a in memory sqlite.. @@ -23,9 +23,9 @@ public class WebLauncherTest extends WebLauncher { ConfigBaseVariable.dbHost = "memory"; // for test we need to connect all time the DB ConfigBaseVariable.dbKeepConnected = "true"; - - ConfigBaseVariable.dbHost = "localhost"; - ConfigBaseVariable.dbUser = "root"; - ConfigBaseVariable.dbPassword = "ZERTYSDGFVHSDFGHJYZSDFGSQxfgsqdfgsqdrf4564654"; + + //ConfigBaseVariable.dbHost = "localhost"; + //ConfigBaseVariable.dbUser = "root"; + //ConfigBaseVariable.dbPassword = "ZERTYSDGFVHSDFGHJYZSDFGSQxfgsqdfgsqdrf4564654"; } } diff --git a/front/src/common b/front/src/common index ea5a4f6..9fc25b4 160000 --- a/front/src/common +++ b/front/src/common @@ -1 +1 @@ -Subproject commit ea5a4f6b7537eb707916f4610bf79fbe86c6296f +Subproject commit 9fc25b4feaeba509ff39f70b24d97be47f4b30e1