1

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

谢谢

4

2 回答 2

1

根据https://community.jboss.org/thread/178998,RemeberMe没有集成 seam-security-3.1,但课程已经准备好了。

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;}
}
于 2012-08-05T10:05:16.913 回答
0

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

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

于 2011-09-01T06:04:09.920 回答