Spring 通常在启动应用程序时急切地加载 Spring 安全配置。我在 Spring Security 中使用 OAuth
我正在维护一个用于存储 SSO 相关值(如 jwk-url、client_id、client_secret)的配置表。该值将由管理员用户通过 CRUD 在同一个 Spring Boot 应用程序中填充。
那么只有 jwk-url 可以在 Spring 安全配置中进行配置(refer below code - jwkSetUri(...))。这在应用程序启动时不可用。
所以我想在将值加载到表中后初始化 spring 安全配置,就像运行时的延迟加载(@Lazy)一样。我知道如何延迟加载常规类/服务。
但是我仍然不确定如何configure(HttpSecurity http)在运行时调用该方法以及如何传递 HttpSecurity 参数。当我在运行时尝试像延迟加载一样调用new ResourceServerConfiguration()时,我没有看到 configure() 方法被调用。(或者)这个类需要在需要时作为 bean 和延迟加载来维护。但仍然不确定如何在代码中调用 configure()。
另一件事是如何在运行时刷新/重新加载 spring 安全配置,如果管理员更改了 JWK url。那么只有 spring 安全配置才能使更改生效。
@Configuration
@EnableWebSecurity
public class ResourceServerConfiguration extends WebSecurityConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws Exception {
http.cors()
.and()
.csrf().disable()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
.authorizeRequests()
.anyRequest().authenticated()
.and()
.oauth2ResourceServer()
.authenticationEntryPoint(oAuth2AuthenticationEntryPoint)
.accessDeniedHandler(oAuth2AccessDeniedHandler)
.jwt() …Run Code Online (Sandbox Code Playgroud) java spring spring-security spring-boot spring-security-oauth2
我需要在 Rest Assured post call 中发送视频文件和 JSON 对象。
结构如下:
{ "sample" : { "name" : "sample-name", "kind" : "upload", "video_file" : 这里的多部分文件 } }
所以我确实喜欢以下内容
代码:
given()
.header("Accept", "application/json")
.header(auth)
.config(rConfig)
.body(body)
.multiPart("sample[video_file]", new File("path"), "video/mp4")
.formParam("sample[name]", "Video Upload")
.formParam("sample[kind]", "upload")
.log().all().
expect()
.statusCode(expectedStatusCode)
.post(url);
Run Code Online (Sandbox Code Playgroud)
在 Rest Assured 中使用 multipart 时,我无法使用应用程序/JSON。我明确地对表单参数中的值进行了硬编码,并以多部分形式发送了媒体文件,现在它工作正常。
如何在单个内部对象中发送所有表单参数数据。
为什么某些 MP4 文件的 mime-type 是 application/octet-stream 而不是 video/mp4?
我已经在终端 (CLI) 中使用文件命令进行了检查
user@anto:~/Videos/VTB$ file --mime-type -b GDPR.mp4
video/mp4
user@anto:~/Videos/VTB$ file --mime-type -b Test-vid1.mp4
application/octet-stream
user@anto:~/Videos/VTB$ file --mime-type -b SampleVideoLarge.mov
video/quicktime
user@anto:~/Videos/VTB$ file --mime-type -b SampleVideo21.mp4
video/mp4
user@anto:~/Videos/VTB$ file --mime-type -b VTBSample-new.mp4
application/octet-stream.
Run Code Online (Sandbox Code Playgroud)
谁能告诉我原因吗?如何处理这种哑剧类型。带有application/octet-stream 的视频文件是正确的 mp4 文件还是错误的文件?
我的前端使用React,后端使用Spring boot。这个想法是通过调用授权服务器来启用 OAuth2 身份验证并生成访问令牌。
假设客户可以使用他们选择的任何授权服务器。因此代码应该使用通用协议/依赖项来支持任何身份验证服务器。
因此,我必须使用 openid connect(处理角色)和通用 npm 包来实现 Oauth2 身份验证,以支持所有 Oauth2 授权服务器(KeyCloak、AWS Cognitio、Okta...)。我不想为每个 OAuth 服务器使用任何特定的包(比如 KeyCloak 有一个单独的包 keycloak-js,我不需要那个)。
注意: 客户一次将使用一个身份验证服务器(比如 Aws cognito)。我刚开始用 KeyCloak 进行测试。但是 React 代码npm 包和配置
Run Code Online (Sandbox Code Playgroud)client id, client secret, client app, grant type
通常应该支持任何授权服务器。在我的应用程序中,仅使用来自 OAuth 服务器的用户管理和访问控制没有社交登录。
如果有人使用相同的 npm 包来支持所有授权服务器,请让我知道或提供一些关于如何执行此操作的想法。感谢你的帮助。
java ×2
api ×1
json ×1
oauth-2.0 ×1
reactjs ×1
rest-assured ×1
spring ×1
spring-boot ×1
video ×1