1
0
mirror of synced 2026-05-22 21:33:16 +00:00

Remove superfluous comments

Use '^\s+//\ \~\ .*$' and '^\s+//\ ============+$' regular expression
searches to remove superfluous comments.

Prior to this commit, many classes would have comments to indicate
blocks of code (such as constructors/methods/instance fields). These
added a lot of noise and weren't all that helpful, especially given
the outline views available in most modern IDEs.

Issue gh-8945
This commit is contained in:
Phillip Webb
2020-07-23 15:09:07 -07:00
committed by Rob Winch
parent b7fc18262d
commit 71bc145ae4
406 changed files with 12 additions and 2190 deletions
@@ -46,17 +46,11 @@ import org.springframework.test.context.junit4.SpringRunner;
@ContextConfiguration(classes = ApacheDsContainerConfig.class)
public class SpringSecurityLdapTemplateITests {
// ~ Instance fields
// ================================================================================================
@Autowired
private DefaultSpringSecurityContextSource contextSource;
private SpringSecurityLdapTemplate template;
// ~ Methods
// ========================================================================================================
@Before
public void setUp() {
template = new SpringSecurityLdapTemplate(this.contextSource);
@@ -45,9 +45,6 @@ import static org.assertj.core.api.Assertions.fail;
@ContextConfiguration(classes = ApacheDsContainerConfig.class)
public class BindAuthenticatorTests {
// ~ Instance fields
// ================================================================================================
@Autowired
private DefaultSpringSecurityContextSource contextSource;
@@ -55,9 +52,6 @@ public class BindAuthenticatorTests {
private Authentication bob;
// ~ Methods
// ========================================================================================================
@Before
public void setUp() {
this.authenticator = new BindAuthenticator(this.contextSource);
@@ -47,9 +47,6 @@ import static org.assertj.core.api.Assertions.*;
@ContextConfiguration(classes = ApacheDsContainerConfig.class)
public class PasswordComparisonAuthenticatorTests {
// ~ Instance fields
// ================================================================================================
@Autowired
private DefaultSpringSecurityContextSource contextSource;
@@ -59,9 +56,6 @@ public class PasswordComparisonAuthenticatorTests {
private Authentication ben;
// ~ Methods
// ========================================================================================================
@Before
public void setUp() {
authenticator = new PasswordComparisonAuthenticator(this.contextSource);
@@ -50,9 +50,6 @@ public class DefaultLdapAuthoritiesPopulatorTests {
private DefaultLdapAuthoritiesPopulator populator;
// ~ Methods
// ========================================================================================================
@Before
public void setUp() {
populator = new DefaultLdapAuthoritiesPopulator(this.contextSource, "ou=groups");
@@ -58,9 +58,6 @@ public class NestedLdapAuthoritiesPopulatorTests {
private LdapAuthority circularJavaDevelopers;
// ~ Methods
// ========================================================================================================
@Before
public void setUp() {
populator = new NestedLdapAuthoritiesPopulator(this.contextSource, "ou=jdeveloper");
@@ -37,20 +37,11 @@ import java.net.URISyntaxException;
*/
public final class LdapUtils {
// ~ Static fields/initializers
// =====================================================================================
private static final Log logger = LogFactory.getLog(LdapUtils.class);
// ~ Constructors
// ===================================================================================================
private LdapUtils() {
}
// ~ Methods
// ========================================================================================================
public static void closeContext(Context ctx) {
if (ctx instanceof DirContextAdapter) {
return;
@@ -55,8 +55,6 @@ import java.util.Set;
*/
public class SpringSecurityLdapTemplate extends LdapTemplate {
// ~ Static fields/initializers
// =====================================================================================
private static final Log logger = LogFactory.getLog(SpringSecurityLdapTemplate.class);
public static final String[] NO_ATTRS = new String[0];
@@ -69,15 +67,9 @@ public class SpringSecurityLdapTemplate extends LdapTemplate {
private static final boolean RETURN_OBJECT = true;
// ~ Instance fields
// ================================================================================================
/** Default search controls */
private SearchControls searchControls = new SearchControls();
// ~ Constructors
// ===================================================================================================
public SpringSecurityLdapTemplate(ContextSource contextSource) {
Assert.notNull(contextSource, "ContextSource cannot be null");
setContextSource(contextSource);
@@ -85,9 +77,6 @@ public class SpringSecurityLdapTemplate extends LdapTemplate {
searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
}
// ~ Methods
// ========================================================================================================
/**
* Performs an LDAP compare operation of the value of an attribute for a particular
* directory entry.
@@ -37,9 +37,6 @@ import java.util.List;
*/
public abstract class AbstractLdapAuthenticator implements LdapAuthenticator, InitializingBean, MessageSourceAware {
// ~ Instance fields
// ================================================================================================
private final ContextSource contextSource;
/**
@@ -60,9 +57,6 @@ public abstract class AbstractLdapAuthenticator implements LdapAuthenticator, In
/** Stores the patterns which are used as potential DN matches */
private MessageFormat[] userDnFormat = null;
// ~ Constructors
// ===================================================================================================
/**
* Create an initialized instance with the {@link ContextSource} provided.
* @param contextSource
@@ -72,9 +66,6 @@ public abstract class AbstractLdapAuthenticator implements LdapAuthenticator, In
this.contextSource = contextSource;
}
// ~ Methods
// ========================================================================================================
public void afterPropertiesSet() {
Assert.isTrue((userDnFormat != null) || (userSearch != null),
"Either an LdapUserSearch or DN pattern (or both) must be supplied.");
@@ -43,14 +43,8 @@ import javax.naming.directory.DirContext;
*/
public class BindAuthenticator extends AbstractLdapAuthenticator {
// ~ Static fields/initializers
// =====================================================================================
private static final Log logger = LogFactory.getLog(BindAuthenticator.class);
// ~ Constructors
// ===================================================================================================
/**
* Create an initialized instance using the {@link BaseLdapPathContextSource}
* provided.
@@ -62,9 +56,6 @@ public class BindAuthenticator extends AbstractLdapAuthenticator {
super(contextSource);
}
// ~ Methods
// ========================================================================================================
public DirContextOperations authenticate(Authentication authentication) {
DirContextOperations user = null;
Assert.isInstanceOf(UsernamePasswordAuthenticationToken.class, authentication,
@@ -117,18 +117,12 @@ import org.springframework.util.Assert;
*/
public class LdapAuthenticationProvider extends AbstractLdapAuthenticationProvider {
// ~ Instance fields
// ================================================================================================
private LdapAuthenticator authenticator;
private LdapAuthoritiesPopulator authoritiesPopulator;
private boolean hideUserNotFoundExceptions = true;
// ~ Constructors
// ===================================================================================================
/**
* Create an instance with the supplied authenticator and authorities populator
* implementations.
@@ -152,9 +146,6 @@ public class LdapAuthenticationProvider extends AbstractLdapAuthenticationProvid
this.setAuthoritiesPopulator(new NullLdapAuthoritiesPopulator());
}
// ~ Methods
// ========================================================================================================
private void setAuthenticator(LdapAuthenticator authenticator) {
Assert.notNull(authenticator, "An LdapAuthenticator must be supplied");
this.authenticator = authenticator;
@@ -31,9 +31,6 @@ import org.springframework.ldap.core.DirContextOperations;
*/
public interface LdapAuthenticator {
// ~ Methods
// ========================================================================================================
/**
* Authenticates as a user and obtains additional user information from the directory.
* @param authentication
@@ -48,30 +48,18 @@ import org.springframework.util.Assert;
*/
public final class PasswordComparisonAuthenticator extends AbstractLdapAuthenticator {
// ~ Static fields/initializers
// =====================================================================================
private static final Log logger = LogFactory.getLog(PasswordComparisonAuthenticator.class);
// ~ Instance fields
// ================================================================================================
private PasswordEncoder passwordEncoder = new LdapShaPasswordEncoder(KeyGenerators.shared(0));
private String passwordAttributeName = "userPassword";
private boolean usePasswordAttrCompare = false;
// ~ Constructors
// ===================================================================================================
public PasswordComparisonAuthenticator(BaseLdapPathContextSource contextSource) {
super(contextSource);
}
// ~ Methods
// ========================================================================================================
public DirContextOperations authenticate(final Authentication authentication) {
Assert.isInstanceOf(UsernamePasswordAuthenticationToken.class, authentication,
"Can only process UsernamePasswordAuthenticationToken objects");
@@ -32,20 +32,11 @@ import javax.naming.ldap.Control;
*/
public class PasswordPolicyControl implements Control {
// ~ Static fields/initializers
// =====================================================================================
/** OID of the Password Policy Control */
public static final String OID = "1.3.6.1.4.1.42.2.27.8.5.1";
// ~ Instance fields
// ================================================================================================
private final boolean critical;
// ~ Constructors
// ===================================================================================================
/**
* Creates a non-critical (request) control.
*/
@@ -61,9 +52,6 @@ public class PasswordPolicyControl implements Control {
this.critical = critical;
}
// ~ Methods
// ========================================================================================================
/**
* Retrieves the ASN.1 BER encoded value of the LDAP control. The request value for
* this control is always empty.
@@ -27,9 +27,6 @@ import javax.naming.ldap.ControlFactory;
*/
public class PasswordPolicyControlFactory extends ControlFactory {
// ~ Methods
// ========================================================================================================
/**
* Creates an instance of PasswordPolicyResponseControl if the passed control is a
* response control of this type. Attributes of the result are filled with the correct
@@ -50,14 +50,8 @@ import org.springframework.dao.DataRetrievalFailureException;
*/
public class PasswordPolicyResponseControl extends PasswordPolicyControl {
// ~ Static fields/initializers
// =====================================================================================
private static final Log logger = LogFactory.getLog(PasswordPolicyResponseControl.class);
// ~ Instance fields
// ================================================================================================
private final byte[] encodedValue;
private PasswordPolicyErrorStatus errorStatus;
@@ -66,9 +60,6 @@ public class PasswordPolicyResponseControl extends PasswordPolicyControl {
private int timeBeforeExpiration = Integer.MAX_VALUE;
// ~ Constructors
// ===================================================================================================
/**
* Decodes the Ber encoded control data. The ASN.1 value of the control data is:
*
@@ -98,9 +89,6 @@ public class PasswordPolicyResponseControl extends PasswordPolicyControl {
}
}
// ~ Methods
// ========================================================================================================
/**
* Returns the unchanged value of the response control. Returns the unchanged value of
* the response control as byte array.
@@ -194,18 +182,12 @@ public class PasswordPolicyResponseControl extends PasswordPolicyControl {
return sb.toString();
}
// ~ Inner Interfaces
// ===============================================================================================
private interface PPolicyDecoder {
void decode() throws IOException;
}
// ~ Inner Classes
// ==================================================================================================
/**
* Decoder based on Netscape ldapsdk library
*/
@@ -41,14 +41,8 @@ import javax.naming.directory.SearchControls;
*/
public class FilterBasedLdapUserSearch implements LdapUserSearch {
// ~ Static fields/initializers
// =====================================================================================
private static final Log logger = LogFactory.getLog(FilterBasedLdapUserSearch.class);
// ~ Instance fields
// ================================================================================================
private final ContextSource contextSource;
/**
@@ -78,9 +72,6 @@ public class FilterBasedLdapUserSearch implements LdapUserSearch {
*/
private final String searchFilter;
// ~ Constructors
// ===================================================================================================
public FilterBasedLdapUserSearch(String searchBase, String searchFilter, BaseLdapPathContextSource contextSource) {
Assert.notNull(contextSource, "contextSource must not be null");
Assert.notNull(searchFilter, "searchFilter must not be null.");
@@ -98,9 +89,6 @@ public class FilterBasedLdapUserSearch implements LdapUserSearch {
}
}
// ~ Methods
// ========================================================================================================
/**
* Return the LdapUserDetails containing the user's information
* @param username the username to search for.
@@ -29,9 +29,6 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException;
*/
public interface LdapUserSearch {
// ~ Methods
// ========================================================================================================
/**
* Locates a single user in the directory and returns the LDAP information for that
* user.
@@ -100,14 +100,8 @@ import org.springframework.util.Assert;
*/
public class DefaultLdapAuthoritiesPopulator implements LdapAuthoritiesPopulator {
// ~ Static fields/initializers
// =====================================================================================
private static final Log logger = LogFactory.getLog(DefaultLdapAuthoritiesPopulator.class);
// ~ Instance fields
// ================================================================================================
/**
* A default role which will be assigned to all authenticated users if set
*/
@@ -154,9 +148,6 @@ public class DefaultLdapAuthoritiesPopulator implements LdapAuthoritiesPopulator
*/
private Function<Map<String, List<String>>, GrantedAuthority> authorityMapper;
// ~ Constructors
// ===================================================================================================
/**
* Constructor for group search scenarios. <tt>userRoleAttributes</tt> may still be
* set as a property.
@@ -188,9 +179,6 @@ public class DefaultLdapAuthoritiesPopulator implements LdapAuthoritiesPopulator
};
}
// ~ Methods
// ========================================================================================================
/**
* This method should be overridden if required to obtain any additional roles for the
* given user (on top of those obtained from the standard search implemented by this
@@ -33,9 +33,6 @@ import org.springframework.ldap.core.DirContextOperations;
*/
public interface LdapAuthoritiesPopulator {
// ~ Methods
// ========================================================================================================
/**
* Get the list of authorities for the user.
* @param userData the context object which was returned by the LDAP authenticator.
@@ -26,9 +26,6 @@ import org.springframework.security.core.userdetails.UserDetails;
*/
public interface LdapUserDetails extends UserDetails, CredentialsContainer {
// ~ Methods
// ========================================================================================================
/**
* The DN of the entry for this user's account.
* @return the user's DN
@@ -51,9 +51,6 @@ public class LdapUserDetailsImpl implements LdapUserDetails, PasswordPolicyData
private static final long serialVersionUID = SpringSecurityCoreVersion.SERIAL_VERSION_UID;
// ~ Instance fields
// ================================================================================================
private String dn;
private String password;
@@ -75,15 +72,9 @@ public class LdapUserDetailsImpl implements LdapUserDetails, PasswordPolicyData
private int graceLoginsRemaining = Integer.MAX_VALUE;
// ~ Constructors
// ===================================================================================================
protected LdapUserDetailsImpl() {
}
// ~ Methods
// ========================================================================================================
@Override
public Collection<GrantedAuthority> getAuthorities() {
return authorities;
@@ -186,9 +177,6 @@ public class LdapUserDetailsImpl implements LdapUserDetails, PasswordPolicyData
return sb.toString();
}
// ~ Inner Classes
// ==================================================================================================
/**
* Variation of essence pattern. Used to create mutable intermediate object
*/
@@ -39,9 +39,6 @@ import org.springframework.util.Assert;
*/
public class LdapUserDetailsMapper implements UserDetailsContextMapper {
// ~ Instance fields
// ================================================================================================
private final Log logger = LogFactory.getLog(LdapUserDetailsMapper.class);
private String passwordAttributeName = "userPassword";
@@ -52,9 +49,6 @@ public class LdapUserDetailsMapper implements UserDetailsContextMapper {
private boolean convertToUpperCase = true;
// ~ Methods
// ========================================================================================================
@Override
public UserDetails mapUserFromContext(DirContextOperations ctx, String username,
Collection<? extends GrantedAuthority> authorities) {
@@ -31,9 +31,6 @@ import org.junit.Test;
*/
public class LdapUtilsTests {
// ~ Methods
// ========================================================================================================
@Test
public void testCloseContextSwallowsNamingException() throws Exception {
final DirContext dirCtx = mock(DirContext.class);
@@ -46,9 +46,6 @@ import org.springframework.security.ldap.userdetails.LdapUserDetailsMapper;
*/
public class LdapAuthenticationProviderTests {
// ~ Methods
// ========================================================================================================
@Test
public void testSupportsUsernamePasswordAuthenticationToken() {
LdapAuthenticationProvider ldapProvider = new LdapAuthenticationProvider(new MockAuthenticator(),
@@ -177,9 +174,6 @@ public class LdapAuthenticationProviderTests {
}
}
// ~ Inner Classes
// ==================================================================================================
class MockAuthenticator implements LdapAuthenticator {
public DirContextOperations authenticate(Authentication authentication) {
@@ -25,14 +25,8 @@ import org.springframework.ldap.core.DirContextOperations;
*/
public class MockUserSearch implements LdapUserSearch {
// ~ Instance fields
// ================================================================================================
DirContextOperations user;
// ~ Constructors
// ===================================================================================================
public MockUserSearch() {
}
@@ -40,9 +34,6 @@ public class MockUserSearch implements LdapUserSearch {
this.user = user;
}
// ~ Methods
// ========================================================================================================
public DirContextOperations searchForUser(String username) {
return user;
}
@@ -33,9 +33,6 @@ import org.springframework.security.authentication.UsernamePasswordAuthenticatio
*/
public class PasswordComparisonAuthenticatorMockTests {
// ~ Methods
// ========================================================================================================
@Test
public void ldapCompareOperationIsUsedWhenPasswordIsNotRetrieved() throws Exception {
final DirContext dirCtx = mock(DirContext.class);
@@ -27,9 +27,6 @@ import org.junit.Test;
*/
public class PasswordPolicyResponseControlTests {
// ~ Methods
// ========================================================================================================
/**
* Useful method for obtaining data from a server for use in tests
*/