【问题标题】:Remember Me in Seam 3在接缝 3 中记住我
【发布时间】:2011-11-07 17:57:13
【问题描述】:

如何使用seam security 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}"/>

谢谢

【问题讨论】:

  • 你的错误是什么?发生了什么让您知道它不起作用?
  • 令牌表没有数据写入
  • 你使用了 Justin 的那个功能吗? @JustinSatyr
  • 我没有测试这个,我只是为了你的利益,所以以后看到这个的人可以更容易地帮助你。

标签: jsf-2 seam3


【解决方案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;}
}

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2013-01-07
      • 2012-04-12
      • 1970-01-01
      • 1970-01-01
      • 2012-01-14
      • 2011-12-01
      • 2012-01-30
      • 2011-11-06
      • 1970-01-01
      相关资源
      最近更新 更多