我们有一个基于Spring Boot的微服务架构,在该架构中,我们有多个相互对话的微服务以及一个连接到不同微服务的Javascript UI。
由于这是一个内部应用程序,并且我们需要将它们连接到SAML2端点以提供SSO,因此将所有这些连接在一起让我有些头疼。理想情况下,微服务在其自身(JWT)和UI之间使用oAuth2,但是用户身份验证是通过SAML2完成的
我要实现以下目标:
所以我尝试了很多不同的东西。我能说的是:
我想我最麻烦的是oauth2资源服务器和SAML服务的连接点。
关于SAML,我有以下可以正常工作的方法:
@Configuration
@EnableWebSecurity
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
@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;
@Autowired
SAMLUserDetailsService samlUserDetailsService;
@Override
protected void configure(HttpSecurity http) throws Exception {
http.antMatcher("/**")
.authorizeRequests()
.antMatchers("/oauth/**").authenticated()
.and().exceptionHandling()
.and()
.authorizeRequests()
.antMatchers("/saml*").permitAll()
.anyRequest().authenticated()
.and()
.apply(saml()).userDetailsService(samlUserDetailsService)
.serviceProvider()
.keyStore()
.storeFilePath("saml/keystore.jks")
.password(this.password)
.keyname(this.keyAlias)
.keyPassword(this.password)
.and()
.protocol("https")
.hostname(String.format("%s:%s", "localhost", this.port))
.basePath("/")
.and() …Run Code Online (Sandbox Code Playgroud) spring spring-security spring-security-ldap spring-boot spring-security-oauth2
使用 JNDI 向 LDAP 进行身份验证
LDAP注入可以使用这些参数来完成吗
Context.SECURITY_PRINCIPAL="用户1"
Context.SECURITY_CREDENTIALS="密码"
DefaultLdapAuthoritiesPopulator 设置搜索范围为“ONE_LEVEL”,但我需要搜索“SUBSCOPE”以获取用户所属组的列表。
我一直遵循“配置”风格的 Spring 设置(代码,而不是 XML)。虽然有大量关于如何在 XML 中配置自定义 LdapAuthoritiesPopulator 的示例,但我对如何在代码中执行此操作感到困惑。
这是我到目前为止所拥有的:
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.ldapAuthentication()
.contextSource().url("ldap://ldap.company.org/")
.and()
.userSearchBase("o=company.org,c=us")
.userSearchFilter("(uid={0})")
.groupSearchBase("o=company.org,c=us")
.groupSearchFilter("(&(objectClass=groupOfUniqueNames)(uniqueMember={0}))");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.formLogin().and().authorizeRequests()
.antMatchers("/api/**").authenticated()
.anyRequest().permitAll();
}
}
Run Code Online (Sandbox Code Playgroud)
缺少的是我需要能够在 DefaultLdapAuthoritiesPopulator 上设置搜索范围。该类本身公开了“setSearchSubtree”方法,但 LdapAuthenticationProviderConfigurer 不提供配置它的方法。
有什么建议么?
我正在使用 Spring Boot 构建休息 Web 服务。身份验证是使用 Spring Security 和 OAuth2 实现的。用户通过 LDAP 服务器进行身份验证。这是我的 websecurityconfig
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private RestAuthenticationSuccessHandler authenticationSuccessHandler;
@Autowired
private RestAuthenticationEntryPoint restAuthenticationEntryPoint;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.httpBasic()
.and()
.csrf().disable()
.sessionManagement().sessionCreationPolicy(
SessionCreationPolicy.STATELESS)
.and()
.exceptionHandling()
.authenticationEntryPoint(restAuthenticationEntryPoint)
.and()
.authorizeRequests()
.antMatchers("/").permitAll()
.antMatchers("/login").permitAll()
.antMatchers("/logout").permitAll()
.antMatchers("/ristore/**").authenticated()
.anyRequest().authenticated()
.and()
.formLogin()
.successHandler(authenticationSuccessHandler)
.failureHandler(new SimpleUrlAuthenticationFailureHandler());
}
@Override
@Bean
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
@Bean
public RestAuthenticationSuccessHandler mySuccessHandler(){
return new RestAuthenticationSuccessHandler();
}
@Bean …Run Code Online (Sandbox Code Playgroud) rest access-token oauth-2.0 spring-security-ldap spring-boot
在 Spring security 中,我想对以 api/** 开头的 URL 使用基本身份验证,对于以 /ldap/ 开头的 URL 使用 LDAP Rest 身份验证。我的当前代码还允许使用基本身份验证的ldap/。
即使我将它们用作单独的 AuthenticationProviders(如 LdapAuthProvider 和 BasicAuthProvider),问题仍然存在,我如何使用它来指向特定的 url
@Configuration
@EnableWebSecurity
public class WebSecurityConfig {
@Configuration
@Order(1)
public class BasicAuthenticationProvider extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/swagger-ui*", "/info", "/health").permitAll()
.and().authorizeRequests().antMatchers("/order/**").fullyAuthenticated()
.and().httpBasic().and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and().csrf().disable()
.anonymous().disable();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(inMemoryUserDetailsManager());
}
}
@Configuration
@Order(2)
public class LdapAuthenticationProvider extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws …Run Code Online (Sandbox Code Playgroud) spring spring-mvc spring-security spring-security-ldap spring-boot
我正在尝试将我的 webSecurity 配置为使用 ldap 和基本身份验证 (jdbc) 以及新的基于组件的安全配置(无 WebSecurityConfigurerAdapter),但我无法让它同时使用两者。
所需的结果是 spring 第一次尝试 ldap,如果找不到(或者暂时失败就足够了),则尝试使用基本身份验证登录。
该项目是从较旧的 Spring-Boot 版本迁移而来的,使用 WebSecurityConfigurerAdapter 可以使用以下代码:
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter
{
@Override
protected void configure(HttpSecurity http) throws Exception
{
http.authorizeRequests().antMatchers("/services/**").permitAll().anyRequest().authenticated();
http.httpBasic();
http.formLogin().permitAll().loginPage("/login").defaultSuccessUrl("/customer/overview", true);
http.logout().permitAll();
http.csrf().disable();
http.headers().frameOptions().disable();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception
{
auth.userDetailsService(userDetails);
//@formatter:off
auth.ldapAuthentication()
.userSearchFilter("(uid={0})")
.userSearchBase("ou=people")
.groupSearchFilter("(uniqueMember={0})")
.groupSearchBase("ou=groups")
.groupRoleAttribute("cn")
.rolePrefix("ROLE_")
.userDetailsContextMapper(customLdapUserDetailsContextMapper())
.contextSource()
.url(ldapUrl);
//@formatter:on
}
@Bean
CustomLdapUserDetailsContextMapper customLdapUserDetailsContextMapper()
{
CustomLdapUserDetailsContextMapper mapper = new CustomLdapUserDetailsContextMapper();
mapper.setCustomUserDetailsService(userDetailsService());
return mapper;
}
//Implementation of custom contextMapper …Run Code Online (Sandbox Code Playgroud) 我有一个工作概念验证应用程序,它可以在测试服务器上通过LDAP成功验证Active Directory,但生产应用程序必须通过TLS进行验证 - 域控制器关闭任何不通过TLS启动的连接.
我已经在Eclipse中安装了LDAP浏览器,我确实可以在其中使用TLS绑定,但我不能在我的生活中弄清楚如何让我的应用程序使用TLS.
ldap.xml:
<bean id="ldapAuthenticationProvider"
class="my.project.package.OverrideActiveDirectoryLdapAuthenticationProvider">
<!-- this works to authenticate by binding as the user in question -->
<constructor-arg value="test.server"/>
<constructor-arg value="ldap://192.168.0.2:389"/>
<!-- this doesn't work, because the server requires a TLS connection -->
<!-- <constructor-arg value="production.server"/> -->
<!-- <constructor-arg value="ldaps://192.168.0.3:389"/> -->
<property name="convertSubErrorCodesToExceptions" value="true"/>
</bean>
Run Code Online (Sandbox Code Playgroud)
OverrideActiveDirectoryLdapAuthenticationProvider是一个覆盖类,它扩展了Spring ActiveDirectoryLdapAuthenticationProvider类的副本,由于某种原因被指定final.我覆盖的原因与自定义用户对象上填充权限/权限的方式有关(我们将使用相关组的组成员身份来构建用户的权限,或者我们将从AD用户对象的字段中读取).在其中,我只是重写loadUserAuthorities()方法,但我怀疑我可能还需要覆盖bindAsUser()方法或可能的doAuthentication()方法.
XML和一个覆盖类是我的应用程序管理身份验证的唯一两个地方,而不是让Spring完成工作.我已经阅读了几个要启用TLS的地方我需要扩展DefaultTlsDirContextAuthenticationStrategy类,但是我在哪里连接它?是否有命名空间解决方案?我是否需要完全做其他事情(即放弃使用Spring ActiveDirectoryLdapAuthenticationProvider而改为使用LdapAuthenticationProvider)?
任何帮助表示赞赏.
java ldap active-directory spring-security spring-security-ldap
我有Grails Spring Security插件连接到一个Active Directory服务器没有问题.但是,我需要连接到多个服务器.我们在一台AD服务器上有一些用户,在另一台服务器上有其他用户,因此我们需要尝试在两个位置查找用户.
例如,在Java中,我的工作如下:
<authentication-manager>
<authentication-provider ref="provider1"/>
<authentication-provider ref="provider2"/>
...
</authentication-manager>
<ldap-server id="provider1"
url="ldap://LDAPSERVER1.mycompany.intranet"
manager-dn="OU=std_users,OU=users,DC=mycompany,DC=intranet"
manager-password="blah"/>
<ldap-server id="provider2"
url="ldap://DIFFERENT_LDAPSERVER.mycompany.intranet"
manager-dn="OU=std_users,OU=external_users,DC=mycompany,DC=intranet"
manager-password="blah"/>
Run Code Online (Sandbox Code Playgroud)
在Grails中,我可以配置一个AD服务器,但无法确定如何配置多个:
// LDAP config
grails.plugin.springsecurity.ldap.context.managerDn = 'CN=blah,OU=std_users,OU=users,DC=mycompany,DC=intranet'
grails.plugin.springsecurity.ldap.context.managerPassword = 'the_password'
grails.plugin.springsecurity.ldap.context.server = 'ldap://theserver.mycompany.intranet'
grails.plugin.springsecurity.ldap.authorities.ignorePartialResultException = true // typically needed for Active Directory
grails.plugin.springsecurity.ldap.search.base = 'OU=std_users,OU=users,DC=mycompany,DC=intranet'
grails.plugin.springsecurity.ldap.search.filter="sAMAccountName={0}" // for Active Directory you need this
grails.plugin.springsecurity.ldap.search.searchSubtree = true
grails.plugin.springsecurity.ldap.auth.hideUserNotFoundExceptions = false
Run Code Online (Sandbox Code Playgroud)
我知道你可以创建一个以空格分隔的服务器列表,但是这对我来说不起作用,因为它只有一个连接后才会尝试其中一个服务器,而我需要它来尝试在两者中寻找用户.
我想我可能需要陷入resources.groovy文件,但不知道从哪里开始 - 有没有人配置多个AD位置?
我唯一的另一个想法是创建一个虚拟目录,将一个目录中的所有用户聚集在一起.有谁能建议这样做的好方法?我一直在看http://myvd.sourceforge.net/usecases.html
任何帮助,将不胜感激.一直在谷歌搜索,我没有更接近解决方案.
grails active-directory spring-security spring-security-ldap
我在spring-boot应用程序中使用LDAP身份验证(基于注释的配置).我想自定义UserDetails对象.默认的UserDetails实现是LdapUserDetailsImpl.我想扩展这个类,并添加一些额外的iterfaces并绑定到spring-security.我的配置类:
@Configuration
protected static class AuthenticationConfiguration extends GlobalAuthenticationConfigurerAdapter {
@Autowired
private UserService userService;
@Autowired
private Environment env;
@Override
public void init(AuthenticationManagerBuilder auth) throws Exception {
AuthMethod authMethod = AuthMethod.valueOf(env.getRequiredProperty("auth_method"));
switch (authMethod) {
case LDAP:
auth.ldapAuthentication()
.userDnPatterns(env.getRequiredProperty("ldap.user_dn_patterns"))
.groupSearchBase(env.getRequiredProperty("ldap.group_search_base"))
.contextSource()
.url(env.getRequiredProperty("ldap.url"));
break;
default:
auth.userDetailsService(userService);
break;
}
}
@Bean
public LdapContextSource contextSource () {
LdapContextSource contextSource= new LdapContextSource();
contextSource.setUrl(env.getRequiredProperty("ldap.url"));
contextSource.setUserDn(env.getRequiredProperty("ldap.user"));
contextSource.setPassword(env.getRequiredProperty("ldap.password"));
contextSource.afterPropertiesSet();
return contextSource;
}
}
Run Code Online (Sandbox Code Playgroud)
UserService是自定义身份验证方法(它是数据库/ jpa身份验证).UserDetails访问器(当auth方法是LDAP时,它返回LdapUserDetailsImpl对象):
@Component("activeUserAccessor")
public class ActiveUserAccessorImpl implements ActiveUserAccessor
{
public UserDetails getActiveUser()
{
return (UserDetails) …Run Code Online (Sandbox Code Playgroud) spring ldap spring-security spring-security-ldap spring-boot
应用程序学问题很长,但总之我想知道如何org.springframework.ldap.core.LdapTemplate#ignorePartialResultException使用Spring Java Config 设置标志。
长期存在的问题是...
我想使用我们公司的Active Directory进行身份验证(这意味着用户/密码检查),然后再进行授权(因此他们有权使用哪些角色)。
我采用了春季ldap指南,并进行了更改以连接到我们公司的Active Directory,而不是使用指南的LDIF文件。通过调试,我知道程序连接到Active Directory并正确验证了用户身份,但是在检索权限时,出现以下异常:
Unprocessed Continuation Reference(s); nested exception is javax.naming.PartialResultException
Run Code Online (Sandbox Code Playgroud)
从谷歌搜索中,我看到这是一个常见的LDAP / ActiveDirectory问题,我需要设置标志以忽略引用。我遵循了这个SO问题中的示例。但是,我仍然遇到异常,通过调试,我可以发现在为用户搜索角色时,以下方法中发生了错误。
org.springframework.ldap.core.LdapTemplate#search(org.springframework.ldap.core.SearchExecutor, org.springframework.ldap.core.NameClassPairCallbackHandler, org.springframework.ldap.core.DirContextProcessor)
Run Code Online (Sandbox Code Playgroud)
作为参考,我的WebSecurityConfig文件:
Unprocessed Continuation Reference(s); nested exception is javax.naming.PartialResultException
Run Code Online (Sandbox Code Playgroud) active-directory spring-ldap spring-security-ldap spring-java-config
我们正在创建一个grails aplication,我们希望用户使用他们的Active Directory凭据登录.此外,我们希望为此应用程序的业务所有者提供控制谁可以访问某些链接(操作)的能力.因此我们在grails应用程序中使用以下插件:
因为我们希望授权业务用户在必要时动态创建具有特定权限(操作)的自定义角色,我们认为最好的Spring Security配置是基于Requestmap数据库的方法
到目前为止,我们已完成如下:
问题/问题
spring-security-core插件创建了以下表:
这些是支持角色创建的表,即角色的URL分配.但是,Person_Authoritity表作为约定名称意味着它是PERSON和AUTHORITY(ROLE)之间的多对多关系,因为一个人可能有多个角色.我的问题是我没有Person,因为该人已存在于Active Directory(外部源)中,并且未在应用程序中创建.
有没有办法让经过身份验证的用户成为PERSON?Spring安全解决方案需要Person行或对象,但您更喜欢引用它.
我也在这里发布了这个问题:
谢谢,
grails spring-security spring-ldap grails-plugin spring-security-ldap
我们正在尝试使用 LDAP 进行身份验证构建一个 Spring 应用程序,但是一旦我们覆盖 WebSecurityConfigurerAdapter 中的配置方法,我们就会收到 NoClassDefFoundError。
我们的应用程序是用 java11 编写的,我们使用基于代码/基于注释的配置。我们在使用 Spring 嵌入式 LDAP 服务器时遇到了一些问题,因此我们切换到 OpenLDAP。我们使用 JXplorer 验证了服务器。
这就是我们当前的方法:
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.ldap.core.support.LdapContextSource;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
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;
@Configuration
@EnableWebSecurity
public class LdapTestConfig extends WebSecurityConfigurerAdapter
{
@Autowired
Environment env;
public LdapContextSource contextSource()
{
LdapContextSource contextSource = new LdapContextSource();
contextSource.setUrl(env.getRequiredProperty("ldap.url"));
contextSource.setBase(env.getRequiredProperty("ldap.baseDn"));
contextSource.setUserDn(env.getRequiredProperty("ldap.bindDn"));
contextSource.setPassword(env.getRequiredProperty("ldap.password"));
contextSource.afterPropertiesSet();
return contextSource;
}
// This is the method, causing my issue
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception
{ …Run Code Online (Sandbox Code Playgroud) spring-boot ×6
spring ×5
ldap ×3
grails ×2
java ×2
spring-ldap ×2
access-token ×1
java-11 ×1
oauth-2.0 ×1
rest ×1
spring-mvc ×1