2

我想在登录后重定向用户到他的个人页面?. 我有 3 个用户,例如

  1. 管理员可以访问所有页面
  2. 学生可以访问学生目录下的页面
  3. 教师可以访问教师目录下的页面

这个怎么做?

任何帮助或想法?

更新 这里是我的 shiro.ini

[main]
ds = org.apache.shiro.jndi.JndiObjectFactory
ds.requiredType   = javax.sql.DataSource
ds.resourceName = jdbc/myDataSource
ds.resourceRef = true
jdbcRealm = org.apache.shiro.realm.jdbc.JdbcRealm 

# password hashing specification
sha256Matcher = org.apache.shiro.authc.credential.HashedCredentialsMatcher
sha256Matcher.hashAlgorithmName=SHA-256
jdbcRealm.credentialsMatcher = $sha256Matcher

jdbcRealm.permissionsLookupEnabled = true 
jdbcRealm.authenticationQuery = SELECT password FROM users WHERE username = ? 
jdbcRealm.userRolesQuery = SELECT role_name FROM user_roles WHERE username = ? 
jdbcRealm.permissionsQuery = SELECT roleper FROM roles_permissions WHERE role_name = ? 

jdbcRealm.dataSource = $ds
authc = com.java.MyFilter
jdbcRealm.authorizationCachingEnabled = false

# specify login page 
authc.loginUrl = /login.jsp 

# redirect after successful login
authc.successUrl = /home.jsp

# roles filter: redirect to error page if user does not have access rights
roles.unauthorizedUrl = /accessdenied.jsp


# request parameter with login error information; if not present filter assumes 'shiroLoginFailure'
authc.failureKeyAttribute = simpleShiroApplicationLoginFailure


[urls] 


/login.jsp = authc

# only users with some roles are allowed to use role-specific pages 
/admin/** = authc,roles[admin]
/stu/** = authc,roles[student]
/teach/** = authc,roles[teacher]


# enable authc filter for all application pages
/ApacheShiroDemo/** = authc
4

1 回答 1

1

我在使用权限的路上确实喜欢这个......在我的jsp页面中

     if (currentUser.isAuthenticated()) {

      MyRealm myRealm = new MyRealm();
      Connection conn = ConnectionProvider.getConnection();
      String username = currentUser.getPrincipals().toString();
      String defaultpage = myRealm.getDefaultPage(conn, username);

      if (currentUser.hasRole("admin")) {
          response.sendRedirect("admin/adminpage.jsp");
      }
      else if (currentUser.hasRole("student")) {

       if (defaultpage.equalsIgnoreCase("teacherpage") && currentUser.isPermitted("page:teacherpage")) {                             
         response.sendRedirect("teacher/teacherpage.jsp");
       } else{
         response.sendRedirect("student/studentpage.jsp");
       }
    }
    else if (currentUser.hasRole("teacher")) {

       if (defaultpage.equalsIgnoreCase("studentpage") && currentUser.isPermitted("page:studentpage")) {                             
         response.sendRedirect("teacher/studentpage.jsp");
       } else{
         response.sendRedirect("student/teacherpage.jsp");
       } 
  }
于 2013-10-30T13:51:20.730 回答