Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
wangzhen
/
shiro-test
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit d55801a6
authored
Aug 29, 2024
by
wangzhen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor the classes of the RBAC to PermissionService.
1 parent
82665a43
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
13 deletions
src/main/java/com/myxrk/rbac/aspect/ErrorHandler.java
src/main/java/com/myxrk/rbac/config/ShiroConfig.java
src/main/java/com/myxrk/rbac/controller/LoginController.java
src/main/java/com/myxrk/rbac/controller/ShiroController.java
src/main/java/com/myxrk/rbac/aspect/ErrorHandler.java
View file @
d55801a
...
...
@@ -8,6 +8,8 @@ import org.apache.shiro.authz.AuthorizationException;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.RestControllerAdvice
;
import
org.springframework.web.servlet.ModelAndView
;
import
org.springframework.web.servlet.resource.NoResourceFoundException
;
@Slf4j
@RestControllerAdvice
...
...
@@ -19,6 +21,15 @@ public class ErrorHandler {
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
)
public
Result
<
Object
>
handleCustomException
(
BaseException
e
)
{
log
.
warn
(
"Biz Exception was thrown!"
,
e
);
...
...
src/main/java/com/myxrk/rbac/config/ShiroConfig.java
View file @
d55801a
...
...
@@ -68,8 +68,8 @@ public class ShiroConfig {
/* 3. common url start */
shiroFilter
.
setLoginUrl
(
"/auth/login"
);
shiroFilter
.
setSuccessUrl
(
"/
auth
/index"
);
shiroFilter
.
setUnauthorizedUrl
(
"/
auth
/401"
);
shiroFilter
.
setSuccessUrl
(
"/
shiro
/index"
);
shiroFilter
.
setUnauthorizedUrl
(
"/
shiro
/401"
);
/* common url end */
return
shiroFilter
;
...
...
src/main/java/com/myxrk/rbac/controller/LoginController.java
View file @
d55801a
...
...
@@ -19,16 +19,6 @@ public class LoginController {
@PostMapping
(
"/login"
)
public
String
doLogin
()
{
return
"redirect:/shiro/info"
;
}
@GetMapping
(
"/index"
)
public
String
index
()
{
return
"index"
;
}
@GetMapping
(
"/401"
)
public
String
page401
()
{
return
"401"
;
return
"/shiro/info"
;
}
}
src/main/java/com/myxrk/rbac/controller/ShiroController.java
View file @
d55801a
...
...
@@ -14,6 +14,7 @@ import org.apache.shiro.subject.Subject;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.servlet.ModelAndView
;
@RestController
@RequestMapping
(
"/shiro"
)
...
...
@@ -84,4 +85,18 @@ public class ShiroController {
public
Result
<
SysUser
>
getUsers
()
{
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
;
}
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment