在Seam 3记住我

时间:2011-08-31 15:43:57

标签: jsf-2 seam3

如何使用seam security 3的记忆功能??? ???

我尝试接缝2但不起作用...... 这里我的components.xml ...不确定这个文件是否用于seam 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}"/>

由于

2 个答案:

答案 0 :(得分:1)

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

来自Seam2的已知RememberMe有两种模式:

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

    < / LI>
  • 第二种模式支持在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;}
}

答案 1 :(得分:0)

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

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