我使用的是Spring Security 3.0.6和JSF Mojarra 2.1.18和Primefaces 3.5。
我创建了一个注入Spring Security的AuthenticationManager的LoginManagedBean。
@ManagedBean
@SessionScoped
public class LoginManagedBean implements Serializable {
private static final long serialVersionUID = 1L;
private static transient final Log logger = LogFactory.getLog(LoginManagedBean.class);
private LoginDTO login;
private String username;
private String password;
@ManagedProperty(value = "#{authenticationManager}")
private transient AuthenticationManager authenticationManager = null;
...它起作用了。但是如果登录失败,我再也不能使用正确的值登录了。我认为我需要清除/重置authenticationManager对象,但我不知道如何清除/重置。有什么建议吗?提前感谢!
发布于 2013-03-12 23:40:51
你应该用另一种方式。
1)定义身份验证管理器
<s:authentication-manager>
<s:authentication-provider>
<s:user-service>
<s:user name="root" password="root"/>
</s:user-service>
</s:authentication-provider>
</s:authentication-manager>2)定义安全配置和表单登录
<s:http auto-config="true" use-expressions="true">
<s:intercept-url pattern="/favicon.ico" access="permitAll"/>
<s:intercept-url pattern="/resources/**" access="permitAll"/>
<s:intercept-url pattern="/login**" access="isAnonymous"/>
<s:intercept-url pattern="/pages/*" access="hasAuthority('ROLE_USER')"/>
<s:form-login login-page="/login.xhtml" default-target-url="/"
authentication-failure-url="/login.xhtml?loginFailed=true"/>
</s:http>3)将@EnableWebMvc放在一些@Configuration上
4)在login.xml创建表单以将数据(字段j_username和j_password)发布到/j_spring_security_check
5)向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>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>https://stackoverflow.com/questions/15364161
复制相似问题