- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有两个安全区域,我为其提供基于表单的登录。
/用户
/admin
以下按预期工作:
?error
参数重定向到登录页面以下不起作用:
注销时,我重定向到 /user/login?logout
以显示消息“您已注销”,表明注销成功。但是,这不起作用,而是将重定向到 /user/login?logout
重定向到 /user/login
,因此不会显示任何消息。
当我删除自定义注销处理程序 .logoutSuccessHandler(logoutSuccessHandler())
时,改为包含 .logoutSuccessUrl("/user/login?logout").permitAll()
有效!
但是我希望此处理程序在注销时执行其他操作。
@Configuration
@Order(1)
public static class FormLoginUser extends WebSecurityConfigurerAdapter {
@Bean
public AccessDeniedHandler accessDeniedHandler() {
return new UserCustomAccessDeniedHandler();
}
@Bean
public LogoutSuccessHandler logoutSuccessHandler() {
return new UserCustomLogoutSuccessHandler();
}
@Bean
public AuthenticationSuccessHandler authenticationSuccessHandler() {
return new UserCustomAuthenticationSuccessHandler();
}
private AuthenticationDetailsSource<HttpServletRequest, WebAuthenticationDetails> authenticationDetailsSource() {
return WebAuthenticationDetails::new;
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.antMatcher("/user/**")
.authorizeRequests().anyRequest().hasRole("USER")
.and()
.formLogin()
.loginPage("/user/login")
.permitAll()
.authenticationDetailsSource(authenticationDetailsSource())
.successHandler(authenticationSuccessHandler())
.and()
.logout()
.logoutUrl("/user/logout")
.logoutSuccessUrl("/user/login?logout").permitAll()
.logoutSuccessHandler(logoutSuccessHandler())
.and()
.exceptionHandling().accessDeniedHandler(accessDeniedHandler())
;
}
}
@Configuration
@Order(2)
public static class FormLoginAdmin extends WebSecurityConfigurerAdapter {
@Bean
public AccessDeniedHandler adminAccessDeniedHandler() {
return new AdminCustomAccessDeniedHandler();
}
@Bean
public LogoutSuccessHandler adminLogoutSuccessHandler() {
return new AdminCustomLogoutSuccessHandler();
}
@Bean
public AuthenticationSuccessHandler adminAuthenticationSuccessHandler() {
return new AdminCustomAuthenticationSuccessHandler();
}
private AuthenticationDetailsSource<HttpServletRequest, WebAuthenticationDetails> authenticationDetailsSource() {
return WebAuthenticationDetails::new;
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.antMatcher("/admin/**")
.authorizeRequests().anyRequest().hasRole("ADMIN")
.and()
.formLogin()
.loginPage("/admin/login")
.authenticationDetailsSource(authenticationDetailsSource())
.successHandler(adminAuthenticationSuccessHandler())
.permitAll()
.and()
.logout()
.logoutUrl("/admin/logout")
.logoutSuccessHandler(adminLogoutSuccessHandler())
.and()
.exceptionHandling().accessDeniedHandler(adminAccessDeniedHandler());
}
}
这是我的 CustomLogoutHandler:
public class UserCustomLogoutSuccessHandler extends
SimpleUrlLogoutSuccessHandler implements LogoutSuccessHandler {
@Override
public void onLogoutSuccess(
HttpServletRequest request,
HttpServletResponse response,
Authentication authentication)
throws IOException, ServletException {
this.setDefaultTargetUrl("/user/login?logout");
super.onLogoutSuccess(request, response, authentication);
}
}
在 DevTools 中,我可以清楚地看到,每当我尝试访问 URL /user/login?logout
时,GET-Request 结果为 302,然后为 发出新请求用户/登录
。当我手动编辑浏览器 URL 行中的 URL 或从应用程序通过 FORM-Post 触发注销时,就会发生这种情况。
当我删除 logoutSuccessHandler
时,我可以在浏览器中手动输入 URL 并在应用程序中从我的 FORM-Post 触发它。
我也试过:
/user
-> 破坏了登录Order(1)
定义第三种配置,明确允许在登录和注销页面上使用 GET 和 POST -> 这也破坏了登录.antMatcher
而是使用 .antMatchers
,但是我认为我将无法拥有两个不同的 FormLogins最佳答案
我知道这类问题会打上一个大大的问号,让我挠头思考为什么?
解决方案是。
@Override
protected void configure(HttpSecurity http) throws Exception
{
http
.antMatcher("/user/**").authorizeRequests()
.antMatchers("/user/login").permitAll() //solution
.anyRequest().hasRole("USER")
.and()
.formLogin()
.loginPage("/user/login")
.permitAll()
.authenticationDetailsSource(authenticationDetailsSource())
.successHandler(authenticationSuccessHandler())
.and()
.logout()
.logoutUrl("/user/logout")
.logoutSuccessUrl("/user/login?logout").permitAll()
.logoutSuccessHandler(logoutSuccessHandler())
.and()
.exceptionHandling().accessDeniedHandler(accessDeniedHandler());
}
想知道为什么吗?
来自之前的配置您的资源 /user/login
是受限资源,只有在authenticated = true
和 hasRole = "User"
在您的注销成功处理程序中,您正在使 session 无效并重定向到 /user/login?logout
页面,但是 /user/login
是受限资源,因此 FilterSecurityInterceptor
将重定向到配置的登录页面(.loginPage("/user/login")
。因此您不会收到任何传入查询字符串的参数。
因此,解决方案总是将登录页面作为不受限制的资源。
关于java - Redirect from CustomLogoutHandler to 'login?logout' 被重定向到 'login',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58338235/
好吧,我读了 Facebook 建议,告诉我最好是当用户从我的网站注销时关闭 Facebook session 。 信息在这里:https://developers.facebook.com/docs
我使用的是 Django 1.6.1,我在 /admin 处收到此错误该项目是一个新项目,没有使用其他模型。 Reverse for 'logout' with arguments '()' and
我对使用 passport-saml 进行身份验证时注销用户的正确方法有疑问。 带有 passport-saml 的示例脚本显示注销如下: app.get('/logout', function(re
我已经用 Spring Security 3.0.2 实现了一个登录-注销系统,一切都很好,但是对于这一点:在我添加了一个带有 invalid-session-url 属性的 session 管理标签
使用Phoenix框架,如何在用户注销并按下浏览器后退按钮后阻止用户访问之前的页面? 最佳答案 浏览器能够访问该页面是因为默认情况下允许缓存响应。如果您想防止这种情况发生,您需要在需要身份验证的页面上
我正在尝试通过第三方单一登录提供程序(例如rpxnow)提供身份验证功能。登录页面的每次刷新后,我无法检索提供者设置的cookie,因此当用户希望注销时可以删除它们吗? 还有其他方法可以正常注销用户,
当我调试ssh时,我发现“logout”的返回值是他之前的命令。例如, [server1 ~] $ ssh root@server2 /* login server2 from server1 *
使用with语句时,是否需要调用imap4类的close和logout方法? docs不要提供太多上下文。 Changed in version 3.5: Support for the with s
我正在使用云代码,并且有两个 Parse 帐户。我已经授权了第一个 Parse 帐户,但我想将云代码添加到新的 Parse 帐户,但每当我执行 Parse add 时,它会自动将我带到我拥有的 par
我想弄清楚如何覆盖 auth_views.logout 方法。通常我在覆盖类方法方面不会有问题,但是我意识到我正在尝试覆盖一个 View ,这可以在 Django 中做到吗? 我想覆盖 View 的原
我希望用户能够通过 HTTP 基本身份验证模式登录。 问题是我还希望他们能够再次注销 - 奇怪的是浏览器似乎不支持这一点。 这被认为是一种社交黑客风险 - 用户将其计算机解锁并打开浏览器,其他人可以轻
编写一个小代码 fragment ,其中 ParseUser 在满足某些条件后注销。有时它工作得很好,有时它会抛出如下所示的类转换期望 java.lang.classcastexception: or
有没有办法在页面首次加载时运行 FB.logout()?还是只有当用户点击它并触发它时才有可能?谢谢! 最佳答案 您不需要 jQuery,只需在您的 window.fbAsyncInit 函数中添加对
当我编写每个 C++ 程序时,例如那个程序: #include #include using namespace std; int main() { int n; cout > n
我使用 Django 函数进行登录,但它不显示我的模板。代码在这里: Views.py class Logout(View): #import pdb; pdb.set_trace()
我为我的 Spring Boot 应用程序实现了 JWT 身份验证。总的来说,它是这样工作的: 客户端将用户名、密码发送到登录端点。 服务器检查提供的凭据是否有效。 如果不是,它将返回一个错误 如果是
Laravel 自动授权讲解 看到这部分文档,经常看见的一句话就是php artisan make:auth,经常好奇这段代码到底干了什么,现在就来扒一扒。 路由 路由文件中会新加入以下内容:
我在我的应用程序中使用 AWS Cognito。 在注销时,我正在调用 Logout Endpoint . 但是在注销后,我仍然可以使用旧的刷新 token 生成 id-tokens。 这意味着我的注
我在服务器端有两种方法,如下所示: var Future = require("fibers/future"); Meteor.methods({ foo: function () {
我有一个使用默认 Lotus Notes http 登录的 Lotus Notes 应用程序。 在我们的开发者服务器上,Notes 有一个将登录请求发送到 names.nsf 的 html 表单 注
我是一名优秀的程序员,十分优秀!