j_username
login.jsp に " " および " "と共にカスタム フィールドがj_password
あり、ユーザーを認証する必要があります。次のように CustomUsernamePasswordAuthenticationFilter を使用してカスタム フィールドにアクセスしています。
public class CustomUsernamePasswordAuthenticationFilter extends UsernamePasswordAuthenticationFilter {
@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) {
String myCustomField= request.getParameter("myCustomField");
request.getSession().setAttribute("CUSTOM_FIELD", myCustomField);
return super.attemptAuthentication(request, response);
}
}
loadByUsername
UserDetailsService クラスのメソッドでセッションにアクセスしようとしましたが、エラーが発生しました。カスタム UserDetailsService のコードは次のとおりです。
public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException, DataAccessException {
ServletRequestAttributes attr = (ServletRequestAttributes)RequestContextHolder.currentRequestAttributes();
HttpSession session = attr.getRequest().getSession();
User userObject = dbObject.retrieveUser(userName,myCustomParameter)
// code here to retrieve my user from the DB using the userName and myCustomParameter that was retrieved from login.jsp and put in the session. Get the custom parameter from the session here.
if (userObject == null)
throw new UsernameNotFoundException("user not found");
return new AuthenticationUserDetails(userObject);
}
認証のためにこのカスタム パラメータにアクセスする方法はありますか? セッションを介して送信しても機能していないようです。