小编Ste*_*eve的帖子

使用 Spring Security 和 Rabbitmq 进行 OAuth2 授权

目前,我们有许多 Spring 微服务与 REST 端点和 RabbitMQ 队列进行通信。我们刚刚在所有服务上实现了 OAuth2 安全性,并且 REST 端点得到了适当的保护。

我们编写了一个库,用于创建 RabbitTemplate 和 AmqpAdmin bean,以便不必在每个服务中都完成样板代码。我们在 Spring 中连接到 RabbitMQ 服务器,其中一个特定用户用于常规客户端,另一个用于管理员。我们不想以个人用户身份连接到 RabbitMQ 服务器。

如果我们在rabbit消息头中传递访问令牌,是否可以将RabbitTemplate配置为在处理消息之前检查令牌?这是可以/应该在模板的 AfterReceive/BeforePublish 处理器中全局完成的事情吗?或者是否需要在每个侦听器方法中单独检查?

谢谢

java spring spring-rabbit spring-amqp spring-security-oauth2

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

如何使用 Spring Security 允许访问特定的 React Hash 路由?

我试图限制未经身份验证的用户访问我们的 Reactjs 单页应用程序中的任何路由。我们使用 HashRouter 来处理 UI 端的路由,因此我们的 url 看起来像http://localhost/app/#/Homehttp://localhost/app/#/Login等。我们使用 Spring Security使用 JWT 的 OAuth2。

当向应用程序发出请求时,所有请求都以 /app/ 形式传入,而不是 /app/#/Login、/app/#/Home 等。这对我来说很有意义,因为路由是在客户端上完成渲染的正确的路线,但它会导致尝试保护应用程序的问题。为了允许访问登录路由,我需要允许 Spring Security 中的所有人访问 /app/,这将打开所有内容。

是否可以在 Spring Security 中保护 React Hash 路由,或者我必须在路由器的 UI 端处理这个问题?

登录配置

@EnableWebSecurity(debug = true)
@Configuration
@Order(Ordered.HIGHEST_PRECEDENCE + 1)
public class LoginConfig extends WebSecurityConfigurerAdapter {

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http
                .antMatcher("/app/#/login")
                .httpBasic().disable()
                .formLogin().disable()
                .authorizeRequests()
                .antMatchers(HttpMethod.OPTIONS).permitAll()
                .antMatchers(HttpMethod.GET, "/favicon.ico").permitAll()
                .antMatchers("/app/#/login").permitAll()
                .anyRequest().authenticated()
        ;
    }
}
Run Code Online (Sandbox Code Playgroud)

登录配置授予所有人访问权限

@EnableWebSecurity(debug = true)
@Configuration
@Order(Ordered.HIGHEST_PRECEDENCE + 1)
public …
Run Code Online (Sandbox Code Playgroud)

spring-security jwt reactjs spring-security-oauth2 react-router

4
推荐指数
1
解决办法
1717
查看次数