Sun*_*aha 5 spring spring-security oauth-2.0 spring-boot
如何在 \xe2\x80\x9cOAUTH2\xe2\x80\x9d 启用的 spring-boot 应用程序中禁用身份验证?\n这通常是测试或构建阶段所必需的。
\n当我们想要进行测试/构建并且我们没有\xe2\x80\x99t 即时可用的 OAuth2 令牌时,这是一个有效的场景。\n以下是要遵循的步骤:
\n\n创建一个没有 OAuth2 配置的 YAML 文件(即application-{profile_name}.yml)并在其中添加以下属性:
Security.ignored = /** \nsecurity.basic.enable=false\nRun Code Online (Sandbox Code Playgroud)添加一个绕过 HTTP/S 请求授权的类。注意:此类应具有相同的配置文件名称(即{profile_name})。
@Profile({"profile_name"})\npublic class DisableOAuth2Config {\n\n @Bean\n public ResourceServerConfigurer resourceServerConfigurer() {\n return new ResourceServerConfigurerAdapter() {\n @Override\n public void configure(HttpSecurity http) throws Exception {\n http\n .authorizeRequests()\n .antMatchers("/**").permitAll();\n }\n };\n }\n}\nRun Code Online (Sandbox Code Playgroud)Profile在课堂上提供SecurityConfiguration我们仍然想要安全的地方。@Profile({"local","dev","aws"}),这将区分启用/禁用安全性的配置文件。
注:请检查注释@EnableResourceServe、@EnableWebSecurity和@EnableGlobalMethodSecurity(prePostEnabled = true)。它们应该只在SecurityConfiguration课堂上可用。不是多个地方,也不是在SpringBoot课堂上。
| 归档时间: |
|
| 查看次数: |
7328 次 |
| 最近记录: |