spring - 在 Grails 的 Spring Security Rest Plugin 中注销时出现 404

标签 spring rest grails spring-security spring-security-rest

我正在使用 Spring Security Rest Plugin 在我的项目 ( Grails - Angularjs ) 上设置安全系统适用于 Grails 2.4.4 的 v1.5.4(使用 spring 安全核心 2.0.0)。关于这个插件的文档可以找到here .

我正在使用 postman chrome rest 客户端测试登录和注销,我可以登录,但是当我注销时得到 404。

在文档中明确表示:

The logout filter exposes an endpoint for deleting tokens. It will read the token from an HTTP header. If found, will delete it from the storage, sending a 200 response. Otherwise, it will send a 404 response

You can configure it in Config.groovy using this properties:

Config key...................................................................................Default value

grails.plugin.springsecurity.rest.logout.endpointUrl....................../api/logout grails.plugin.springsecurity.rest.token.validation.headerName....X-Auth-Token



因此,在成功登录后,我尝试使用 GET 方法注销该 URL( my_host_url/api/logout )并发送 header X-Auth-Token 使用我之前从登录获得的 token 。

但我一直收到 404。见下图

enter image description here

编辑 :我正在设置这样的链图(为了获得无状态行为):
grails.plugin.springsecurity.filterChain.chainMap = [
        '/api/**': 'JOINED_FILTERS,-exceptionTranslationFilter,-authenticationProcessingFilter,-securityContextPersistenceFilter,-rememberMeAuthenticationFilter',  // Stateless chain
        '/**': 'JOINED_FILTERS,-restTokenValidationFilter,-restExceptionTranslationFilter'                                                                          // Traditional chain
]

所以。我在这里做错了什么,或者我错过了什么?

提前致谢!

最佳答案

您错过了文档的另一个摘录。这是您引用的 block 之前的警告消息,并说:

Logout is not possible when using JWT tokens (the default strategy), as no state is kept in the server.

If you still want to have logout, you can provide your own implementation by creating a subclass of JwtTokenStorageService and overriding the methods storeToken and removeToken. Then, register your implementation in resources.groovy as tokenStorageService.

关于spring - 在 Grails 的 Spring Security Rest Plugin 中注销时出现 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41744671/

相关文章:

java - 使用本地化模式进行 Spring @Pattern bean 验证?

java - Spring Security 5.1.5 与 WebFlux 用户禁用不起作用

Spring:正确设置@ComponentScan

grails - Grails命令对象是否支持多个MultipartFile?

PostgreSQL 到 Java 数据类型 (Grails)

java - 在 Spring 中启用日志记录

web-services - Get 和 post 方法与 HTTP 和 REST 的区别

REST 和事务回滚

android - 通过 http REST 和 EJB3 连接两个 android 应用程序

grails - 如何从gsp传递 Controller 中方法调用的参数?