【问题标题】:IBM WebSphere 8.5.5.8(Liberty) + Spring Security 3.1.3.RELEASEIBM WebSphere 8.5.5.8(Liberty) + Spring Security 3.1.3.RELEASE
【发布时间】:2016-06-22 11:19:35
【问题描述】:

我们有一个基于 appfuse starter kit 版本 2.2.1 构建的示例 Web 应用程序,它使用 Spring security 3.1.3.RELEASE。我们将在 WAS 7 上部署它,并在 IBM WebSphere 8.5.5.8(Liberty) 上对其进行测试。 我们的问题是在登录请求成功/失败后,某些东西破坏了请求的 servletPath 值并将其设置为 null。

((HttpServletRequest) 请求).getServletPath()

这是 LocaleFilter 尝试使用 getServletPath() 的 /j_security_check 值执行 chain.doFilter 的时候,我们遇到了:

应用程序类 'org.springframework.security.web.util.AntPathRequestMatcher.getRequestPath:116' 引发的异常 java.lang.NullPointerException: 在 org.springframework.security.web.util.AntPathRequestMatcher.getRequestPath(AntPathRequestMatcher.java:116) 在 org.springframework.security.web.util.AntPathRequestMatcher.matches(AntPathRequestMatcher.java:100) 在 org.springframework.security.web.DefaultSecurityFilterChain.matches(DefaultSecurityFilterChain.java:42) 在 org.springframework.security.web.FilterChainProxy.getFilters(FilterChainProxy.java:203) 在 org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:176) 在 org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160) 在 org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) 在 org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259) 在 com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:207) 在[内部课程] 在 com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:59) 在 com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:207) 在[内部课程] 在 org.tukey.web.filters.urlrewrite.NormalRewrittenUrl.doRewrite(NormalRewrittenUrl.java:213) 在 org.tukey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:171) 在 org.tukey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145) 在 org.tukey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92) 在 org.tukey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:394) 在 com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:207) 在[内部课程] 在 ir.dpi.webapp.filter.LocaleFilter.doFilterInternal(LocaleFilter.java:67) 在 org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) 在 com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:207) 在[内部课程] 在 org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) 在 org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) 在 com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:207) 在[内部课程] 在 com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.java:129) 在 com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:77) 在 com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:207) 在[内部课程]

这是我们的security.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:beans="http://www.springframework.org/schema/beans" xmlns:p="http://www.springframework.org/schema/p"
         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd">

<http pattern="/images/**" security="none"/>
<http pattern="/styles/**" security="none"/>
<http pattern="/scripts/**" security="none"/>

<http auto-config="false" create-session="always">
    <intercept-url pattern="/app/admin/**" access="ROLE_ADMIN"/>
    <intercept-url pattern="/app/passwordHint*" access="ROLE_ANONYMOUS,ROLE_ADMIN,ROLE_USER"/>
    <intercept-url pattern="/app/signup*" access="ROLE_ANONYMOUS,ROLE_ADMIN,ROLE_USER"/>
    <intercept-url pattern="/app/**" access="ROLE_ADMIN,ROLE_USER"/>
    <form-login login-page="/login" authentication-failure-url="/login?error=true" login-processing-url="/j_security_check"/>
    <remember-me user-service-ref="userDao" key="e37f4b31-0c45-11dd-bd0b-0800200c9a66"/>
</http>

<authentication-manager >
    <authentication-provider user-service-ref="userDao" >
        <password-encoder ref="passwordEncoder" >
            <salt-source ref="saltSource" />
        </password-encoder>
    </authentication-provider>
</authentication-manager>

<beans:bean id="saltSource" class="org.springframework.security.authentication.dao.ReflectionSaltSource"
    p:userPropertyToUse="username"/>


<global-method-security>
    <protect-pointcut expression="execution(* *..service.UserManager.getUsers(..))" access="ROLE_ADMIN"/>
    <protect-pointcut expression="execution(* *..service.UserManager.removeUser(..))" access="ROLE_ADMIN"/>
</global-method-security>
</beans:beans>

任何帮助将不胜感激。

【问题讨论】:

    标签: java spring-security websphere appfuse


    【解决方案1】:

    我使用this code ranch topic 找到了解决方案。 AppFuse 使用不同的过滤器(javax.servlet),IBM WebSphere 的 Wrapping 机制对会话创建优先级很敏感。所以我在 web.xml 文件中向上移动了 Spring securityFilter 映射。

         <filter-mapping>
            <filter-name>securityFilter</filter-name>
            <url-pattern>/*</url-pattern>
            <dispatcher>REQUEST</dispatcher>
            <dispatcher>FORWARD</dispatcher>
            <dispatcher>INCLUDE</dispatcher>
         </filter-mapping>
    
         <filter-mapping>
            <filter-name>sitemesh</filter-name>
            <url-pattern>/*</url-pattern>
            <dispatcher>REQUEST</dispatcher>
            <dispatcher>FORWARD</dispatcher>
         </filter-mapping>
    
         <filter-mapping>
            <filter-name>encodingFilter</filter-name>
            <url-pattern>/*</url-pattern>
         </filter-mapping>
         ...
    

    现在登录过程已经完成。

    请注意,在 Liberty server.xml 中设置这些设置至关重要:

    <httpSession cookieName="MY_LIBERTY_COOKIE" />
    <basicRegistry />
    

    IBM WebSphere Application Server(WAS Full) 中的等效设置设置在:

    会话管理 -> 常规属性 -> 启用 cookie

    同样在 WAS 版本 7(可能适用于其他版本)中需要使用:

    <http auto-config="false" disable-url-rewriting="true" create-session="always">
    

    在 spring security.xml 文件中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-20
      • 1970-01-01
      相关资源
      最近更新 更多