You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by cwittner <cu...@ints.com> on 2018/11/21 22:08:25 UTC

Re: Shiro redirecting to login page after successful login when added Hazlecast

Were you able to figure this out? I am attempting to switch to using
HazelCast as the distributed cache service instead of zookeeper. 

After authenticating through the authc filter subsequent calls to
SecurityUtils.getSubject() are not showing as authenticated. 



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

Re: Shiro redirecting to login page after successful login when added Hazlecast

Posted by Brian Demers <br...@gmail.com>.
Take a look at this doc:
https://shiro.apache.org/web.html#Web-SessionManagement

If you are still running into issues, your best bet might be to create a
simplified example that reproduces the issue send it our way.

Keep us posted!


On Thu, May 23, 2019 at 8:03 AM trinadhm <ma...@sbwc.ga.gov> wrote:

> Hi Brain,
>
> I have shiro + hazelcast session running on tomcat. As you said, there
> might
> be conflict of JSESSIONID of Tomcat and Shiro. When I changed the name of
> the Cookie in Shiro config, the application start working, but some of the
> ajax request are not responding.
>
> How to make shiro take control of the session when deployed in Tomcat? Can
> you please guide me through on this?
>
>
>
> --
> Sent from: http://shiro-user.582556.n2.nabble.com/
>

Re: Shiro redirecting to login page after successful login when added Hazlecast

Posted by trinadhm <ma...@sbwc.ga.gov>.
Hi Brain,

I have shiro + hazelcast session running on tomcat. As you said, there might
be conflict of JSESSIONID of Tomcat and Shiro. When I changed the name of
the Cookie in Shiro config, the application start working, but some of the
ajax request are not responding.

How to make shiro take control of the session when deployed in Tomcat? Can
you please guide me through on this?



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

Re: Shiro redirecting to login page after successful login when added Hazlecast

Posted by Brian Demers <br...@gmail.com>.
Probably the session flow, make sure your ajax requests inbound are going
through the same filter path as _regular_ requests

On Tue, Feb 26, 2019 at 10:42 AM trinadhm <ma...@sbwc.ga.gov> wrote:

> Brain,
>
> Thank you. I will try to find more information. Is there anything that I
> need to focus on i.e. cookies and how to check for shiro session?
>
> In the previous post I attached log as well. Did you had a chance to look
> at
> it?
>
>
>
> --
> Sent from: http://shiro-user.582556.n2.nabble.com/
>

Re: Shiro redirecting to login page after successful login when added Hazlecast

Posted by trinadhm <ma...@sbwc.ga.gov>.
Brain,

Thank you. I will try to find more information. Is there anything that I
need to focus on i.e. cookies and how to check for shiro session?

In the previous post I attached log as well. Did you had a chance to look at
it?



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

Re: Shiro redirecting to login page after successful login when added Hazlecast

Posted by Brian Demers <br...@gmail.com>.
I'm not sure, I think creating a simplified example might be the easiest
path forward, it looks like you have a lot of various pieces.

On Tue, Feb 26, 2019 at 9:58 AM trinadhm <ma...@sbwc.ga.gov> wrote:

> Yes. Shiro is first in the order.
>
>
>         <filter>
>             <filter-name>shiroFilter</filter-name>
>
>
> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
>             <init-param>
>                 <param-name>targetFilterLifecycle</param-name>
>                 <param-value>true</param-value>
>             </init-param>
>         </filter>
>
>
>
>
>         <filter-mapping>
>             <filter-name>shiroFilter</filter-name>
>             <url-pattern>/*</url-pattern>
>         </filter-mapping>
>
>
>
> --
> Sent from: http://shiro-user.582556.n2.nabble.com/
>

Re: Shiro redirecting to login page after successful login when added Hazlecast

Posted by trinadhm <ma...@sbwc.ga.gov>.
Yes. Shiro is first in the order.


	<filter>
	    <filter-name>shiroFilter</filter-name>
	   
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
	    <init-param>
	        <param-name>targetFilterLifecycle</param-name>
	        <param-value>true</param-value>
	    </init-param>
	</filter>
	
	
	
	
	<filter-mapping>
	    <filter-name>shiroFilter</filter-name>
	    <url-pattern>/*</url-pattern>
	</filter-mapping>



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

Re: Shiro redirecting to login page after successful login when added Hazlecast

Posted by Brian Demers <br...@gmail.com>.
What is the order of your filters? Is Shiro first?


On Tue, Feb 26, 2019 at 8:16 AM trinadhm <ma...@sbwc.ga.gov> wrote:

> Brain,
>
> I cannot put it together as this involves lot of components integrated.
> I think I found an issue, but not sure how to fix. As I said earlier I am
> using JSF 2 + Spring + Primefaces
>
> When I login first time, the request pass through FacesAjaxAwareUserFilter
> and redirecting back to Login page. When I try to login second time, it
> taking me to home page since the request did not pass through
> FacesAjaxAwareUserFilter. Once logged in, if I try to do click any
> action,the request pass through FacesAjaxAwareUserFilter and takes me back
> to Login Page.
>
> I know how to configure in shiro.ini
> user=web.filter.FacesAjaxAwareUserFilter
> user.loginUrl=/pages/pub/lgn/login.xhtml
>
> but in Spring not sure how to configure in above way
>
>
> Spring Shiro configuration
>
> <bean id="shiroFilter"
> class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
>             <property name="securityManager" ref="securityManager"/>
>             <property name="loginUrl" value="/pages/pub/lgn/login.xhtml"/>
>             <property name="successUrl" value="/page/sec/cmn/home.xhtml" />
>             <property name="unauthorizedUrl"
> value="/pages/sec/err/accessdenied.xhtml"/>
>             <property name="filters">
>                 <util:map>
>                     <entry key="user" value-ref="userFilter"/>
>                 </util:map>
>             </property>
>             <property name="filterChainDefinitions">
>                 <value>
>                         /javax.faces.resource/** = noSessionCreation, anon
>                         /pages/pub/lgn/login.xhtml = noSessionCreation,
> anon
>                                 /pages/pub/** = anon
>                                 /logout = logout
>                                 /pages/sec/** = user
>                                 /rest/** =      noSessionCreation, anon
>                 </value>
>             </property>
>         </bean>
>         <bean id="userFilter" class="web.filter.FacesAjaxAwareUserFilter"/>
>
> public class FacesAjaxAwareUserFilter extends UserFilter {
>
>     private static final String FACES_REDIRECT_XML = "<?xml version=\"1.0\"
> encoding=\"UTF-8\"?>"
>             + "<partial-response><redirect
> url=\"%s\"></redirect></partial-response>";
>
>     @Override
>     protected void redirectToLogin(ServletRequest req, ServletResponse res)
> throws IOException {
>         HttpServletRequest request = (HttpServletRequest) req;
>
>         if ("partial/ajax".equals(request.getHeader("Faces-Request"))) {
>             res.setContentType("text/xml");
>             res.setCharacterEncoding("UTF-8");
>             res.getWriter().printf(FACES_REDIRECT_XML,
> request.getContextPath() + getLoginUrl());
>         } else {
>             super.redirectToLogin(req, res);
>         }
>     }
>
> }
>
>
>
> --
> Sent from: http://shiro-user.582556.n2.nabble.com/
>

Re: Shiro redirecting to login page after successful login when added Hazlecast

Posted by trinadhm <ma...@sbwc.ga.gov>.
Brain,

I cannot put it together as this involves lot of components integrated.
I think I found an issue, but not sure how to fix. As I said earlier I am
using JSF 2 + Spring + Primefaces

When I login first time, the request pass through FacesAjaxAwareUserFilter
and redirecting back to Login page. When I try to login second time, it
taking me to home page since the request did not pass through
FacesAjaxAwareUserFilter. Once logged in, if I try to do click any
action,the request pass through FacesAjaxAwareUserFilter and takes me back
to Login Page.

I know how to configure in shiro.ini
user=web.filter.FacesAjaxAwareUserFilter
user.loginUrl=/pages/pub/lgn/login.xhtml

but in Spring not sure how to configure in above way


Spring Shiro configuration

<bean id="shiroFilter"
class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
	    <property name="securityManager" ref="securityManager"/>
	    <property name="loginUrl" value="/pages/pub/lgn/login.xhtml"/>
	    <property name="successUrl" value="/page/sec/cmn/home.xhtml" />
	    <property name="unauthorizedUrl"
value="/pages/sec/err/accessdenied.xhtml"/>
	    <property name="filters">
	        <util:map>
	            <entry key="user" value-ref="userFilter"/>
	        </util:map>
	    </property>
	    <property name="filterChainDefinitions">
	        <value>
	        	/javax.faces.resource/** = noSessionCreation, anon
	        	/pages/pub/lgn/login.xhtml = noSessionCreation, anon
				/pages/pub/** = anon
				/logout = logout
				/pages/sec/** = user
				/rest/** = 	noSessionCreation, anon
	        </value>
	    </property>
	</bean>
	<bean id="userFilter" class="web.filter.FacesAjaxAwareUserFilter"/>

public class FacesAjaxAwareUserFilter extends UserFilter {

    private static final String FACES_REDIRECT_XML = "<?xml version=\"1.0\"
encoding=\"UTF-8\"?>"
            + "<partial-response><redirect
url=\"%s\"></redirect></partial-response>";

    @Override
    protected void redirectToLogin(ServletRequest req, ServletResponse res)
throws IOException {
        HttpServletRequest request = (HttpServletRequest) req;

        if ("partial/ajax".equals(request.getHeader("Faces-Request"))) {
            res.setContentType("text/xml");
            res.setCharacterEncoding("UTF-8");
            res.getWriter().printf(FACES_REDIRECT_XML,
request.getContextPath() + getLoginUrl());
        } else {
            super.redirectToLogin(req, res);
        }
    }

}



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

Re: Shiro redirecting to login page after successful login when added Hazlecast

Posted by Brian Demers <br...@gmail.com>.
Can you put together a reproduce sample and stick it on github?

On Mon, Feb 25, 2019 at 2:40 PM trinadhm <ma...@sbwc.ga.gov> wrote:

> Thank you Brain. I was following the same documentation and configured
> everything as explained
> Somehow I was unable to make it work on single node. When I commented out
> Filter, I was able to login.
> Once login, if I try to click on any of the menu, it is taking me back to
> login page.
>
> I am using Spring + JSF 2 + Shiro + tomcat 8.5
>
>
>
> --
> Sent from: http://shiro-user.582556.n2.nabble.com/
>

Re: Shiro redirecting to login page after successful login when added Hazlecast

Posted by trinadhm <ma...@sbwc.ga.gov>.
Thank you Brain. I was following the same documentation and configured
everything as explained
Somehow I was unable to make it work on single node. When I commented out
Filter, I was able to login.
Once login, if I try to click on any of the menu, it is taking me back to
login page.

I am using Spring + JSF 2 + Shiro + tomcat 8.5 



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

Re: Shiro redirecting to login page after successful login when added Hazlecast

Posted by Brian Demers <br...@gmail.com>.
This post is a little older, but take a look at this post:
https://stormpath.com/blog/hazelcast-support-apache-shiro and let us know
if that helps

On Mon, Feb 25, 2019 at 1:51 PM trinadhm <ma...@sbwc.ga.gov> wrote:

> Hi cwittner,
>
> I would like to use Hazelcast along with Shiro. Can you help out fixing
> this
> issue?
>
> How to identify the session key? What is the custom session object? Can you
> provide me sample code?
>
>
>
> --
> Sent from: http://shiro-user.582556.n2.nabble.com/
>

Re: Shiro redirecting to login page after successful login when added Hazlecast

Posted by trinadhm <ma...@sbwc.ga.gov>.
Hi cwittner,

I would like to use Hazelcast along with Shiro. Can you help out fixing this
issue?

How to identify the session key? What is the custom session object? Can you
provide me sample code?



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

Re: Shiro redirecting to login page after successful login when added Hazlecast

Posted by Brian Demers <br...@gmail.com>.
Thanks for the follow-up!

On Mon, Jan 7, 2019 at 5:19 PM cwittner <cu...@ints.com> wrote:

> I figured out my problem. My environment uses a custom session object that
> extends SimpleSession. The attributes object was not being serialized or
> deserialized  properly from the hazelcast objects. I copied the
> SimpleSession readObject and writeObject logic into my custom class and the
> hazelcast cache is working properly now.
>
>
>
> --
> Sent from: http://shiro-user.582556.n2.nabble.com/
>

Re: Shiro redirecting to login page after successful login when added Hazlecast

Posted by cwittner <cu...@ints.com>.
I figured out my problem. My environment uses a custom session object that
extends SimpleSession. The attributes object was not being serialized or
deserialized  properly from the hazelcast objects. I copied the
SimpleSession readObject and writeObject logic into my custom class and the
hazelcast cache is working properly now.



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

Re: Shiro redirecting to login page after successful login when added Hazlecast

Posted by Curtis Wittner <cu...@ints.com>.
I have a single node under tomcat and shiro is setting a session cookie.
The session key is the same between requests. I did find that the
authentication information is not being cached in hazelcast. The map under
the realm cache name is empty.

On Mon, Nov 26, 2018 at 8:58 AM Brian Demers <br...@gmail.com> wrote:

> Is JBoss setting a session cookie? If so that might be the issue (as you
> want Shiro to manage the session)
>
> On Mon, Nov 26, 2018 at 11:53 AM trinadhm <ma...@sbwc.ga.gov> wrote:
>
>> 2 nodes with JBoss EAP 6.4.
>>
>>
>>
>> --
>> Sent from: http://shiro-user.582556.n2.nabble.com/
>>
> --

Curtis Wittner
Senior Software Developer
Integrated Services, Inc.
curtis.wittner@ints.com
www.ints.com
P:800-252-3099 x 235
F:503-968-9100

Re: Shiro redirecting to login page after successful login when added Hazlecast

Posted by Brian Demers <br...@gmail.com>.
Is JBoss setting a session cookie? If so that might be the issue (as you
want Shiro to manage the session)

On Mon, Nov 26, 2018 at 11:53 AM trinadhm <ma...@sbwc.ga.gov> wrote:

> 2 nodes with JBoss EAP 6.4.
>
>
>
> --
> Sent from: http://shiro-user.582556.n2.nabble.com/
>

Re: Shiro redirecting to login page after successful login when added Hazlecast

Posted by trinadhm <ma...@sbwc.ga.gov>.
2 nodes with JBoss EAP 6.4.



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

Re: Shiro redirecting to login page after successful login when added Hazlecast

Posted by Brian Demers <br...@gmail.com>.
How many nodes do you have?

On Mon, Nov 26, 2018 at 11:45 AM trinadhm <ma...@sbwc.ga.gov> wrote:

> Hi,
>
> I was unable to fix it and moved on. We are not using Hazelcast or any
> other
> software.
>
>
>
> --
> Sent from: http://shiro-user.582556.n2.nabble.com/
>

Re: Shiro redirecting to login page after successful login when added Hazlecast

Posted by trinadhm <ma...@sbwc.ga.gov>.
Hi,

I was unable to fix it and moved on. We are not using Hazelcast or any other
software.



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