Spring-JavaEE用户在身份验证后仍然为空
我是JavaEE/Spring的新手,在过去的两天里我一直在与安全性作斗争。我终于可以用JavaEE进行身份验证,用Spring进行授权了。不幸的是,我无法从Spring访问JavaEE身份验证来进行授权 该应用程序的总体思路如下:Spring-JavaEE用户在身份验证后仍然为空,spring,security,jakarta-ee,spring-security,Spring,Security,Jakarta Ee,Spring Security,我是JavaEE/Spring的新手,在过去的两天里我一直在与安全性作斗争。我终于可以用JavaEE进行身份验证,用Spring进行授权了。不幸的是,我无法从Spring访问JavaEE身份验证来进行授权 该应用程序的总体思路如下: 如果您未登录,Spring security会将您重定向到登录页面 登录页面是唯一被JavaEE锁定的页面。它输出一个表单以进行身份验证 成功登录后,用户将重定向到主页,该主页应具有与之关联的身份验证对象 注意,强调应该,因为它不是。无论出于何种原因,用户都会以经过
web.xml
中的相关片段:
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</filter>
<security-constraint>
<web-resource-collection>
<web-resource-name>Home Page Only</web-resource-name>
<description>Rely on Spring for Authorization</description>
<url-pattern>/login</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>*</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/login</form-login-page>
<form-error-page>/loginfailed</form-error-page>
</form-login-config>
</login-config>
springSecurityFilterChain
org.springframework.web.filter.DelegatingFilterProxy
springSecurityFilterChain
/*
仅主页
依赖Spring进行授权
/登录
*
形式
/登录
/登录失败
以及我的用于spring的security-content.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:lang="http://www.springframework.org/schema/lang"
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://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<http auto-config='true' use-expressions="true">
<intercept-url pattern="/about" access="permitAll"/>
<intercept-url pattern="/login" access="permitAll"/>
<intercept-url pattern="/loginfailed" access="permitAll"/>
<intercept-url pattern="/css/*" access="permitAll"/>
<intercept-url pattern="/resources/*" access="permitAll"/>
<intercept-url pattern="/images/*" access="permitAll"/>
<intercept-url pattern="/js/*" access="permitAll"/>
<intercept-url pattern="/**" access="hasRole('ROLE_USER')" />
<form-login default-target-url='/index.jsp'
always-use-default-target='true' login-page="/login"
authentication-failure-url="/loginfailed"
/>
</http>
<authentication-manager alias="authenticationManager">
<authentication-provider ref="securityRef"/>
</authentication-manager>
<beans:bean id="securityRef"
class="my.custom.authprovider.AuthenticationProviderImpl"/>
</beans:beans>
有什么想法吗?如果要使用Java EE身份验证,应该配置 预验证数据处理过滤器(更准确地说是J2eePreAuthenticatedProcessingFilter)。 此外,您需要配置J2eeBasedPreAuthenticatedWebAuthenticationDetailsSource以填充用户授予的权限: 顺便问一下,您认为使用JavaEE表单身份验证有哪些优势 在评论后添加 如果需要使用JavaEE身份验证,应该纠正您的方法:您应该通过JavaEE身份验证来保护整个应用程序。 在这种情况下,到Spring Security的每个请求都将通过JavaEE容器进行身份验证,Spring Security可以通过J2eePreAuthenticatedProcessingFilter对请求进行身份验证。 因此,修正后的流量
老实说,我不想使用它,但应用程序运行在WAS服务器上,该服务器设置为使用J2EE对Active Directory进行身份验证。我以前尝试过用不同的设置使用J2eePreAuthenticatedProcessingFilter。我将尝试在这个设置中使用它,并让您知道结果是什么。