Added route for Forbidden errors

This commit is contained in:
Francesco 2023-11-08 17:22:01 +01:00
parent 0e389e69ec
commit 79a8af91e8
3 changed files with 47 additions and 0 deletions

View File

@ -33,6 +33,7 @@ import jakarta.servlet.http.HttpServletResponse;
import tech.ailef.snapadmin.external.SnapAdmin;
import tech.ailef.snapadmin.external.SnapAdminProperties;
import tech.ailef.snapadmin.external.exceptions.SnapAdminException;
import tech.ailef.snapadmin.external.exceptions.SnapAdminForbiddenException;
import tech.ailef.snapadmin.external.exceptions.SnapAdminNotFoundException;
import tech.ailef.snapadmin.internal.UserConfiguration;

View File

@ -662,6 +662,14 @@ public class SnapAdminController {
return "settings/appearance";
}
@GetMapping("/forbidden")
public String forbidden(Model model) {
model.addAttribute("error", "Forbidden");
model.addAttribute("status", "403");
model.addAttribute("message", "You don't have the privileges to perform this action");
return "other/error";
}
@PostMapping("/settings")
public String settings(@RequestParam Map<String, String> params, Model model) {
String next = params.getOrDefault("next", "settings/settings");

View File

@ -0,0 +1,38 @@
/*
* SnapAdmin - An automatically generated CRUD admin UI for Spring Boot apps
* Copyright (C) 2023 Ailef (http://ailef.tech)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package tech.ailef.snapadmin.external.exceptions;
import org.springframework.http.HttpStatus;
import org.springframework.web.server.ResponseStatusException;
public class SnapAdminForbiddenException extends ResponseStatusException {
private static final long serialVersionUID = 4090093290330473479L;
public SnapAdminForbiddenException(String message) {
super(HttpStatus.NOT_FOUND, message);
}
@Override
public String getMessage() {
return getReason();
}
}