小编Ele*_*ana的帖子

Spring Security 5 populating authorities based on JWT claims

As I see Spring Security OAuth2.x project was moved to Spring Security 5.2.x. I try to implement authorization and resource server in new way. Everythin is working correctly except one thing - @PreAuthorize annotation. When I try to use this with standard @PreAuthorize("hasRole('ROLE_USER')") I always get forbidden. What I see is that the Principal object which is type of org.springframework.security.oauth2.jwt.Jwt is not able to resolve authorities and I have no idea why.

org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken@44915f5f: Principal: org.springframework.security.oauth2.jwt.Jwt@2cfdbd3; Credentials: [PROTECTED]; Authenticated: true; Details: …
Run Code Online (Sandbox Code Playgroud)

java spring oauth spring-security spring-security-oauth2

7
推荐指数
2
解决办法
6204
查看次数

找不到预期的 CSRF 令牌

我正在尝试使用以下配置禁用最新 Spring Cloud 中的 Spring 安全性:

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled = true)
@Order(SecurityProperties.DEFAULT_FILTER_ORDER)
public class WebSecurityConfigSec extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable().cors().disable()
                .authorizeRequests().anyRequest().permitAll();
    }

    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring()
                .antMatchers("/**");
    }
}
Run Code Online (Sandbox Code Playgroud)

应用程序.yml

spring:
    main:
        allow-bean-definition-overriding: true
security:
    ignored=/**:
    enable-csrf: false
Run Code Online (Sandbox Code Playgroud)

我还尝试添加:

@EnableWebSecurity
@Configuration
public class WebSecurityConfig extends
   WebSecurityConfigurerAdapter {

  @Override
  protected void configure(HttpSecurity http) throws Exception {
    http
      .csrf().disable();
  }
}
Run Code Online (Sandbox Code Playgroud)

但这不起作用。

我收到错误:An expected CSRF token cannot be found …

spring spring-security spring-boot spring-oauth2

5
推荐指数
1
解决办法
1万
查看次数