3

我想要做的是在我的登录页面上读取一个 http 参数,例如login.html?param=value,然后传递value给我的 AuthenticationProvider。我的想法是以某种方式保存value在一个隐藏的参数中,但我仍然不知道如何传递它。这可能吗?我该怎么做呢?

编辑:遵循 Sanath 的建议并阅读了一些内容后,我终于能够解决问题——如果您对我是如何做到的感兴趣,请看下面。

4

1 回答 1

6

我做了以下事情,最后它就像一个魅力。

在我的 bean 配置文件中,我必须输入:

<http auto-config="true>
  ...
  <form-login ... authentication-details-source-ref="myWebAuthDetSource"/>
  ...
</http>
<beans:bean id="myWebAuthDetSource" class="com.my.pack.age.MyWebAuthDetSource"/>
...

然后我已经像这样设置了我的WebAuthenticationDetailsSource实现:

public class MyWebAuthDetSource implements AuthenticationDetailsSource<HttpServletRequest, MyWebAuthDets> {
  public MyWebAuthDetSource buildDetails (HttpServletRequest context) {
    return new MyWebAuthDets(context);
  }
}

然后我的AuthenticationDetails实现如下:

public class MyWebAuthDets extends WebAuthenticationDetails {
  private final String parameter;
  public MyWebAuthDets(HttpServletRequest request) {
    super(request);
    this.parameter = request.getParameter("paramId");
  }
}

And then I overlook the most simple fact, that the authentication process processes only what it gets on submit from the login form, so I simply had to add the following in login.jsp:

...
<form id="j_spring_security_check" ... >
  <input type="hidden" name="paramID" value="${param['paramID']}" />
  ...
</form>
...

And that was all. Now I can add an authenticationProvider and get my parameter with .getDetails() from the authenticationToken.

Thanks again @Sanath.

于 2013-03-19T07:45:51.427 回答