You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by lp...@apache.org on 2017/10/26 09:32:14 UTC
[60/71] [abbrv] ambari git commit: AMBARI-21307 Refactor - using the
LdapConnectionTemplate for ldap operations
http://git-wip-us.apache.org/repos/asf/ambari/blob/c15cc0f3/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionServiceTest.java
deleted file mode 100644
index 878d1f0..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionServiceTest.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * 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 org.apache.ambari.server.ldap.service.ads;
-
-
-import java.util.Map;
-
-import org.apache.ambari.server.ldap.domain.AmbariLdapConfigKeys;
-import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
-import org.apache.ambari.server.ldap.domain.TestAmbariLdapConfigurationFactory;
-import org.apache.ambari.server.ldap.service.LdapConnectionService;
-import org.apache.directory.api.ldap.model.constants.SchemaConstants;
-import org.apache.directory.ldap.client.api.LdapConnection;
-import org.easymock.EasyMockRule;
-import org.easymock.TestSubject;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.collect.Maps;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-
-public class DefaultLdapAttributeDetectionServiceTest {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(DefaultLdapAttributeDetectionServiceTest.class);
-
- @Rule
- public EasyMockRule mocks = new EasyMockRule(this);
-
- private AmbariLdapConfiguration testLdapConfiguration;
- private TestAmbariLdapConfigurationFactory ldapConfigurationFactory = new TestAmbariLdapConfigurationFactory();
-
- private LdapConnection connection;
-
- @TestSubject
- private DefaultLdapAttributeDetectionService attributeDetectionService = new DefaultLdapAttributeDetectionService();
-
- @Before
- public void before() {
-
- Map<String, Object> initialProps = Maps.newHashMap();
- initialProps.put(AmbariLdapConfigKeys.BIND_DN.key(), "");
- testLdapConfiguration = ldapConfigurationFactory.createLdapConfiguration(initialProps);
- }
-
- @Test
- public void testShouldUserNameAttributeBeDetectedWhenSearchReturnsValidUsers() throws Exception {
- // GIVEN
-// a set of entries returned from the LDAP search
-
- // WHEN
- AmbariLdapConfiguration ambariLdapConfiguration = attributeDetectionService.detectLdapUserAttributes(connection, testLdapConfiguration);
-
- // THEN
- Assert.assertNotNull(ambariLdapConfiguration);
- Assert.assertEquals("The username attribute is not the expected", "uid", ambariLdapConfiguration.userNameAttribute());
-
- }
-
-
- @Test
- public void functionalTest() throws Exception {
- // GIVEN
- AmbariLdapConfiguration ambariLdapConfiguration = ldapConfigurationFactory.createLdapConfiguration(getTestPropertiesMap());
- LdapConnectionService connectionService = new DefaultLdapConnectionService();
- LdapConnection ldapConnection = connectionService.createLdapConnection(ambariLdapConfiguration);
-
- // WHEN
- AmbariLdapConfiguration config = attributeDetectionService.detectLdapUserAttributes(ldapConnection, ambariLdapConfiguration);
- config = attributeDetectionService.detectLdapGroupAttributes(ldapConnection, ambariLdapConfiguration);
-
- Gson gson = new GsonBuilder().create();
- LOGGER.info(gson.toJson(config));
-
- // THEN
- ldapConnection.close();
-
- }
-
- private Map<String, Object> getTestPropertiesMap() {
- Map<String, Object> ldapPropsMap = Maps.newHashMap();
-
- ldapPropsMap.put(AmbariLdapConfigKeys.ANONYMOUS_BIND.key(), "true");
- ldapPropsMap.put(AmbariLdapConfigKeys.SERVER_HOST.key(), "ldap.forumsys.com");
- ldapPropsMap.put(AmbariLdapConfigKeys.SERVER_PORT.key(), "389");
- ldapPropsMap.put(AmbariLdapConfigKeys.BIND_DN.key(), "cn=read-only-admin,dc=example,dc=com");
- ldapPropsMap.put(AmbariLdapConfigKeys.BIND_PASSWORD.key(), "password");
- ldapPropsMap.put(AmbariLdapConfigKeys.DN_ATTRIBUTE.key(), SchemaConstants.CN_AT);
-
- ldapPropsMap.put(AmbariLdapConfigKeys.USER_SEARCH_BASE.key(), "dc=example,dc=com");
- ldapPropsMap.put(AmbariLdapConfigKeys.GROUP_SEARCH_BASE.key(), "dc=example,dc=com");
-
- return ldapPropsMap;
-
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/c15cc0f3/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java
deleted file mode 100644
index 2844054..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * 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 org.apache.ambari.server.ldap.service.ads;
-
-import static org.junit.Assert.assertNotNull;
-
-import java.util.Map;
-
-import org.apache.ambari.server.ldap.domain.AmbariLdapConfigKeys;
-import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
-import org.apache.ambari.server.ldap.domain.TestAmbariLdapConfigurationFactory;
-import org.apache.ambari.server.ldap.service.LdapConfigurationService;
-import org.apache.ambari.server.ldap.service.LdapConnectionService;
-import org.apache.directory.api.ldap.model.constants.SchemaConstants;
-import org.apache.directory.api.ldap.model.cursor.EntryCursor;
-import org.apache.directory.api.ldap.model.entry.Entry;
-import org.apache.directory.api.ldap.model.message.SearchScope;
-import org.apache.directory.ldap.client.api.LdapConnection;
-import org.apache.directory.ldap.client.api.LdapConnectionConfig;
-import org.apache.directory.ldap.client.api.LdapNetworkConnection;
-import org.apache.directory.ldap.client.api.search.FilterBuilder;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.collect.Maps;
-
-public class DefaultLdapConfigurationServiceTest {
- private static final Logger LOGGER = LoggerFactory.getLogger(DefaultLdapConfigurationService.class);
- private static final String TEST_USER = "einstein";
-
- private TestAmbariLdapConfigurationFactory ldapConfigurationFactory = new TestAmbariLdapConfigurationFactory();
-
- LdapConfigurationService ldapConfigurationService = new DefaultLdapConfigurationService();
-
-
- @Test
- public void testCheckAttributes() throws Exception {
-
- // WHEN
- LdapConnectionConfig config = new LdapConnectionConfig();
- config.setLdapHost("172.22.112.167");
- config.setLdapPort(389);
- LdapConnection connection = new LdapNetworkConnection(config);
-
- // THEN
- connection.bind("CN=Robert Levas,CN=Users,DC=HWQE,DC=HORTONWORKS,DC=COM", "Hadoop1234");
-
- String filter = FilterBuilder.and(
- FilterBuilder.equal(SchemaConstants.OBJECT_CLASS_AT, "person"),
- FilterBuilder.equal("name", "User1 Levas")).toString();
-
- EntryCursor cursor = connection.search("OU=levas,DC=hwqe,DC=hortonworks,DC=com", filter, SearchScope.SUBTREE);
-
- for (Entry entry : cursor) {
- assertNotNull(entry);
- System.out.println(entry);
- }
-
- cursor.close();
-
- }
-
- @Test
- public void testCheckUserAttributes() throws Exception {
- // GIVEN
- Map<String, Object> ldapPropsMap = Maps.newHashMap();
-
- ldapPropsMap.put(AmbariLdapConfigKeys.ANONYMOUS_BIND.key(), "true");
- ldapPropsMap.put(AmbariLdapConfigKeys.SERVER_HOST.key(), "ldap.forumsys.com");
- ldapPropsMap.put(AmbariLdapConfigKeys.SERVER_PORT.key(), "389");
- ldapPropsMap.put(AmbariLdapConfigKeys.BIND_DN.key(), "dc=example,dc=com");
-
- ldapPropsMap.put(AmbariLdapConfigKeys.USER_OBJECT_CLASS.key(), SchemaConstants.PERSON_OC);
- ldapPropsMap.put(AmbariLdapConfigKeys.USER_NAME_ATTRIBUTE.key(), SchemaConstants.UID_AT);
- ldapPropsMap.put(AmbariLdapConfigKeys.USER_SEARCH_BASE.key(), "dc=example,dc=com");
-
-
- AmbariLdapConfiguration ambariLdapConfiguration = ldapConfigurationFactory.createLdapConfiguration(ldapPropsMap);
- LdapConnectionService connectionService = new DefaultLdapConnectionService();
- LdapConnection ldapConnection = connectionService.createLdapConnection(ambariLdapConfiguration);
-
- ldapConfigurationService.checkUserAttributes(ldapConnection, "einstein", "", ambariLdapConfiguration);
- }
-
- @Test
- public void testRetrieveGorupsForuser() throws Exception {
- // GIVEN
- Map<String, Object> ldapPropsMap = Maps.newHashMap();
-
- ldapPropsMap.put(AmbariLdapConfigKeys.ANONYMOUS_BIND.key(), "true");
- ldapPropsMap.put(AmbariLdapConfigKeys.SERVER_HOST.key(), "ldap.forumsys.com");
- ldapPropsMap.put(AmbariLdapConfigKeys.SERVER_PORT.key(), "389");
- ldapPropsMap.put(AmbariLdapConfigKeys.BIND_DN.key(), "dc=example,dc=com");
-
- ldapPropsMap.put(AmbariLdapConfigKeys.USER_OBJECT_CLASS.key(), SchemaConstants.PERSON_OC);
- ldapPropsMap.put(AmbariLdapConfigKeys.USER_NAME_ATTRIBUTE.key(), SchemaConstants.UID_AT);
- ldapPropsMap.put(AmbariLdapConfigKeys.USER_SEARCH_BASE.key(), "dc=example,dc=com");
-
-
- AmbariLdapConfiguration ambariLdapConfiguration = ldapConfigurationFactory.createLdapConfiguration(ldapPropsMap);
- LdapConnectionService connectionService = new DefaultLdapConnectionService();
- LdapConnection ldapConnection = connectionService.createLdapConnection(ambariLdapConfiguration);
-
- ldapConfigurationService.checkGroupAttributes(ldapConnection, "uid=einstein,dc=example,dc=com", ambariLdapConfiguration);
- }
-
- @Test
- public void testListSupportedProperties(){
- StringBuilder sb = new StringBuilder().append(System.lineSeparator());
- for (AmbariLdapConfigKeys configKey : AmbariLdapConfigKeys.values()) {
- sb.append(configKey.key()).append(System.lineSeparator());
- }
- LOGGER.info(sb.toString());
-
- }
-}
\ No newline at end of file