根据https://community.jboss.org/thread/178998,RemeberMe没有集成 seam-security-3.1,但课程已经准备好了。
Seam2中已知的 RememberMe有两种模式:
幸运的是,为第一种模式实施解决方法并不难。成功登录后,您可以设置 cookie:
FacesContext.getCurrentInstance().addResponseCookie("cookieName", "myToken", null);
然后确保CookieBean
在登录之前调用您自己的
<ui:fragment rendered="#{cookieBean.dummy}"/>
<h:form id="fLogin">
<h:inputText value="#{credentials.username}"/>
<h:inputSecret value="#{credentials.password}" redisplay="true"/>
<h:commandButton value="LOGIN" action="#{identity.login}"/>
</h:form>
您CookieBean
可以检查您的 cookie 是否可用,将提供的令牌映射到用户名,然后在表单中填写用户名。
@Named @SessionScoped
public class CookieBean implements Serializable
{
@Inject Credentials credentials;
@PostConstruct
public void init()
{
Map<String, Object> cookies = FacesContext.getCurrentInstance().
getExternalContext().getRequestCookieMap();
// Check if you cookie is available
// Do some stuff with your cookie
// Cookie cookie = (Cookie) cookies.get("cookieName");
credentials.setUsername("myUserName");
}
public boolean getDummy() {return false;}
}