开发者社区> 问答> 正文

JFinal整合Shiro遇到的问题报错 

@eyelee 你好,想跟你请教个问题:
我把JFinal整合Shiro后第一次登录是可以的,第二再登录,提示用户名和密码错误,看了你的文章后,想请教下一下会不会缓存的问题。

展开
收起
kun坤 2020-06-03 10:48:42 625 0
1 条回答
写回答
取消 提交回答
  • jfinal-drampie  动态数据库权限

    public class MyJdbcAuthzService implements JdbcAuthzService { @Override public Map<String, AuthzHandler> getJdbcAuthz() { //加载数据库的url配置 Map<String, AuthzHandler> authzJdbcMaps = new HashMap<String, AuthzHandler>(); //    Map<String, AuthzHandler> authzJdbcMaps = new TreeMap<String, AuthzHandler>( //        new Comparator<String>() { //          public int compare(String k1, String k2) { //            return new Integer(k2.length()).compareTo(k1.length()); //          } // //        }); //遍历角色 List<Role> roles = Role.dao.findAll(); List<Permission> permissions = null; for (Role role : roles) { //角色可用 if (role.getDate("daleted_at") == null) { permissions = Permission.dao.findByRole("", role.get("id")); //遍历权限 for (Permission permission : permissions) { //权限可用 if (permission.getDate("daleted_at") == null) { if (permission.getStr("url") != null && !permission.getStr("url").isEmpty()) { authzJdbcMaps.put(permission.getStr("url"), new JdbcPermissionAuthzHandler(permission.getStr("value"))); } } } } } return authzJdbcMaps; } }
    --create role--

    INSERT INTO sec_role(id,name, value, intro, pid,left_code,right_code,created_at) VALUES (sec_role_id_seq.nextval,'超级管理员','R_ADMIN','',0,1,8, current_timestamp), (sec_role_id_seq.nextval,'系统管理员','R_MANAGER','',1,2,7,current_timestamp), (sec_role_id_seq.nextval,'会员','R_MEMBER','',2,3,4,current_timestamp), (sec_role_id_seq.nextval,'普通用户','R_USER','',2,5,6,current_timestamp);

    --create permission-- INSERT INTO sec_permission(id, name, value, url, intro,pid,left_code,right_code, created_at) VALUES (sec_permission_id_seq.nextval,'管理员目录','P_D_ADMIN','/admin/','',0,1,6,current_timestamp), (sec_permission_id_seq.nextval,'角色权限管理','P_ROLE','/admin/role/','',1,2,3,current_timestamp), (sec_permission_id_seq.nextval,'用户管理','P_USER','/admin/user/','',1,4,5,current_timestamp), (sec_permission_id_seq.nextval,'会员目录','P_D_MEMBER','/member/','',0,9,10,current_timestamp), (sec_permission_id_seq.nextval,'普通用户目录','P_D_USER','/user/**','',0,11,12,current_timestamp);

    //如果系统不重启需要加载新权限到全局过滤 ShiroKit.addJdbcAuthz(authority.getStr("url"),authority.getStr("auth_key"));

    java.lang.IllegalStateException: org.apache.shiro.session.UnknownSessionException: There is no session with id [2515c5d2-37c7-4738-8e0b-9dfe7de08f0c]
    而且会出现这个错误 ######应该是session配置问题 你shiro 配置文件贴出来 登录验证代码也能贴出来吗?######[main]

    shiro.loginUrl = /

    #realm

    myRealm = com.topteam.shiro.ShiroDbRealm

    securityManager.realm = $myRealm

    #cache

    shiroCacheManager = org.apache.shiro.cache.ehcache.EhCacheManager

    shiroCacheManager.cacheManagerConfigFile = classpath:ehcache-shiro.xml

    securityManager.cacheManager = $shiroCacheManager

    #session

    sessionDAO = org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO

    sessionManager = org.apache.shiro.web.session.mgt.DefaultWebSessionManager

    sessionDAO.activeSessionsCacheName = shiro-activeSessionCache

    sessionManager.sessionDAO = $sessionDAO

    securityManager.sessionManager = $sessionManager

    securityManager.sessionManager.globalSessionTimeout = 1800000

    #这里的规则,web.xml中的配置的ShiroFilter会使用到

    [urls]

    /logout = logout

    /common/** = authc

    /admin/** = authc,roles[administrator] 

    /business/** = roles[administrator]

    /business/base/** = authc,roles[administrator]

    /business/crm/** = authc,roles[nvestmentManager]

    ######log.info("用户认证开始:" + username + " , " + password); 

    AuthenticationToken token = new UsernamePasswordToken(username,password);  

    Subject currentUser = SecurityUtils.getSubject();

    if (StringKit.notBlank(username) && StringKit.notBlank(password)) {

    try {

    currentUser.login(token);

    log.info("User [" + currentUser.getPrincipal() + "] logged in successfully.");

    log.info("用户认证完毕:" + username);

    }catch (AuthenticationException ae) {

    log.info("用户认证失败:" + "unexpected condition.");

    }

    }

    ######

    log.info("用户认证开始:" + username + " , " + password); AuthenticationToken token = new UsernamePasswordToken(username,password);
    Subject currentUser = SecurityUtils.getSubject(); if (StringKit.notBlank(username) && StringKit.notBlank(password)) { try { currentUser.login(token); log.info("User [" + currentUser.getPrincipal() + "] logged in successfully."); log.info("用户认证完毕:" + username); }catch (AuthenticationException ae) { log.info("用户认证失败:" + "unexpected condition."); } }

    ###### 我也遇到这个问题了....你的问题解决了没有啊......

    2020-06-03 10:48:50
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Java Spring Boot开发实战系列课程【第7讲】:Spring Boot 2.0安全机制与MVC身份验证实战(Java面试题) 立即下载
Java Spring Boot开发实战系列课程【第15讲】:Spring Boot 2.0 API与Spring REST Docs实战 立即下载
Java Spring Boot开发实战系列课程【第6讲】:Spring Boot 2.0实战MyBatis与优化(Java面试题) 立即下载