-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests, documentation, and a configuration template, for Shiro->LDAP s…
…upport ref: #605
- Loading branch information
1 parent
3fcb7b6
commit f8bb73b
Showing
13 changed files
with
348 additions
and
38 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
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
59 changes: 59 additions & 0 deletions
59
src/server/src/test/java/io/cassandrareaper/acceptance/ReaperShiroIT.java
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* | ||
* Copyright 2019-2019 The Last Pickle Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.cassandrareaper.acceptance; | ||
|
||
import java.util.Optional; | ||
|
||
import cucumber.api.CucumberOptions; | ||
import cucumber.api.junit.Cucumber; | ||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.runner.RunWith; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
@RunWith(Cucumber.class) | ||
@CucumberOptions( | ||
features = "classpath:io.cassandrareaper.acceptance/access_control.feature", | ||
plugin = {"pretty"} | ||
) | ||
public final class ReaperShiroIT { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(ReaperIT.class); | ||
private static ReaperTestJettyRunner runner; | ||
private static final String MEMORY_CONFIG_FILE = "cassandra-reaper-access-control-enabled-at.yaml"; | ||
|
||
private ReaperShiroIT() {} | ||
|
||
@BeforeClass | ||
public static void setUp() throws Exception { | ||
LOG.info( | ||
"setting up testing Reaper runner with {} seed hosts defined and memory storage", | ||
TestContext.TEST_CLUSTER_SEED_HOSTS.size()); | ||
|
||
runner = new ReaperTestJettyRunner(MEMORY_CONFIG_FILE, Optional.empty()); | ||
BasicSteps.addReaperRunner(runner); | ||
} | ||
|
||
@AfterClass | ||
public static void tearDown() { | ||
LOG.info("Stopping reaper service..."); | ||
runner.runnerInstance.after(); | ||
} | ||
|
||
} |
79 changes: 79 additions & 0 deletions
79
src/server/src/test/java/io/cassandrareaper/resources/auth/EmbeddedLdapTest.java
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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* | ||
* Copyright 2019-2019 The Last Pickle Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.cassandrareaper.resources.auth; | ||
|
||
import java.util.List; | ||
|
||
|
||
import com.unboundid.ldap.sdk.LDAPInterface; | ||
import com.unboundid.ldap.sdk.SearchResult; | ||
import com.unboundid.ldap.sdk.SearchResultEntry; | ||
import com.unboundid.ldap.sdk.SearchScope; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.zapodot.junit.ldap.EmbeddedLdapRule; | ||
import org.zapodot.junit.ldap.EmbeddedLdapRuleBuilder; | ||
|
||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
/** | ||
* Test using objectclass: org.zapodot:embedded-ldap-junit | ||
*/ | ||
public final class EmbeddedLdapTest { | ||
|
||
public static final String DOMAIN_DSN = "dc=cassandra-reaper,dc=io"; | ||
|
||
@Rule | ||
public EmbeddedLdapRule embeddedLdapRule | ||
= EmbeddedLdapRuleBuilder.newInstance().usingDomainDsn(DOMAIN_DSN).importingLdifs("test-ldap-users.ldif").build(); | ||
|
||
@Test | ||
public void shouldFindAllPersons() throws Exception { | ||
LDAPInterface ldapConnection = embeddedLdapRule.ldapConnection(); | ||
SearchResult searchResult = ldapConnection.search(DOMAIN_DSN, SearchScope.SUB, "(objectClass=person)"); | ||
assertThat(3, equalTo(searchResult.getEntryCount())); | ||
List<SearchResultEntry> searchEntries = searchResult.getSearchEntries(); | ||
assertThat(searchEntries.get(0).getAttribute("cn").getValue(), equalTo("John Steinbeck")); | ||
assertThat(searchEntries.get(1).getAttribute("cn").getValue(), equalTo("Micha Kops")); | ||
assertThat(searchEntries.get(2).getAttribute("cn").getValue(), equalTo("Santa Claus")); | ||
} | ||
|
||
@Test | ||
public void shouldFindExactPerson0() throws Exception { | ||
LDAPInterface ldapConnection = embeddedLdapRule.ldapConnection(); | ||
|
||
SearchResult searchResult = ldapConnection | ||
.search("cn=John Steinbeck,ou=Users,dc=cassandra-reaper,dc=io", SearchScope.SUB, "(objectClass=person)"); | ||
|
||
assertThat(1, equalTo(searchResult.getEntryCount())); | ||
assertThat(searchResult.getSearchEntries().get(0).getAttribute("cn").getValue(), equalTo("John Steinbeck")); | ||
} | ||
|
||
@Test | ||
public void shouldFindExactPerson1() throws Exception { | ||
LDAPInterface ldapConnection = embeddedLdapRule.ldapConnection(); | ||
|
||
SearchResult searchResult = ldapConnection | ||
.search("uid=sclaus,ou=Users,dc=cassandra-reaper,dc=io", SearchScope.SUB, "(objectClass=person)"); | ||
|
||
assertThat(1, equalTo(searchResult.getEntryCount())); | ||
assertThat(searchResult.getSearchEntries().get(0).getAttribute("cn").getValue(), equalTo("Santa Claus")); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/server/src/test/java/io/cassandrareaper/resources/auth/LoginResourceLdapTest.java
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* | ||
* Copyright 2019-2019 The Last Pickle Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.cassandrareaper.resources.auth; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
import org.apache.shiro.authc.UsernamePasswordToken; | ||
import org.apache.shiro.config.Ini; | ||
import org.apache.shiro.io.ResourceUtils; | ||
import org.apache.shiro.web.config.WebIniSecurityManagerFactory; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.zapodot.junit.ldap.EmbeddedLdapRule; | ||
import org.zapodot.junit.ldap.EmbeddedLdapRuleBuilder; | ||
|
||
import static io.cassandrareaper.resources.auth.EmbeddedLdapTest.DOMAIN_DSN; | ||
|
||
|
||
public final class LoginResourceLdapTest { | ||
|
||
@Rule | ||
public EmbeddedLdapRule embeddedLdapRule | ||
= EmbeddedLdapRuleBuilder.newInstance().usingDomainDsn(DOMAIN_DSN).importingLdifs("test-ldap-users.ldif").build(); | ||
|
||
@Test | ||
public void testLoginLdap() throws IOException { | ||
try (InputStream is = ResourceUtils.getInputStreamForPath("classpath:test-shiro-ldap.ini")) { | ||
Ini ini = new Ini(); | ||
ini.load(is); | ||
int port = embeddedLdapRule.embeddedServerPort(); | ||
ini.setSectionProperty("main", "ldapRealm.contextFactory.url", "ldap://localhost:" + port); | ||
new WebIniSecurityManagerFactory(ini).getInstance().authenticate(new UsernamePasswordToken("sclaus", "abcdefg")); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.