diff --git a/ldap/src/main/java/org/springframework/security/ldap/DefaultLdapUsernameToDnMapper.java b/ldap/src/main/java/org/springframework/security/ldap/DefaultLdapUsernameToDnMapper.java index cd96068adb9..2570376cb14 100644 --- a/ldap/src/main/java/org/springframework/security/ldap/DefaultLdapUsernameToDnMapper.java +++ b/ldap/src/main/java/org/springframework/security/ldap/DefaultLdapUsernameToDnMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,6 @@ import javax.naming.ldap.LdapName; -import org.springframework.ldap.core.DistinguishedName; import org.springframework.ldap.support.LdapNameBuilder; /** @@ -44,18 +43,6 @@ public DefaultLdapUsernameToDnMapper(String userDnBase, String usernameAttribute this.usernameAttribute = usernameAttribute; } - /** - * Assembles the Distinguished Name that should be used the given username. - * @deprecated Use {@link #buildLdapName(String)} instead - */ - @Override - @Deprecated - public DistinguishedName buildDn(String username) { - DistinguishedName dn = new DistinguishedName(this.userDnBase); - dn.add(this.usernameAttribute, username); - return dn; - } - @Override public LdapName buildLdapName(String username) { return LdapNameBuilder.newInstance(this.userDnBase).add(this.usernameAttribute, username).build(); diff --git a/ldap/src/main/java/org/springframework/security/ldap/LdapUsernameToDnMapper.java b/ldap/src/main/java/org/springframework/security/ldap/LdapUsernameToDnMapper.java index 63b197755ba..a1fbb015490 100644 --- a/ldap/src/main/java/org/springframework/security/ldap/LdapUsernameToDnMapper.java +++ b/ldap/src/main/java/org/springframework/security/ldap/LdapUsernameToDnMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,8 +18,6 @@ import javax.naming.ldap.LdapName; -import org.springframework.ldap.core.DistinguishedName; - /** * Constructs an Ldap Distinguished Name from a username. * @@ -27,14 +25,6 @@ */ public interface LdapUsernameToDnMapper { - /** - * @deprecated Use {@link #buildLdapName(String)} instead - */ - @Deprecated - DistinguishedName buildDn(String username); - - default LdapName buildLdapName(String username) { - return org.springframework.ldap.support.LdapUtils.newLdapName(buildDn(username)); - } + LdapName buildLdapName(String username); } diff --git a/ldap/src/main/java/org/springframework/security/ldap/LdapUtils.java b/ldap/src/main/java/org/springframework/security/ldap/LdapUtils.java index 66b0e89e86e..a2ed238b94b 100644 --- a/ldap/src/main/java/org/springframework/security/ldap/LdapUtils.java +++ b/ldap/src/main/java/org/springframework/security/ldap/LdapUtils.java @@ -28,7 +28,6 @@ import org.apache.commons.logging.LogFactory; import org.springframework.ldap.core.DirContextAdapter; -import org.springframework.ldap.core.DistinguishedName; import org.springframework.ldap.support.LdapNameBuilder; import org.springframework.security.crypto.codec.Utf8; import org.springframework.util.Assert; @@ -101,18 +100,7 @@ public static String getRelativeName(String fullDn, Context baseCtx) throws Nami /** * Gets the full dn of a name by prepending the name of the context it is relative to. * If the name already contains the base name, it is returned unaltered. - * @deprecated Use {@link #getFullDn(LdapName, Context)} */ - @Deprecated - public static DistinguishedName getFullDn(DistinguishedName dn, Context baseCtx) throws NamingException { - DistinguishedName baseDn = new DistinguishedName(baseCtx.getNameInNamespace()); - if (dn.contains(baseDn)) { - return dn; - } - baseDn.append(dn); - return baseDn; - } - public static LdapName getFullDn(LdapName dn, Context baseCtx) throws NamingException { LdapName baseDn = LdapNameBuilder.newInstance(baseCtx.getNameInNamespace()).build(); if (dn.startsWith(baseDn)) { diff --git a/ldap/src/main/java/org/springframework/security/ldap/userdetails/LdapUserDetailsManager.java b/ldap/src/main/java/org/springframework/security/ldap/userdetails/LdapUserDetailsManager.java index 3d945a0805f..ae4636e311e 100644 --- a/ldap/src/main/java/org/springframework/security/ldap/userdetails/LdapUserDetailsManager.java +++ b/ldap/src/main/java/org/springframework/security/ldap/userdetails/LdapUserDetailsManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,7 +48,6 @@ import org.springframework.ldap.core.AttributesMapperCallbackHandler; import org.springframework.ldap.core.ContextSource; import org.springframework.ldap.core.DirContextAdapter; -import org.springframework.ldap.core.DistinguishedName; import org.springframework.ldap.core.LdapTemplate; import org.springframework.ldap.core.SearchExecutor; import org.springframework.ldap.support.LdapNameBuilder; @@ -289,39 +288,23 @@ public boolean userExists(String username) { * Creates a DN from a group name. * @param group the name of the group * @return the DN of the corresponding group, including the groupSearchBase - * @deprecated */ - @Deprecated - protected DistinguishedName buildGroupDn(String group) { - DistinguishedName dn = new DistinguishedName(this.groupSearchBase); - dn.add(this.groupRoleAttributeName, group.toLowerCase(Locale.ROOT)); - return dn; - } - - protected LdapName buildGroupName(String group) { - return LdapNameBuilder.newInstance(buildGroupDn(group)).build(); + protected LdapName buildGroupDn(String group) { + return LdapNameBuilder.newInstance(this.groupSearchBase) + .add(this.groupRoleAttributeName, group.toLowerCase(Locale.ROOT)) + .build(); } protected void copyToContext(UserDetails user, DirContextAdapter ctx) { this.userDetailsMapper.mapUserToContext(user, ctx); } - @Deprecated - protected void addAuthorities(DistinguishedName userDn, Collection authorities) { - modifyAuthorities(LdapNameBuilder.newInstance(userDn).build(), authorities, DirContext.ADD_ATTRIBUTE); - } - protected void addAuthorities(LdapName userDn, Collection authorities) { - addAuthorities(new DistinguishedName(userDn), authorities); - } - - @Deprecated - protected void removeAuthorities(DistinguishedName userDn, Collection authorities) { - modifyAuthorities(LdapNameBuilder.newInstance(userDn).build(), authorities, DirContext.REMOVE_ATTRIBUTE); + modifyAuthorities(LdapNameBuilder.newInstance(userDn).build(), authorities, DirContext.ADD_ATTRIBUTE); } protected void removeAuthorities(LdapName userDn, Collection authorities) { - removeAuthorities(new DistinguishedName(userDn), authorities); + modifyAuthorities(LdapNameBuilder.newInstance(userDn).build(), authorities, DirContext.REMOVE_ATTRIBUTE); } private void modifyAuthorities(final LdapName userDn, final Collection authorities, @@ -332,7 +315,7 @@ private void modifyAuthorities(final LdapName userDn, final Collection