forked from apache/nifi
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NIFI-8978 Add KerberosUserService to DBCPConnectionPool/HadoopDBCPCon…
…nectionPool Signed-off-by: Pierre Villard <[email protected]> This closes apache#5399.
- Loading branch information
1 parent
3a8da7b
commit 2ae4f90
Showing
7 changed files
with
164 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
package org.apache.nifi.dbcp; | ||
|
||
import org.apache.nifi.kerberos.KerberosCredentialsService; | ||
import org.apache.nifi.kerberos.KerberosUserService; | ||
import org.apache.nifi.kerberos.MockKerberosCredentialsService; | ||
import org.apache.nifi.processor.exception.ProcessException; | ||
import org.apache.nifi.reporting.InitializationException; | ||
|
@@ -39,6 +40,8 @@ | |
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class DBCPServiceTest { | ||
private static final String SERVICE_ID = DBCPConnectionPool.class.getName(); | ||
|
@@ -69,6 +72,38 @@ public void setService() throws InitializationException { | |
runner.setProperty(service, DBCPConnectionPool.DB_DRIVERNAME, "org.apache.derby.jdbc.EmbeddedDriver"); | ||
} | ||
|
||
@Test | ||
public void testCustomValidateOfKerberosProperties() throws InitializationException { | ||
// direct principal + password and no kerberos services is valid | ||
runner.setProperty(service, DBCPConnectionPool.KERBEROS_PRINCIPAL, "[email protected]"); | ||
runner.setProperty(service, DBCPConnectionPool.KERBEROS_PASSWORD, "fooPassword"); | ||
runner.assertValid(service); | ||
|
||
// direct principal + password with kerberos credential service is invalid | ||
final KerberosCredentialsService kerberosCredentialsService = enabledKerberosCredentialsService(runner); | ||
runner.setProperty(service, DBCPConnectionPool.KERBEROS_CREDENTIALS_SERVICE, kerberosCredentialsService.getIdentifier()); | ||
runner.assertNotValid(service); | ||
|
||
// kerberos credential service by itself is valid | ||
runner.removeProperty(service, DBCPConnectionPool.KERBEROS_PRINCIPAL); | ||
runner.removeProperty(service, DBCPConnectionPool.KERBEROS_PASSWORD); | ||
runner.assertValid(service); | ||
|
||
// kerberos credential service with kerberos user service is invalid | ||
final KerberosUserService kerberosUserService = enableKerberosUserService(runner); | ||
runner.setProperty(service, DBCPConnectionPool.KERBEROS_USER_SERVICE, kerberosUserService.getIdentifier()); | ||
runner.assertNotValid(service); | ||
|
||
// kerberos user service by itself is valid | ||
runner.removeProperty(service, DBCPConnectionPool.KERBEROS_CREDENTIALS_SERVICE); | ||
runner.assertValid(service); | ||
|
||
// kerberos user service with direct principal + password is invalid | ||
runner.setProperty(service, DBCPConnectionPool.KERBEROS_PRINCIPAL, "[email protected]"); | ||
runner.setProperty(service, DBCPConnectionPool.KERBEROS_PASSWORD, "fooPassword"); | ||
runner.assertNotValid(service); | ||
} | ||
|
||
@Test | ||
public void testNotValidWithNegativeMinIdleProperty() { | ||
runner.setProperty(service, DBCPConnectionPool.MIN_IDLE, "-1"); | ||
|
@@ -249,4 +284,24 @@ private void assertConnectionNotNullDynamicProperty(final String propertyName, f | |
assertNotNull(connection); | ||
} | ||
} | ||
|
||
private KerberosUserService enableKerberosUserService(final TestRunner runner) throws InitializationException { | ||
final KerberosUserService kerberosUserService = mock(KerberosUserService.class); | ||
when(kerberosUserService.getIdentifier()).thenReturn("userService1"); | ||
runner.addControllerService(kerberosUserService.getIdentifier(), kerberosUserService); | ||
runner.enableControllerService(kerberosUserService); | ||
return kerberosUserService; | ||
} | ||
|
||
private KerberosCredentialsService enabledKerberosCredentialsService(final TestRunner runner) throws InitializationException { | ||
final KerberosCredentialsService credentialsService = mock(KerberosCredentialsService.class); | ||
when(credentialsService.getIdentifier()).thenReturn("credsService1"); | ||
when(credentialsService.getPrincipal()).thenReturn("principal1"); | ||
when(credentialsService.getKeytab()).thenReturn("keytab1"); | ||
|
||
runner.addControllerService(credentialsService.getIdentifier(), credentialsService); | ||
runner.enableControllerService(credentialsService); | ||
return credentialsService; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
import org.apache.nifi.hadoop.KerberosProperties; | ||
import org.apache.nifi.kerberos.KerberosContext; | ||
import org.apache.nifi.kerberos.KerberosCredentialsService; | ||
import org.apache.nifi.kerberos.KerberosUserService; | ||
import org.apache.nifi.processor.Processor; | ||
import org.apache.nifi.reporting.InitializationException; | ||
import org.apache.nifi.util.MockKerberosContext; | ||
|
@@ -30,6 +31,9 @@ | |
|
||
import java.io.File; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class HadoopDBCPConnectionPoolTest { | ||
|
||
private File krbConfFile; | ||
|
@@ -75,7 +79,7 @@ public void testCustomValidateWhenAllowExplicitKeytab() throws InitializationExc | |
runner.removeProperty(hadoopDBCPService, kerberosProps.getKerberosKeytab()); | ||
runner.assertValid(hadoopDBCPService); | ||
|
||
// Configure a KeberosCredentialService, should become invalid | ||
// Configure a KerberosCredentialService, should become invalid | ||
final KerberosCredentialsService kerberosCredentialsService = new MockKerberosCredentialsService( | ||
"[email protected]", "src/test/resources/fake.keytab"); | ||
runner.addControllerService("kerb-credentials", kerberosCredentialsService); | ||
|
@@ -90,6 +94,32 @@ public void testCustomValidateWhenAllowExplicitKeytab() throws InitializationExc | |
// Remove principal property, only using keytab service, should become valid | ||
runner.removeProperty(hadoopDBCPService, kerberosProps.getKerberosPrincipal()); | ||
runner.assertValid(hadoopDBCPService); | ||
|
||
// Configure KerberosUserService, should be invalid since KerberosCredentialService also configured | ||
final KerberosUserService kerberosUserService = mock(KerberosUserService.class); | ||
when(kerberosUserService.getIdentifier()).thenReturn("userService1"); | ||
runner.addControllerService(kerberosUserService.getIdentifier(), kerberosUserService); | ||
runner.enableControllerService(kerberosUserService); | ||
runner.setProperty(hadoopDBCPService, HadoopDBCPConnectionPool.KERBEROS_USER_SERVICE, kerberosUserService.getIdentifier()); | ||
runner.assertNotValid(hadoopDBCPService); | ||
|
||
// Remove KerberosCredentialService, should be valid with only KerberosUserService | ||
runner.removeProperty(hadoopDBCPService, HadoopDBCPConnectionPool.KERBEROS_CREDENTIALS_SERVICE); | ||
runner.assertValid(hadoopDBCPService); | ||
|
||
// Configure explicit principal and keytab, should be invalid while kerberos user service is set | ||
runner.setProperty(hadoopDBCPService, kerberosProps.getKerberosPrincipal(), "[email protected]"); | ||
runner.setProperty(hadoopDBCPService, kerberosProps.getKerberosKeytab(), "src/test/resources/fake.keytab"); | ||
runner.assertNotValid(hadoopDBCPService); | ||
|
||
// Remove explicit keytab, set explicit password, still invalid while kerberos user service set | ||
runner.removeProperty(hadoopDBCPService, kerberosProps.getKerberosKeytab()); | ||
runner.setProperty(hadoopDBCPService, kerberosProps.getKerberosPassword(), "password"); | ||
runner.assertNotValid(hadoopDBCPService); | ||
|
||
// Remove kerberos user service, should be valid | ||
runner.removeProperty(hadoopDBCPService, HadoopDBCPConnectionPool.KERBEROS_USER_SERVICE); | ||
runner.assertValid(hadoopDBCPService); | ||
} | ||
|
||
@Test | ||
|