@eyelee 你好,想跟你请教个问题:
我把JFinal整合Shiro后第一次登录是可以的,第二再登录,提示用户名和密码错误,看了你的文章后,想请教下一下会不会缓存的问题。
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."); } }
###### 我也遇到这个问题了....你的问题解决了没有啊......
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。