标签: spring-ldap

我可以从 LDAP 更改自己的 Active Directory 密码(无需管理帐户)

我没有(也不会)拥有管理员帐户。我想从 java 更改 Active Directory 中自己(用户)的密码。我怎样才能做到这一点?

使用来自网络的代码:

private void changePass() throws Exception {
    String oldpass = this.encodePassword("oldpass!");
    String newpass = this.encodePassword("newpass!");
    Attribute oldattr = new BasicAttribute("unicodePwd", oldpass);
    Attribute newattr = new BasicAttribute("unicodePwd", newpass);
    ModificationItem olditem = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, oldattr);
    ModificationItem newitem = new ModificationItem(DirContext.ADD_ATTRIBUTE, newattr);
    ModificationItem repitem = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, newattr);
    ModificationItem[] mods = new ModificationItem[2];
    mods[0] = olditem;
    mods[1] = newitem;
    // ldapTemplate.modifyAttributes("cn=administrator,cn=Users", mods);
    ldapTemplate.modifyAttributes("cn=smith,cn=Users", new ModificationItem[] { repitem });
}
Run Code Online (Sandbox Code Playgroud)

这是上下文源

<bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource">
    <property name="url" value="ldap://ldapserver:389"/>
    <property …
Run Code Online (Sandbox Code Playgroud)

java ldap active-directory spring-ldap

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

Spring LDAP基本用法

我试图通过设置最基本的工作程序来弄清楚Spring LDAP(不是 Spring安全事件)是如何工作的,但似乎实际的身份验证中断了.

这是我得到的错误:

Exception in thread "main" java.lang.NullPointerException
    at org.springframework.ldap.core.support.AbstractContextSource.getReadOnlyContext(AbstractContextSource.java:125)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:287)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:237)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:588)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:546)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:401)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:421)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:441)

在抛出异常的方法中执行的代码是:

return getContext(authenticationSource.getPrincipal(),
                  authenticationSource.getCredentials());
Run Code Online (Sandbox Code Playgroud)

所以我似乎需要在应用程序上下文中设置身份验证源?我真的迷路了.

这是我的代码:

package se.test.connector.ldap;

import java.util.List;
import javax.naming.NamingException;
import javax.naming.directory.Attributes;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.ldap.core.AttributesMapper;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.core.support.LdapContextSource;
import org.springframework.ldap.filter.EqualsFilter;

public class LdapTest {

    public static void main(String[] args) {
        LdapContextSource ctxSrc = new LdapContextSource();
        ctxSrc.setUrl("ldap://<ldapUrl>:389");
        ctxSrc.setBase("DC=bar,DC=test,DC=foo");
        ctxSrc.setUserDn("<username>@bar.test.foo");
        ctxSrc.setPassword("<password>");

        LdapTemplate tmpl = …
Run Code Online (Sandbox Code Playgroud)

java spring spring-ldap

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

如何在Spring LDAP中添加LDAP缓存?

我想在本地缓存LDAP用户数据以允许更快的查询.Spring LDAP提供了这样的功能吗?我怎样才能做到这一点?

我使用Spring Security 3.1和Spring LDAP 1.3.1进行身份验证和授权.如果存在,使用内置机制为LDAP建立缓存会很好.

Spring LDAP配置:

的applicationContext-ldap.xml:

<?xml  version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/jee
        http://www.springframework.org/schema/jee/spring-jee.xsd
    ">

    <!-- Ldap -->
    <jee:jndi-lookup id="ldapUrl" jndi-name="appName/ldapUrl" expected-type="java.lang.String" />
    <jee:jndi-lookup id="ldapUser" jndi-name="appName/ldapUser" expected-type="java.lang.String" />
    <jee:jndi-lookup id="ldapPassword" jndi-name="appName/ldapPassword" expected-type="java.lang.String" />

    <!-- for authentication and search purpose -->
    <bean id="ldapContextSource" class="org.springframework.ldap.core.support.LdapContextSource">
        <property name="url" ref="ldapUrl" />
        <property name="userDn" ref="ldapUser" />
        <property name="password" ref="ldapPassword" />
        <property name="pooled" value="true" />
    </bean>

    <bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
        <property name="contextSource" ref="ldapContextSource" />
    </bean>

    <!-- for pagination search …
Run Code Online (Sandbox Code Playgroud)

spring ldap spring-security spring-ldap

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

具有LDAP和数据库角色的Spring Security

在我们的新保险项目中,我正在尝试使用Ldap 实现.

一旦用户在AD中找到,我想在AD上检查用户名/密码.我想从用户表(app授权用户)授权他在数据库中具有访问级别.有人可以提供样品/指出我的资源.

spring spring-security spring-ldap

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

使用自定义模式定义进行Spring Ldap单元测试

我正在尝试使用Spring Ldap为嵌入式ldap进行单元测试.但是我需要为自定义objectClasses/attributes定义使用自定义模式.如何使用Spring Ldap测试(LdapTestUtils?)进行配置?

实际上,如果我运行测试,它失败说我的自定义objectClass"myOb"未在模式中定义,并带有以下消息:

org.springframework.ldap.UncategorizedLdapException: Failed to populate LDIF; nested exception is javax.naming.directory.NoSuchAttributeException: [LDAP: error code 16 - NO_SUCH_ATTRIBUTE: failed for     Add Request :
...
: OID for name 'myOb' was not found within the OID registry]; remaining name 'cn=123456, ou=MyUser, o=company.com'
Run Code Online (Sandbox Code Playgroud)

如果我objectClass: myOb从ldif 发表评论,则测试失败并显示空值(未读取属性).

这是我的测试类:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = LdapConfiguration.class, loader = AnnotationConfigContextLoader.class)
public class LdapTest {

    // Ldap port
    private static final int LDAP_PORT = 18880;

    // Base DN for test data
    private static final …
Run Code Online (Sandbox Code Playgroud)

java spring unit-testing ldap spring-ldap

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

具有错误的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万
查看次数

为什么Nginx以相反的顺序提供客户端SSL DN?

我很好奇为什么有些Web服务器(例如Nginx)以相反的顺序提供客户端SSL DN.

Web应用程序将DN发布到Java Web服务,该服务正在尝试创建Java javax.naming.ldap.LdapName.

标准订单(LDAP或X500Name):

"CN=Jimmy Blooptoop,OU=Someplace,OU=Employees,DC=Bloopsoft-Inc"
Run Code Online (Sandbox Code Playgroud)

逆序(OpenSSL Oneline格式)(Nginx返回_ $ ssl_client_s_dn_):

"/DC=Bloopsoft-Inc/OU=Employees/OU=Someplace/CN=Jimmy Blooptoop"
Run Code Online (Sandbox Code Playgroud)

为什么是这样?

哪一个与LDAP RFC匹配?

他们俩都这样?

关于LDAP RFC的说明:

有许多与LDAP相关的RFC:https://www.ldap.com/ldap-specifications-defined-in-rfcs

许多人提到不同的人,这里是对他们的快速历史的尝试:

  • 1993年7月:RFC 1485 - 杰出名称的字符串表示
  • 1995年3月:RFC 1779 - 可分辨名称的字符串表示
  • 1997年12月:RFC 2253 - 轻量级目录访问协议(v3):可分辨名称的UTF-8字符串表示
  • 2002年9月:RFC 3377 - 轻量级目录访问协议(v3):技术规范(更新RFC 2253)
  • 2003年3月:RFC 3494 - 轻量级目录访问协议版本2(LDAPv2)到历史状态(退休RFC 1485,RFC 1779)
  • 2006年6月:RFC 4514 - 轻量级目录访问协议(LDAP):可分辨名称的字符串表示

最新的One,其他人已废弃: RFC 4514:轻量级目录访问协议(LDAP):可分辨名称的字符串表示

Java库:

是否存在来回转换的Java库(从反向转换为非反转)?LdapName抛出InvalidNameException.似乎应该有,倒退格式经常出现.

Java库:

Ngninx备注:

链接:

java openssl ldap nginx spring-ldap

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

在Spring Boot中设置LDAP身份验证的超时值

我使用Spring LDAP身份验证:

auth
            .ldapAuthentication()
            .userSearchFilter("userPrincipalName={0}")
            .contextSource()
            .managerDn(ldapAuthenticationConfig.getManagerDn())
            .managerPassword(ldapAuthenticationConfig.getManagerPassword())
            .url(ldapAuthenticationConfig.getUrl());
Run Code Online (Sandbox Code Playgroud)

但是,当LDAP服务器不可用时,在登录页面上花费太多时间.我想知道我是否可以在相当长的一段时间内登录.

这是我使用的依赖项:

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-ldap</artifactId>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

如何在Spring Boot中为LDAP身份验证设置超时值?

timeout spring-ldap spring-boot

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

Spring 5 LDAP 身份验证和 JWT 令牌作为响应

您好,我一直在尝试配置 spring,使其在用户/密码通过 LDAP 服务器身份验证时返回 JWT 令牌;考虑下面的用例;

在此处输入图片说明

在上图中,我已将 WebSecurity 配置为使用 Bearer 检查/过滤请求。见下面的代码

网络安全配置文件

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    private JwtAuthenticationEntryPoint unauthorizedHandler;

    @Autowired
    JwtAuthorizationTokenFilter authenticationTokenFilter;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        // Configure Web Security
        // Allow only /auth/
        // Disallow all others
        http
        .csrf().disable()
        .exceptionHandling().authenticationEntryPoint(unauthorizedHandler)
        .and()
        .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
        .and()
        .authorizeRequests()
        .antMatchers(HttpMethod.POST,
                     "/auth/**")
        .permitAll()
        .anyRequest().authenticated();      

        //Custom JWT 
        http.addFilterBefore(authenticationTokenFilter, UsernamePasswordAuthenticationFilter.class);

        // disable page caching
        http.headers().cacheControl();

    }
}
Run Code Online (Sandbox Code Playgroud)

验证控件.java

@RestController
@RequestMapping("auth")
public class AuthCtrl {

    private static final Logger …
Run Code Online (Sandbox Code Playgroud)

java spring spring-security spring-ldap jwt

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

Microsoft 安全公告 ADV190023(LDAP 通道绑定和 LDAP 签名)的 Spring LDAP 影响

我们正在使用 Spring Security Ldap 库 (v4.0.4) 从我们客户端的 Active Directory (ldap://domain:389) 中获取用户列表,并对他们进行身份验证以登录到我们的 Web 应用程序。

微软最近发布了启用 LDAP 通道绑定和 LDAP 签名的公告:https : //portal.msrc.microsoft.com/en-us/security-guidance/advisory/ADV190023

“LDAP 通道绑定和 LDAP 签名提供了提高 LDAP 客户端和 Active Directory 域控制器之间通信安全性的方法。Active Directory 域控制器上存在一组不安全的 LDAP 通道绑定和 LDAP 签名默认配置,允许 LDAP 客户端与其通信没有强制执行 LDAP 通道绑定和 LDAP 签名。这可以打开 Active Directory 域控制器以提升特权漏洞。”

我们被问到在他们的服务器上启用 LDAP 通道绑定和 LDAP 签名是否会影响我们的流程。我在文档中找不到关于这些的信息:https : //docs.spring.io/spring-security/site/docs/current/reference/htmlsingle/#ldap

Spring Security Ldap 库 (v4.0.4) 是否支持这些?如果是这样,我们是否应该更改任何配置以确保事情不受影响?

spring active-directory spring-security spring-ldap spring-security-ldap

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