[FIX] wrong condition

This commit is contained in:
Edouard DUPIN 2024-01-18 23:48:06 +01:00
parent 7ce71f91d5
commit 251d544fc1

View File

@ -40,14 +40,14 @@ import jakarta.ws.rs.core.SecurityContext;
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public class ApplicationResource { public class ApplicationResource {
final Logger logger = LoggerFactory.getLogger(ApplicationResource.class); final Logger logger = LoggerFactory.getLogger(ApplicationResource.class);
public ApplicationResource() {} public ApplicationResource() {}
public List<Long> getUserListOfApplication(final Long userId) { public List<Long> getUserListOfApplication(final Long userId) {
final List<Long> out = new ArrayList<>(); final List<Long> out = new ArrayList<>();
List<UserLinkApplication> links = null; List<UserLinkApplication> links = null;
try { try {
links = DataAccess.getsWhere(UserLinkApplication.class, new Condition(new QueryCondition("userId", "=", userId))); links = DataAccess.getsWhere(UserLinkApplication.class, new Condition(new QueryCondition("object1id", "=", userId)));
} catch (final Exception e) { } catch (final Exception e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
@ -60,7 +60,7 @@ public class ApplicationResource {
} }
return out; return out;
} }
public List<Long> getListOfUsers(final Long applicationId) { public List<Long> getListOfUsers(final Long applicationId) {
final List<Long> out = new ArrayList<>(); final List<Long> out = new ArrayList<>();
List<UserLinkApplication> links = null; List<UserLinkApplication> links = null;
@ -83,7 +83,7 @@ public class ApplicationResource {
// Generic /application/ // Generic /application/
// //
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
@GET @GET
@RolesAllowed(value = { "USER", "ADMIN" }) @RolesAllowed(value = { "USER", "ADMIN" })
public List<Application> getApplications(@Context final SecurityContext sc) throws Exception { public List<Application> getApplications(@Context final SecurityContext sc) throws Exception {
@ -103,7 +103,7 @@ public class ApplicationResource {
} }
return out; return out;
} }
@POST @POST
@RolesAllowed("ADMIN") @RolesAllowed("ADMIN")
public Application create(final Application application) throws Exception { public Application create(final Application application) throws Exception {
@ -121,20 +121,20 @@ public class ApplicationResource {
application.updatedAt = null; application.updatedAt = null;
return DataAccess.insert(application); return DataAccess.insert(application);
} }
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// //
// Generic /application/{id} // Generic /application/{id}
// //
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
@GET @GET
@Path("{id}") @Path("{id}")
@RolesAllowed("ADMIN") @RolesAllowed("ADMIN")
public Application get(@PathParam("id") final Long id) throws Exception { public Application get(@PathParam("id") final Long id) throws Exception {
return DataAccess.get(Application.class, id); return DataAccess.get(Application.class, id);
} }
@PATCH @PATCH
@Path("{id}") @Path("{id}")
@RolesAllowed("ADMIN") @RolesAllowed("ADMIN")
@ -143,7 +143,7 @@ public class ApplicationResource {
DataAccess.updateWithJson(Application.class, id, jsonRequest); DataAccess.updateWithJson(Application.class, id, jsonRequest);
return DataAccess.get(Application.class, id); return DataAccess.get(Application.class, id);
} }
@DELETE @DELETE
@Path("{id}") @Path("{id}")
@RolesAllowed("ADMIN") @RolesAllowed("ADMIN")
@ -151,29 +151,29 @@ public class ApplicationResource {
public void remove(@Context final SecurityContext sc, @PathParam("id") final long applicationId) throws Exception { public void remove(@Context final SecurityContext sc, @PathParam("id") final long applicationId) throws Exception {
DataAccess.delete(Application.class, applicationId); DataAccess.delete(Application.class, applicationId);
} }
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// //
// Generic /{id}/* // Generic /{id}/*
// //
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
@GET @GET
@Path("{id}/users") @Path("{id}/users")
@RolesAllowed(value = { "ADMIN" }) @RolesAllowed(value = { "ADMIN" })
public List<Long> getApplicationUsers(@PathParam("id") final Long applicationId) throws Exception { public List<Long> getApplicationUsers(@PathParam("id") final Long applicationId) throws Exception {
// special case for SSO: (all user have access on the SSO...). // special case for SSO: (all user have access on the SSO...).
this.logger.debug("Request list of user for an applciation: {}", applicationId); this.logger.debug("Request list of user for an applciation: {}", applicationId);
return getListOfUsers(applicationId); return getListOfUsers(applicationId);
} }
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// //
// Generic /application/* // Generic /application/*
// //
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
@GET @GET
@Path("small") @Path("small")
@RolesAllowed(value = { "USER", "ADMIN" }) @RolesAllowed(value = { "USER", "ADMIN" })
@ -190,10 +190,10 @@ public class ApplicationResource {
} }
return out; return out;
} }
public record AddUserData( public record AddUserData(
long userId) {} long userId) {}
// TODO : review the function to correct admin only access... // TODO : review the function to correct admin only access...
@POST @POST
@Path("{id}/users") @Path("{id}/users")
@ -203,7 +203,7 @@ public class ApplicationResource {
AddOnManyToMany.addLink(UserAuth.class, data.userId, "application", applicationId); AddOnManyToMany.addLink(UserAuth.class, data.userId, "application", applicationId);
return true; return true;
} }
// TODO : review the function to correct admin only access... // TODO : review the function to correct admin only access...
@DELETE @DELETE
@Path("{id}/users") @Path("{id}/users")
@ -213,7 +213,7 @@ public class ApplicationResource {
AddOnManyToMany.removeLink(UserAuth.class, data.userId, "application", applicationId); AddOnManyToMany.removeLink(UserAuth.class, data.userId, "application", applicationId);
return true; return true;
} }
// TODO : review the function to correct admin only access... // TODO : review the function to correct admin only access...
@GET @GET
@Path("{id}/rights") @Path("{id}/rights")
@ -222,7 +222,7 @@ public class ApplicationResource {
this.logger.debug("getApplications rights"); this.logger.debug("getApplications rights");
return DataAccess.getsWhere(RightDescription.class, new Condition(new QueryCondition("applicationId", "=", applicationId))); return DataAccess.getsWhere(RightDescription.class, new Condition(new QueryCondition("applicationId", "=", applicationId)));
} }
@GET @GET
@Path("get_token") @Path("get_token")
@RolesAllowed(value = { "USER", "ADMIN" }) @RolesAllowed(value = { "USER", "ADMIN" })
@ -230,7 +230,7 @@ public class ApplicationResource {
final GenericContext gc = (GenericContext) sc.getUserPrincipal(); final GenericContext gc = (GenericContext) sc.getUserPrincipal();
this.logger.info("get application TOKEN application name='{}'", application); this.logger.info("get application TOKEN application name='{}'", application);
this.logger.debug("== USER ? {}", gc.userByToken.name); this.logger.debug("== USER ? {}", gc.userByToken.name);
if (application == null) { if (application == null) {
final String result = "Input error missing parameter: 'application'"; final String result = "Input error missing parameter: 'application'";
this.logger.debug(" result: {}", result); this.logger.debug(" result: {}", result);
@ -243,7 +243,7 @@ public class ApplicationResource {
isDev = true; isDev = true;
} }
this.logger.debug("Search for '{}' base of '{}'", applicationName, application); this.logger.debug("Search for '{}' base of '{}'", applicationName, application);
Application appl = null; Application appl = null;
try { try {
appl = DataAccess.getWhere(Application.class, new Condition(new QueryCondition("name", "=", applicationName))); appl = DataAccess.getWhere(Application.class, new Condition(new QueryCondition("name", "=", applicationName)));
@ -254,7 +254,7 @@ public class ApplicationResource {
this.logger.debug(" result: {}", result); this.logger.debug(" result: {}", result);
return Response.status(500).entity(result).build(); return Response.status(500).entity(result).build();
} }
if (appl == null) { if (appl == null) {
final String result = "Authentiocate-wrong email/login '" + applicationName + "')"; final String result = "Authentiocate-wrong email/login '" + applicationName + "')";
this.logger.error(" result: {}", result); this.logger.error(" result: {}", result);
@ -295,7 +295,7 @@ public class ApplicationResource {
} }
return Response.status(201).entity("{ \"url\":\"" + returnAdress + "\", \"jwt\":\"" + ret + "\"}").build(); return Response.status(201).entity("{ \"url\":\"" + returnAdress + "\", \"jwt\":\"" + ret + "\"}").build();
} }
@GET @GET
@Path("return") @Path("return")
@RolesAllowed(value = { "USER", "ADMIN" }) @RolesAllowed(value = { "USER", "ADMIN" })
@ -305,7 +305,7 @@ public class ApplicationResource {
this.logger.debug("====================================="); this.logger.debug("=====================================");
final GenericContext gc = (GenericContext) sc.getUserPrincipal(); final GenericContext gc = (GenericContext) sc.getUserPrincipal();
this.logger.debug("== USER ? {}", gc.userByToken); this.logger.debug("== USER ? {}", gc.userByToken);
if (application == null) { if (application == null) {
final String result = "Input error missing parameter: 'application'"; final String result = "Input error missing parameter: 'application'";
this.logger.error(" result: {}", result); this.logger.error(" result: {}", result);
@ -318,7 +318,7 @@ public class ApplicationResource {
isDev = true; isDev = true;
} }
this.logger.debug("Search for '{}' base of '{}'", applicationName, application); this.logger.debug("Search for '{}' base of '{}'", applicationName, application);
Application appl = null; Application appl = null;
try { try {
appl = DataAccess.getWhere(Application.class, new Condition(new QueryCondition("name", "=", applicationName))); appl = DataAccess.getWhere(Application.class, new Condition(new QueryCondition("name", "=", applicationName)));
@ -329,7 +329,7 @@ public class ApplicationResource {
this.logger.error(" result: {}", result); this.logger.error(" result: {}", result);
return Response.status(500).entity(result).build(); return Response.status(500).entity(result).build();
} }
if (appl == null) { if (appl == null) {
final String result = "Authentiocate-wrong email/login '" + applicationName + "')"; final String result = "Authentiocate-wrong email/login '" + applicationName + "')";
this.logger.error(" result: {}", result); this.logger.error(" result: {}", result);
@ -341,5 +341,5 @@ public class ApplicationResource {
} }
return Response.status(201).entity("{ \"url\":\"" + returnAdress + "\"}").build(); return Response.status(201).entity("{ \"url\":\"" + returnAdress + "\"}").build();
} }
} }