目前,我正在使用以下配置来验证添加 jwt 的 key ,该 key 在每个请求上解密授权 token :
security:
oauth2:
resource:
jwt:
keyValue: test
下面是 http 安全配置,使用它只允许特定端点
@Configuration
@EnableResourceServer
@ConditionalOnProperty(name = "securityEnabled")
public class ResourceServiceConfiguration extends ResourceServerConfigurerAdapter {
@Override
public void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity
// we don't need CSRF because our token is invulnerable
.csrf().disable()
// don't create session
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
.authorizeRequests()
// allow anonymous requests to root
.antMatchers( HttpMethod.GET, "/" ).permitAll()
.anyRequest().hasAuthority("admin");
}
}
我想做的是,不是从 application.yml 获取这个键值,而是在服务启动期间以某种方式添加这个键值,从文件系统中获取它并让资源服务器配置处理其余的事情为我。无休止的谷歌搜索让我一无所获,尽管我最好的猜测是 Autowiring 身份验证管理器并覆盖该方法,但我认为这不适用于 Spring 的 http 安全性。
任何帮助都会很棒,谢谢。
最佳答案
在我看来,您想要执行 Externalized Configuration 中详细说明的操作.
例如,有一个类似 yourfile.properties
的文件,其中包含
security.oauth2.resource.jwt.key-value=yourkey
然后使用 --spring.config.location=yourfile.properties
参数启动您的应用。
关于spring-boot - 文件中的 Spring Boot http 安全 jwt key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48407532/