我正在使用spring oauth2和JWT令牌.有人可以帮助我如何撤销JWT令牌?
正如 http://projects.spring.io/spring-security-oauth/docs/oauth2.html所述,撤销是通过刷新令牌完成的.但它似乎没有用.
在Spring Security 4发布之后,它改进了对测试的支持,我想更新我当前的Spring security oauth2资源服务器测试.
目前,我有一个帮助器类,它OAuth2RestTemplate使用连接到实际ResourceOwnerPasswordResourceDetails的测试ClientId来设置一个使用,以便AccessTokenUri为我的测试请求一个有效的令牌.这个resttemplate然后用于在我的@WebIntegrationTests中发出请求.
我想通过利用Spring Security 4中的新测试支持,放弃对实际AuthorizationServer的依赖,并在我的测试中使用有效(如果有限)用户凭据.
到现在为止我都在尝试使用@WithMockUser,@WithSecurityContext,SecurityMockMvcConfigurers.springSecurity()和SecurityMockMvcRequestPostProcessors.*都没能进入通过身份验证的电话MockMvc,我找不到在Spring示例项目的任何这样的工作的例子.
任何人都可以帮助我使用某种模拟凭证来测试我的oauth2资源服务器,同时仍然测试所施加的安全限制吗?
**编辑**示例代码可在此处获取:https://github.com/timtebeek/resource-server-testing 对于每个测试类,我理解为什么它不能正常工作,但我正在寻找方法这将允许我轻松测试安全设置.
我现在正在考虑创建一个非常宽松的OAuthServer src/test/java,这可能会有所帮助.有没有人有任何其他建议?
我正在从Spring Boot 1.4.9迁移到Spring Boot 2.0以及Spring Security 5,我正在尝试通过OAuth 2进行身份验证.但是我收到此错误:
java.lang.IllegalArgumentException:没有为id"null"映射PasswordEncoder
从Spring Security 5的文档中,我了解到密码的存储格式已更改.
在我当前的代码中,我创建了我的密码编码器bean:
@Bean
public BCryptPasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
Run Code Online (Sandbox Code Playgroud)
但它给了我以下错误:
编码密码看起来不像BCrypt
所以我按照Spring Security 5文档更新编码器:
@Bean
public PasswordEncoder passwordEncoder() {
return PasswordEncoderFactories.createDelegatingPasswordEncoder();
}
Run Code Online (Sandbox Code Playgroud)
现在如果我可以在数据库中看到密码,那么它就是存储的
{bcrypt}$2a$10$LoV/3z36G86x6Gn101aekuz3q9d7yfBp3jFn7dzNN/AL5630FyUQ
Run Code Online (Sandbox Code Playgroud)
随着第一个错误消失,现在当我尝试进行身份验证时,我收到以下错误:
java.lang.IllegalArgumentException:没有为id"null"映射PasswordEncoder
为了解决这个问题,我尝试了Stackoverflow的以下所有问题:
这是一个类似于我的问题,但没有回答:
注意:我已将加密密码存储在数据库中,因此无需再次编码UserDetailsService.
在Spring security 5文档中,他们建议您可以使用以下方法处理此异常:
DelegatingPasswordEncoder.setDefaultPasswordEncoderForMatches(的PasswordEncoder)
如果这是修复,那么我应该把它放在哪里?我试过把它放在PasswordEncoder像下面这样的bean中,但它没有用:
DelegatingPasswordEncoder def = new DelegatingPasswordEncoder(idForEncode, encoders);
def.setDefaultPasswordEncoderForMatches(passwordEncoder);
Run Code Online (Sandbox Code Playgroud)
MyWebSecurity类
@Configuration
@EnableWebSecurity
public class SecurityConfiguration …Run Code Online (Sandbox Code Playgroud) java spring spring-security spring-boot spring-security-oauth2
我一直在尝试使用Dave Syer的指南实现OAuth2身份验证服务器,并从JHipster获得一些灵感.但我无法弄清楚这一切是如何一起工作的.
当我使用ResourceServerConfigurerAdapter时,看起来使用WebSecurityConfigurerAdapter的安全设置被覆盖.
@Configuration
@EnableResourceServer
public class OAuth2ResourceConfig extends ResourceServerConfigurerAdapter {
private TokenExtractor tokenExtractor = new BearerTokenExtractor();
@Override
public void configure(HttpSecurity http) throws Exception {
http
.addFilterAfter(contextClearer(), AbstractPreAuthenticatedProcessingFilter.class)
.authorizeRequests()
.anyRequest().authenticated().and().httpBasic();
}
private OncePerRequestFilter contextClearer() {
return new OncePerRequestFilter() {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
if (tokenExtractor.extract(request) == null) {
SecurityContextHolder.clearContext();
}
filterChain.doFilter(request, response);
}
};
}
@Component
public class CustomWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
private final AuthenticationManager authenticationManager;
@Autowired
public CustomWebSecurityConfigurerAdapter(AuthenticationManager authenticationManager) { …Run Code Online (Sandbox Code Playgroud) 我正在使用Spring Boot + Spring Security OAuth2应用程序,我认为该应用程序的灵感来自Dave Syer的示例.应用程序配置为OAuth2授权服务器,单个公共客户端使用资源所有者密码凭据流.成功的令牌配置为JWT.
公共Angular客户端向/ oauth/token发送一个POST请求,其中包含一个包含客户端ID和密码的基本auth头(这是让客户端进行身份验证的最简单方法,即使秘密不是私有的).请求正文包含用户名,密码和授予类型"密码".
除了作为身份验证服务器之外,该应用程序还是用户,团队和组织的RESTful资源服务器.
我正在尝试使用Spring Social添加额外的SSO身份验证流程.我已经将Spring Social配置为通过/ auth/[provider]通过外部提供程序进行身份验证; 但是,以下请求不再正确设置SecurityContext.可能是Spring Security OAuth服务器或客户端覆盖了SecurityContext?
如果我可以在Spring Social流程之后正确设置SecurityContext,我有一个新的TokenGranter,允许新的授权类型"social",它将检查SecurityContextHolder以获得预先认证的用户.
我对SecurityContext的特定问题的解决方案感兴趣(我认为这是Spring OAuth +社交集成的问题),或者是与外部提供程序进行身份验证以及从我们自己的auth服务器获取有效JWT的不同方法.
谢谢!
spring-security single-sign-on spring-social spring-boot spring-security-oauth2
Spring Security 5.2.2 已经合并了 Spring Security OAuth 项目,但没有合并 AuthorizationServer 或 ResourceServer。Spring Security 5.2.2 中 AuthorizationServer 的替代品是什么?
本文档包含将 OAuth 2.0 客户端和资源服务器从 Spring Security OAuth 2.x 迁移到 Spring Security 5.2.x 的指南。由于 Spring Security 不提供授权服务器支持,因此迁移 Spring Security OAuth 授权服务器超出了本文档的范围。
我正在尝试使用spring-security-oauth2.0基于Java的配置.我的配置已完成,但是当我在tomcat上部署应用程序并点击/oauth/token访问令牌的url时,会Oauth生成以下错误:
<oauth>
<error_description>Full authentication is required to access this resource</error_description>
<error>unauthorized</error>
</oauth>
Run Code Online (Sandbox Code Playgroud)
我的配置在Git中心,请点击链接
代码很大,所以请参考git.我正在使用chrome postman客户端发送请求.以下是我的要求.
POST /dummy-project-web/oauth/token HTTP/1.1
Host: localhost:8081
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
grant_type=client_credentials&client_id=abc%40gmail.com&client_secret=12345678
Run Code Online (Sandbox Code Playgroud)
错误就像,URL是安全的Oauth,但在配置中,我给予访问此URL的所有权限.这个问题究竟是什么?
我们有基于spring security oauth2的应用程序.一切都很好.但我无法将默认令牌端点从"/ oauth/token"更改为"/ external/oauth/token".
我的spring-servlet.xml
<http pattern="/external/oauth/token" create-session="stateless"
authentication-manager-ref="clientAuthenticationManager"
use-expressions="true" xmlns="http://www.springframework.org/schema/security">
<intercept-url pattern="/external/oauth/token" access="isFullyAuthenticated()" />
<anonymous enabled="false" />
<http-basic entry-point-ref="clientAuthenticationEntryPoint" />
<!-- include this only if you need to authenticate clients via request parameters -->
<custom-filter ref="clientCredentialsTokenEndpointFilter" after="BASIC_AUTH_FILTER" />
<access-denied-handler ref="oauthAccessDeniedHandler"/>
</http>
<oauth:authorization-server client-details-service-ref="clientDetails"
token-services-ref="tokenServices"
user-approval-handler-ref="userApprovalHandler" token-endpoint-url="/external/oauth/token">
<oauth:authorization-code />
<oauth:implicit />
<oauth:refresh-token />
<oauth:client-credentials />
<oauth:password />
</oauth:authorization-server>
Run Code Online (Sandbox Code Playgroud)
但是当我访问此端点时的结果是
{
error: "unauthorized"
error_description: "An Authentication object was not found in the SecurityContext"
}
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?请建议.
我正在尝试使用受Oauth2或Http-Basic身份验证保护的资源来实现API.
当我加载首先将http-basic身份验证应用于资源的WebSecurityConfigurerAdapter时,不接受Oauth2令牌身份验证.反之亦然.
示例配置: 这将http-basic身份验证应用于所有/ user/**资源
@Configuration
@EnableWebMvcSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
private LoginApi loginApi;
@Autowired
public void setLoginApi(LoginApi loginApi) {
this.loginApi = loginApi;
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(new PortalUserAuthenticationProvider(loginApi));
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/users/**").authenticated()
.and()
.httpBasic();
}
@Override
@Bean
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
}
Run Code Online (Sandbox Code Playgroud)
这将oauth令牌保护应用于/ user/**资源
@Configuration
@EnableResourceServer
protected static class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws …Run Code Online (Sandbox Code Playgroud) 我在一些oauth2实现中看到了授权服务器在发出访问令牌时返回的响应的附加信息.我想知道是否有办法使用spring-security-oauth2来实现这一目标.我希望能够在访问令牌响应中包含一些用户权限,以便我的消费应用程序不需要管理用户权限,但仍然可以将用户设置在他们自己的安全上下文中并应用他们自己的任何spring-security检查.
我想另一种选择是使用JWT令牌并与客户端应用程序共享适当的信息,以便他们可以解析令牌中的用户/权限并将其设置在上下文中.这让我更加不舒服,因为我更愿意控制哪些客户端应用程序可以访问此信息(仅限受信任的应用程序),而AFAIK只有授权服务器和资源服务器应该知道如何解析JWT令牌.