use of org.apache.accumulo.harness.TestingKdc in project accumulo by apache.
the class SimpleProxyBase method setup.
@Before
public void setup() throws Exception {
// Create a new client for each test
if (isKerberosEnabled()) {
UserGroupInformation.loginUserFromKeytab(clientPrincipal, clientKeytab.getAbsolutePath());
proxyClient = new TestProxyClient(hostname, proxyPort, factory, proxyPrimary, UserGroupInformation.getCurrentUser());
client = proxyClient.proxy();
creds = client.login(clientPrincipal, properties);
TestingKdc kdc = getKdc();
final ClusterUser user = kdc.getClientPrincipal(0);
// Create another user
client.createLocalUser(creds, user.getPrincipal(), s2bb("unused"));
// Login in as that user we just created
UserGroupInformation.loginUserFromKeytab(user.getPrincipal(), user.getKeytab().getAbsolutePath());
final UserGroupInformation badUgi = UserGroupInformation.getCurrentUser();
// Get a "Credentials" object for the proxy
TestProxyClient badClient = new TestProxyClient(hostname, proxyPort, factory, proxyPrimary, badUgi);
try {
Client badProxy = badClient.proxy();
badLogin = badProxy.login(user.getPrincipal(), properties);
} finally {
badClient.close();
}
// Log back in as the test user
UserGroupInformation.loginUserFromKeytab(clientPrincipal, clientKeytab.getAbsolutePath());
// Drop test user, invalidating the credentials (not to mention not having the krb credentials anymore)
client.dropLocalUser(creds, user.getPrincipal());
} else {
proxyClient = new TestProxyClient(hostname, proxyPort, factory);
client = proxyClient.proxy();
creds = client.login("root", properties);
// Create 'user'
client.createLocalUser(creds, "user", s2bb(SharedMiniClusterBase.getRootPassword()));
// Log in as 'user'
badLogin = client.login("user", properties);
// Drop 'user', invalidating the credentials
client.dropLocalUser(creds, "user");
}
// Create some unique names for tables, namespaces, etc.
String[] uniqueNames = getUniqueNames(2);
// Create a general table to be used
tableName = uniqueNames[0];
client.createTable(creds, tableName, true, TimeType.MILLIS);
// Create a general namespace to be used
namespaceName = uniqueNames[1];
client.createNamespace(creds, namespaceName);
}
use of org.apache.accumulo.harness.TestingKdc in project accumulo by apache.
the class KerberosReplicationIT method startKdc.
@BeforeClass
public static void startKdc() throws Exception {
kdc = new TestingKdc();
kdc.start();
krbEnabledForITs = System.getProperty(MiniClusterHarness.USE_KERBEROS_FOR_IT_OPTION);
if (null == krbEnabledForITs || !Boolean.parseBoolean(krbEnabledForITs)) {
System.setProperty(MiniClusterHarness.USE_KERBEROS_FOR_IT_OPTION, "true");
}
rootUser = kdc.getRootUser();
}
use of org.apache.accumulo.harness.TestingKdc in project accumulo by apache.
the class SimpleProxyBase method setUpProxy.
/**
* Does the actual test setup, invoked by the concrete test class
*/
public static void setUpProxy() throws Exception {
assertNotNull("Implementations must initialize the TProtocolFactory", factory);
Connector c = SharedMiniClusterBase.getConnector();
Instance inst = c.getInstance();
waitForAccumulo(c);
hostname = InetAddress.getLocalHost().getCanonicalHostName();
Properties props = new Properties();
props.put("instance", inst.getInstanceName());
props.put("zookeepers", inst.getZooKeepers());
final String tokenClass;
if (isKerberosEnabled()) {
tokenClass = KerberosToken.class.getName();
TestingKdc kdc = getKdc();
// Create a principal+keytab for the proxy
proxyKeytab = new File(kdc.getKeytabDir(), "proxy.keytab");
hostname = InetAddress.getLocalHost().getCanonicalHostName();
// Set the primary because the client needs to know it
proxyPrimary = "proxy";
// Qualify with an instance
proxyPrincipal = proxyPrimary + "/" + hostname;
kdc.createPrincipal(proxyKeytab, proxyPrincipal);
// Tack on the realm too
proxyPrincipal = kdc.qualifyUser(proxyPrincipal);
props.setProperty("kerberosPrincipal", proxyPrincipal);
props.setProperty("kerberosKeytab", proxyKeytab.getCanonicalPath());
props.setProperty("thriftServerType", "sasl");
// Enabled kerberos auth
Configuration conf = new Configuration(false);
conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION, "kerberos");
UserGroupInformation.setConfiguration(conf);
// Login for the Proxy itself
UserGroupInformation.loginUserFromKeytab(proxyPrincipal, proxyKeytab.getAbsolutePath());
// User for tests
ClusterUser user = kdc.getRootUser();
clientPrincipal = user.getPrincipal();
clientKeytab = user.getKeytab();
} else {
clientPrincipal = "root";
tokenClass = PasswordToken.class.getName();
properties.put("password", SharedMiniClusterBase.getRootPassword());
hostname = "localhost";
}
props.put("tokenClass", tokenClass);
ClientConfiguration clientConfig = SharedMiniClusterBase.getCluster().getClientConfig();
String clientConfPath = new File(SharedMiniClusterBase.getCluster().getConfig().getConfDir(), "client.conf").getAbsolutePath();
props.put("clientConfigurationFile", clientConfPath);
properties.put("clientConfigurationFile", clientConfPath);
proxyPort = PortUtils.getRandomFreePort();
proxyServer = Proxy.createProxyServer(HostAndPort.fromParts(hostname, proxyPort), factory, props, clientConfig).server;
while (!proxyServer.isServing()) sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
}
use of org.apache.accumulo.harness.TestingKdc in project accumulo by apache.
the class KerberosClientOptsTest method startKdc.
@BeforeClass
public static void startKdc() throws Exception {
kdc = new TestingKdc();
kdc.start();
}
use of org.apache.accumulo.harness.TestingKdc in project accumulo by apache.
the class KerberosTokenEmbeddedKDCTest method startKdc.
@BeforeClass
public static void startKdc() throws Exception {
kdc = new TestingKdc();
kdc.start();
}
Aggregations