You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by ry99 <ry...@ostrich-emulators.com> on 2020/12/20 13:01:21 UTC

shiro 1.7.0 + spring beans

Hi Folks,
I'm trying to use Shiro to protect a REST-based web service. I'm using
Spring 5.3.2 and Shiro 1.7.0, and following the instructions at
https://shiro.apache.org/spring-framework.html#web-applications. 

However, it appears that the recommended imports only use default values,
and do not reference the other beans I've created. For example, following
the instructions, I have created a bean to provide a
ShiroFilterChainDefinition, but AbstractShiroWebFilterConfiguration doesn't
use mine; it already has a default one autowired. The same seems to hold
true for my Realm--my bean creating it is called, but the object isn't used.

How do I use my beans instead of the defaults?

Please advise,



--
Sent from: http://shiro-user.582556.n2.nabble.com/

Re: shiro 1.7.0 + spring beans

Posted by ry99 <ry...@ostrich-emulators.com>.
Aha! I re-found the problem I was having. It turns out the function name is
essential for Shiro to use your beans. For example, if you name your
ShiroFilterChainDefinition bean anything other than
"shiroFilterChainDefinition", the system won't use it in initialization. 

This reminds me a bit of when Spring was XML-based, but I've not seen it
much since the move to annotations. After all, the point of the @Bean
annotation is to tell Spring that function creates a bean, and the return
type is used to figure out what type of thing it provides.

Anyway, I've uploaded a non-working example here: 
https://github.com/ry99/shiro-example
<https://github.com/ry99/shiro-example>  . The function
"Config::improperlyNamedShiroFilterChainDefinition()" creates a
DefaultShiroFilterChainDefinition that never gets used.

I don't suppose this is a bug so much as a gotcha. I've included some
details here for the next time I stumble upon this problem . 

It might be helpful if the documentation mentioned it, and also which things
can be configured with beans. For example, I had to do some digging to
figure out that "rememberMeManager()" was the function I needed to implement
to disable remember-me.




--
Sent from: http://shiro-user.582556.n2.nabble.com/

Re: shiro 1.7.0 + spring beans

Posted by Brian Demers <br...@gmail.com>.
No worries!  If you figure it out let us know what it was. Someone else
might stumble on the same problem, or it could lead us to improve something
;)

On Mon, Dec 21, 2020 at 3:08 PM ry99 <ry...@ostrich-emulators.com> wrote:

> Well, I'm feeling a little sheepish now, because as I was trying to make a
> minimally viable project, I couldn't reproduce the behavior I was seeing.
> My
> only conclusion is that the bug lay somewhere in all the cruft I hacked
> out.
> Sorry for the run-around.
>
>
>
> --
> Sent from: http://shiro-user.582556.n2.nabble.com/
>

Re: shiro 1.7.0 + spring beans

Posted by ry99 <ry...@ostrich-emulators.com>.
Well, I'm feeling a little sheepish now, because as I was trying to make a
minimally viable project, I couldn't reproduce the behavior I was seeing. My
only conclusion is that the bug lay somewhere in all the cruft I hacked out.
Sorry for the run-around.



--
Sent from: http://shiro-user.582556.n2.nabble.com/

Re: shiro 1.7.0 + spring beans

Posted by Brian Demers <br...@gmail.com>.
Can you create a simple sample project and stick it on GitHub?  That might
help us narrow down what is going on.


On Sun, Dec 20, 2020 at 8:01 AM ry99 <ry...@ostrich-emulators.com> wrote:

> Hi Folks,
> I'm trying to use Shiro to protect a REST-based web service. I'm using
> Spring 5.3.2 and Shiro 1.7.0, and following the instructions at
> https://shiro.apache.org/spring-framework.html#web-applications.
>
> However, it appears that the recommended imports only use default values,
> and do not reference the other beans I've created. For example, following
> the instructions, I have created a bean to provide a
> ShiroFilterChainDefinition, but AbstractShiroWebFilterConfiguration doesn't
> use mine; it already has a default one autowired. The same seems to hold
> true for my Realm--my bean creating it is called, but the object isn't
> used.
>
> How do I use my beans instead of the defaults?
>
> Please advise,
>
>
>
> --
> Sent from: http://shiro-user.582556.n2.nabble.com/
>