带有 Jersey、Oauth ResourceServer 和 EnableGlobalMethodSecurity 的 Spring 启动不起作用

问题描述

我正在尝试使用 jersey (jax-rs) 实现一个资源的 Spring Boot 应用程序工作。该应用程序配置了一个 ResourceServer,并且使用 JWT 令牌进行身份验证工作正常。所以我可以使用 HttpSecurity 配置控制访问。

但是在我的资源中,我想使用 GlobalMethodSecurity。所以基本上我只想允许调用者使用 JWT 令牌并使用注释(例如@RolesAllowed))进行角色检查)

不幸的是,我所有的@RolesAllowed 都被忽略了。

我正在做这样的事情:https://github.com/phosphene/spring-boot-session-jersey-test-demo

就是这个例子 - 尽管启用了全局方法,但实际上并没有任何注释。

那么,到目前为止我做了什么?我启用了全局方法安全性。此外,我的 scanBasePackages 确实包含我项目中的所有类(资源等)。

@Configuration
@SpringBootApplication(scanBasePackages = {"org.jaun.clubmanager"})
@EnableWebSecurity
@EnableGlobalMethodSecurity(
    securedEnabled = true,jsr250Enabled = true,prePostEnabled = true)
public class MemberApplication {
}

我有一个 JerseConfig注册我的所有资源:

@Component
@ApplicationPath("/api")
public class JerseyConfig extends ResourceConfig {

    public JerseyConfig() {

        register(...);
    
    }
}

我的 ResourceServer 类看起来像这样(并且有效,这意味着如果没有 Bearer 令牌,访问将被拒绝)。准备就绪的东西总是被允许并用于我的 docker:

@Configuration
@EnableResourceServer
public class OAuth2ResourceServerConfig extends ResourceServerConfigurerAdapter {

    // ...

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http.cors() //
            .and() //
            .authorizeRequests() //
                .antMatchers("/**/readiness").permitAll();
    }
}

现在,当我将 @DenyAll 添加到我的球衣时,允许访问资源。怎么了?

@Path("/subscription-periods")
@DenyAll
public class SubscriptionPeriodResource {
}

我好像遗漏了一些小东西。我阅读了所有其他类似的 google 帖子,但还没有找到解决方案。

如果你想看我的项目。它在这里https://github.com/olijaun/club-manager spring boot 项目位于 club-manager-springboot 文件夹中。例如,我想要保护的资源之一是:https://github.com/olijaun/club-manager/blob/master/club-manager-member/src/main/java/org/jaun/clubmanager/member/application/resource/SubscriptionPeriodResource.java

感谢您的任何提示

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)