标签: spring-ldap

具有错误的Active Directory Ldap凭据的会话/ Redis序列化错误的Spring启动

嗨,我是Spring和Java的新手,我正在尝试实现本教程中描述的Gateway认证服务器https://spring.io/guides/tutorials/spring-security-and-angular-js/

我得到了一切工作,然后尝试对我们公司的Ldap服务器实施身份验证.如果我使用有效的用户名和密码,它可以工作.当我使用无效凭据时,应用程序错误.

我没有工作,所以我没有确切的错误,但它返回一个ldap错误(com.sun.jndi.ldap.LdapCtx),Redis正在尝试序列化它.

我的配置中是否缺少某些内容.根据我的阅读,我认为我应该寻找一种方法来包装/扩展类并实现Serializable,但我不确定使用Spring Boot执行此操作的方法最少.

任何帮助是极大的赞赏.

谢谢,

Mike Kowalski

PS我一直在动态语言和框架工作到现在为止(Javascript/Node,Php/Laravel)

以下是我认为安全配置的相关部分:

@Configuration
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

  @Override
  protected void configure(HttpSecurity http) throws Exception {
    http
      .formLogin()
      .defaultSuccessUrl("/")
      .loginPage("/login")
      .permitAll()
      .and()
      .logout()
      .logoutSuccessUrl("/logout")
      .permitAll();


    http
      .authorizeRequests()
        .antMatchers("/login").permitAll()
        .anyRequest().authenticated()
    .and()
      .csrf().csrfTokenRepository(csrfTokenRepository())
    .and()
      .addFilterAfter(csrfHeaderFilter(), CsrfFilter.class);
  }

  @Override
   protected void configure(AuthenticationManagerBuilder authManagerBuilder)          throws Exception {
    authManagerBuilder
      .authenticationProvider(activeDirectoryLdapAuthenticationProvider())
        .userDetailsService(userDetailsService());
   }

   @Bean
   public AuthenticationManager authenticationManager() {
      return new ProviderManager(
        Arrays.asList(activeDirectoryLdapAuthenticationProvider())
      );
   }

   @Bean
   public AuthenticationProvider activeDirectoryLdapAuthenticationProvider() {
  ActiveDirectoryLdapAuthenticationProvider provider = new     ActiveDirectoryLdapAuthenticationProvider( …
Run Code Online (Sandbox Code Playgroud)

java ldap active-directory spring-ldap redis

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

在 Active Directory LDAP 中添加具有密码的用户

这是我第一次使用 StackOverflow,希望能在这里得到一些回复。我正在使用 Windows Active Directory 2008 使用 spring-ldap api 来存储来自 java 的新用户

我的问题是我无法添加带有密码的用户。我在某处读到在 AD 中设置密码,我应该使用该unicodePwd属性。来源: http ://geekswithblogs.net/lance/archive/2005/08/19/LdapAuthenticationASP.aspx

public void insertContact(ContactDTO contactDTO) {
    try{

     Attributes personAttributes = new BasicAttributes();
     BasicAttribute personBasicAttribute = new BasicAttribute("objectclass");
     personBasicAttribute.add("person");
     personBasicAttribute.add("user");
     personAttributes.put(personBasicAttribute);

      personAttributes.put("givenName", contactDTO.getCommonName());
      personAttributes.put("cn", contactDTO.getCommonName());
      personAttributes.put("sn", contactDTO.getLastName());
      personAttributes.put("description", contactDTO.getDescription());

      personAttributes.put("unicodePwd",
          this.createUnicodePassword(contactDTO.getPassword()) );
      personAttributes.put("userPrincipalName", contactDTO.getUserLoginName());
      personAttributes.put("sAMAccountName", contactDTO.getsAMAccountName());
      personAttributes.put("displayname", contactDTO.getDisplayname());
      //  personAttributes.put( "pwdLastSet", "0" );
      //  personAttributes.put( "LockOutTime", "0" );

      personAttributes.put("userAccountControl", "544");

      BasicAttribute roomAttribute = new BasicAttribute("roomNumber");
      for(String r : contactDTO.getRoomNumber())
      {
        roomAttribute.add(r);
      }

      personAttributes.put(roomAttribute); …
Run Code Online (Sandbox Code Playgroud)

java ldap active-directory spring-ldap

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

Spring LDAP异常 - 未注册UserDetailsS​​ervice

我正在尝试为JSF网站使用Spring Security 3.0.2 LDAP身份验证.当我在applicationContext-security.xml中使用以下配置时,我得到此异常 - org.springframework.beans.factory.BeanCreationException:创建名为'org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices#0'的bean时出错: bean的初始化失败; 嵌套异常是org.springframework.context.ApplicationContextException:没有注册UserDetailsS​​ervice.

<authentication-manager>
    <ldap-authentication-provider
        user-search-filter="(uid={0})" user-search-base="ou=users,ou=system"
        group-search-base="ou=groups,ou=system">
    </ldap-authentication-provider>
</authentication-manager>

<ldap-server id="ldapServer" url="ldap://localhost:10389"
    root="" />
Run Code Online (Sandbox Code Playgroud)

我刚刚进行了实验,发现添加以下内容可以使事情发挥作用.

<ldap-user-service server-ref="ldapServer" user-search-filter="(uid={0})" />
Run Code Online (Sandbox Code Playgroud)

但我在Spring LDAP文档中找不到对此的引用.如果我不添加此内容,为什么会出现上述异常?我对这种解决方法不满意,因为我需要在两个地方编写user-search-filter属性.

PS:我已经检查过Spring Security LDAP - 没有注册UserDetailsS​​ervice.异常是不同的,我猜Spring Security版本也不同.

spring-security spring-ldap

5
推荐指数
1
解决办法
3593
查看次数

根据用户名和远程IP地址使用不同的AuthenticationProvider

在基于 Spring Security 3.2 的应用程序中,我需要根据用户名和远程 IP 地址中的特定模式,针对两个不同的提供者对用户进行身份验证。

如果它们符合某些规则,则应根据 进行身份验证,否则应使用使用现有自定义实现的ActiveDirectoryLdapAuthenticationProvider标准进行身份验证。AuthenticationProviderUserDetailsService

我需要延长什么?AuthenticationManager或者AuthenticationProvider?任何示例代码将不胜感激:-)

注意:我已经成功尝试<authentication-provider />在 中添加两个节点<authentication-manager />,并且效果很好。但令我困扰的是,我的 Ldap 服务器每次身份验证尝试都会受到攻击(即使是那些不适合它的尝试)

spring spring-security spring-ldap

5
推荐指数
1
解决办法
2129
查看次数

如何查看spring ldapTemplate生成的查询

我正在使用 spring ldapTemplate 1.3.2 版从活动目录查询结果。我们希望能够看到 ldapTemplate.search() 和类似方法生成的查询,以便调试我们产品到客户的部署。

到目前为止,我们已经尝试查看文档以查看是否有“toString”方法可以提供此功能,但没有找到任何内容。我们还改变了log4j.properties文件调试级别:log4j.logger.org.springframework.security=DEBUG。这似乎给了我们更详细的输出,但实际上并没有显示完整的 ldap 查询字符串。

任何帮助,将不胜感激。

java spring ldap spring-ldap

5
推荐指数
1
解决办法
2548
查看次数

Spring LDAP 与 UnboundId LDAP

我们正在构建一个新的库,它需要对我们的主要身份管理 LDAP 系统进行读/写。

我们正在考虑使用 Spring LDAP ( http://projects.spring.io/spring-ldap/ )、UnboundId LDAP ( https://www.ldap.com/unboundid-ldap-sdk-for-java ) 或http ://www.ldaptive.org(可以使用 UnboundId LDAP)。

由于我们在使用 Spring LDAP 的项目中使用 Spring 库/框架可能更容易。

任何人都对较新版本的 Spring LDAP 或 UnboundId LDAP 有很好的经验?两者之间有什么优缺点吗?

看起来 Spring LDAP 开发已经停滞(有一段时间没有提交,版本有限)。有人知道 Spring LDAP 开发是否仍然活跃吗?

谢谢您的帮助。

布鲁斯

ldap spring-ldap unboundid-ldap-sdk

5
推荐指数
1
解决办法
2124
查看次数

Spring annotation @ Entry.base不支持SpEL

我使用Spring Data LDAP和Spring Boot为嵌入式UnboundID服务器提供开箱即用的支持.但是,当我使用Spring Data LDAP的@Entry注释时,我需要base根据我是使用嵌入式UnboundID LDAP服务器还是远程Active Directory服务器在注释中指定不同的注释.

我试图通过指定以下内容来使用SpEL和基于配置文件的属性执行此操作:

@Entry(base = "${ldap.person.base}", ...)
Run Code Online (Sandbox Code Playgroud)

然后,我有一个application.propretiesldap.person.base=OU=AD Person Baseapplication-embedded.propertiesldap.person.base=OU=Embedded Person Base.

但是,@Entry注释似乎不支持SpEL评估:

javax.naming.InvalidNameException:名称无效:$ {ldap.person.base}

Spring LDAP中有一个未解决的问题,即添加对此的支持,但是在Spring LDAP支持之前,是否有任何解决方法或其他方式可以实现此目的?

java spring spring-ldap spring-el spring-boot

5
推荐指数
1
解决办法
698
查看次数

Spring Security LDAP 登录错误凭证

我正在尝试使用 Spring Security 来连接 LDAP,但它总是显示错误的凭据问题。
我想我的代码可能有问题:

\n\n
@Configuration\n@EnableWebSecurity\n@EnableGlobalMethodSecurity(prePostEnabled = true)\npublic class SecurityConfig extends WebSecurityConfigurerAdapter {\n    @Override\n    public void configure(WebSecurity web) throws Exception {\n        web.debug(true);\n    }\n    @Autowired\n    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {\n\n        auth.ldapAuthentication().userDnPatterns("sAMAccountName={0},OU=SupportUsers,OU=Users,OU=company,DC=ad,DC=company,DC=com,DC=pl")\n            .contextSource(contextSource()).passwordCompare().passwordAttribute("userPassword");\n    }\n    protected void configure(HttpSecurity http) throws Exception {\n        http\n            .authorizeRequests()\n                .anyRequest().fullyAuthenticated()\n                .and()\n            .formLogin();\n        http.csrf().disable(); //Vaadin already have built in csrf\n    }\n    @Bean\n    public LdapContextSource contextSource () {\n        LdapContextSource contextSource= new LdapContextSource();\n        contextSource.setUrl("ldap://192.168.2.2:389");\n        contextSource.setBase("dc=ad,dc=company,dc=com,dc=pl");\n        contextSource.setUserDn("CN=lister,OU=SupportUsers,OU=Users,OU=company,DC=ad,DC=company,DC=com,DC=pl");\n        contextSource.setPassword("examplePassword");\n        contextSource.setAnonymousReadOnly(false);\n        contextSource.setPooled(true);\n        contextSource.afterPropertiesSet();\n        return contextSource;\n    }\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

我在代码中找不到错误,也许我做错了事情。这是我的 pom.xml:

\n\n …

java spring spring-security spring-ldap maven

5
推荐指数
1
解决办法
5443
查看次数

Spring LDAP 身份验证 Salted SHA 类型中的错误凭据密码

我有一个使用 REST 服务进行 LDAP 身份验证的项目。我的 LDAP 配置具有 Salted SHA (SSHA) 密码哈希方法。在 Spring 的支持 SHA 方法的 LDAP 身份验证最佳实践指南中,当我使用该方法时,我得到了错误的凭据,而凭据却正常。

我的配置类参考:

@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    public void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth
            .ldapAuthentication()
                .userSearchFilter("uid={0}")
                .contextSource(contextSource())
                .passwordCompare()
                    .passwordEncoder(new LdapShaPasswordEncoder())
                    .passwordAttribute("userPassword");
    }

    @Bean
    public DefaultSpringSecurityContextSource contextSource() {
        return new DefaultSpringSecurityContextSource(Arrays.asList("ldap://localhost:8389/"), "dc=springframework,dc=org");
    }
}
Run Code Online (Sandbox Code Playgroud)

我的 ldif 配置;

dn: uid=ben,ou=people,dc=springframework,dc=org
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: Ben Alex
sn: Alex
uid: ben
userPassword: {SSHA}pcFdFhO/NS98EhTRup60PMkHMWFRDkJ3jUu1Zg==
Run Code Online (Sandbox Code Playgroud)

我原来的密码是Test1234. 我的pom.xml …

java spring spring-security spring-ldap ssha

5
推荐指数
1
解决办法
7459
查看次数

LdapCtxFactory 因为模块 java.naming 不会将 com.sun.jndi.ldap 导出到未命名模块

WebSecurityConfigurerAdapter:

@Component
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter
{
   @Override
   protected void configure(HttpSecurity httpSecurity) throws Exception
   {
      httpSecurity
               .authorizeRequests()
               .antMatchers("/abc/**").permitAll()
               .anyRequest()
               .authenticated()
               .and()
               .csrf()
               .disable()
               .httpBasic();
   }

   @Override
   public void configure(AuthenticationManagerBuilder auth) throws Exception
   {
      auth.ldapAuthentication()
          .userDnPatterns("uid={0},ou=people")
          .userSearchBase("ou=people")
          .userSearchFilter("uid={0}")
          .groupSearchBase("ou=groups")
          .groupSearchFilter("uniqueMember={0}")
          .contextSource()
          .url("ldap://localhost:8389/dc=concretepage,dc=com")
          .and()
          .passwordCompare()
          .passwordEncoder(passwordEncoder())
          .passwordAttribute("userPassword");
   }

   @Bean
   public PasswordEncoder passwordEncoder() {
      BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
      return passwordEncoder;
   }
Run Code Online (Sandbox Code Playgroud)

春季版本:SPRING_BOOT_VERSION = "2.6.6"

plugins {
    id 'java-library'
}

dependencies {
    implementation "org.springframework.boot:spring-boot:${SPRING_BOOT_VERSION}"
    implementation "org.springframework.boot:spring-boot-starter-web:${SPRING_BOOT_VERSION}"
    implementation "org.springframework.boot:spring-boot-starter-thymeleaf:${SPRING_BOOT_VERSION}"

    api "javax.servlet:javax.servlet-api:${JAVAX_SERVLET_VERSION}" …
Run Code Online (Sandbox Code Playgroud)

java ldap spring-ldap gradle spring-boot

5
推荐指数
1
解决办法
9531
查看次数