Announcement Announcement Module
Collapse
No announcement yet.
Spring Authentication With DWR Page Title Module
Move Remove Collapse
This topic is closed
X
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • #46
    It is working for me!
    Now we have to organize it a bit, i think we should separate web, dwr, spring and acegi stuff. Also authentication, authorization and acegi query.
    Perhaps some unittesting won't hurt anyone (i don't do it so i can't help with that!).
    Regards,

    Comment


    • #47
      Pretty close...I'm getting null with this call though:
      Code:
      		MethodInvocation methodInvocation = 
      			MethodInvocationUtils.
      			create(object, methodName);
      I've tested that the correct object instance is passed. I'm passing an instance of AuthenticationServiceImpl. For the method name I'm passing "login".

      So just need to figure out what's happening here....

      Comment


      • #48
        Originally posted by ole.ersoy View Post
        Pretty close...I'm getting null with this call though:
        Code:
        		MethodInvocation methodInvocation = 
        			MethodInvocationUtils.
        			create(object, methodName);
        I've tested that the correct object instance is passed. I'm passing an instance of AuthenticationServiceImpl. For the method name I'm passing "login".

        So just need to figure out what's happening here....
        You have to make a reference to the interface or base class, not to the implementation.

        Regards,

        Comment


        • #49
          Originally posted by ole.ersoy View Post
          Pretty close...I'm getting null with this call though:
          Code:
          		MethodInvocation methodInvocation = 
          			MethodInvocationUtils.
          			create(object, methodName);
          I've tested that the correct object instance is passed. I'm passing an instance of AuthenticationServiceImpl. For the method name I'm passing "login".

          So just need to figure out what's happening here....
          I'm having the same problem!
          Have you found out how to solve that/where is the problem?

          Regards,

          Comment


          • #50
            Still working on it. Need to take my daughter to soccer practice soon, but hope to get some more time in tonight.

            Comment


            • #51
              Sorry - Just looked at your other posts. Did you figure it out. I also tried just hardcoding the parameters:

              Code:
              		
              MethodInvocation methodInvocation = 
              			MethodInvocationUtils.
              			create(AuthenticationServiceImpl.class, "login")
              ;
              And I still get null...

              Comment


              • #52
                Originally posted by ole.ersoy View Post
                Sorry - Just looked at your other posts. Did you figure it out. I also tried just hardcoding the parameters:

                Code:
                		
                MethodInvocation methodInvocation = 
                			MethodInvocationUtils.
                			create(AuthenticationServiceImpl.class, "login")
                ;
                And I still get null...
                I'm debugging it with eclipse now... (i had some ports in use so i haven't been able to do that until now!!! :S).
                When methodInvocationPrivilegeEvaluator ask for the obj.getClass() it answers class $Proxy106 :S, and it have to answer org.siri.servicios.UsuarioServiceImpl in this case.
                I think it is related with the AOP part, particulary with org.springframework.aop.framework.ProxyFactoryBean .
                Perhaps we can ask if there is a workarround for this, perhaps defining which is the answer to getClass() method! (to the implementation's class).

                Regards,

                Comment


                • #53
                  Unit tested it as well:
                  Code:
                  	public void testMethodInvocation()
                  	{
                  		MethodInvocation methodInvocation = 
                  			MethodInvocationUtils.
                  			create(AuthenticationServiceImpl.class, "login");
                  		
                  		assertNull(methodInvocation);
                  	}

                  Comment


                  • #54
                    I created another thread asking about it here:
                    http://forum.springsource.org/showth...213#post245213

                    Comment


                    • #55
                      I have discovered it again (i'm on fire :P).
                      We can supose that there are not repeated methods and search for the method by name (manually, because it is not a hash map but an array).
                      Looking into it,
                      REgards,

                      Comment


                      • #56
                        Well, this is it (again :P).
                        Code:
                            public boolean isCallable(String jsBeanName, String methodName){
                        
                                Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
                                Container ct = WebContextFactory.get().getContainer();
                                Object obj = ct.getBean(jsBeanName);
                                
                                MethodInvocation mi = null;
                        
                                for(Method m: obj.getClass().getMethods())
                                	if (m.getName().equals(methodName)) mi = new SimpleMethodInvocation(m,null);
                                
                                return methodInvocationPrivilegeEvaluator.isAllowed(mi, authentication);
                            };
                        }
                        TESTING!!!!

                        Regards,

                        Comment


                        • #57
                          It is working for me.
                          I tested against some of my exported classes and it is working as expected (tested different users, and different classes).
                          Regards,

                          Comment


                          • #58
                            Originally posted by nickar View Post
                            It is working for me.
                            I tested against some of my exported classes and it is working as expected (tested different users, and different classes).
                            Regards,
                            I've done some simplifications just to get a functional prototype, but it is wrong to assume that we won't have 2 methods with the same name.
                            We could improve this algorithm by watching how dwr does that mapping.
                            Regards,

                            Comment


                            • #59
                              Hey - Nice work! I guess org.springframework.security.util.MethodInvocation UtilsMethodInvocationUtils is busted because I tested finding the method on the class as well, using some of your code, and both of these tests pass:

                              Code:
                              	public void testMethodInvocation()
                              	{
                              		MethodInvocation methodInvocation = 
                              			MethodInvocationUtils.
                              			create(AuthenticationServiceImpl.class, "login");
                              		
                              		assertNull(methodInvocation);
                              	}
                              	
                              	public void testFindMethod()
                              	{
                              		String methodName = "login";
                              		
                              		boolean methodFound = false;
                              		
                                      for(Method m: AuthenticationServiceImpl.class.getMethods())
                                      {
                                  		methodFound = true;
                                      }
                                      assertTrue(methodFound);
                                  };
                              Yeah I see what you are saying with possibility of overloaded methods. The API for MethodInvocationUtils:

                              http://static.springframework.org/sp...tionUtils.html

                              Has this method:
                              create(Object object, String methodName, Object[] args)
                              Generates a MethodInvocation for specified methodName on the passed object, using the args to locate the method.
                              So as your saying I'm sure DWR has the algorithm for constructing the object array that is the method arguments. Except they are doing it with the proxy call parameters. So they must have a utility class for figuring out the type of a parameter and they are using that to build the Object[] argument array used to find the method. So for exampe with:

                              proxy.method(String, int);
                              proxy.method(String, String);

                              They need to figure out whether the second argument is a String or an int.

                              In our case I think we need something like:

                              Map<String, Object[]>

                              The String key would be the method declaration with arguments. For example:

                              com.example.MyClass#myMethod(Array<int>, String)

                              And the Object[] would be the corresponding argument array.

                              So we would use method string to lookup the argument array and then pass that along with the method name to MethodInvocationNUtils.create(Object object, String methodName, Object[] args)....Once MethodInvocationUtils gets fixed....

                              OK - I'm going to play more with your code now to see whether I can get it working on my end.

                              Again - Nice work!

                              Comment


                              • #60
                                Hi.

                                Looks like you guys are having fun . Just a quick word on MethodInvocationUtils.

                                The "create" methods are intended to take an instance and the code will look for the method on the class of which the object is an instance. If you want to pass a class, then use one of the "createWithClass" methods.

                                Comment

                                Working...
                                X