Skip to content

Commit

Permalink
HIVE-28502: Refactor method names that start with capital letters in …
Browse files Browse the repository at this point in the history
…PasswdAuthenticationProvider class
  • Loading branch information
Dmitriy Fingerman committed Sep 11, 2024
1 parent 4b089c2 commit f88dd25
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class TestJdbcNonKrbSASLWithMiniKdc extends TestJdbcWithMiniKdc{

public static class CustomAuthenticator implements PasswdAuthenticationProvider {
@Override
public void Authenticate(String user, String password) throws AuthenticationException {
public void authenticate(String user, String password) throws AuthenticationException {
if (!(SASL_NONKRB_USER1.equals(user) && SASL_NONKRB_PWD.equals(password)) &&
!(SASL_NONKRB_USER2.equals(user) && SASL_NONKRB_PWD.equals(password))) {
throw new AuthenticationException("Authentication failed");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private void init(){
}

@Override
public void Authenticate(String user, String password) throws AuthenticationException {
public void authenticate(String user, String password) throws AuthenticationException {

if(!userMap.containsKey(user)){
throw new AuthenticationException("Invalid user : "+user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private void init(){
}

@Override
public void Authenticate(String user, String password) throws AuthenticationException {
public void authenticate(String user, String password) throws AuthenticationException {

if(!userMap.containsKey(user)){
throw new AuthenticationException("Invalid user : "+user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
public class AnonymousAuthenticationProviderImpl implements PasswdAuthenticationProvider {

@Override
public void Authenticate(String user, String password) throws AuthenticationException {
public void authenticate(String user, String password) throws AuthenticationException {
// no-op authentication
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public class CustomAuthenticationProviderImpl implements PasswdAuthenticationPro
}

@Override
public void Authenticate(String user, String password) throws AuthenticationException {
customProvider.Authenticate(user, password);
public void authenticate(String user, String password) throws AuthenticationException {
customProvider.authenticate(user, password);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public LdapAuthenticationProviderImpl(HiveConf conf) {
}

@Override
public void Authenticate(String user, String password) throws AuthenticationException {
public void authenticate(String user, String password) throws AuthenticationException {
DirSearch search = null;
String bindUser = this.conf.getVar(HiveConf.ConfVars.HIVE_SERVER2_PLAIN_LDAP_BIND_USER);
String bindPassword = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class PamAuthenticationProviderImpl implements PasswdAuthenticationProvid
}

@Override
public void Authenticate(String user, String password) throws AuthenticationException {
public void authenticate(String user, String password) throws AuthenticationException {

if (pamServiceNames == null || pamServiceNames.trim().isEmpty()) {
throw new AuthenticationException("No PAM services are set.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ public interface PasswdAuthenticationProvider {
* @throws AuthenticationException When a user is found to be
* invalid by the implementation
*/
void Authenticate(String user, String password) throws AuthenticationException;
void authenticate(String user, String password) throws AuthenticationException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.apache.hive.service.auth;

import java.io.IOException;
import java.net.InetAddress;
import java.security.Security;
import java.util.HashMap;

Expand Down Expand Up @@ -160,7 +159,7 @@ public void handle(Callback[] callbacks) throws IOException, UnsupportedCallback
PasswdAuthenticationProvider provider =
AuthenticationProviderFactory.getAuthenticationProvider(authMethod);
try {
provider.Authenticate(username, password);
provider.authenticate(username, password);
} catch (Exception e) {
LOG.error("Login attempt is failed for user : " + username + ". Error Messsage : " + e.getMessage());
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public boolean authenticate(HttpServletRequest request, HttpServletResponse resp
String clientUserName = validateCookie(request);
if (clientUserName == null) {
clientUserName = getUsername(request);
authProvider.Authenticate(clientUserName, getPassword(request));
authProvider.authenticate(clientUserName, getPassword(request));

String cookieToken = HttpAuthUtils.createCookieToken(clientUserName);
Cookie hs2Cookie = signAndCreateCookie(cookieToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ private String doPasswdAuth(HttpServletRequest request, String authType)
AuthMethods authMethod = AuthMethods.getValidAuthMethod(authType);
PasswdAuthenticationProvider provider =
AuthenticationProviderFactory.getAuthenticationProvider(authMethod, hiveConf);
provider.Authenticate(userName, httpAuthService.getPassword(request));
provider.authenticate(userName, httpAuthService.getPassword(request));
} catch (Exception e) {
throw new HttpAuthenticationException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,21 @@ public void setup() throws AuthenticationException {
public void authenticateGivenBlankPassword() throws Exception {
auth = new LdapAuthenticationProviderImpl(conf, new LdapSearchFactory());
expectAuthenticationExceptionForInvalidPassword();
auth.Authenticate("user", "");
auth.authenticate("user", "");
}

@Test
public void authenticateGivenStringWithNullCharacterForPassword() throws Exception {
auth = new LdapAuthenticationProviderImpl(conf, new LdapSearchFactory());
expectAuthenticationExceptionForInvalidPassword();
auth.Authenticate("user", "\0");
auth.authenticate("user", "\0");
}

@Test
public void authenticateGivenNullForPassword() throws Exception {
auth = new LdapAuthenticationProviderImpl(conf, new LdapSearchFactory());
expectAuthenticationExceptionForInvalidPassword();
auth.Authenticate("user", null);
auth.authenticate("user", null);
}

@Test
Expand All @@ -93,7 +93,7 @@ public void testAuthenticateNoUserOrGroupFilter() throws NamingException, Authen
when(factory.getInstance(conf, "cn=user1,ou=Users,dc=mycorp,dc=com", "Blah")).thenThrow(AuthenticationException.class);

auth = new LdapAuthenticationProviderImpl(conf, factory);
auth.Authenticate("user1", "Blah");
auth.authenticate("user1", "Blah");

verify(factory, times(2)).getInstance(isA(HiveConf.class), anyString(), eq("Blah"));
verify(search, atLeastOnce()).close();
Expand Down Expand Up @@ -271,7 +271,7 @@ public void testAuthenticateWhenUserMembershipKeyFilterPasses() throws NamingExc
when(search.isUserMemberOfGroup("user1", groupDn)).thenReturn(true);

auth = new LdapAuthenticationProviderImpl(conf, factory);
auth.Authenticate("user1", "Blah");
auth.authenticate("user1", "Blah");

verify(factory, times(1)).getInstance(isA(HiveConf.class), anyString(), eq("Blah"));
verify(search, times(1)).findGroupDn(anyString());
Expand All @@ -293,7 +293,7 @@ public void testAuthenticateWhenUserMembershipKeyFilterFails() throws NamingExce
when(search.isUserMemberOfGroup("user1", groupDn)).thenReturn(false);

auth = new LdapAuthenticationProviderImpl(conf, factory);
auth.Authenticate("user1", "Blah");
auth.authenticate("user1", "Blah");
}

@Test
Expand All @@ -316,7 +316,7 @@ public void testAuthenticateWhenUserMembershipKeyFilter2x2PatternsPasses() throw
when(search.isUserMemberOfGroup("user1", "cn=HIVE-USERS2,ou=Groups,ou=branch1,dc=mycorp,dc=com")).thenReturn(true);

auth = new LdapAuthenticationProviderImpl(conf, factory);
auth.Authenticate("user1", "Blah");
auth.authenticate("user1", "Blah");

verify(factory, times(1)).getInstance(isA(HiveConf.class), anyString(), eq("Blah"));
verify(search, times(2)).findGroupDn(anyString());
Expand All @@ -341,7 +341,7 @@ public void testAuthenticateWithBindInCredentialFilePasses() throws Authenticati
when(search.findUserDn(eq(authUser))).thenReturn(authFullUser);

auth = new LdapAuthenticationProviderImpl(conf, factory);
auth.Authenticate(authUser, authPass);
auth.authenticate(authUser, authPass);

verify(factory, times(1)).getInstance(isA(HiveConf.class), eq(bindUser), eq(bindPass));
verify(factory, times(1)).getInstance(isA(HiveConf.class), eq(authFullUser), eq(authPass));
Expand All @@ -359,7 +359,7 @@ public void testAuthenticateWithBindInMissingCredentialFilePasses() throws Authe
conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, credentialsPath);

auth = new LdapAuthenticationProviderImpl(conf, factory);
auth.Authenticate(authUser, authPass);
auth.authenticate(authUser, authPass);

verify(factory, times(1)).getInstance(isA(HiveConf.class), eq(authUser), eq(authPass));
}
Expand All @@ -377,7 +377,7 @@ public void testAuthenticateWithBindUserPasses() throws AuthenticationException,
when(search.findUserDn(eq(authUser))).thenReturn(authFullUser);

auth = new LdapAuthenticationProviderImpl(conf, factory);
auth.Authenticate(authUser, authPass);
auth.authenticate(authUser, authPass);

verify(factory, times(1)).getInstance(isA(HiveConf.class), eq(bindUser), eq(bindPass));
verify(factory, times(1)).getInstance(isA(HiveConf.class), eq(authFullUser), eq(authPass));
Expand All @@ -400,7 +400,7 @@ public void testAuthenticateWithBindUserFailsOnAuthentication() throws Authentic
when(search.findUserDn(eq(authUser))).thenReturn(authFullUser);

auth = new LdapAuthenticationProviderImpl(conf, factory);
auth.Authenticate(authUser, authPass);
auth.authenticate(authUser, authPass);
}

@Test
Expand All @@ -417,7 +417,7 @@ public void testAuthenticateWithBindUserFailsOnGettingDn() throws Authentication
when(search.findUserDn(eq(authUser))).thenThrow(NamingException.class);

auth = new LdapAuthenticationProviderImpl(conf, factory);
auth.Authenticate(authUser, authPass);
auth.authenticate(authUser, authPass);
}

@Test
Expand All @@ -433,7 +433,7 @@ public void testAuthenticateWithBindUserFailsOnBinding() throws AuthenticationEx
when(factory.getInstance(any(HiveConf.class), eq(bindUser), eq(bindPass))).thenThrow(AuthenticationException.class);

auth = new LdapAuthenticationProviderImpl(conf, factory);
auth.Authenticate(authUser, authPass);
auth.authenticate(authUser, authPass);
}

private void expectAuthenticationExceptionForInvalidPassword() {
Expand All @@ -444,7 +444,7 @@ private void expectAuthenticationExceptionForInvalidPassword() {
private void authenticateUserAndCheckSearchIsClosed(String user) throws IOException {
auth = new LdapAuthenticationProviderImpl(conf, factory);
try {
auth.Authenticate(user, "password doesn't matter");
auth.authenticate(user, "password doesn't matter");
} finally {
verify(search, atLeastOnce()).close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private LdapAuthenticationTestCase(Builder builder) {

public void assertAuthenticatePasses(Credentials credentials) {
try {
ldapProvider.Authenticate(credentials.getUser(), credentials.getPassword());
ldapProvider.authenticate(credentials.getUser(), credentials.getPassword());
} catch (AuthenticationException e) {
String message = String.format("Authentication failed for user '%s' with password '%s'",
credentials.getUser(), credentials.getPassword());
Expand All @@ -60,7 +60,7 @@ public void assertAuthenticateFailsUsingWrongPassword(Credentials credentials) {

public void assertAuthenticateFails(String user, String password) {
try {
ldapProvider.Authenticate(user, password);
ldapProvider.authenticate(user, password);
Assert.fail(String.format("Expected authentication to fail for %s", user));
} catch (AuthenticationException expected) {
Assert.assertNotNull("Expected authentication exception", expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public static void afterTests() {

public static class DummyLdapAuthenticationProviderImpl implements PasswdAuthenticationProvider {
@Override
public void Authenticate(String user, String password) throws AuthenticationException {
public void authenticate(String user, String password) throws AuthenticationException {
if (!(user.equals(VALID_USER) && password.equals(VALID_PASS)))
throw new AuthenticationException();
}
Expand Down

0 comments on commit f88dd25

Please sign in to comment.