问题标签 [spring-security-oauth2]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
spring-security - 如果没有令牌在带有 OAuth2 弹簧安全性的标头中传递,为什么过滤器链会继续?
我正在尝试将 OAuth2 与 Spring Security 一起使用,并带有以下配置 xml:
我成功生成了一个令牌。现在,在尝试访问受保护的资源时,如果我在标头中传递令牌,一切正常。但如果我不通过令牌,就会绕过安全性。
我检查了 OAuth2AuthenticationProcessingFilter 的代码:
任何想法,如果令牌不存在,为什么此过滤器会跳过安全性?我应该添加一些其他过滤器来处理这种情况吗?
spring - 404 oauth2 成功授权后,未找到带有 URI 的 HTTP 请求的映射
我对 Spring REST oAuth2 配置有疑问。Springs 看到并映射了我的 URL,但在 oauth2 安全检查(成功)声称没有匹配的 URL 之后。但我不知道为什么,因为 Spring 在应用程序初始化时看到了它。我能够正确地使用 /oauth/token 进行身份验证并生成令牌。我只是无法处理不需要令牌授权的请求。
Spring 4.0.6、spring-security 3.2.4、Spring-security-oauth2 2.0.1
来自上下文初始化的日志
发送请求后
和配置
用户控制器的一部分
我想要实现的是保护所有请求,并且只有其中一些请求可以免费访问(或者可能只有授权标头与 client_id 匹配)。
java - Spring security oauth2:在 REST Web 服务中获取用户名
我创建了一个 RESTful Web 服务来对工作流执行操作。使用我自己的授权服务器的 oauth2 保护 Web 服务。我想在我的工作流程中添加有关谁对其执行操作的信息。我不知道是谁获得了调用 Web 服务的用户名。
对于 Web 服务实现,我使用 jersey (1.18.1),为了安全,我使用 spring-security-oauth2 (2.0.2.RELEASE)。
我正在使用数据库令牌存储,其中包含一个看起来包含正确信息的表 OAUTH_ACCESS_TOKEN (TOKEN_ID, TOKEN, AUTHENTICATION_ID, USER_NAME, CLIENT_ID, AUTHENTICATION, REFRESH_TOKEN)。它有用户名和令牌,但令牌看起来像一个序列化的 java 对象,所以我不能自己查询它。
网络服务:
Web服务安全配置:
授权服务器配置:
spring - 使用 spring 进行多个社交登录
我的 webapp 中有多个 WebSecurityConfigurerAdapters,每个部分对应一个应用程序,并且需要有多个具有不同行为的“使用 FB/Google 登录”按钮。
我一直在尝试为每个 WebSecurityConfigurerAdapter 配置多个 SpringSocialConfigurers ,但这似乎不起作用,因为一次只能使用一个。
有想法该怎么解决这个吗?
和
spring-security - 如何使用 Spring Security OAuth2 在 Spring Boot 中注册自定义 BasicAuthenticationFilter AuthenticationProvider
语境
我正在开发一个应用程序,该应用程序允许经过身份验证的用户创建OAuth2 不记名令牌以与组织发布的 API 一起使用。这个想法是允许用户自行生成/撤销此类令牌,类似于 GitHub 的Personal API 令牌。然后,用户可以使用已发行的令牌来获得对受保护资源的编程访问权限。在此配置中,OAuth“客户端”、“授权服务器”和“资源服务器”属于组织。目前,所有这些服务都驻留在同一个进程中。
为此,我正在尝试支持Resource Owner Password Credentials Grant类型。实施环境包括以下内容:
- 弹簧靴
- 春季安全 OAuth2
实现的一个限制是无法访问存储的密码。此处理被委托给执行实际身份验证的内部 Web 服务。
问题
由于无法访问存储密码的限制,不能使用默认配置,DaoAuthenticationProvider
因为它需要访问提供者UserDetails
返回的对象提供的密码UserDetailsService
。
我的猜测是我需要AuthenticationProvider
用自定义实现替换它。然而,所有这样做的尝试似乎都没有奏效。
以下似乎在 的parent
引用中正确注册AuthenticationManager
,但在运行时未委托给(由于DaoAuthenticationProvider
优先):
似乎无论我尝试什么(参见下面的参考资料),ProviderManager
当在其方法中BasicAuthenticationFilter
调用时,我总是得到以下两个提供程序:Authentication authResult = authenticationManager.authenticate(authRequest)
doFilter
[ org.springframework.security.authentication.AnonymousAuthenticationProvider@366815e4, org.springframework.security.authentication.dao.DaoAuthenticationProvider@5da3e311 ]
我相信这可能是AuthorizationServerSecurityConfigurer
'clientCredentialsTokenEndpointFilter
方法的结果。但是,此类已标记final
,因此无法自定义。
任何建议或指示将不胜感激。
资源
我尝试过/研究过的事情:
- http://projects.spring.io/spring-security-oauth/docs/oauth2.html#toc_7
- http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#howto-change-the-authenticationmanager-and-add-user-accounts
- Spring Security 3.2:@Autowire 不适用于 Spring MVC 应用程序中的 java 配置和自定义 AuthenticationProvider?
- 如何在自定义过滤器中使用 Java 配置注入 AuthenticationManager
- 具有 Spring Security 和 Java Config 的自定义身份验证提供程序
- https://gist.github.com/SlyDen/9408539 -https://github.com/royclarkson/spring-rest-service-oauth/blob/master/src/main/java/hello/WebSecurityConfiguration.java
- https://github.com/spring-projects/spring-boot/blob/master/spring-boot-samples/spring-boot-sample-web-secure/src/main/java/sample/ui/secure/SampleWebSecureApplication。爪哇
- https://github.com/spring-projects/spring-security-oauth/blob/master/samples/oauth2/sparklr/src/main/java/org/springframework/security/oauth/examples/sparklr/config/OAuth2ServerConfig。爪哇
- https://github.com/spring-projects/spring-security-oauth/blob/6d9de66787cb60249f0de00ffe9075366a803924/tests/annotation/vanilla/src/main/java/demo/Application.java
- https://github.com/spring-projects/spring-security-javaconfig/blob/master/samples/oauth2-sparklr/src/main/java/org/springframework/security/oauth/examples/sparklr/config/SecurityConfiguration。爪哇
oauth-2.0 - 如何使用 Spring Boot 和 Spring Security OAuth2 实现“个人访问令牌”
我正在尝试创建一个应用程序,该应用程序允许经过身份验证的用户创建OAuth2 不记名令牌以与组织发布的 API 一起使用。这个想法是允许用户自行生成/撤销此类令牌,类似于 GitHub 的Personal API 令牌。然后,用户可以使用已发行的令牌以编程方式访问同一组织公开的受保护资源。
此应用程序需要:
- 用于对用户进行身份验证并允许用户生成和撤销令牌的 UI
- 允许用户身份验证和令牌生成、撤销和存储的服务器端 RESTful API
理想情况下,此应用程序将是无状态的,并且不需要会话,使用SPA。
围绕实施的一些问题:
- 公开的 API 是否应该是使用资源所有者密码凭证授予类型的
@EnableAuthorizationServer
/oauth/token
端点?如果是这样,将客户端凭据暴露给 UI 是否不安全?这可以避免吗? - API 是否应该公开一个直接调用的新的专用端点
AuthorizationServerTokenServices
?如果是这样,如何实现? - 是否有使用 Spring Boot 和 Spring Security OAuth2 的参考实现?
任何建议或参考将不胜感激。
spring - 使用 Spring-security @PreAuthorize 注释和 OAuth2 保护 REST API
我正在为一些弹簧安全 OAuth2 配置而苦苦挣扎。
我在用着:
- Spring.version:4.0.5.RELEASE
- Spring 安全版本:3.2.5.RELEASE
- Spring security oauth 版本:2.0.2.RELEASE
- 球衣版本:1.18.1
我想使用 Spring 安全性的 PreAuthorize 注释来保护我的 REST API,我在其中定义了有权访问该方法的角色:
当我为具有角色“ROLE_ADMIN”的用户使用有效的不记名令牌调用 API 方法时,出现以下异常:
使用邮递员时,我看到以下错误描述:
这是我的安全配置:
这是我的 web.xml 配置:
spring - Spring OAuth2-在授权中传递令牌:Bearer
我在 Request 标头中将 oauth2 令牌作为 Authorization: Bearer 传递。但是,如果您使用例如 Chrome 开发人员工具,您可以看到令牌并基本上复制它并使用它来调用我们的服务。如何防止/隐藏令牌,使其不会显示在开发人员工具中。
java - 升级 Spring Security OAuth2
我正在尝试将 Spring security OAuth2 配置从 2.0.0.RC1 升级到 2.0.3.RELEASE。当时我从 sprklr 示例中复制了配置并使其工作。因此,它基于基于 xml 的 Spring Security OAuth2 配置的工作示例。
现在,我已升级到 Spring Security 最新版本(撰写本文时为 2.0.3),并尝试将其转换为 java config。我在下面发布 xml 配置和 java 配置。
和java配置(到目前为止..)
添加更多信息(根据 Dave Syer 的问题)
不生成令牌,请参阅下文了解更多信息。
要求:
回复:
{"error":"unauthorized","error_description":"在 SecurityContext 中找不到 Authentication 对象"}
服务器日志:
(10 月 14 日更新)
Java安全配置;
spring - How to add content to an Spring oauth2 access token?
If I understand the oauth2 spec correctly I should be able to add custom content like an user_id to the oauth2 access token. The server can then decode the access-token and add an User Domain Object to the SecurityContextHolder.
(Of course I could add the user_id to every REST API method but this would mean a lot of refactoring)
Right now from reading the manual I think that I need to implement or extend a TokenEnhancer. Since I am using a javascript client maybe I should extend JwtAccessTokenConverter? Am I on the right path here?