我正在使用Spring Security 3.0.0和持久性RememberMe.当服务器重新启动并且浏览器窗口仍然打开时,我们需要能够继续使用该应用程序而无需登录 - 如果记住我已被选中.
我得到一个org.springframework.security.web.authentication.rememberme.CookieTheftException:无效的记住我令牌(系列/令牌)不匹配.当我尝试在服务器重启后继续使用该应用程序时,意味着以前的cookie盗窃攻击.我注意到processAutoLoginCookie方法被调用两次.我不知道为什么.方法本身的行为似乎是正确的,即更新数据库中的令牌并更新客户端中的cookie.
任何有关这方面的帮助将不胜感激.
谢谢.
在为网站实现"记住我"功能的同时,为什么我们使事情变得复杂并且在会话令牌之外有一个名为mem me token的令牌.
据我所知,记住我可以使用令牌登录并创建一个新的会话令牌,而会话令牌只持续几分钟或直到用户关闭浏览器.为什么我们不能将会话令牌本身的到期持续时间增加到我们希望用户登录的所需时间?
我需要在运行tomcat的基于flex的应用程序中实现这样的功能,我想知道需要记住我的令牌
此外,是否有可能在tomcat中开箱即用?
我按照github设计维基上的教程进行了操作:https: //github.com/plataformatec/devise/wiki/OmniAuth%3A-Overview
所以我为回调创建了一个omniauth控制器,但它绕过了正常的会话控制器,因此,没有设置可记忆的cookie.
解决这个问题的最佳方法是什么?
谢谢你的帮助.
编辑:我的控制器代码的要点:https://gist.github.com/913164 所以我认为重定向中的标志只是设置会话cookie,而不是可记忆的.
编辑2:我还有一个后门用于开发登录并避免我的本地机器上的FB连接:
def backdoor
if RAILS_ENV == "development"
@user = User.first
@user.remember_me!
sign_in_and_redirect @user, :event => :authentication
end
end
Run Code Online (Sandbox Code Playgroud)
也不起作用,所以我可能在其他地方遇到问题.
我正在开发一个应用程序,我需要捕获并响应身份验证事件以采取适当的操作.目前,AuthenticationSuccessEvent
当用户手动登录时,我正好赶上Spring抛出.我现在正在尝试实现Remember-Me功能.记录帮助我弄清楚我想要捕获的事件是什么InteractiveAuthenticationSuccessEvent
.有人可以看看下面的代码并帮助我回应这个新事件吗?
@Override
public void onApplicationEvent(ApplicationEvent event) {
log.info(event.toString()); // debug only: keep track of all events
if (event instanceof AuthenticationSuccessEvent) {
AuthenticationSuccessEvent authEvent = (AuthenticationSuccessEvent)event;
lock.writeLock().lock();
try {
sessionAuthMap.put(((WebAuthenticationDetails)authEvent.getAuthentication().getDetails()).getSessionId(), authEvent.getAuthentication());
} finally {
lock.writeLock().unlock();
}
} else if (event instanceof HttpSessionDestroyedEvent) {
HttpSessionDestroyedEvent destroyEvent = (HttpSessionDestroyedEvent)event;
lock.writeLock().lock();
try {
sessionAuthMap.remove(destroyEvent.getId());
} finally {
lock.writeLock().unlock();
}
}
}
Run Code Online (Sandbox Code Playgroud)
附加信息:
我在原始帖子中没有提到在Map中存储Session Id和Authentication对象的要求是由于我正在使用Google Earth插件.GE充当独立的,不相关的用户代理,因此用户的会话信息永远不会被GE传递给服务器.出于这个原因,我重写GE的请求URL以包含用户的活动会话ID(来自前面提到的Map)作为参数,因此我们可以验证所述会话ID对于登录用户确实有效.所有这一切都已到位,因为我们有GE需要的KML,但是我们不能允许用户通过Firebug获取直接的,不受保护的URL或者你有什么.
Spring Config :(抱歉,有点捏造格式化)
<sec:http use-expressions="true">
<sec:intercept-url pattern="/Login.html*" access="permitAll"/>
<sec:intercept-url pattern="/j_spring_security*" access="permitAll" method="POST"/> …
Run Code Online (Sandbox Code Playgroud) 我已经以编程方式实现了登录功能.
此代码如下:
$token = new UsernamePasswordToken($user, $user->getPassword(), 'main', $user->getRoles());
$this->get('security.context')->setToken($token);
$event = new InteractiveLoginEvent($this->getRequest(),$token);
$this->get('event_dispatcher')->dispatch('security.interactive_login', $event);
Run Code Online (Sandbox Code Playgroud)
在此之后,我该如何实现记住我?
(我知道如何使用表单,但我想实现以编程方式记住我.)
请帮忙...
最初的想法:在“改进的持久登录 Cookie 最佳实践”一文中,( http://jaspan.com/improved_persistent_login_cookie_best_practice ) bjaspan 提出了一种通过创建系列标识符来捕捉潜在 cookie 窃贼的聪明方法,简单来说, 如果两台计算机尝试使用相同的系列标识符,则标记可能存在安全问题。
问题:然而,正如“基于表单的网站身份验证的权威指南”第二部分第 1 点正确指出的那样,黑客只需在为自己复制用户的 cookie 后删除它,就很容易打败它。由于这篇文章相当受欢迎,任何有足够技巧来窃取 cookie 的人都可能知道删除旧的。
问题:是否有解决方案可以克服这个问题?能够检测 cookie 盗窃(即使不是即时的)的好处对于持久登录安全是相当有价值的。有没有更好的方法来防止或检测 cookie 盗窃?
我遇到了一个问题,我记得我的配置:
[nio-8080-exec-8] s.s.w.a.r.RememberMeAuthenticationFilter : SecurityContextHolder not populated with remember-me token, as it already contained: 'org.springframework.security.authentication.UsernamePasswordAuthenticationToken@73939efa: Principal: Member ...
Run Code Online (Sandbox Code Playgroud)
这是我的Spring安全配置:
@Configuration
@EnableWebSecurity
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
@Autowired
private MemberUserDetailsService memberUserDetailsService;
@Autowired
private BCryptPasswordEncoder passwordEncoder;
@Autowired
private AccessDecisionManager accessDecisionManager;
@Autowired
private ApplicationEventPublisher eventPublisher;
@Override
protected void configure(HttpSecurity http) throws Exception {
//@formatter:off
http
.headers()
.cacheControl()
.and()
.and()
.csrf()
.csrfTokenRepository(csrfTokenRepository())
.and()
.rememberMe()
.tokenValiditySeconds(60*60*24*7)
.and()
.exceptionHandling()
.accessDeniedHandler(accessDeniedHandler())
.and()
.formLogin()
.loginProcessingUrl("/api/signin")
.failureHandler(authenticationFailureHandler())
.successHandler(authenticationSuccessHandler())
.and()
.logout()
.logoutRequestMatcher(new AntPathRequestMatcher("/api/signout"))
.logoutSuccessHandler(logoutSuccessHandler())
.and()
.addFilterAfter(new CsrfHeaderFilter(), CsrfFilter.class)
.authorizeRequests() …
Run Code Online (Sandbox Code Playgroud) 我在理解 Laravel 记住我功能时遇到一些问题。
remember_me
记住我功能和表中的列之间有什么联系users
?谢谢。
我正在使用Spring Security的RememberMe服务来保持用户的身份验证.
我想找到一种简单的方法将RememberMe cookie设置为会话cookie而不是固定的到期时间.对于我的应用程序,cookie应该持续到用户关闭浏览器.
有关如何最好地实现这一点的任何建议?对此的任何担忧都是潜在的安全问题?
这样做的主要原因是,使用基于cookie的令牌,我们的负载均衡器后面的任何服务器都可以为受保护的请求提供服务,而无需依赖用户的身份验证来存储在HttpSession中.事实上,我明确告诉Spring Security永远不会使用命名空间创建会话.此外,我们使用的是亚马逊的Elastic Load Balancing,因此不支持粘性会话.
注意:虽然我知道截至4月8日,亚马逊现在支持粘性会话,但我仍然不想出于其他一些原因使用它们.也就是说,一台服务器的不合时宜的消亡仍会导致与之相关的所有用户丢失会话. http://aws.amazon.com/about-aws/whats-new/2010/04/08/support-for-session-stickiness-in-elastic-load-balancing/
我一直在尝试使用RedBean ORM(http://redbeanphp.com)来实现Silex安全提供程序包的UserInterface和UserProviderInterface.
由于RedBean ORM处理其对象函数的方式,我需要将bean对象包装在另一个类中.
这适用于身份验证,但是对于记住我功能的测试失败.
我注意到安全包在链的某个地方序列化对象.
我想也许这就是错误的原因,所以我在我的包装器类中创建了"id"和"password"的属性,并使用__sleep和__wakeup方法在睡眠期间忽略bean并在唤醒时重新加载它.尽管在__wakeup期间一切似乎都正常加载,但"记住我"功能的测试仍然失败.
我已经创建了我的代码的github存储库.如果有人有任何想法,我会非常感激!
出于某种原因,RedBean,Silex和PHPUnit不允许自己被包含在存储库中.一个简单的作曲家更新应该为你拉下来.如果有人有任何想法,我也会感谢你的回答.
github存储库可以在以下位置找到:
https://github.com/christianmagill/silex-redbean-security
适用的文件是
要在数据库中创建测试用户:
/setup.php
要运行测试:
的index.php
我的UserInterface实现:
/src/App/Model/UserSecurityWrapper.php
我的UserProviderInterface的实现:
/src/App/Model/UserProvider.php
我修改过的测试:
/src/App/Test/RememberMeRedBeanServiceProviderTest.php
原始测试:
/vendor/silex/silex/tests/Silex/Tests/Provider/RememberMeServiceProviderTest.php