You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by bflueras <fl...@gmail.com> on 2012/11/22 10:21:44 UTC

@RequiresAuthentication annotation for anonymous classes does not work

Hello all,
I have a service class with some methods and an abstract class called Intf 
to which it delegates the work.
I want to secure the access to the service method doStuff(), but I've got
the following problem: 
If I annotate with @RequiresAuthentication the "doStuff()" method of the
ServiceClass it works (#1), 
but if I use the same annotation on the interface Intf's "doRealStuff()"
(#2) method it doesn't work anymore, not even when I add the annotation on
the Intf class (#3). 

//@RequiresAuthentication (#3) does NOT work
public abstract class Intf<T> {
   //@RequiresAuthentication (#2) does NOT work
   T doRealStuff();
}

public class ServiceClass<T> {
   private final Intf delegate;
   //constructor here

   //@RequiresAuthentication (#1) works
   public T doStuff() {
      return new Intf {
         public T doRealStuff() {
            // do real stuff
         } 
     };
   }
}

What can the problem be? I think that perhaps it's an anonymous class it
gets skipped somehow but I find the behaviour awkward.
The configuration of shiro.ini is fine, because in works but I can provide
it if necessary.

Thank you.



--
View this message in context: http://shiro-user.582556.n2.nabble.com/RequiresAuthentication-annotation-for-anonymous-classes-does-not-work-tp7577970.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: @RequiresAuthentication annotation for anonymous classes does not work

Posted by bflueras <fl...@gmail.com>.
Hi Jared and thanks a lot, it makes perfectly sense now. If only what you are
suggesting could be done so easily in my case...I have hundreads of
anonymous instances. I'll think about how I could tinker it  :)
Regards,




--
View this message in context: http://shiro-user.582556.n2.nabble.com/RequiresAuthentication-annotation-for-anonymous-classes-does-not-work-tp7577970p7577976.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: @RequiresAuthentication annotation for anonymous classes does not work

Posted by Jared Bunting <ja...@peachjean.com>.
So that's going to be the difference.  The annotation only works when AOP
is applied, and Guice can only apply AOP to objects that it instantiates.
So if you have Guice instantiate Intf, the annotation should work.

-Jared
On Nov 22, 2012 7:38 AM, "bflueras" <fl...@gmail.com> wrote:

> The Intf class in instantiated in the services "doStuff()".
> Guice makes the bindings (instances) for Service class, and I have
> shiro-guice (1.2.1) properly set up in my maven module.
>
>
>
> --
> View this message in context:
> http://shiro-user.582556.n2.nabble.com/RequiresAuthentication-annotation-for-anonymous-classes-does-not-work-tp7577970p7577974.html
> Sent from the Shiro User mailing list archive at Nabble.com.
>

Re: @RequiresAuthentication annotation for anonymous classes does not work

Posted by bflueras <fl...@gmail.com>.
The Intf class in instantiated in the services "doStuff()".
Guice makes the bindings (instances) for Service class, and I have
shiro-guice (1.2.1) properly set up in my maven module.



--
View this message in context: http://shiro-user.582556.n2.nabble.com/RequiresAuthentication-annotation-for-anonymous-classes-does-not-work-tp7577970p7577974.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: @RequiresAuthentication annotation for anonymous classes does not work

Posted by Jared Bunting <ja...@peachjean.com>.
How are you instantiating these classes?  What is providing the AOP?
On Nov 22, 2012 3:22 AM, "bflueras" <fl...@gmail.com> wrote:

> Hello all,
> I have a service class with some methods and an abstract class called Intf
> to which it delegates the work.
> I want to secure the access to the service method doStuff(), but I've got
> the following problem:
> If I annotate with @RequiresAuthentication the "doStuff()" method of the
> ServiceClass it works (#1),
> but if I use the same annotation on the interface Intf's "doRealStuff()"
> (#2) method it doesn't work anymore, not even when I add the annotation on
> the Intf class (#3).
>
> //@RequiresAuthentication (#3) does NOT work
> public abstract class Intf<T> {
>    //@RequiresAuthentication (#2) does NOT work
>    T doRealStuff();
> }
>
> public class ServiceClass<T> {
>    private final Intf delegate;
>    //constructor here
>
>    //@RequiresAuthentication (#1) works
>    public T doStuff() {
>       return new Intf {
>          public T doRealStuff() {
>             // do real stuff
>          }
>      };
>    }
> }
>
> What can the problem be? I think that perhaps it's an anonymous class it
> gets skipped somehow but I find the behaviour awkward.
> The configuration of shiro.ini is fine, because in works but I can provide
> it if necessary.
>
> Thank you.
>
>
>
> --
> View this message in context:
> http://shiro-user.582556.n2.nabble.com/RequiresAuthentication-annotation-for-anonymous-classes-does-not-work-tp7577970.html
> Sent from the Shiro User mailing list archive at Nabble.com.
>