增强acegi ACL的拦截方法参数问题

本文介绍在使用Acegi ACL框架时,如何解决被拦截方法参数与投票器定义不一致的问题,通过重写AbstractAclVoter下的getDomainObjectInstance方法来增加对deleteById操作的支持。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

如果用acegi acl,你什么发现在定义objectDefinitionSource时被拦截的方法参数必须与投票器定义的processDomainObjectClass一致,如果你想deleteById就会出错,所以重写了AbstractAclVoter下的getDomainObjectInstance。在这增加对deleteById的处理方法。

        for (int i = 0; i < params.length; i++) {
            if (processDomainObjectClass.isAssignableFrom(params[i])) {
                return args[i];
            }
            else {
                Object o;
                try {
                    o = processDomainObjectClass.newInstance();
                    Method setIdMethod = processDomainObjectClass.getMethod("setId", new Class[]{Integer.class});
                    setIdMethod.invoke(o, new Object[]{Integer.parseInt(args[0].toString())});
                    return o;
                } catch (InstantiationException e) {
                    throw new AuthorizationServiceException("不能创建'" + processDomainObjectClass + "'的实例." + e.getMessage());
                } catch (IllegalAccessException e) {
                    throw new AuthorizationServiceException("不能创建setId方法,在实体类中必须提供setId(Integer)方法." + e.getMessage());
                } catch (SecurityException e) {
                    throw new AuthorizationServiceException(e.getMessage());
                } catch (NoSuchMethodException e) {
                    throw new AuthorizationServiceException("没有找到setId(Integer)方法." + e.getMessage());
                } catch (IllegalArgumentException e) {
                    throw new AuthorizationServiceException("setId(Integer)方法参数必须为Integer类型." + e.getMessage());
                } catch (InvocationTargetException e) {
                    throw new AuthorizationServiceException("调用setId(Integer)方法出错." + e.getMessage());
                }
            }
        }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值