AuthenticationPostUpdateListenerEvent code:
/** * @author 叶天兵 */ @SuppressWarnings("serial") public class AuthenticationPostUpdateListenerEvent implements PostUpdateEventListener { private UpdateAcegiCache updateAcegiCache; /** * @param updateAcegiCache 要设置的 updateAcegiCache */ public void setUpdateAcegiCache(UpdateAcegiCache updateAcegiCache) { this.updateAcegiCache = updateAcegiCache; } /** * 修改RBAC操作时,修改AcegiCache */ public void onPostUpdate(PostUpdateEvent updateEvent) { // TODO 自动生成方法存根 Object obj = updateEvent.getEntity(); //如果修改User,就修改userCache if(obj instanceof Users){ Users user = (Users) obj; updateAcegiCache.modifyUserInCache(user, user.getUserName()); } //修改Authorities时修改resourceCache if(obj instanceof Authorities){ Authorities auth = (Authorities) obj; updateAcegiCache.modifyAuthritiesInCache(auth, auth.getAuthProtected()); } //修改Role 时修改userCache和resourceCahce if(obj instanceof Role){ Role role = (Role) obj; updateAcegiCache.modifyRoleInCache(role, role.getRoleName()); } } } |
hibernateEvent对数据的操作进行监听,在修改users,role,authorities时,修改userCache和resourceCache实现其动态更新.PostInsertEventListener,PostDeleteEventListener同理.
跟踪了一下控制台信息,当transaction执行commit的操作之后,eventListener才执行其操作,这样就保证了更新数据表之后,立即更新user,和resource的缓存信息.
最后login.jsp
<form action="check" method="post"> <table width="513" border="0" cellpadding="0" cellspacing="0"> <tr> <td colspan="3" align="center" height="15"> ${ACEGI_SECURITY_LAST_EXCEPTION.message} </td> </tr> <tr> <td width="139" rowspan="2"> </td> <td width="157" height="30"> <input type="text" name="j_username" value="${ACEGI_SECURITY_LAST_USERNAME }" size="18" height="15" tabindex="1"/> </td> <td width="217" rowspan="2"> <input type="submit" name="submit" value="登录"nbsp; <input type="reset" name="reset" value="重写"</td> </tr> <tr> <td height="30"> <input type="password" name="j_password" > </td> </tr> <tr> <td> </td> <td height="21" align="left"> <input type="checkbox" name="rememberMe"> <font color="#FFFFFF">两周后不登录</font> </td> <td> </td> </tr> </table> </form> |
excuse me to write blog first time,so it's very badly.
and introduce 2 website to study spring:
and also,i often study many knowledge from javaeye,like openSessionInView