Spring security 允许通过SpringWebSecurity有限地访问受保护的资源

Spring security 允许通过SpringWebSecurity有限地访问受保护的资源,spring-security,Spring Security,需要一些建议 我使用SpringWeb安全性,例如 @Override public void configure(HttpSecurity http) throws Exception { http .headers().frameOptions().disable() .and() .authorizeRequests() .antMatchers("/app/profile-info").permitAll()

需要一些建议

我使用SpringWeb安全性,例如

 @Override
public void configure(HttpSecurity http) throws Exception {
    http
        .headers().frameOptions().disable()
    .and()
        .authorizeRequests()
        .antMatchers("/app/profile-info").permitAll()
        .antMatchers("/app/**").authenticated()
        .antMatchers("/management/health").permitAll();

}
要访问API“应用程序”,您必须经过身份验证。但是,我希望允许任何人在一段时间内使用应用程序api,例如,他们每天可以使用api 3次,之后需要注册该服务

我研究了几种解决方案,例如使用ip和存储他们使用API的次数


我想知道spring security中是否有一种机制可以实现上述功能?我找不到任何东西

您描述的问题不是身份验证问题,而是授权问题

我的看法是,应该识别和验证用户(例如,如果可以在不注册的情况下使用服务,则应通过IP/SMS/等进行注册或识别)。然后,将给定配额与用户(DB中的一个简单字段)关联,并在执行API中的任何方法之前进行检查。据我所知,它可以通过SpringSecurity实现,通过自定义属性检查用户是否超出配额

另外,请注意一个问题:用户可以尝试更快地访问资源(通过创建大量同时请求),而不是在数据库中更新配额计数器。在我一直使用的几个spring应用程序中看到了它