#396 feature - Refactoring error management
1 files deleted
1 files added
8 files modified
| .. | .. |
|---|
| 1 | +package net.curisit.securis; |
|---|
| 2 | + |
|---|
| 3 | +import javax.ws.rs.ForbiddenException; |
|---|
| 4 | +import javax.ws.rs.core.MediaType; |
|---|
| 5 | +import javax.ws.rs.core.Response; |
|---|
| 6 | +import javax.ws.rs.core.Response.Status; |
|---|
| 7 | +import javax.ws.rs.ext.ExceptionMapper; |
|---|
| 8 | +import javax.ws.rs.ext.Provider; |
|---|
| 9 | + |
|---|
| 10 | +@Provider |
|---|
| 11 | +public class DefaultExceptionHandler implements ExceptionMapper<Exception> { |
|---|
| 12 | + |
|---|
| 13 | + public static final String ERROR_MESSAGE_HEADER = "X-SECURIS-ERROR"; |
|---|
| 14 | + |
|---|
| 15 | + public DefaultExceptionHandler() { |
|---|
| 16 | + MainApp.log.info("Creating DefaultExceptionHandler "); |
|---|
| 17 | + } |
|---|
| 18 | + |
|---|
| 19 | + @Override |
|---|
| 20 | + public Response toResponse(Exception e) { |
|---|
| 21 | + // log.info("Creating DefaultExceptionHandler "); |
|---|
| 22 | + // e.printStackTrace(); |
|---|
| 23 | + if (e instanceof ForbiddenException) |
|---|
| 24 | + return Response.status(Status.UNAUTHORIZED).header(ERROR_MESSAGE_HEADER, "Unathorized access to the application").type(MediaType.APPLICATION_JSON).build(); |
|---|
| 25 | + |
|---|
| 26 | + return Response.serverError().header(ERROR_MESSAGE_HEADER, "Unexpected error: " + e.toString()).type(MediaType.APPLICATION_JSON).build(); |
|---|
| 27 | + } |
|---|
| 28 | +} |
|---|
| .. | .. |
|---|
| 5 | 5 |
|
|---|
| 6 | 6 | import javax.inject.Inject;
|
|---|
| 7 | 7 | import javax.inject.Named;
|
|---|
| 8 | | -import javax.ws.rs.core.MediaType;
|
|---|
| 9 | | -import javax.ws.rs.core.Response;
|
|---|
| 10 | | -import javax.ws.rs.ext.ExceptionMapper;
|
|---|
| 11 | | -import javax.ws.rs.ext.Provider;
|
|---|
| 12 | 8 |
|
|---|
| 13 | 9 | import net.curisit.securis.ioc.RequestsModule;
|
|---|
| 14 | 10 | import net.curisit.securis.ioc.SecurisModule;
|
|---|
| .. | .. |
|---|
| 17 | 13 | import org.eclipse.jetty.server.Server;
|
|---|
| 18 | 14 | import org.eclipse.jetty.server.handler.ContextHandlerCollection;
|
|---|
| 19 | 15 | import org.eclipse.jetty.server.handler.ResourceHandler;
|
|---|
| 16 | +import org.eclipse.jetty.servlet.ErrorPageErrorHandler;
|
|---|
| 20 | 17 | import org.eclipse.jetty.servlet.FilterHolder;
|
|---|
| 21 | 18 | import org.eclipse.jetty.servlet.ServletContextHandler;
|
|---|
| 22 | 19 | import org.eclipse.jetty.servlet.ServletHolder;
|
|---|
| .. | .. |
|---|
| 35 | 32 |
|
|---|
| 36 | 33 | public class MainApp {
|
|---|
| 37 | 34 |
|
|---|
| 38 | | - private static final Logger log = LoggerFactory.getLogger(MainApp.class);
|
|---|
| 35 | + static final Logger log = LoggerFactory.getLogger(MainApp.class);
|
|---|
| 39 | 36 |
|
|---|
| 40 | 37 | private static Server server;
|
|---|
| 41 | 38 | private static Injector injector = null;
|
|---|
| .. | .. |
|---|
| 74 | 71 |
|
|---|
| 75 | 72 | context.setInitParameter("resteasy.role.based.security", "true");
|
|---|
| 76 | 73 | context.setInitParameter("resteasy.providers", DefaultExceptionHandler.class.getName());
|
|---|
| 77 | | - context.addFilter(new FilterHolder(injector.getInstance(AuthFilter.class)), "/*", null);
|
|---|
| 74 | + // context.addFilter(new FilterHolder(injector.getInstance(AuthFilter.class)), "/*", null);
|
|---|
| 78 | 75 | context.addFilter(new FilterHolder(injector.getInstance(PersistFilter.class)), "/*", null);
|
|---|
| 79 | 76 | ServletHolder sh = new ServletHolder(HttpServletDispatcher.class);
|
|---|
| 80 | 77 | sh.setName("resteasy");
|
|---|
| .. | .. |
|---|
| 86 | 83 | { "/main.html" });
|
|---|
| 87 | 84 | context.setHandler(staticResources);
|
|---|
| 88 | 85 |
|
|---|
| 89 | | - // ErrorPageErrorHandler errorHandler = new ErrorPageErrorHandler();
|
|---|
| 90 | | - // context.setErrorHandler(errorHandler);
|
|---|
| 86 | + ErrorPageErrorHandler errorHandler = new ErrorPageErrorHandler();
|
|---|
| 87 | + context.setErrorHandler(errorHandler);
|
|---|
| 91 | 88 | // errorHandler.addErrorPage(HttpResponseCodes.SC_FORBIDDEN, "/login");
|
|---|
| 92 | 89 | // errorHandler.addErrorPage(HttpResponseCodes.SC_NOT_FOUND, "/");
|
|---|
| 93 | 90 | // errorHandler.addErrorPage(javax.ws.rs.NotFoundException.class, "/");
|
|---|
| 94 | 91 | // errorHandler.addErrorPage(javax.ws.rs.ForbiddenException.class, "/");
|
|---|
| 95 | 92 | // errorHandler.addErrorPage(javax.ws.rs.ForbiddenException.class.getCanonicalName(), "/");
|
|---|
| 96 | 93 | // errorHandler.addErrorPage(ErrorPageErrorHandler.GLOBAL_ERROR_PAGE, "/");
|
|---|
| 97 | | - context.setWelcomeFiles(new String[]
|
|---|
| 98 | | - { "/index" });
|
|---|
| 99 | 94 | log.info("Error Handlers: " + context.getErrorHandler());
|
|---|
| 100 | 95 | ContextHandlerCollection contexts = new ContextHandlerCollection();
|
|---|
| 101 | 96 |
|
|---|
| .. | .. |
|---|
| 107 | 102 | server.start();
|
|---|
| 108 | 103 | server.join();
|
|---|
| 109 | 104 | log.info("Started server in: http://127.0.0.1:9997/");
|
|---|
| 110 | | - }
|
|---|
| 111 | | -
|
|---|
| 112 | | - @Provider
|
|---|
| 113 | | - public static class DefaultExceptionHandler implements ExceptionMapper<Exception> {
|
|---|
| 114 | | -
|
|---|
| 115 | | - public DefaultExceptionHandler() {
|
|---|
| 116 | | - log.info("Creating DefaultExceptionHandler ");
|
|---|
| 117 | | - }
|
|---|
| 118 | | -
|
|---|
| 119 | | - @Override
|
|---|
| 120 | | - public Response toResponse(Exception e) {
|
|---|
| 121 | | - // log.info("Creating DefaultExceptionHandler ");
|
|---|
| 122 | | - e.printStackTrace();
|
|---|
| 123 | | - // For simplicity I am preparing error xml by hand.
|
|---|
| 124 | | - // Ideally we should create an ErrorResponse class to hold the error info.
|
|---|
| 125 | | - StringBuilder response = new StringBuilder("<response>");
|
|---|
| 126 | | - response.append("<status>ERROR</status>");
|
|---|
| 127 | | - response.append("<message>" + e.getMessage() + "</message>");
|
|---|
| 128 | | - response.append("</response>");
|
|---|
| 129 | | - return Response.serverError().entity(response.toString()).type(MediaType.APPLICATION_XML).build();
|
|---|
| 130 | | - }
|
|---|
| 131 | 105 | }
|
|---|
| 132 | 106 |
|
|---|
| 133 | 107 | }
|
|---|
deleted file mode 100644| .. | .. |
|---|
| 1 | | -package net.curisit.securis; |
|---|
| 2 | | - |
|---|
| 3 | | -import java.io.IOException; |
|---|
| 4 | | -import java.io.Writer; |
|---|
| 5 | | - |
|---|
| 6 | | -import javax.servlet.http.HttpServletRequest; |
|---|
| 7 | | - |
|---|
| 8 | | -import org.eclipse.jetty.server.handler.ErrorHandler; |
|---|
| 9 | | - |
|---|
| 10 | | -public class SecurisErrorHandler extends ErrorHandler { |
|---|
| 11 | | - |
|---|
| 12 | | - public static String HEADER_ERROR_MESSAGE = "X-SECURIS-ERROR"; |
|---|
| 13 | | - |
|---|
| 14 | | - @Override |
|---|
| 15 | | - protected void writeErrorPageHead(HttpServletRequest request, Writer writer, int code, String message) throws IOException { |
|---|
| 16 | | - // TODO Auto-generated method stub |
|---|
| 17 | | - super.writeErrorPageHead(request, writer, code, message); |
|---|
| 18 | | - } |
|---|
| 19 | | -} |
|---|
| .. | .. |
|---|
| 30 | 30 | import org.slf4j.Logger; |
|---|
| 31 | 31 | import org.slf4j.LoggerFactory; |
|---|
| 32 | 32 | |
|---|
| 33 | | -//@Provider |
|---|
| 34 | | -//@Priority(Priorities.AUTHENTICATION) |
|---|
| 35 | | -//public class SecurityInterceptor implements javax.ws.rs.container.ContainerRequestFilter { |
|---|
| 36 | | - |
|---|
| 37 | 33 | @Provider |
|---|
| 38 | | -// @ServerInterceptor |
|---|
| 39 | | -// @Precedence("SECURITY") |
|---|
| 40 | | -// public class SecurityInterceptor implements PreProcessInterceptor { |
|---|
| 41 | 34 | // @PreMatching |
|---|
| 42 | 35 | @Priority(Priorities.AUTHENTICATION) |
|---|
| 43 | 36 | public class SecurityInterceptor implements javax.ws.rs.container.ContainerRequestFilter { |
|---|
| .. | .. |
|---|
| 23 | 23 | import javax.ws.rs.core.Response.Status; |
|---|
| 24 | 24 | |
|---|
| 25 | 25 | import net.curisit.integrity.commons.Utils; |
|---|
| 26 | | -import net.curisit.securis.SecurisErrorHandler; |
|---|
| 26 | +import net.curisit.securis.DefaultExceptionHandler; |
|---|
| 27 | 27 | import net.curisit.securis.db.Application; |
|---|
| 28 | 28 | import net.curisit.securis.utils.TokenHelper; |
|---|
| 29 | 29 | |
|---|
| .. | .. |
|---|
| 88 | 88 | Application app = em.find(Application.class, Integer.parseInt(appid)); |
|---|
| 89 | 89 | if (app == null) { |
|---|
| 90 | 90 | log.error("Application with id {} not found in DB", appid); |
|---|
| 91 | | - return Response.status(Status.NOT_FOUND).header(SecurisErrorHandler.HEADER_ERROR_MESSAGE, "Application not found with ID: " + appid).build(); |
|---|
| 91 | + |
|---|
| 92 | + return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Application not found with ID: " + appid).build(); |
|---|
| 92 | 93 | } |
|---|
| 93 | 94 | return Response.ok(app).build(); |
|---|
| 94 | 95 | } |
|---|
| .. | .. |
|---|
| 121 | 122 | Application currentapp = em.find(Application.class, Integer.parseInt(appid)); |
|---|
| 122 | 123 | if (currentapp == null) { |
|---|
| 123 | 124 | log.error("Application with id {} not found in DB", appid); |
|---|
| 124 | | - return Response.status(Status.NOT_FOUND).header(SecurisErrorHandler.HEADER_ERROR_MESSAGE, "Application not found with ID: " + appid).build(); |
|---|
| 125 | + return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Application not found with ID: " + appid).build(); |
|---|
| 125 | 126 | } |
|---|
| 126 | 127 | currentapp.setName(app.getName()); |
|---|
| 127 | 128 | currentapp.setDescription(app.getDescription()); |
|---|
| .. | .. |
|---|
| 141 | 142 | Application app = em.find(Application.class, Integer.parseInt(appid)); |
|---|
| 142 | 143 | if (app == null) { |
|---|
| 143 | 144 | log.error("Application with id {} can not be deleted, It was not found in DB", appid); |
|---|
| 144 | | - return Response.status(Status.NOT_FOUND).header(SecurisErrorHandler.HEADER_ERROR_MESSAGE, "Application not found with ID: " + appid).build(); |
|---|
| 145 | + return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Application not found with ID: " + appid).build(); |
|---|
| 145 | 146 | } |
|---|
| 146 | 147 | |
|---|
| 147 | 148 | if (app.getLicenseTypes() != null && app.getLicenseTypes().size() > 0) { |
|---|
| 148 | | - return Response.status(Status.FORBIDDEN).header(SecurisErrorHandler.HEADER_ERROR_MESSAGE, "Application can not be deleted becasue has assigned one or more License types, ID: " + appid).build(); |
|---|
| 149 | + return Response.status(Status.FORBIDDEN).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Application can not be deleted becasue has assigned one or more License types, ID: " + appid).build(); |
|---|
| 149 | 150 | } |
|---|
| 150 | 151 | |
|---|
| 151 | 152 | em.remove(app); |
|---|
| .. | .. |
|---|
| 24 | 24 | |
|---|
| 25 | 25 | import net.curisit.integrity.commons.Utils; |
|---|
| 26 | 26 | import net.curisit.integrity.exception.CurisException; |
|---|
| 27 | | -import net.curisit.securis.SecurisErrorHandler; |
|---|
| 27 | +import net.curisit.securis.DefaultExceptionHandler; |
|---|
| 28 | 28 | import net.curisit.securis.db.License; |
|---|
| 29 | 29 | import net.curisit.securis.db.Pack; |
|---|
| 30 | 30 | import net.curisit.securis.db.User; |
|---|
| .. | .. |
|---|
| 111 | 111 | pack = em.find(Pack.class, lic.getPackId()); |
|---|
| 112 | 112 | if (pack == null) { |
|---|
| 113 | 113 | log.error("License pack with id {} not found in DB", lic.getPackId()); |
|---|
| 114 | | - return Response.status(Status.NOT_FOUND).header(SecurisErrorHandler.HEADER_ERROR_MESSAGE, "License's pack not found with ID: " + lic.getPackId()).build(); |
|---|
| 114 | + return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "License's pack not found with ID: " + lic.getPackId()).build(); |
|---|
| 115 | 115 | } |
|---|
| 116 | 116 | } |
|---|
| 117 | 117 | |
|---|
| .. | .. |
|---|
| 121 | 121 | } catch (CurisException ex) { |
|---|
| 122 | 122 | String createdByUsername = lic.getCreatedById(); |
|---|
| 123 | 123 | log.error("License created by user with id {} not found in DB", createdByUsername); |
|---|
| 124 | | - return Response.status(Status.NOT_FOUND).header(SecurisErrorHandler.HEADER_ERROR_MESSAGE, "License's created by user not found with ID: " + createdByUsername).build(); |
|---|
| 124 | + return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "License's created by user not found with ID: " + createdByUsername).build(); |
|---|
| 125 | 125 | } |
|---|
| 126 | 126 | |
|---|
| 127 | 127 | try { |
|---|
| .. | .. |
|---|
| 130 | 130 | } catch (CurisException ex) { |
|---|
| 131 | 131 | String canceledByUsername = lic.getCreatedById(); |
|---|
| 132 | 132 | log.error("License canceled by user with id {} not found in DB", canceledByUsername); |
|---|
| 133 | | - return Response.status(Status.NOT_FOUND).header(SecurisErrorHandler.HEADER_ERROR_MESSAGE, "License's canceled by user not found with ID: " + canceledByUsername).build(); |
|---|
| 133 | + return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "License's canceled by user not found with ID: " + canceledByUsername).build(); |
|---|
| 134 | 134 | } |
|---|
| 135 | 135 | |
|---|
| 136 | 136 | lic.setCreationTimestamp(new Date()); |
|---|
| .. | .. |
|---|
| 166 | 166 | pack = em.find(Pack.class, lic.getPackId()); |
|---|
| 167 | 167 | if (pack == null) { |
|---|
| 168 | 168 | log.error("License pack with id {} not found in DB", lic.getPackId()); |
|---|
| 169 | | - return Response.status(Status.NOT_FOUND).header(SecurisErrorHandler.HEADER_ERROR_MESSAGE, "License's pack not found with ID: " + lic.getPackId()).build(); |
|---|
| 169 | + return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "License's pack not found with ID: " + lic.getPackId()).build(); |
|---|
| 170 | 170 | } |
|---|
| 171 | 171 | } |
|---|
| 172 | 172 | User createdBy = null; |
|---|
| .. | .. |
|---|
| 175 | 175 | } catch (CurisException ex) { |
|---|
| 176 | 176 | String createdByUsername = lic.getCreatedById(); |
|---|
| 177 | 177 | log.error("License created by user with id {} not found in DB", createdByUsername); |
|---|
| 178 | | - return Response.status(Status.NOT_FOUND).header(SecurisErrorHandler.HEADER_ERROR_MESSAGE, "License's created by user not found with ID: " + createdByUsername).build(); |
|---|
| 178 | + return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "License's created by user not found with ID: " + createdByUsername).build(); |
|---|
| 179 | 179 | } |
|---|
| 180 | 180 | |
|---|
| 181 | 181 | User canceledBy = null; |
|---|
| .. | .. |
|---|
| 184 | 184 | } catch (CurisException ex) { |
|---|
| 185 | 185 | String canceledByUsername = lic.getCreatedById(); |
|---|
| 186 | 186 | log.error("License canceled by user with id {} not found in DB", canceledByUsername); |
|---|
| 187 | | - return Response.status(Status.NOT_FOUND).header(SecurisErrorHandler.HEADER_ERROR_MESSAGE, "License's canceled by user not found with ID: " + canceledByUsername).build(); |
|---|
| 187 | + return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "License's canceled by user not found with ID: " + canceledByUsername).build(); |
|---|
| 188 | 188 | } |
|---|
| 189 | 189 | |
|---|
| 190 | 190 | lic.setCreatedBy(createdBy); |
|---|
| .. | .. |
|---|
| 206 | 206 | License org = em.find(License.class, Integer.parseInt(licId)); |
|---|
| 207 | 207 | if (org == null) { |
|---|
| 208 | 208 | log.error("License with id {} can not be deleted, It was not found in DB", licId); |
|---|
| 209 | | - return Response.status(Status.NOT_FOUND).header(SecurisErrorHandler.HEADER_ERROR_MESSAGE, "License was not found, ID: " + licId).build(); |
|---|
| 209 | + return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "License was not found, ID: " + licId).build(); |
|---|
| 210 | 210 | } |
|---|
| 211 | 211 | |
|---|
| 212 | 212 | em.remove(org); |
|---|
| .. | .. |
|---|
| 23 | 23 | import javax.ws.rs.core.Response.Status; |
|---|
| 24 | 24 | |
|---|
| 25 | 25 | import net.curisit.integrity.commons.Utils; |
|---|
| 26 | | -import net.curisit.securis.SecurisErrorHandler; |
|---|
| 26 | +import net.curisit.securis.DefaultExceptionHandler; |
|---|
| 27 | 27 | import net.curisit.securis.db.Application; |
|---|
| 28 | 28 | import net.curisit.securis.db.LicenseType; |
|---|
| 29 | 29 | import net.curisit.securis.utils.TokenHelper; |
|---|
| .. | .. |
|---|
| 108 | 108 | app = em.find(Application.class, lt.getApplicationId()); |
|---|
| 109 | 109 | if (app == null) { |
|---|
| 110 | 110 | log.error("LicenseType application with id {} not found in DB", lt.getApplicationId()); |
|---|
| 111 | | - return Response.status(Status.NOT_FOUND).header(SecurisErrorHandler.HEADER_ERROR_MESSAGE, "License type's app not found with ID: " + lt.getApplicationId()).build(); |
|---|
| 111 | + return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "License type's app not found with ID: " + lt.getApplicationId()).build(); |
|---|
| 112 | 112 | } |
|---|
| 113 | 113 | } else { |
|---|
| 114 | 114 | log.error("Application is missing for current license type data"); |
|---|
| 115 | | - return Response.status(Status.NOT_FOUND).header(SecurisErrorHandler.HEADER_ERROR_MESSAGE, "Application is missing for current license type data").build(); |
|---|
| 115 | + return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Application is missing for current license type data").build(); |
|---|
| 116 | 116 | } |
|---|
| 117 | 117 | |
|---|
| 118 | 118 | lt.setApplication(app); |
|---|
| .. | .. |
|---|
| 135 | 135 | LicenseType currentlt = em.find(LicenseType.class, Integer.parseInt(ltid)); |
|---|
| 136 | 136 | if (currentlt == null) { |
|---|
| 137 | 137 | log.error("LicenseType with id {} not found in DB", ltid); |
|---|
| 138 | | - return Response.status(Status.NOT_FOUND).header(SecurisErrorHandler.HEADER_ERROR_MESSAGE, "License type not found with ID: " + ltid).build(); |
|---|
| 138 | + return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "License type not found with ID: " + ltid).build(); |
|---|
| 139 | 139 | } |
|---|
| 140 | 140 | Application app = null; |
|---|
| 141 | 141 | if (lt.getApplicationId() != null) { |
|---|
| 142 | 142 | app = em.find(Application.class, lt.getApplicationId()); |
|---|
| 143 | 143 | if (app == null) { |
|---|
| 144 | 144 | log.error("LicenseType application with id {} not found in DB", lt.getApplicationId()); |
|---|
| 145 | | - return Response.status(Status.NOT_FOUND).header(SecurisErrorHandler.HEADER_ERROR_MESSAGE, "License type's app not found with ID: " + lt.getApplicationId()).build(); |
|---|
| 145 | + return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "License type's app not found with ID: " + lt.getApplicationId()).build(); |
|---|
| 146 | 146 | } |
|---|
| 147 | 147 | } |
|---|
| 148 | 148 | currentlt.setCode(lt.getCode()); |
|---|
| .. | .. |
|---|
| 25 | 25 | import javax.ws.rs.core.Response.Status; |
|---|
| 26 | 26 | |
|---|
| 27 | 27 | import net.curisit.integrity.commons.Utils; |
|---|
| 28 | | -import net.curisit.securis.SecurisErrorHandler; |
|---|
| 28 | +import net.curisit.securis.DefaultExceptionHandler; |
|---|
| 29 | 29 | import net.curisit.securis.db.Organization; |
|---|
| 30 | 30 | import net.curisit.securis.db.User; |
|---|
| 31 | 31 | import net.curisit.securis.security.BasicSecurityContext; |
|---|
| .. | .. |
|---|
| 146 | 146 | parentOrg = em.find(Organization.class, org.getParentOrgId()); |
|---|
| 147 | 147 | if (parentOrg == null) { |
|---|
| 148 | 148 | log.error("Organization parent with id {} not found in DB", org.getParentOrgId()); |
|---|
| 149 | | - return Response.status(Status.NOT_FOUND).header(SecurisErrorHandler.HEADER_ERROR_MESSAGE, "Organization's parent not found with ID: " + org.getParentOrgId()).build(); |
|---|
| 149 | + return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Organization's parent not found with ID: " + org.getParentOrgId()).build(); |
|---|
| 150 | 150 | } |
|---|
| 151 | 151 | } |
|---|
| 152 | 152 | List<User> users = null; |
|---|
| .. | .. |
|---|
| 157 | 157 | User user = em.find(User.class, username); |
|---|
| 158 | 158 | if (user == null) { |
|---|
| 159 | 159 | log.error("Organization user with id {} not found in DB", username); |
|---|
| 160 | | - return Response.status(Status.NOT_FOUND).header(SecurisErrorHandler.HEADER_ERROR_MESSAGE, "Organization's user not found with ID: " + username).build(); |
|---|
| 160 | + return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Organization's user not found with ID: " + username).build(); |
|---|
| 161 | 161 | } |
|---|
| 162 | 162 | users.add(user); |
|---|
| 163 | 163 | } |
|---|
| .. | .. |
|---|
| 186 | 186 | Organization currentOrg = em.find(Organization.class, Integer.parseInt(orgid)); |
|---|
| 187 | 187 | if (currentOrg == null) { |
|---|
| 188 | 188 | log.error("Organization with id {} not found in DB", orgid); |
|---|
| 189 | | - return Response.status(Status.NOT_FOUND).header(SecurisErrorHandler.HEADER_ERROR_MESSAGE, "Organization not found with ID: " + orgid).build(); |
|---|
| 189 | + return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Organization not found with ID: " + orgid).build(); |
|---|
| 190 | 190 | } |
|---|
| 191 | 191 | Organization parentOrg = null; |
|---|
| 192 | 192 | if (org.getParentOrgId() != null) { |
|---|
| 193 | 193 | parentOrg = em.find(Organization.class, org.getParentOrgId()); |
|---|
| 194 | 194 | if (parentOrg == null) { |
|---|
| 195 | 195 | log.error("Organization parent with id {} not found in DB", org.getParentOrgId()); |
|---|
| 196 | | - return Response.status(Status.NOT_FOUND).header(SecurisErrorHandler.HEADER_ERROR_MESSAGE, "Organization's parent not found with ID: " + org.getParentOrgId()).build(); |
|---|
| 196 | + return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Organization's parent not found with ID: " + org.getParentOrgId()).build(); |
|---|
| 197 | 197 | } |
|---|
| 198 | 198 | if (isCyclicalRelationship(currentOrg.getId(), parentOrg)) { |
|---|
| 199 | 199 | log.error("Organization parent generate a cyclical relationship, parent id {}, current id: {}", org.getParentOrgId(), currentOrg.getId()); |
|---|
| 200 | | - return Response.status(Status.FORBIDDEN).header(SecurisErrorHandler.HEADER_ERROR_MESSAGE, "Cyclical relationships are not allowed, please change the parent organization, current Parent: " + parentOrg.getName()).build(); |
|---|
| 200 | + return Response.status(Status.FORBIDDEN).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Cyclical relationships are not allowed, please change the parent organization, current Parent: " + parentOrg.getName()).build(); |
|---|
| 201 | 201 | } |
|---|
| 202 | 202 | } |
|---|
| 203 | 203 | |
|---|
| .. | .. |
|---|
| 209 | 209 | User user = em.find(User.class, username); |
|---|
| 210 | 210 | if (user == null) { |
|---|
| 211 | 211 | log.error("Organization user with id '{}' not found in DB", username); |
|---|
| 212 | | - return Response.status(Status.NOT_FOUND).header(SecurisErrorHandler.HEADER_ERROR_MESSAGE, "Organization's user not found with ID: " + username).build(); |
|---|
| 212 | + return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Organization's user not found with ID: " + username).build(); |
|---|
| 213 | 213 | } |
|---|
| 214 | 214 | users.add(user); |
|---|
| 215 | 215 | } |
|---|
| .. | .. |
|---|
| 238 | 238 | Organization org = em.find(Organization.class, Integer.parseInt(orgid)); |
|---|
| 239 | 239 | if (org == null) { |
|---|
| 240 | 240 | log.error("Organization with id {} can not be deleted, It was not found in DB", orgid); |
|---|
| 241 | | - return Response.status(Status.NOT_FOUND).header(SecurisErrorHandler.HEADER_ERROR_MESSAGE, "Organization was not found, ID: " + orgid).build(); |
|---|
| 241 | + return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Organization was not found, ID: " + orgid).build(); |
|---|
| 242 | 242 | } |
|---|
| 243 | 243 | if (org.getChildOrganizations() != null && org.getChildOrganizations().size() > 0) { |
|---|
| 244 | 244 | log.error("Organization has children and can not be deleted, ID: " + orgid); |
|---|
| 245 | | - return Response.status(Status.FORBIDDEN).header(SecurisErrorHandler.HEADER_ERROR_MESSAGE, "Organization has children and can not be deleted, ID: " + orgid).build(); |
|---|
| 245 | + return Response.status(Status.FORBIDDEN).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Organization has children and can not be deleted, ID: " + orgid).build(); |
|---|
| 246 | 246 | } |
|---|
| 247 | 247 | |
|---|
| 248 | 248 | em.remove(org); |
|---|
| .. | .. |
|---|
| 24 | 24 | |
|---|
| 25 | 25 | import net.curisit.integrity.commons.Utils; |
|---|
| 26 | 26 | import net.curisit.integrity.exception.CurisException; |
|---|
| 27 | | -import net.curisit.securis.SecurisErrorHandler; |
|---|
| 27 | +import net.curisit.securis.DefaultExceptionHandler; |
|---|
| 28 | 28 | import net.curisit.securis.db.Pack; |
|---|
| 29 | 29 | import net.curisit.securis.db.User; |
|---|
| 30 | 30 | import net.curisit.securis.utils.TokenHelper; |
|---|
| .. | .. |
|---|
| 150 | 150 | Pack org = em.find(Pack.class, Integer.parseInt(packId)); |
|---|
| 151 | 151 | if (org == null) { |
|---|
| 152 | 152 | log.error("Pack with id {} can not be deleted, It was not found in DB", packId); |
|---|
| 153 | | - return Response.status(Status.NOT_FOUND).header(SecurisErrorHandler.HEADER_ERROR_MESSAGE, "Pack was not found, ID: " + packId).build(); |
|---|
| 153 | + return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Pack was not found, ID: " + packId).build(); |
|---|
| 154 | 154 | } |
|---|
| 155 | 155 | |
|---|
| 156 | 156 | em.remove(org); |
|---|
| .. | .. |
|---|
| 27 | 27 | import javax.ws.rs.core.Response.Status; |
|---|
| 28 | 28 | |
|---|
| 29 | 29 | import net.curisit.integrity.commons.Utils; |
|---|
| 30 | +import net.curisit.securis.DefaultExceptionHandler; |
|---|
| 30 | 31 | import net.curisit.securis.db.Organization; |
|---|
| 31 | 32 | import net.curisit.securis.db.User; |
|---|
| 32 | 33 | import net.curisit.securis.utils.TokenHelper; |
|---|
| .. | .. |
|---|
| 122 | 123 | Organization o = em.find(Organization.class, orgId); |
|---|
| 123 | 124 | if (o == null) { |
|---|
| 124 | 125 | log.error("User organization with id {} not found in DB", orgId); |
|---|
| 125 | | - return Response.status(Status.NOT_FOUND).header("SECURIS_ERROR", "User's organization not found with ID: " + orgId).build(); |
|---|
| 126 | + return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "User's organization not found with ID: " + orgId).build(); |
|---|
| 126 | 127 | } |
|---|
| 127 | 128 | orgs.add(o); |
|---|
| 128 | 129 | } |
|---|
| .. | .. |
|---|
| 161 | 162 | Organization o = em.find(Organization.class, orgId); |
|---|
| 162 | 163 | if (o == null) { |
|---|
| 163 | 164 | log.error("User organization with id {} not found in DB", orgId); |
|---|
| 164 | | - return Response.status(Status.NOT_FOUND).header("SECURIS_ERROR", "User's user not found with ID: " + orgId).build(); |
|---|
| 165 | + return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "User's user not found with ID: " + orgId).build(); |
|---|
| 165 | 166 | } |
|---|
| 166 | 167 | orgs.add(o); |
|---|
| 167 | 168 | } |
|---|