- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
作为上下文,很长一段时间以来,我一直在尝试获得一个相当简单的 @SprintBootApplication 以及与 WSO2 Identity Server 集成的附加 @EnableOAuth2Sso 注释。
在我看来,这项工作应该是一个配置问题(如 Spring Cloud Security 上所宣传的那样) - 但到目前为止我还没有运气。
为了了解发生了什么,我使用我的调试器单步执行 spring-security-oauth2 代码以找出发生了什么。在这样做时,我注意到我的 AccessTokenRequest 的 PreservedState 永远为空,并导致与 CSRF 相关的 InvalidRequestException。这是相关代码:
public class AuthorizationCodeAccessTokenProvider extends OAuth2AccessTokenSupport implements AccessTokenProvider {
....
private MultiValueMap<String, String> getParametersForTokenRequest(AuthorizationCodeResourceDetails resource,
AccessTokenRequest request) {
MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
form.set("grant_type", "authorization_code");
form.set("code", request.getAuthorizationCode());
Object preservedState = request.getPreservedState();
if (request.getStateKey() != null || stateMandatory) {
// The token endpoint has no use for the state so we don't send it back, but we are using it
// for CSRF detection client side...
if (preservedState == null) {
throw new InvalidRequestException(
"Possible CSRF detected - state parameter was required but no state could be found");
}
}
http://localhost:9998/loginstate=Uu8ril&code=20ffbb6e4107ce3c5cf9ee22065f4f2
spring:
profiles: default
security:
oauth2:
client:
accessTokenUri: https://localhost:9443/oauth2/token
userAuthorizationUri: https://localhost:9443/oauth2/authorize
clientId: yKSD9XwET9XJ3srGEFXP6AfHhAka
clientSecret: zuPTcdJH435h3wgl055XNZ5ffNMa
scope: openid
clientAuthenticationScheme: header
resource:
userInfoUri: https://localhost:9443/oauth2/userinfo?schema=openid
最佳答案
事实证明,在提供的代码部分中引用的 reservedState 为 null 的原因是因为正在创建一个新的 bean Oauth2ClientContext 实例,而这正是不应该发生的 - OAuth2ClientContext 的全部目的是存储状态。就 OAuth2 协议(protocol)(RFC 6749)而言,保存状态对于防止跨站点请求伪造非常重要(参见第 10.12 节)。
解决这个问题是一件简单的事情,即启用调试日志记录并将针对 WSO2 IS 生成的输出与一个工作示例所看到的内容进行比较。在我的例子中,我总是回归到的工作示例是 Spring 团队自己提供的示例。
这是客户端配置(application.yml),然后使用 Spring 团队 SSO 服务器记录输出测试:
spring:
profiles: default
security:
oauth2:
client:
accessTokenUri: http://192.168.0.113:32768/uaa/oauth/token
userAuthorizationUri: http://192.168.0.113:32768/uaa/oauth/authorize
clientId: acme
clientSecret: acmesecret
resource:
jwt:
keyValue: |
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnGp/Q5lh0P8nPL21oMMrt2RrkT9AW5jgYwLfSUnJVc9G6uR3cXRRDCjHqWU5WYwivcF180A6CWp/ireQFFBNowgc5XaA0kPpzEtgsA5YsNX7iSnUibB004iBTfU9hZ2Rbsc8cWqynT0RyN4TP1RYVSeVKvMQk4GT1r7JCEC+TNu1ELmbNwMQyzKjsfBXyIOCFU/E94ktvsTZUHF4Oq44DBylCDsS1k7/sfZC2G5EU7Oz0mhG8+Uz6MSEQHtoIi6mc8u64Rwi3Z3tscuWG2ShtsUFuNSAFNkY7LkLn+/hxLCu2bNISMaESa8dG22CIMuIeRLVcAmEWEWH5EEforTg+QIDAQAB
-----END PUBLIC KEY-----
id: openid
serviceId: ${PREFIX:}resource
请注意,没有提到创建
的行OAuth2ClientContext .
DEBUG o.s.security.web.FilterChainProxy - /login?code=9HLSpP&state=G9kpy3 at position 6 of 12 in additional filter chain; firing Filter: 'OAuth2ClientAuthenticationProcessingFilter'
DEBUG o.s.s.w.u.m.AntPathRequestMatcher - Checking match of request : '/login'; against '/login'
DEBUG o.s.s.o.c.f.OAuth2ClientAuthenticationProcessingFilter - Request is to process authentication
INFO o.s.s.o.c.DefaultOAuth2ClientContext - Getting access token request
DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'scopedTarget.accessTokenRequest'
DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.security.oauth2.config.annotation.web.configuration.OAuth2ClientConfiguration'
DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'scopedTarget.accessTokenRequest'
INFO o.s.s.o.client.OAuth2RestTemplate - Longer lived state key: G9kpy3
INFO o.s.s.o.client.OAuth2RestTemplate - Removing preserved state in oauth2context
INFO o.s.s.o.c.DefaultOAuth2ClientContext - Found preserved state: http://localhost:9999/login
这是客户端配置 (application.yml),然后使用 WSO2IS 5.0.0 记录输出测试:
spring:
profiles: wso2
server:
port: 9998
security:
oauth2:
client:
accessTokenUri: https://localhost:9443/oauth2/token
userAuthorizationUri: https://localhost:9443/oauth2/authorize
clientId: yKSD9XwET9XJ3srGEFXP6AfHhAka
clientSecret: zuPTcdJH435h3wgl055XNZ5ffNMa
scope: openid
clientAuthenticationScheme: header
resource:
userInfoUri: https://localhost:9443/oauth2/userinfo?schema=openid
注意
的行创建 bean 'scopedTarget.oauth2ClientContext' 的实例 .
DEBUG o.s.security.web.FilterChainProxy - /login?state=PWhQwv&code=372ff0c197a4c85a0caf070cc9a6678 at position 6 of 12 in additional filter chain; firing Filter: 'OAuth2ClientAuthenticationProcessingFilter'
DEBUG o.s.s.w.u.m.AntPathRequestMatcher - Checking match of request : '/login'; against '/login'
DEBUG o.s.s.o.c.f.OAuth2ClientAuthenticationProcessingFilter - Request is to process authentication
DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'scopedTarget.oauth2ClientContext'
DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2RestOperationsConfiguration$SessionScopedConfiguration$ClientContextConfiguration'
DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'scopedTarget.oauth2ClientContext'
INFO o.s.s.o.c.DefaultOAuth2ClientContext - Getting access token request
DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'scopedTarget.accessTokenRequest'
DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.security.oauth2.config.annotation.web.configuration.OAuth2ClientConfiguration'
DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'scopedTarget.accessTokenRequest'
INFO o.s.s.o.client.OAuth2RestTemplate - Longer lived state key: PWhQwv
INFO o.s.s.o.client.OAuth2RestTemplate - Removing preserved state in oauth2context
INFO o.s.s.o.c.DefaultOAuth2ClientContext - Found preserved state: null
最后,下一个调用端口自然是确定为什么 OAuth2ClientContext 不是使用 WSO2 IS 配置创建的。调查表明这是因为 WSO2 IS 没有传回预期的 JSESSIONID,因此将找不到 session 范围的 OAuth2ClientContext。
private MultiValueMap<String, String> getParametersForTokenRequest(AuthorizationCodeResourceDetails resource,
AccessTokenRequest request) {
MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
form.set("grant_type", "authorization_code");
form.set("code", request.getAuthorizationCode());
request.setPreservedState("http://localhost:9998/login");
Object preservedState = request.getPreservedState();
关于spring-security - 为什么 AccessTokenRequest 的 PreservedState 永远为空,并导致与 CSRF 相关的 InvalidRequestException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34219911/
有人可以解释预定义谓词forall如何在列表中找到最小值吗? 最佳答案 对于列表L,您可以使用: member(Min,L), forall(member(N,L), N>=Min). 但是,尽管这是
编辑:澄清一下,我正在搜索的对象数组确实已按搜索变量的字母数字顺序进行了预排序。 我做了一个二分搜索函数并将它嵌套在另一个函数中。出于某种原因,每次我使用二进制搜索都无法找到相关的字符数组。 基本上,
是否可以阻止用户(甚至是管理员)终止我的程序? 或者万一被杀死,它会迅速恢复自身? 更新:澄清一下:我正在编写一个监控程序,类似于家长控制,它记录用户对 PC 的操作。你可以通过查看我最近的其他问题来
我有一个 for 循环,我希望它永远递增。 我的代码: for a in (0...Float::INFINITY).step(2) puts a end 输出: 0.0 2.0 4.0 Et
我很困惑。我有一个运行Ubuntu 14.04的VM。我在这里遵循了以下程序:http://clang.llvm.org/docs/LibASTMatchersTutorial.html,现在正在运行
这是我的代码 #include #include #include #include #include #include #include #include #include usi
我有一个程序会或多或少地通过标准输入使用 COPY FROM 将大量数据复制到 Postgres 9 中。 这目前工作正常,但我正在缓冲数据 block ,然后分批运行 COPY FROM 操作。 我
我想我不小心在某个地方安装了 Foreverjs 并启动了它。每次我杀死这个进程时,另一个进程就会取代它的位置 ] 1 我不知道永远在哪里(或者这实际上是导致它的原因),因为我在本地安装了它。 最佳答
我得到了一个 forever: command not found 当我使用 forever 命令作为 cronjob 运行 nodejs 进程时出现错误(在亚马逊 ec2 机器中):我正在使用的 b
我创建了一些容器,它们还没有准备好使用,总是“重新启动”状态: docker ps CONTAINER ID IMAGE COMMAND
我试图永远重复一个 IO 操作,但是将一个执行的结果输入到下一个执行中。像这样的东西: -- poorly named iterateM :: Monad m => (a -> m a) -> a -
这里的代码样式问题。 我看着this问题,它询问.NET CLR是否真的总是初始化字段值。 (答案是肯定的。)但令我感到惊讶的是,我不确定执行此操作始终是个好主意。我的想法是,如果我看到这样的声明:
美好的一天,我对永久启动\停止脚本有一些问题。 中央操作系统 6.2 内核 2.6.32-220.el6.x86_64 node.js v0.6.19 npm v 1.1.24 永远@0.9.2 我创
我在让管道与 paramiko 一起工作时遇到问题。 这个有效: ssh = paramiko.SSHClient() [...] stdin, stdout, stderr = ssh.exec_c
我希望守护我的 Node.js 应用程序。 Upstart 和永远有什么区别?另外,还有其他我可能想要考虑的软件包吗? 最佳答案 正如评论中指出的,upstart将用于启动 forever脚本,因为
我有以下查询,其中包含在 5 秒内返回数据的选择查询。但是当我在前面添加创建物化 View 命令时,查询需要创建物化 View 。 最佳答案 当您创建物化 View 时,实际上是创建了 Oracle
当我今天访问我的项目的 Google Cloud 控制台并单击“计算引擎”或“云存储”时,它只会永远显示“正在加载”。几天前,我能够看到我的虚拟机和存储桶。有没有办法让控制台再次工作? 谢谢, 麦克风
我编写了一个函数,它当前显示 1000 以下的所有质数。 我可以继续增大 1000 以生成更多数字,但我不知道如何让它在运行后一直持续下去。 func generatePrimes() { l
这是由 another question 触发的. 具体来说,我有一个进程中的 COM 类,它在 CLSID registry 中定义。因为有 ThreadingModel of Both . 我们的
我正在试用新的 React Hooks的 useEffect API,它似乎永远在无限循环中运行!我只希望 useEffect 中的回调运行一次。这是我的引用代码: 单击“运行代码片段”以查看“运行
我是一名优秀的程序员,十分优秀!