我是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,而是将其设置为匹配的用户(来自我的数据库).我的问题是如何做到这一点.
我已经尝试实现从本教程复制的自定义数据库支持的UserDetailsService .然而,无论我如何尝试将其添加到我的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) 我有一个表示分数时间序列的 Pandas DataFrame。我想使用该分数根据以下标准计算 CookiePoints 列:
请参阅下面的示例:
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,并且理想情况下仅使用矢量化操作。