我希望我的 Spring 应用程序尝试两种预身份验证方法(站点管理员 and Java EE 容器身份验证).
- 如果这些过滤器中的任何一个找到用户名 - 我想根据我的用户数据库检查该用户名,并根据我在数据库中看到的内容分配角色。 (我有一个 AuthenticationUserDetailsService 的实现,它为我做到了这一点。)
- 如果没有 - 向用户显示登录页面。根据我的用户数据库检查他们在表单中输入的凭据。
Siteminder 集成正在运行。登录表单也可以正常工作。我的问题是 Java EE 预身份验证。它永远不会发挥作用。
我的 applicationContext-security.xml:
<!-- HTTP security configurations -->
<sec:http auto-config="true" use-expressions="true">
<sec:form-login login-processing-url="/resources/j_spring_security_check" always-use-default-target="true" default-target-url="/" login-page="/login"
authentication-failure-url="/login?login_error=t" />
<sec:logout logout-url="/resources/j_spring_security_logout" />
<sec:access-denied-handler error-page="/accessDenied" />
<sec:remember-me user-service-ref="customUserDetailsService" token-validity-seconds="86400" key="OptiVLM-VaultBalance" />
<sec:custom-filter position="PRE_AUTH_FILTER" ref="siteminderFilter"/>
<sec:custom-filter after="PRE_AUTH_FILTER" ref="jeePreAuthenticatedFilter"/>
<!-- various intercept-url elements here, skipped for brevity -->
</sec:http>
<!-- Authentication Manager -->
<sec:authentication-manager alias="authenticationManager">
<!-- J2EE container pre-authentication or Siteminder -->
<sec:authentication-provider ref="customPreAuthenticatedAuthenticationProvider" />
<!-- Default provider -->
<sec:authentication-provider user-service-ref="customUserDetailsService" />
</sec:authentication-manager>
<!-- Siteminder pre-authentication -->
<bean id="siteminderFilter" class="org.springframework.security.web.authentication.preauth.RequestHeaderAuthenticationFilter">
<property name="principalRequestHeader" value="SM_USER" />
<property name="authenticationManager" ref="authenticationManager" />
<property name="exceptionIfHeaderMissing" value="false" />
</bean>
<!-- J2EE pre-authentication -->
<bean id="jeePreAuthenticatedFilter" class="org.springframework.security.web.authentication.preauth.j2ee.J2eePreAuthenticatedProcessingFilter">
<property name="authenticationManager" ref="authenticationManager" />
</bean>
<!-- Custom pre-authentication provider -->
<bean id="customPreAuthenticatedAuthenticationProvider" class="org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider">
<property name="preAuthenticatedUserDetailsService" ref="customAuthenticationUserDetailsService" />
</bean>
我在 Websphere 中启用了 Java 2 安全性,并且以“admin5”身份登录。 (我的用户数据库中有一个使用此用户名的用户。)但是当我访问应用程序时,永远不会调用“customAuthenticationUserDetailsService”bean 来验证用户名。我知道这一点,因为“customAuthenticationUserDetailsService”进行了大量的日志记录,清楚地显示了它正在做什么。当我使用 Siteminder 预身份验证时 - 'customAuthenticationUserDetailsService' 工作得很好,我在日志中得到一些跟踪输出。但不适用于 J2EE 身份验证...
我的猜测是其中一件事情正在发生:
a) Java EE 预身份验证过滤器未定位用户名,因此它从不调用身份验证管理器
b) Java EE 预身份验证过滤器工作正常,但由于某种原因身份验证管理器从未调用我的自定义身份验证提供程序
顺便说一句,使用“customUserDetailsService”的默认身份验证提供程序也不会启动。同样,我可以这么说,因为日志中没有“customUserDetailsService”的输出。
您能建议一下这里可能存在什么问题吗?如果不是解决方案,那么我们将不胜感激有关如何解决此问题的建议。