Results 1 to 4 of 4

Thread: AbstractAclVoter incorrectly determines the type of generic arguments

  1. #1
    Join Date
    Feb 2009
    Posts
    12

    Angry AbstractAclVoter incorrectly determines the type of generic arguments

    In AbstractAclVoter in the getDomainObjectInstance method there is the following line used to get the type of the reflected method arguments:

    Code:
    params = invocation.getMethod().getParameterTypes();
    which is fine except where the class is using generics, such as in a generic CRUD DAO in the classic Hibernate generic DAO pattern. In this case the code will return object for the type of the parameter. A better way would be to use the method specified at http://www.artima.com/weblogs/viewpo...?thread=208860 to determine the type of the arguments to a method.

    Should I raise a bug for this?

  2. #2

    Default

    Im glad to see someone had the same problem I currently have. Did you find a solution?

  3. #3
    Join Date
    Feb 2009
    Posts
    12

    Lightbulb Here is my code

    I came up with the following. I'm not sure it is the best implementation but it works for me. ClassUtils refers to the code i referenced above.

    Code:
        /**
         * This method is a copy of getDomainObjectInstance in AbstractAclVoter. It calls out
         * to ClassUtils in order to be able to determine the type of generic type arguments. 
         * @param secureObject the object to determine the type of
         * @return the domain object instance
         */
        @SuppressWarnings("unchecked")
        public Object getGenericDomainObjectInstance(Object secureObject) {
            Object[] args;
            Class[] params;
    
            if (secureObject instanceof MethodInvocation) {
                MethodInvocation invocation = (MethodInvocation) secureObject;
                params = invocation.getMethod().getParameterTypes();
                args = invocation.getArguments();
            } else {
                JoinPoint jp = (JoinPoint) secureObject;
                params = ((CodeSignature) jp.getStaticPart().getSignature()).getParameterTypes();
                args = jp.getArgs();
            }
    
            for (int i = 0; i < params.length; i++) {
                Class actualObjectType = ClassUtils.getClass(args[i].getClass());
                if (getProcessDomainObjectClass().isAssignableFrom(actualObjectType)) {
                    return args[i];
                }
            }
    
            throw new AuthorizationServiceException("Secure object: " + secureObject
                + " did not provide any argument of type: " + getProcessDomainObjectClass());
        }

  4. #4

    Default

    Works perfectly! Thankyou so much. Did you ever raise this as a bug/issue?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •