相关疑难解决方法(0)

使用 Spring Security 将数据库和 SAML 身份验证合并到一个应用程序中

我正在尝试使用 spring security(spring-security-starter) 在 spring boot(2.2.4) 应用程序中实现身份验证和授权。

用例:根据用户名,我想将用户重定向到特定的身份验证提供商

  • 如果用户名以“mit.com”结尾,则使用数据库对用户进行身份验证(我正在使用hibernate)-为此,我可以使用spring的UserDetailService
  • 如果用户名以“einfochips.com”结尾,则使用 SAML 2.0 协议对用户进行身份验证 - 使用 Okta、SSOCircle、OneLogin 等身份提供商。

    我不知道我该怎么做。我尝试使用自定义过滤器但无法做到。

我已经阅读了很多文章但无法实现这一目标。

我编写了以下仅使用 SAML 进行身份验证的代码。它运行良好。将用户带到 okta idp 进行登录。

package com.example.demo;

import static org.springframework.security.extensions.saml2.config.SAMLConfigurer.saml;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.saml.userdetails.SAMLUserDetailsService;

@EnableWebSecurity
@Configuration
@EnableGlobalMethodSecurity(securedEnabled = true)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Autowired
    SAMLUserDetailsService userDetailsService;

    @Value("${security.saml2.metadata-url}")
    String metadataUrl;

    @Value("${server.ssl.key-alias}")
    String keyAlias;

    @Value("${server.ssl.key-store-password}")
    String password;

    @Value("${server.port}")
    String port;

    @Value("${server.ssl.key-store}")
    String …
Run Code Online (Sandbox Code Playgroud)

spring-security saml saml-2.0 spring-boot spring-security-saml2

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