acegi+ssh动态实现基于角色的权限管理(五)

  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">&nbsp;</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;&nbsp;
    <input type="reset" name="reset" value="重写"</td>
    </tr>
    <tr>
      <td height="30">
   <input type="password" name="j_password" >    

 </td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td height="21" align="left">
     <input type="checkbox" name="rememberMe">
   <font color="#FFFFFF">两周后不登录</font>
     </td>
      <td>&nbsp;</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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值