From 6ecaed9e5f3aff96de51af2f46ac113031fea63d Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Wed, 1 Jun 2022 00:15:21 +0200 Subject: [PATCH] [DEV] error path --- back/src/org/kar/oauth/api/Front.java | 90 ++++++++++++------------ back/src/org/kar/oauth/api/FrontSSO.java | 82 ++++++++++----------- 2 files changed, 86 insertions(+), 86 deletions(-) diff --git a/back/src/org/kar/oauth/api/Front.java b/back/src/org/kar/oauth/api/Front.java index 23c8448..cc0a25a 100644 --- a/back/src/org/kar/oauth/api/Front.java +++ b/back/src/org/kar/oauth/api/Front.java @@ -1,10 +1,12 @@ package org.kar.oauth.api; import java.io.File; +import java.util.List; import javax.annotation.security.PermitAll; import javax.ws.rs.*; import javax.ws.rs.core.CacheControl; +import javax.ws.rs.core.PathSegment; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.ResponseBuilder; @@ -19,34 +21,39 @@ public class Front { return ""; } private Response retrive(String fileName) throws Exception { - String filePathName = ConfigVariable.getFrontFolder() + File.separator + fileName; + String filePathName = ConfigVariable.getSsoFolder() + File.separator + fileName; String extention = getExtension(filePathName); String mineType = null; - if (extention.equalsIgnoreCase("jpg") || extention.equalsIgnoreCase("jpeg")) { - mineType = "image/jpeg"; - } else if (extention.equalsIgnoreCase("gif")) { - mineType = "image/gif"; - } else if (extention.equalsIgnoreCase("png")) { - mineType = "image/png"; - } else if (extention.equalsIgnoreCase("svg")) { - mineType = "image/svg+xml"; - } else if (extention.equalsIgnoreCase("webp")) { - mineType = "image/webp"; - } else if (extention.equalsIgnoreCase("js")) { - mineType = "application/javascript"; - } else if (extention.equalsIgnoreCase("json")) { - mineType = "application/json"; - } else if (extention.equalsIgnoreCase("ico")) { - mineType = "image/x-icon"; - } else if (extention.equalsIgnoreCase("html")) { - mineType = "text/html"; - } else if (extention.equalsIgnoreCase("css")) { - mineType = "text/css"; + if (!extention.isEmpty()) { + if (extention.equalsIgnoreCase("jpg") || extention.equalsIgnoreCase("jpeg")) { + mineType = "image/jpeg"; + } else if (extention.equalsIgnoreCase("gif")) { + mineType = "image/gif"; + } else if (extention.equalsIgnoreCase("png")) { + mineType = "image/png"; + } else if (extention.equalsIgnoreCase("svg")) { + mineType = "image/svg+xml"; + } else if (extention.equalsIgnoreCase("webp")) { + mineType = "image/webp"; + } else if (extention.equalsIgnoreCase("js")) { + mineType = "application/javascript"; + } else if (extention.equalsIgnoreCase("json")) { + mineType = "application/json"; + } else if (extention.equalsIgnoreCase("ico")) { + mineType = "image/x-icon"; + } else if (extention.equalsIgnoreCase("html")) { + mineType = "text/html"; + } else if (extention.equalsIgnoreCase("css")) { + mineType = "text/css"; + } else { + return Response.status(403). + entity("Not supported model: '" + fileName + "'"). + type("text/plain"). + build(); + } } else { - return Response.status(403). - entity("Not supported model: '" + fileName + "'"). - type("text/plain"). - build(); + mineType = "text/html"; + filePathName = "index.html"; } // reads input image File download = new File(filePathName); @@ -67,35 +74,28 @@ public class Front { return response.build(); } - + @GET @PermitAll() //@Produces(MediaType.APPLICATION_OCTET_STREAM) - //@CacheMaxAge(time = 10, unit = TimeUnit.DAYS) + //@CacheMaxAge(time = 1, unit = TimeUnit.DAYS) public Response retrive0() throws Exception { return retrive("index.html"); } - + @GET - @Path("{baseA}") + @Path("{any: .*}") @PermitAll() //@Produces(MediaType.APPLICATION_OCTET_STREAM) //@CacheMaxAge(time = 10, unit = TimeUnit.DAYS) - public Response retrive1(@PathParam("baseA") String baseA) throws Exception { - return retrive(baseA); - } - - @GET - @Path("assets/images/{baseB}") - @PermitAll() - public Response retrive2(@PathParam("baseB") String baseB) throws Exception { - return retrive("assets" + File.separator + "images" + File.separator + baseB); - } - - @GET - @Path("assets/js_3rd_party/{baseB}") - @PermitAll() - public Response retrive3(@PathParam("baseB") String baseB) throws Exception { - return retrive("assets" + File.separator + "js_3rd_party" + File.separator + baseB); + public Response retrive1(@PathParam("any") List segments) throws Exception { + String filename = ""; + for (PathSegment elem: segments) { + if (!filename.isEmpty()) { + filename += File.separator; + } + filename += elem.getPath(); + } + return retrive(filename); } } diff --git a/back/src/org/kar/oauth/api/FrontSSO.java b/back/src/org/kar/oauth/api/FrontSSO.java index 344083e..ba86e0a 100644 --- a/back/src/org/kar/oauth/api/FrontSSO.java +++ b/back/src/org/kar/oauth/api/FrontSSO.java @@ -1,11 +1,13 @@ package org.kar.oauth.api; import java.io.File; +import java.util.List; import java.util.concurrent.TimeUnit; import javax.annotation.security.PermitAll; import javax.ws.rs.*; import javax.ws.rs.core.CacheControl; +import javax.ws.rs.core.PathSegment; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.ResponseBuilder; @@ -24,31 +26,36 @@ public class FrontSSO { String filePathName = ConfigVariable.getSsoFolder() + File.separator + fileName; String extention = getExtension(filePathName); String mineType = null; - if (extention.equalsIgnoreCase("jpg") || extention.equalsIgnoreCase("jpeg")) { - mineType = "image/jpeg"; - } else if (extention.equalsIgnoreCase("gif")) { - mineType = "image/gif"; - } else if (extention.equalsIgnoreCase("png")) { - mineType = "image/png"; - } else if (extention.equalsIgnoreCase("svg")) { - mineType = "image/svg+xml"; - } else if (extention.equalsIgnoreCase("webp")) { - mineType = "image/webp"; - } else if (extention.equalsIgnoreCase("js")) { - mineType = "application/javascript"; - } else if (extention.equalsIgnoreCase("json")) { - mineType = "application/json"; - } else if (extention.equalsIgnoreCase("ico")) { - mineType = "image/x-icon"; - } else if (extention.equalsIgnoreCase("html")) { - mineType = "text/html"; - } else if (extention.equalsIgnoreCase("css")) { - mineType = "text/css"; + if (!extention.isEmpty()) { + if (extention.equalsIgnoreCase("jpg") || extention.equalsIgnoreCase("jpeg")) { + mineType = "image/jpeg"; + } else if (extention.equalsIgnoreCase("gif")) { + mineType = "image/gif"; + } else if (extention.equalsIgnoreCase("png")) { + mineType = "image/png"; + } else if (extention.equalsIgnoreCase("svg")) { + mineType = "image/svg+xml"; + } else if (extention.equalsIgnoreCase("webp")) { + mineType = "image/webp"; + } else if (extention.equalsIgnoreCase("js")) { + mineType = "application/javascript"; + } else if (extention.equalsIgnoreCase("json")) { + mineType = "application/json"; + } else if (extention.equalsIgnoreCase("ico")) { + mineType = "image/x-icon"; + } else if (extention.equalsIgnoreCase("html")) { + mineType = "text/html"; + } else if (extention.equalsIgnoreCase("css")) { + mineType = "text/css"; + } else { + return Response.status(403). + entity("Not supported model: '" + fileName + "'"). + type("text/plain"). + build(); + } } else { - return Response.status(403). - entity("Not supported model: '" + fileName + "'"). - type("text/plain"). - build(); + mineType = "text/html"; + filePathName = "index.html"; } // reads input image File download = new File(filePathName); @@ -79,25 +86,18 @@ public class FrontSSO { } @GET - @Path("{baseA}") + @Path("{any: .*}") @PermitAll() //@Produces(MediaType.APPLICATION_OCTET_STREAM) //@CacheMaxAge(time = 10, unit = TimeUnit.DAYS) - public Response retrive1(@PathParam("baseA") String baseA) throws Exception { - return retrive(baseA); - } - - @GET - @Path("assets/images/{baseB}") - @PermitAll() - public Response retrive2(@PathParam("baseB") String baseB) throws Exception { - return retrive("assets" + File.separator + "images" + File.separator + baseB); - } - - @GET - @Path("assets/js_3rd_party/{baseB}") - @PermitAll() - public Response retrive3(@PathParam("baseB") String baseB) throws Exception { - return retrive("assets" + File.separator + "js_3rd_party" + File.separator + baseB); + public Response retrive1(@PathParam("any") List segments) throws Exception { + String filename = ""; + for (PathSegment elem: segments) { + if (!filename.isEmpty()) { + filename += File.separator; + } + filename += elem.getPath(); + } + return retrive(filename); } }