Commit d55801a6 by wangzhen

Refactor the classes of the RBAC to PermissionService.

1 parent 82665a43
...@@ -8,6 +8,8 @@ import org.apache.shiro.authz.AuthorizationException; ...@@ -8,6 +8,8 @@ import org.apache.shiro.authz.AuthorizationException;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.resource.NoResourceFoundException;
@Slf4j @Slf4j
@RestControllerAdvice @RestControllerAdvice
...@@ -19,6 +21,15 @@ public class ErrorHandler { ...@@ -19,6 +21,15 @@ public class ErrorHandler {
return Result.error(500, e.getMessage()); return Result.error(500, e.getMessage());
} }
@ExceptionHandler(NoResourceFoundException.class)
public ModelAndView handleNoResourceFoundException(Exception e) {
log.error("Unknown Exception was thrown!", e);
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("404");
return modelAndView;
}
@ExceptionHandler(BaseException.class) @ExceptionHandler(BaseException.class)
public Result<Object> handleCustomException(BaseException e) { public Result<Object> handleCustomException(BaseException e) {
log.warn("Biz Exception was thrown!", e); log.warn("Biz Exception was thrown!", e);
......
...@@ -68,8 +68,8 @@ public class ShiroConfig { ...@@ -68,8 +68,8 @@ public class ShiroConfig {
/* 3. common url start */ /* 3. common url start */
shiroFilter.setLoginUrl("/auth/login"); shiroFilter.setLoginUrl("/auth/login");
shiroFilter.setSuccessUrl("/auth/index"); shiroFilter.setSuccessUrl("/shiro/index");
shiroFilter.setUnauthorizedUrl("/auth/401"); shiroFilter.setUnauthorizedUrl("/shiro/401");
/* common url end */ /* common url end */
return shiroFilter; return shiroFilter;
......
...@@ -19,16 +19,6 @@ public class LoginController { ...@@ -19,16 +19,6 @@ public class LoginController {
@PostMapping("/login") @PostMapping("/login")
public String doLogin() { public String doLogin() {
return "redirect:/shiro/info"; return "/shiro/info";
}
@GetMapping("/index")
public String index() {
return "index";
}
@GetMapping("/401")
public String page401() {
return "401";
} }
} }
...@@ -14,6 +14,7 @@ import org.apache.shiro.subject.Subject; ...@@ -14,6 +14,7 @@ import org.apache.shiro.subject.Subject;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
@RestController @RestController
@RequestMapping("/shiro") @RequestMapping("/shiro")
...@@ -84,4 +85,18 @@ public class ShiroController { ...@@ -84,4 +85,18 @@ public class ShiroController {
public Result<SysUser> getUsers() { public Result<SysUser> getUsers() {
return Result.success(permissionService.getAllUsers()); return Result.success(permissionService.getAllUsers());
} }
@GetMapping("/index")
public ModelAndView index() {
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("index");
return modelAndView;
}
@GetMapping("/401")
public ModelAndView page401() {
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("401");
return modelAndView;
}
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!