Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions hbase-http/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
</exclusion>
<exclusion>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,73 @@
import java.net.HttpURLConnection;
import java.net.URL;
import org.apache.commons.codec.binary.Base64;
import org.apache.directory.server.core.integ.CreateLdapServerRule;
import org.apache.directory.ldap.client.template.LdapConnectionTemplate;
import org.apache.directory.server.core.api.DirectoryService;
import org.apache.directory.server.core.integ.ApacheDSTestExtension;
import org.apache.directory.server.ldap.LdapServer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.http.resource.JerseyResource;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.extension.ExtendWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Base class for setting up and testing an HTTP server with LDAP authentication.
*/
@ExtendWith(ApacheDSTestExtension.class)
public class LdapServerTestBase extends HttpServerFunctionalTest {
private static final Logger LOG = LoggerFactory.getLogger(LdapServerTestBase.class);

@ClassRule
public static CreateLdapServerRule ldapRule = new CreateLdapServerRule();

protected static HttpServer server;
protected static URL baseUrl;

/**
* The following fields are set by ApacheDSTestExtension. These are normally inherited from
* AbstractLdapTestUnit, but this class already has a parent. We only use ldapServer, but
* declaring that one alone does not work.
*/

/** The class DirectoryService instance */
public static DirectoryService classDirectoryService;

/** The test DirectoryService instance */
public static DirectoryService methodDirectoryService;

/** The current DirectoryService instance */
public static DirectoryService directoryService;

/** The class LdapServer instance */
public static LdapServer classLdapServer;

/** The test LdapServer instance */
public static LdapServer methodLdapServer;

/** The current LdapServer instance */
public static LdapServer ldapServer;

/** The Ldap connection template */
public static LdapConnectionTemplate ldapConnectionTemplate;

/** The current revision */
public static long revision = 0L;

/**
* End of fields required by ApacheDSTestExtension
*/

private static final String AUTH_TYPE = "Basic ";

protected static LdapServer getLdapServer() {
return classLdapServer;
}

/**
* Sets up the HTTP server with LDAP authentication before any tests are run.
* @throws Exception if an error occurs during server setup
*/
@BeforeClass
@BeforeAll
public static void setupServer() throws Exception {
Configuration conf = new Configuration();
setLdapConfigurations(conf);
Expand All @@ -66,7 +105,7 @@ public static void setupServer() throws Exception {
* Stops the HTTP server after all tests are completed.
* @throws Exception if an error occurs during server shutdown
*/
@AfterClass
@AfterAll
public static void stopServer() throws Exception {
try {
if (null != server) {
Expand All @@ -90,8 +129,8 @@ protected static void setLdapConfigurations(Configuration conf) {
conf.set(HttpServer.FILTER_INITIALIZERS_PROPERTY,
"org.apache.hadoop.hbase.http.lib.AuthenticationFilterInitializer");
conf.set("hadoop.http.authentication.type", "ldap");
conf.set("hadoop.http.authentication.ldap.providerurl", String.format("ldap://%s:%s",
LdapConstants.LDAP_SERVER_ADDR, ldapRule.getLdapServer().getPort()));
conf.set("hadoop.http.authentication.ldap.providerurl",
String.format("ldap://%s:%s", LdapConstants.LDAP_SERVER_ADDR, getLdapServer().getPort()));
conf.set("hadoop.http.authentication.ldap.enablestarttls", "false");
conf.set("hadoop.http.authentication.ldap.basedn", LdapConstants.LDAP_BASE_DN);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
*/
package org.apache.hadoop.hbase.http;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.util.concurrent.TimeUnit;
import org.apache.directory.server.annotations.CreateLdapServer;
import org.apache.directory.server.annotations.CreateTransport;
import org.apache.directory.server.core.annotations.ApplyLdifs;
Expand All @@ -29,21 +30,19 @@
import org.apache.directory.server.core.annotations.CreatePartition;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.CommonConfigurationKeys;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.http.resource.JerseyResource;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Test class for admin ACLs with LDAP authentication on the HttpServer.
*/
@Category({ MiscTests.class, SmallTests.class })
@Tag("org.apache.hadoop.hbase.testclassification.MiscTests")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to use MiscTests.class.getName? Or maybe we should introduce a String constants for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, MiscTests.getClass().getName() does not work.
But we can add String constants.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened #7322

@Tag("org.apache.hadoop.hbase.testclassification.SmallTests")
@CreateLdapServer(
transports = { @CreateTransport(protocol = "LDAP", address = LdapConstants.LDAP_SERVER_ADDR), })
@CreateDS(name = "TestLdapAdminACL", allowAnonAccess = true,
Expand All @@ -55,18 +54,16 @@

"dn: uid=jdoe," + LdapConstants.LDAP_BASE_DN, "cn: John Doe", "sn: Doe",
"objectClass: inetOrgPerson", "uid: jdoe", "userPassword: secure123" })
@Timeout(value = 1, unit = TimeUnit.MINUTES)
public class TestLdapAdminACL extends LdapServerTestBase {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestLdapAdminACL.class);
private static final Logger LOG = LoggerFactory.getLogger(TestLdapAdminACL.class);

private static final String ADMIN_CREDENTIALS = "bjones:p@ssw0rd";
private static final String NON_ADMIN_CREDENTIALS = "jdoe:secure123";
private static final String WRONG_CREDENTIALS = "bjones:password";

@BeforeClass
@BeforeAll
public static void setupServer() throws Exception {
Configuration conf = new Configuration();
setLdapConfigurationWithACLs(conf);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,26 @@
*/
package org.apache.hadoop.hbase.http;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.util.concurrent.TimeUnit;
import org.apache.directory.server.annotations.CreateLdapServer;
import org.apache.directory.server.annotations.CreateTransport;
import org.apache.directory.server.core.annotations.ApplyLdifs;
import org.apache.directory.server.core.annotations.ContextEntry;
import org.apache.directory.server.core.annotations.CreateDS;
import org.apache.directory.server.core.annotations.CreatePartition;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

/**
* Test class for LDAP authentication on the HttpServer.
*/
@Category({ MiscTests.class, SmallTests.class })
@Tag("org.apache.hadoop.hbase.testclassification.MiscTests")
@Tag("org.apache.hadoop.hbase.testclassification.SmallTests")
@CreateLdapServer(
transports = { @CreateTransport(protocol = "LDAP", address = LdapConstants.LDAP_SERVER_ADDR), })
@CreateDS(name = "TestLdapHttpServer", allowAnonAccess = true,
Expand All @@ -46,12 +45,9 @@
+ "dc: example\n" + "objectClass: top\n" + "objectClass: domain\n\n")) })
@ApplyLdifs({ "dn: uid=bjones," + LdapConstants.LDAP_BASE_DN, "cn: Bob Jones", "sn: Jones",
"objectClass: inetOrgPerson", "uid: bjones", "userPassword: p@ssw0rd" })
@Timeout(value = 1, unit = TimeUnit.MINUTES)
public class TestLdapHttpServer extends LdapServerTestBase {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestLdapHttpServer.class);

private static final String BJONES_CREDENTIALS = "bjones:p@ssw0rd";
private static final String WRONG_CREDENTIALS = "bjones:password";

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1069,8 +1069,8 @@
<!-- Still need this to ignore some errors when building javadoc-->
<doclint>none</doclint>
<!-- Required for testing LDAP integration -->
<apacheds.version>2.0.0.AM26</apacheds.version>
<ldap-api.version>2.0.0</ldap-api.version>
<apacheds.version>2.0.0.AM27</apacheds.version>
<ldap-api.version>2.1.7</ldap-api.version>
<webjars-dir>${project.build.directory}/META-INF/resources/webjars</webjars-dir>
<!-- Web UI dependencies -->
<bootstrap.version>5.3.3</bootstrap.version>
Expand Down