有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Spring安全性仅为一条路径添加安全性

我的用例很简单,但找不到示例。我想允许我的所有端点只包括一条需要基本身份验证且具有USER角色的路径。如何使用Spring Security的antmatchers?我尝试了下面的方法,但在所有请求中都得到了401 Unauthorized

httpSecurity
    .authorizeRequests()
        .antMatchers("/api/**").hasRole("USER")
        .antMatchers("/**").permitAll();

共 (0) 个答案