Java 身份验证webapp上按角色的shiro重定向
我们正在使用JAX-RS(Jersey)编写JavaWebApp,使用Shiro作为Sequerity 我们有:Java 身份验证webapp上按角色的shiro重定向,java,security,login,jax-rs,shiro,Java,Security,Login,Jax Rs,Shiro,我们正在使用JAX-RS(Jersey)编写JavaWebApp,使用Shiro作为Sequerity 我们有: 3个不同的角色,每个角色都有自己的主页 所有用户的单一登录页面 用户登录时,如何根据身份验证后的角色将用户重定向到自己的主页 来自shiro ini的一些代码: authc.loginUrl = /login.html [urls] /apps/admin/** = authc, roles["admin"] /apps/teacher/** = authc, roles[te
- 3个不同的角色,每个角色都有自己的主页
- 所有用户的单一登录页面
authc.loginUrl = /login.html
[urls]
/apps/admin/** = authc, roles["admin"]
/apps/teacher/** = authc, roles[teacher]
/apps/student/** = authc, roles[student]
Ex:
- /apps/admin/home.html(如果他具有管理员角色)
- /apps/teacher/home.html(如果他有教师角色)
- /apps/student/home.html(如果他有学生角色)
我有同样的要求,我这样做
if (currentUser.isAuthenticated()) {
if (currentUser.hasRole("admin")) {
response.sendRedirect("app/admin/adminpage.jsp");
}
else if (currentUser.hasRole("student") || currentUser.hasRole("admin")) {
response.sendRedirect("app/student/studentpage.jsp");
}
else if (currentUser.hasRole("teacher") || currentUser.hasRole("admin")) {
response.sendRedirect("app/teacher/teacherpage.jsp");
}
}
else {
response.sendRedirect("app/login.jsp");
}
非常感谢。除了使用response.otherUrl)之外,我也是这样做的。我也为SAO aproach编辑了你的答案,如果错了,请纠正我。