简体   繁体   English

配置Hazelcast和Shiro

[英]Configuration Hazelcast and Shiro

I am currently having trouble configuring Shiro and Hazelcast in conjunction: 我目前无法同时配置Shiro和Hazelcast:

web.xml: web.xml中:

<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>
    <filter-name>hazelcastWebFilter</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>

<filter-mapping>
    <filter-name>hazelcastWebFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

ApplicationContext.xml: applicationContext.xml中:

<!-- Hazelcast configuration-->
<hz:hazelcast id="hazelcastInstance">
    <hz:config>
        <hz:instance-name>${hazelcast.instance}</hz:instance-name>
        <hz:group name="${hazelcast.group}" password="${hazelcast.password}"/>
        <hz:network port="${hazelcast.port}" port-auto-increment="${hazelcast.port.autoincrement}">
            <hz:join>
                <hz:multicast enabled="${hazelcast.multicast.enabled}"
                              multicast-group="${hazelcast.multicast.group}"
                              multicast-port="${hazelcast.multicast.port}"
                              multicast-time-to-live="${hazelcast.multicast.timetolive}"
                              multicast-timeout-seconds="${hazelcast.multicast.timeoutseconds}"></hz:multicast>
            </hz:join>
        </hz:network>
    </hz:config>
</hz:hazelcast>
[...]
<bean id="hazelcastWebFilter" class="com.hazelcast.web.WebFilter" depends-on="hazelcastInstance">
    <constructor-arg name="properties">
        <props>
            <prop key="map-name">shiro-activeSessionCache</prop>
            <prop key="sticky-session">${hazelcast.webfilter.stickysession}</prop>
            <prop key="instance-name">${hazelcast.instance}</prop>
        </props>
    </constructor-arg>
</bean>

<!-- Shiro -->
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
    <property name="securityManager" ref="securityManager"/>
    <property name="loginUrl" value="/s/Login.app"/>
    <property name="successUrl" value="/goMain.app"/>
    <property name="unauthorizedUrl" value="/unauthorized.jsp"/>
    <property name="filters">
        <util:map>
            <entry key="authc" value-ref="auth"/>
            <entry key="authcpda" value-ref="pdaAuth"/>
        </util:map>
    </property>
    <property name="filterChainDefinitions">
        <value>
            HERE ARE PATHS onfigured
        </value>
    </property>
</bean>

<bean id="auth" class="org.apache.shiro.web.filter.authc.PassThruAuthenticationFilter">
    <property name="loginUrl" value="/s/Login.app"/>
</bean>

<bean id="pdaAuth" class="org.apache.shiro.web.filter.authc.PassThruAuthenticationFilter">
    <property name="loginUrl" value="/s/pda/login.app"/>
</bean>

<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
    <property name="realm" ref="PRODUCTRealm"/>
    <property name="cacheManager" ref="shiroCacheManager"/>
    <property name="sessionManager" ref="sessionManager"/>
</bean>

<bean id="sessionDAO" class="org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO"></bean>

<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>

<!--<bean id="shiroCacheManager" class="org.apache.shiro.cache.MemoryConstrainedCacheManager"/>-->
<bean id="shiroCacheManager" class="de.logentis.Hazelcast.HazelcastCacheManager"/>

<bean id="sessionManager" class="org.apache.shiro.web.session.mgt.DefaultWebSessionManager">
    <property name="sessionDAO" ref="sessionDAO"/>
    <property name="sessionValidationSchedulerEnabled" value="false"/>
</bean>

<!-- Define the Shiro Realm implementation you want to use to connect to your back-end -->
<!-- security datasource: Netversys DB -->
<bean id="PRODUCTRealm" class="PRODUCTNAMEJdbcRealm">
    <property name="dataSource" ref="dataSource"/>
    <property name="schema" value="${PRODUCTdb.schema}"/>
</bean>

<!-- Enable Shiro Annotations for Spring-configured beans.  Only run after the lifecycleBeanProcessor has run: -->
<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"
      depends-on="lifecycleBeanPostProcessor"/>
<bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
    <property name="securityManager" ref="securityManager"/>
</bean>

HazelcastCacheManager is from: https://github.com/stormpath/shiro-hazelcast-web-sample/blob/master/src/main/java/com/stormpath/samples/shiro/hazelcast/cache/HazelcastCacheManager.java HazelcastCacheManager来自: https : //github.com/stormpath/shiro-hazelcast-web-sample/blob/master/src/main/java/com/stormpath/samples/shiro/hazelcast/cache/HazelcastCacheManager.java

Problem 1: I can't log into the Application. 问题1:我无法登录该应用程序。 I'm instantly logged out. 我立即注销。

Problem 2: A JSESSIONID appears as query parameter (?). 问题2:JSESSIONID显示为查询参数(?)。 Was definitely never before 绝对从来没有

Problem 3: The hazelcastsession seems lost, although a Cookie exists 问题3:尽管存在Cookie,但hazelcastsession似乎丢失了

Problem 4: I have 3 Cookies: 2 JSESSIONID and 1 hazelcast. 问题4:我有3个Cookie:2个JSESSIONID和1个hazelcast。

Any help will be appreciated 任何帮助将不胜感激

As for the JSESSIONID issues, which may cause 1) 至于JSESSIONID问题,可能会导致1)

I don't know about hazelcast, but we had similar issues with using Vaadin and shiro. 我不了解hazelcast,但是在使用Vaadin和shiro时遇到类似的问题。 When the webapplication was using the JSESSION in the url, things got messy. 当Web应用程序在URL中使用JSESSION时,情况变得混乱了。

What helped for us is adding this to web.xml, telling the webserver to only use cookies for session id tracking: 对我们有用的是将其添加到web.xml中,告诉Web服务器仅使用cookie进行会话ID跟踪:

<session-config>
    <cookie-config>
        <!-- this is so we also use it for https -->
        <http-only>false</http-only>
    </cookie-config>
    <tracking-mode>COOKIE</tracking-mode>
</session-config>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM