auth + cleaning
This commit is contained in:
parent
31cb26e54c
commit
af57fa5ac7
@ -2,6 +2,7 @@ package fr.la_banquise.backend.rest;
|
||||
|
||||
import fr.la_banquise.backend.data.model.Site;
|
||||
import fr.la_banquise.backend.services.SiteService;
|
||||
import io.quarkus.security.Authenticated;
|
||||
import io.quarkus.security.identity.SecurityIdentity;
|
||||
import jakarta.annotation.security.RolesAllowed;
|
||||
import jakarta.inject.Inject;
|
||||
@ -28,6 +29,7 @@ public class SiteEndpoints {
|
||||
@GET
|
||||
@Path("/listall")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@RolesAllowed("root")
|
||||
public Response listall() {
|
||||
try {
|
||||
List<Site> sites = siteService.getAllSites();
|
||||
@ -58,6 +60,7 @@ public class SiteEndpoints {
|
||||
@GET
|
||||
@Path("/getbyname")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Authenticated
|
||||
public Response getSiteByName(@QueryParam("name") String name) {
|
||||
try {
|
||||
Site site = siteService.getSiteByName(name);
|
||||
@ -103,48 +106,4 @@ public class SiteEndpoints {
|
||||
.build();
|
||||
}
|
||||
}
|
||||
/*
|
||||
@GET
|
||||
@Path("/all")
|
||||
public Response listContainers() {
|
||||
try {
|
||||
String id = dockerService.listAllContainers();
|
||||
return Response.ok(id).build();
|
||||
} catch (Exception e) {
|
||||
return Response.status(500).entity(Map.of("error",
|
||||
e.getMessage())).build();
|
||||
}
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/start")
|
||||
public Response start(@QueryParam("id") String id) {
|
||||
try {
|
||||
dockerService.start(id);
|
||||
return Response.ok(Map.of("containerId", id, "status",
|
||||
"Running")).build(); } catch (Exception e) { return
|
||||
Response.status(500).entity(Map.of("error", e.getMessage())).build();
|
||||
}
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/stop")
|
||||
public Response stop(@QueryParam("id") String id) {
|
||||
try {
|
||||
dockerService.stop(id);
|
||||
return Response.ok(Map.of("containerId", id, "status",
|
||||
"removed")).build(); } catch (Exception e) { return
|
||||
Response.status(500).entity(Map.of("error", e.getMessage())).build();
|
||||
}
|
||||
}
|
||||
@DELETE
|
||||
@Path("/remove")
|
||||
public Response remove(@QueryParam("id") String id) {
|
||||
try {
|
||||
dockerService.remove(id);
|
||||
return Response.ok(Map.of("containerId", id, "status",
|
||||
"removed")).build(); } catch (Exception e) { return
|
||||
Response.status(500).entity(Map.of("error", e.getMessage())).build();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package fr.la_banquise.backend.rest;
|
||||
|
||||
import fr.la_banquise.backend.rest.request.SujetRequest;
|
||||
import fr.la_banquise.backend.services.SujetService;
|
||||
import io.quarkus.security.Authenticated;
|
||||
import io.quarkus.security.identity.SecurityIdentity;
|
||||
import jakarta.annotation.security.RolesAllowed;
|
||||
import jakarta.inject.Inject;
|
||||
@ -25,6 +26,7 @@ public class SujetEndpoints {
|
||||
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Authenticated
|
||||
public Response getAllSujetsRespo() {
|
||||
if (identity.getRoles().contains("root")) {
|
||||
return Response.ok(sujetService.getAllSujetsAdmin()).build();
|
||||
|
@ -4,6 +4,7 @@ import fr.la_banquise.backend.rest.request.BulkUserRequest;
|
||||
import fr.la_banquise.backend.rest.request.UserRequest;
|
||||
import fr.la_banquise.backend.rest.response.LoggedUserResponse;
|
||||
import fr.la_banquise.backend.services.UserService;
|
||||
import io.quarkus.security.Authenticated;
|
||||
import io.quarkus.security.identity.SecurityIdentity;
|
||||
import jakarta.annotation.security.RolesAllowed;
|
||||
import jakarta.inject.Inject;
|
||||
@ -29,14 +30,21 @@ public class UserEndpoints {
|
||||
|
||||
@GET
|
||||
@Path("/me")
|
||||
@Authenticated
|
||||
public Response getCurrentUser() {
|
||||
System.out.println("=== DEBUG /me endpoint ===");
|
||||
System.out.println("Identity: " + identity);
|
||||
System.out.println("Principal: " + identity.getPrincipal());
|
||||
System.out.println("Principal name: " +
|
||||
identity.getPrincipal().getName());
|
||||
System.out.println("Roles: " + identity.getRoles());
|
||||
LoggedUserResponse user = new LoggedUserResponse(
|
||||
identity.getPrincipal().getName(), identity.getRoles());
|
||||
return Response.ok(user).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
//@RolesAllowed("root")
|
||||
@RolesAllowed("root")
|
||||
public Response getAllUsers() {
|
||||
return Response.ok(userService.getAllUsers()).build();
|
||||
}
|
||||
@ -49,12 +57,12 @@ public class UserEndpoints {
|
||||
}
|
||||
|
||||
@POST
|
||||
//@RolesAllowed("root")
|
||||
@RolesAllowed("root")
|
||||
public Response createUser(UserRequest user) {
|
||||
return Response.ok(userService.createUser(user)).build();
|
||||
}
|
||||
|
||||
@POST
|
||||
/*@POST
|
||||
@RolesAllowed("root")
|
||||
@Path("/jdmi")
|
||||
public Response createJdmiUsers(BulkUserRequest users) {
|
||||
@ -67,7 +75,7 @@ public class UserEndpoints {
|
||||
public Response deleteJDMI() {
|
||||
userService.deleteJDMI();
|
||||
return Response.ok().build();
|
||||
}
|
||||
}*/
|
||||
|
||||
@DELETE
|
||||
@RolesAllowed("root")
|
||||
|
@ -7,9 +7,14 @@ import lombok.AllArgsConstructor;
|
||||
/**
|
||||
* LoggedUserResponse
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
//@AllArgsConstructor
|
||||
@RegisterForReflection
|
||||
public class LoggedUserResponse {
|
||||
public String username;
|
||||
public Set<String> roles;
|
||||
|
||||
public LoggedUserResponse(String username, Set<String> roles) {
|
||||
this.username = username;
|
||||
this.roles = roles;
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ public class UserService {
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
/*@Transactional
|
||||
public void deleteJDMI() {
|
||||
for (Instance instance : instanceService.getAllInstances()) {
|
||||
instanceService.deleteInstance(instance.id);
|
||||
@ -73,5 +73,5 @@ public class UserService {
|
||||
user.instance_port, user.name, usersRequest.tpId);
|
||||
}
|
||||
return new ArrayList<User>();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
@ -39,3 +39,5 @@ quarkus.quinoa.enable-spa-routing=true
|
||||
|
||||
quarkus.docker.docker-host=unix:///run/user/1000/docker.sock
|
||||
#quarkus.security.auth.enabled-in-dev-mode=false
|
||||
|
||||
quarkus.hibernate-orm.sql-load-script=import-dev.sql
|
||||
|
2
src/main/resources/import-dev.sql
Normal file
2
src/main/resources/import-dev.sql
Normal file
@ -0,0 +1,2 @@
|
||||
-- Ce fichier est exécuté automatiquement en mode dev
|
||||
INSERT INTO penguin (name, password, role) VALUES ('root', '$2a$10$lzKAv4aj6s0jtneg0Ikx/eEBb6p.6N6yo7ZF.myqYxEA9MWbMwvNu', 'root');
|
Loading…
x
Reference in New Issue
Block a user