spring - 如何将通用(参数,值)-couple从我的登录控制器传递给我的身份验证提供程序?

ing*_*ous 3 java authentication spring spring-security

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

编辑:根据Sanath的建议,在做了一些阅读后,我终于能够解决问题了 - 如果你对我是怎么做的话,请看下面.

ing*_*ous 6

我做了以下,最后它像一个魅力.

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

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

那我WebAuthenticationDetailsSource就像这样设置我的实现:

public class MyWebAuthDetSource implements AuthenticationDetailsSource<HttpServletRequest, MyWebAuthDets> {
  public MyWebAuthDetSource buildDetails (HttpServletRequest context) {
    return new MyWebAuthDets(context);
  }
}
Run Code Online (Sandbox Code Playgroud)

然后我有我的AuthenticationDetails实现,如:

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

然后我忽略了最简单的事实,即身份验证过程只处理从登录表单提交的内容,因此我只需在login.jsp中添加以下内容:

...
<form id="j_spring_security_check" ... >
  <input type="hidden" name="paramID" value="${param['paramID']}" />
  ...
</form>
...
Run Code Online (Sandbox Code Playgroud)

这就是全部.现在,我可以添加一个authenticationProvider拿到我的参数与.getDetails()从authenticationToken.

再次感谢@Sanath.