SpringSecurity菜单权限管理
权限管理
权限管理事所有系统都要面临的问题,从大的方面可以分为两种维度的权限管理:
RBAC (Role Based Access Control) 和 ABAC (Attribute Based Access Control)。
RBAC 基于用户-角色、角色-权限的模型来给用户赋予一定的权限,粒度比价大,而 ABAC 是基于属性来动态授权,能够细粒度地授权在何种情况下对某个资源具备某个特定操作的权限。
下面看下基于 springSecurity 如何来设计一个 RBAC 的权限管理:
一、配置事件Listener(非web Listener)登录验证成功后,触发Litener,加载菜单
<bean id="interactiveAuthenticationSuccessListener"
class="com.mall.core.web.InteractiveAuthenticationSuccessListener">
<property name="menuService" ref="menuServiceProxy"></property>
<property name="bankRoleGrantRelationService" ref="bankRoleGrantRelationService"></property>
</bean>
<bean id="managerAuthenticationSuccessListener"
class="com.mall.manager.web.listener.ManagerAuthenticationSuccessListener">
<property name="mallStaffService" ref="mallStaffService"></property>
<property name="userLoginInfoService" ref="userLoginInfoService"></property>
</bean>
二、配置菜单拦截器,拦截器会对mappings参数里的请求进行拦截
<bean id="urlMapping"
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping" parent="abstractHandlerMapping">
<property name="interceptors">
<list>
<bean class="com.mall.web.interceptor.AuditExposingHandlerInterceptor"></bean>
<ref local="menuInterceptor" />
</list>
</property>
<property name="mappings">
<value>
/main.html=filenameController
/leftmenu.html=filenameController
</value>
</property>
<property name="order" value="0" />
</bean>