2011-08-31 70 views
1

如何使用煤层安全3的记住我特征?在煤层中记住我3

我试缝2的方式,但它不工作... 这里我的components.xml ...不知道如果此文件被缝3

<security:jpa-token-store token-class="org.jboss.seam.example.seamspace.AuthenticationToken" /> 
<security:remember-me mode="autoLogin"/> 
<event type="org.jboss.seam.security.notLoggedIn"> 

<action execute="#{redirect.captureCurrentView}"/> 

<action execute="#{identity.tryLogin()}"/> 

使用
<action execute="#{redirect.returnToCapturedView}"/> 

感谢

+0

你的错误是什么?会发生什么让你知道它不起作用? –

+0

没有数据写入令牌表 – RLuceac

+0

您是否使用过该功能Justin? @JustinSatyr – RLuceac

回答

0

Seam 3不使用components.xml来配置组件/ bean。

我不认为Seam Security 3(3.0.0.Final)具有内置的“rememberMe”功能。

1

根据https://community.jboss.org/thread/178998 RemeberMe不被整合seam-security-3.1,但是该类已经是prepared

Seam2已知了rememberMe是在两种模式下可用的:

  • 第一模式允许用户名被存储在用户的浏览器作为cookie,并离开密码的进入到浏览器(许多现代浏览器都能记住密码)。

  • 第二种模式支持在cookie中存储唯一的标记,并允许用户在返回站点时自动进行身份验证,而无需提供密码。

幸运的是,为第一种模式实施解决方法并不困难。登录成功后,您可以设置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;} 
}