小编Joa*_*kim的帖子

Spring Security:未调用自定义UserDetailsS​​ervice(使用Auth0身份验证)

我是Spring框架的新手,所以我提前为我理解中的任何漏洞道歉.

我正在使用Auth0来保护我的API,这非常有效.我的设置和配置与Auth0文档中的建议设置相同:

// SecurityConfig.java
@Configuration
@EnableWebSecurity(debug = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    // auth0 config vars here

    @Override
    protected void configure(HttpSecurity http) {
        JwtWebSecurityConfigurer
                .forRS256(apiAudience, issuer)
                .configure(http)
                .authorizeRequests()
                .antMatchers(HttpMethod.GET, "/api/public").permitAll()
                .antMatchers(HttpMethod.GET, "/api/private").authenticated();
    }
}
Run Code Online (Sandbox Code Playgroud)

采用这种设置,弹簧安全主体被设置为用户ID( sub)从JWT令牌:auth0|5b2b....但是,我不想仅仅使用userId,而是将其设置为匹配的用户(来自我的数据库).我的问题是如何做到这一点.

我试过的

我已经尝试实现从本教程复制的自定义数据库支持的UserDetailsS​​ervice .然而,无论我如何尝试将其添加到我的conf中,它都不会被调用.我尝试过几种不同的方式添加它没有效果:

// SecurityConfig.java (changes only)

    // My custom userDetailsService, overriding the loadUserByUsername
    // method from Spring Framework's UserDetailsService.
    @Autowired
    private MyUserDetailsService userDetailsService;

    protected void configure(HttpSecurity http) {
        http.userDetailsService(userDetailsService);  // Option 1
        http.authenticationProvider(authenticationProvider());  // …
Run Code Online (Sandbox Code Playgroud)

java spring spring-security auth0

8
推荐指数
1
解决办法
2444
查看次数

Pandas:根据另一列增加或重置计数

我有一个表示分数时间序列的 Pandas DataFrame。我想使用该分数根据以下标准计算 CookiePoints 列:

  • 每次得分与上一次得分相比有所提高时,都会给出一个 CookiePoint。
  • 每次分数没有提高,所有的 CookiePoints 都会被带走作为惩罚(CookiePoints 设置为 0)。
  • 3 个 Cookiepoints 可以兑换一个 Cookie。因此,在达到 3 之后,CookiePoints 计数应该是 1(如果分数更高)或 0(如果分数不更高)。

请参阅下面的示例:

Score       CookiePoints
14          0
13          0
14          1
17          2
17          0
19          1
20          2
22          3
23          1
17          0
19          1
20          2
22          3
21          0
Run Code Online (Sandbox Code Playgroud)

请注意,这是一个最小的、可重现的示例。解决方案必须使用 Pandas DataFrame,并且理想情况下仅使用矢量化操作。

python pandas

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

标签 统计

auth0 ×1

java ×1

pandas ×1

python ×1

spring ×1

spring-security ×1