首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

spring上Action权限控制

2012-09-14 
spring下Action权限控制实现一个新的标注接口@Target({ ElementType.TYPE, ElementType.METHOD })@Retenti

spring下Action权限控制
实现一个新的标注接口
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface AccessRule {

    Role[] value () default {
    };

    LoginMethod showLoginPageMethod () default LoginMethod.DEFAULT;
}

Action Controller中使用这个标注
比如:@AccessRule({Role.ADMIN})


spring容器注入继承接口BeanPostProcessor的基类 比如UrlRole

UrlRole 的postProcessAfterInitialization方法中
Class cls = bean.getClass();
if (!cls.isAnnotationPresent(Controller.class)) {
            return bean;
        }

        Role[] controllerRole = null;

        if (cls.isAnnotationPresent(AccessRule.class)) {
            AccessRule clsRole = (AccessRule) cls.getAnnotation(AccessRule.class);

            controllerRole = clsRole.value();
        }

得到权限 可以放到一个以url为key的全局map中

web.xml中实现一个Filter 过滤所有的action
在这过程中 根据session来判断用户的权限 是否可以访问此请求
进行相应的跳转




热点排行