小编Dul*_*ter的帖子

Spring Boot Basic Authentication 和 OAuth2 在同一个项目中?

是否可以在我的休息应用程序中对某些端点使用 OAuth2,并为其他一些端点使用基本身份验证。它应该都适用于 spring 安全版本 2.0.1.RELEASE。我希望有人能进一步帮助我。

java intellij-idea spring-security maven spring-boot

7
推荐指数
1
解决办法
3116
查看次数

执行器普罗米修斯的自定义指标

我已经激活了弹簧执行器prometheus endpont /actuator/prometheus.通过添加千分尺和执行器的依赖关系并启用prometheus endpont.我如何获得自定义指标?

java metrics spring-boot spring-boot-actuator prometheus

7
推荐指数
1
解决办法
4636
查看次数

Spring Security REST - 单元测试失败,HttpStatusCode 401 未经授权

我的 Spring Rest 应用程序的单元测试有问题。在我的单元测试中,我总是遇到问题,即我收到 401“未经授权”作为响应状态,但我不知道如何解决这个问题。

我的安全配置是这样的:

@Configuration
@EnableWebSecurity
@Order(1)
public class ApiSecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    private ApiKeyRepository apiKeyRepository;

    @Override
    protected void configure(HttpSecurity httpSecurity) throws Exception {
        ApiKeyAuthFilter filter = new ApiKeyAuthFilter(Globals.HEADER_APIKEY);
        filter.setAuthenticationManager(authentication -> {
            String principal = (String) authentication.getPrincipal();
            Optional<ApiKey> apiKey = apiKeyRepository.findByApiKey(principal);
            if (!apiKey.isPresent()) {
                throw new BadCredentialsException("The API key was not found or not the expected value.");
            }
            authentication.setAuthenticated(true);
            return authentication;
        });
        httpSecurity.
                csrf().disable().
                addFilter(filter).authorizeRequests().anyRequest().authenticated().and().
                regexMatcher("(?i)/api/v1/(?:print|resource)(?:/|$).*").
                sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
    }
}
Run Code Online (Sandbox Code Playgroud)

我的单元测试看起来像:

@RunWith(SpringRunner.class)
@WebMvcTest(ResourceController.class)
public class ResourceControllerTestGetByLogicalFileNameOrDate {

    @Autowired …
Run Code Online (Sandbox Code Playgroud)

java spring-security mockito spring-boot

2
推荐指数
1
解决办法
5364
查看次数