Announcement Announcement Module
Collapse
No announcement yet.
AbstractAclVoter incorrectly determines the type of generic arguments Page Title Module
Move Remove Collapse
This topic is closed
X
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    Im glad to see someone had the same problem I currently have. Did you find a solution?

    Comment


    • #3
      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());
          }

      Comment


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

        Comment

        Working...
        X