我正在尝试使用spring security(spring-security-starter)在spring boot(2.2.4)应用中实现身份验证和授权。
用例:基于用户名,我想为特定的身份验证提供程序重定向用户
如果用户名以'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 keyStoreFilePath; //Uisng SAML2.0 @Override protected void configure(final HttpSecurity http) throws Exception { http.csrf().disable() .authorizeRequests() .antMatchers("/").permitAll() .anyRequest().authenticated() .and() .apply(saml()) .serviceProvider() .keyStore() .storeFilePath(this.keyStoreFilePath) .password(this.password) .keyname(this.keyAlias) .keyPassword(this.password) .and() .protocol("https") .hostname(String.format("%s:%s", "localhost", this.port)) .basePath("/") .and().userDetailsService(userDetailsService) .identityProvider() .metadataFilePath(this.metadataUrl); } }
任何人都可以指导我,以便我可以进行配置,以便可以使用任何IDP(如okta,ssocircle,OneLogin等)
我正在尝试使用spring security(spring-security-starter)在spring boot(2.2.4)应用中实现身份验证和授权。用例:基于用户名,我要将用户重定向到...
public class MitComAuthProvider implements AuthenticationProvider {
public Authentication authenticate(Authentication auth) {
// if user matches 'mit.com', auth with database
// look up and auth
// else return null (to try next auth provider)
}
}