[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)
public class ApplicationResource {
final Logger logger = LoggerFactory.getLogger(ApplicationResource.class);
public ApplicationResource() {}
public List<Long> getUserListOfApplication(final Long userId) {
final List<Long> out = new ArrayList<>();
List<UserLinkApplication> links = null;
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) {
// TODO Auto-generated catch block
e.printStackTrace();
@ -60,7 +60,7 @@ public class ApplicationResource {
}
return out;
}
public List<Long> getListOfUsers(final Long applicationId) {
final List<Long> out = new ArrayList<>();
List<UserLinkApplication> links = null;
@ -83,7 +83,7 @@ public class ApplicationResource {
// Generic /application/
//
////////////////////////////////////////////////////////////////////////////////////////
@GET
@RolesAllowed(value = { "USER", "ADMIN" })
public List<Application> getApplications(@Context final SecurityContext sc) throws Exception {
@ -103,7 +103,7 @@ public class ApplicationResource {
}
return out;
}
@POST
@RolesAllowed("ADMIN")
public Application create(final Application application) throws Exception {
@ -121,20 +121,20 @@ public class ApplicationResource {
application.updatedAt = null;
return DataAccess.insert(application);
}
////////////////////////////////////////////////////////////////////////////////////////
//
// Generic /application/{id}
//
////////////////////////////////////////////////////////////////////////////////////////
@GET
@Path("{id}")
@RolesAllowed("ADMIN")
public Application get(@PathParam("id") final Long id) throws Exception {
return DataAccess.get(Application.class, id);
}
@PATCH
@Path("{id}")
@RolesAllowed("ADMIN")
@ -143,7 +143,7 @@ public class ApplicationResource {
DataAccess.updateWithJson(Application.class, id, jsonRequest);
return DataAccess.get(Application.class, id);
}
@DELETE
@Path("{id}")
@RolesAllowed("ADMIN")
@ -151,29 +151,29 @@ public class ApplicationResource {
public void remove(@Context final SecurityContext sc, @PathParam("id") final long applicationId) throws Exception {
DataAccess.delete(Application.class, applicationId);
}
////////////////////////////////////////////////////////////////////////////////////////
//
// Generic /{id}/*
//
////////////////////////////////////////////////////////////////////////////////////////
@GET
@Path("{id}/users")
@RolesAllowed(value = { "ADMIN" })
public List<Long> 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" })
@ -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,7 +213,7 @@ 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")
@ -222,7 +222,7 @@ public class ApplicationResource {
this.logger.debug("getApplications rights");
return DataAccess.getsWhere(RightDescription.class, new Condition(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,7 +243,7 @@ public class ApplicationResource {
isDev = true;
}
this.logger.debug("Search for '{}' base of '{}'", applicationName, application);
Application appl = null;
try {
appl = DataAccess.getWhere(Application.class, new Condition(new QueryCondition("name", "=", applicationName)));
@ -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);
@ -295,7 +295,7 @@ public class ApplicationResource {
}
return Response.status(201).entity("{ \"url\":\"" + returnAdress + "\", \"jwt\":\"" + ret + "\"}").build();
}
@GET
@Path("return")
@RolesAllowed(value = { "USER", "ADMIN" })
@ -305,7 +305,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);
@ -318,7 +318,7 @@ public class ApplicationResource {
isDev = true;
}
this.logger.debug("Search for '{}' base of '{}'", applicationName, application);
Application appl = null;
try {
appl = DataAccess.getWhere(Application.class, new Condition(new QueryCondition("name", "=", applicationName)));
@ -329,7 +329,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);
@ -341,5 +341,5 @@ public class ApplicationResource {
}
return Response.status(201).entity("{ \"url\":\"" + returnAdress + "\"}").build();
}
}