- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Grails 1.3.7 + spring-security-core 插件
有没有办法从 authFail 闭包中检索在登录表单中输入的密码?我可以通过以下方式获取用户名
session[UsernamePasswordAuthenticationFilter.SPRING_SECURITY_LAST_USERNAME_KEY]
但是似乎没有办法获取密码。
session[UsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_PASSWORD_KEY]
始终返回 null。
最佳答案
首先:不要这样做。我敢打赌,无论你想用它做什么都会破坏安全。将密码写入 HTML 表单中的密码字段就是其中一种不好的情况。在 session 中存储密码也不是一个好主意。
回答您的问题:覆盖 UsernamePasswordAuthenticationFilter 并在 spring 配置中使用您的自定义类。
复制 attemptsAuthentication 的内容并将您需要的任何内容添加到 session 中。在完成所需操作后,从 session 中删除密码是非常明智的做法
request.getSession().removeAttribute(SPRING_SECURITY_LAST_PASSWORD_KEY);
过滤器类别:
public class MyFilter extends UsernamePasswordAuthenticationFilter{
public static final String SPRING_SECURITY_LAST_PASSWORD_KEY = "SPRING_SECURITY_LAST_PASSWORD";
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException {
if (postOnly && !request.getMethod().equals("POST")) {
throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod());
}
String username = obtainUsername(request);
String password = obtainPassword(request);
if (username == null) {
username = "";
}
if (password == null) {
password = "";
}
username = username.trim();
UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username, password);
// Place the last username attempted into HttpSession for views
HttpSession session = request.getSession(false);
if (session != null || getAllowSessionCreation()) {
request.getSession().setAttribute(SPRING_SECURITY_LAST_USERNAME_KEY, TextEscapeUtils.escapeEntities(username));
request.getSession().setAttribute(SPRING_SECURITY_LAST_PASSWORD_KEY, TextEscapeUtils.escapeEntities(password));
}
// Allow subclasses to set the "details" property
setDetails(request, authRequest);
return this.getAuthenticationManager().authenticate(authRequest);
}
}
关于grails - 在 authFail 闭包中检索尝试的密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8902121/
我在一个简单的 GTK 应用程序中有两个小部件: extern crate gdk; extern crate gtk; use super::desktop_entry::DesktopEntry;
我想做这样的事情: const vegetableColors = {corn: 'yellow', peas: 'green'}; const {*} = vegetableColors; cons
该属性它存储在 gradle 中的什么位置? subprojects { println it.class.name // DefaultProject_Decorated depen
我想在 jQuery 闭包中看到窗口属性“otherName”描述符。但 进入 jQuery 闭包 'otherName' 描述符显示未定义,我认为可能 是 getOwnPropertyDescrip
我曾经看过 Douglas Crockford 的一次演讲,在 javascript 的上下文中,他提到将 secret 存储在闭包中可能很有用。 我想这可以在 Java 中像这样天真地实现: pub
我很难理解 Swift 中闭包中真正发生的事情,希望有人能帮助我理解。 class MyClass { func printWhatever(words: String) {
我有两个 3 表:用户、个人资料、friend_request $my_profile_id变量存储用户个人资料ID的值 $my_user_id = Auth::user()->id; $my_pro
我正在尝试通过使用 GLFW 的包装来学习 Swift GLFW 允许添加错误回调: GLFWAPI GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun cb
我是一名优秀的程序员,十分优秀!