http://git-wip-us.apache.org/repos/asf/ambari/blob/f76c87a6/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserResourceProviderDBTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserResourceProviderDBTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserResourceProviderDBTest.java index c4f0f34..db7548f 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserResourceProviderDBTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserResourceProviderDBTest.java @@ -23,6 +23,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.sql.SQLException; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; @@ -45,8 +46,8 @@ import org.apache.ambari.server.controller.utilities.PropertyHelper; import org.apache.ambari.server.orm.InMemoryDefaultTestModule; import org.apache.ambari.server.security.TestAuthenticationFactory; import org.apache.ambari.server.security.authorization.AuthorizationHelper; -import org.junit.AfterClass; -import org.junit.BeforeClass; +import org.junit.After; +import org.junit.Before; import org.junit.Test; import org.powermock.core.classloader.annotations.PrepareForTest; import org.springframework.security.core.Authentication; @@ -63,221 +64,232 @@ import com.google.inject.persist.PersistService; */ @PrepareForTest({AuthorizationHelper.class}) public class UserResourceProviderDBTest { - private static Injector injector; - private static AmbariManagementController amc; - private static Resource.Type userType = Resource.Type.User; - private static UserResourceProvider userResourceProvider; - private static String JDBC_IN_MEMORY_URL_CREATE = - String.format("jdbc:derby:memory:myDB/%s;create=true", Configuration.DEFAULT_DERBY_SCHEMA); - private static String JDBC_IN_MEMORY_URL_DROP = - String.format("jdbc:derby:memory:myDB/%s;drop=true", Configuration.DEFAULT_DERBY_SCHEMA); - - /** - * Sets up the in-memory database for the test suite. - */ - @BeforeClass - public static void setupInMemoryDB() { - InMemoryDefaultTestModule testModule = new InMemoryDefaultTestModule(); - - Properties properties = testModule.getProperties(); - properties.setProperty(Configuration.SERVER_JDBC_URL.getKey(), JDBC_IN_MEMORY_URL_CREATE); - properties.setProperty(Configuration.SERVER_JDBC_DRIVER.getKey(), Configuration.JDBC_IN_MEMORY_DRIVER); - injector = Guice.createInjector(testModule); - - injector.getInstance(PersistService.class).start(); - - amc = injector.getInstance(AmbariManagementController.class); - - Set<String> propertyIds = PropertyHelper.getPropertyIds(userType); - Map<Resource.Type,String> keyPropertyIds = PropertyHelper.getKeyPropertyIds(userType); - - userResourceProvider = new UserResourceProvider(propertyIds, keyPropertyIds, amc); + private static Injector injector; + private static AmbariManagementController amc; + private static Resource.Type userType = Resource.Type.User; + private static UserResourceProvider userResourceProvider; + private static String JDBC_IN_MEMORY_URL_CREATE = + String.format("jdbc:derby:memory:myDB/%s;create=true", Configuration.DEFAULT_DERBY_SCHEMA); + private static String JDBC_IN_MEMORY_URL_DROP = + String.format("jdbc:derby:memory:myDB/%s;drop=true", Configuration.DEFAULT_DERBY_SCHEMA); + + /** + * Sets up the in-memory database for the test suite. + */ + @Before + public void setupInMemoryDB() { + InMemoryDefaultTestModule testModule = new InMemoryDefaultTestModule(); + + Properties properties = testModule.getProperties(); + properties.setProperty(Configuration.SERVER_JDBC_URL.getKey(), JDBC_IN_MEMORY_URL_CREATE); + properties.setProperty(Configuration.SERVER_JDBC_DRIVER.getKey(), Configuration.JDBC_IN_MEMORY_DRIVER); + injector = Guice.createInjector(testModule); + + injector.getInstance(PersistService.class).start(); + + amc = injector.getInstance(AmbariManagementController.class); + + Set<String> propertyIds = PropertyHelper.getPropertyIds(userType); + Map<Resource.Type, String> keyPropertyIds = PropertyHelper.getKeyPropertyIds(userType); + + userResourceProvider = new UserResourceProvider(propertyIds, keyPropertyIds, amc); + injector.injectMembers(userResourceProvider); + } + + /** + * Closes the JPA connection after executing the test suite. + */ + @After + public void teardownInMemoryDB() throws AmbariException, SQLException { + if (injector != null) { + H2DatabaseCleaner.clearDatabaseAndStopPersistenceService(injector); } + } + + /** + * Creates a user, retrieves it and verifies that the username matches the one that was + * created. Deletes the created user and verifies that the username was deleted. + * + * @throws Exception + */ + @Test + public void createUserTest() throws Exception { + Authentication authentication = TestAuthenticationFactory.createAdministrator(); + SecurityContextHolder.getContext().setAuthentication(authentication); + + // create a new user viewUser + Map<String, Object> requestProperties = new HashMap<>(); + requestProperties.put(UserResourceProvider.USER_USERNAME_PROPERTY_ID, "viewUser"); + requestProperties.put(UserResourceProvider.USER_PASSWORD_PROPERTY_ID, "password"); + requestProperties.put(UserResourceProvider.USER_ADMIN_PROPERTY_ID, false); + requestProperties.put(UserResourceProvider.USER_ACTIVE_PROPERTY_ID, true); + + Request request = PropertyHelper.getCreateRequest(Collections.singleton(requestProperties), null); + RequestStatus requestStatus = userResourceProvider.createResources(request); + assertNotNull(requestStatus); + + // verify the created username + Request getRequest = PropertyHelper.getReadRequest(new HashSet<>(Collections.singleton("Users"))); + Predicate predicate = new PredicateBuilder() + .property(UserResourceProvider.USER_USERNAME_PROPERTY_ID).equals("viewUser").toPredicate(); + Set<Resource> resources = userResourceProvider.getResources(getRequest, predicate); + assertEquals(resources.size(), 1); + Resource resource = resources.iterator().next(); + + String userName = resource.getPropertyValue(UserResourceProvider.USER_USERNAME_PROPERTY_ID).toString(); + assertEquals("viewuser", userName); + + // delete the created username + requestStatus = userResourceProvider.deleteResources(request, predicate); + assertNotNull(requestStatus); + + // verify that the username was deleted + resources = userResourceProvider.getResources(getRequest, null); + assertEquals(resources.size(), 0); + } + + /** + * Creates a username in all lowercase. Attempt to add another user whose username differs only + * by case to the previously added user. Verifies that the user cannot be added. + * + * @throws Exception + */ + @Test + public void createExistingUserTest() throws Exception { + Authentication authentication = TestAuthenticationFactory.createAdministrator(); + SecurityContextHolder.getContext().setAuthentication(authentication); - /** - * Closes the JPA connection after executing the test suite. - */ - @AfterClass - public static void teardownInMemoryDB() throws AmbariException, SQLException { - if (injector != null) { - H2DatabaseCleaner.clearDatabaseAndStopPersistenceService(injector); - } - } + /* add a new user */ + Map<String, Object> requestProperties = new HashMap<>(); + requestProperties.put(UserResourceProvider.USER_USERNAME_PROPERTY_ID, "abcd"); + requestProperties.put(UserResourceProvider.USER_PASSWORD_PROPERTY_ID, "password"); + requestProperties.put(UserResourceProvider.USER_ADMIN_PROPERTY_ID, false); + requestProperties.put(UserResourceProvider.USER_ACTIVE_PROPERTY_ID, true); - /** - * Creates a user, retrieves it and verifies that the username matches the one that was - * created. Deletes the created user and verifies that the username was deleted. - * - * @throws Exception - */ - @Test - public void createUserTest() throws Exception { - Authentication authentication = TestAuthenticationFactory.createAdministrator(); - SecurityContextHolder.getContext().setAuthentication(authentication); - - // create a new user viewUser - Map<String, Object> requestProperties = new HashMap<>(); - requestProperties.put(UserResourceProvider.USER_USERNAME_PROPERTY_ID, "viewUser"); - requestProperties.put(UserResourceProvider.USER_PASSWORD_PROPERTY_ID, "password"); - requestProperties.put(UserResourceProvider.USER_ADMIN_PROPERTY_ID, false); - requestProperties.put(UserResourceProvider.USER_ACTIVE_PROPERTY_ID, true); - - Request request = PropertyHelper.getCreateRequest(Collections.singleton(requestProperties), null); - RequestStatus requestStatus = userResourceProvider.createResources(request); - assertNotNull(requestStatus); - - // verify the created username - Request getRequest = PropertyHelper.getReadRequest(new HashSet<>(Arrays.asList("Users"))); - Predicate predicate = new PredicateBuilder() - .property(UserResourceProvider.USER_USERNAME_PROPERTY_ID).equals("viewUser").toPredicate(); - Set<Resource> resources = userResourceProvider.getResources(getRequest, predicate); - assertEquals(resources.size(), 1); - Resource resource = resources.iterator().next(); - - String userName = resource.getPropertyValue(UserResourceProvider.USER_USERNAME_PROPERTY_ID).toString(); - assertEquals(userName, "viewUser"); - - // delete the created username - requestStatus = userResourceProvider.deleteResources(request, predicate); - assertNotNull(requestStatus); - - // verify that the username was deleted - resources = userResourceProvider.getResources(getRequest, null); - assertEquals(resources.size(), 0); - } + Request request = PropertyHelper.getCreateRequest(Collections.singleton(requestProperties), null); + RequestStatus requestStatus = userResourceProvider.createResources(request); + assertNotNull(requestStatus); - /** - * Creates a username in all lowercase. Attempt to add another user whose username differs only - * by case to the previously added user. Verifies that the user cannot be added. - * - * @throws Exception - */ - @Test - public void createExistingUserTest() throws Exception { - Authentication authentication = TestAuthenticationFactory.createAdministrator(); - SecurityContextHolder.getContext().setAuthentication(authentication); + /* try with uppercase version of an existing user */ + requestProperties.put(UserResourceProvider.USER_USERNAME_PROPERTY_ID, "ABCD"); + request = PropertyHelper.getCreateRequest(Collections.singleton(requestProperties), null); + try { + requestStatus = userResourceProvider.createResources(request); + assertTrue("Should fail with user exists", false); + } catch (Exception ex) { + assertTrue(ex.getMessage().contains("User already exists")); + } - /* add a new user */ - Map<String, Object> requestProperties = new HashMap<>(); - requestProperties.put(UserResourceProvider.USER_USERNAME_PROPERTY_ID, "abcd"); - requestProperties.put(UserResourceProvider.USER_PASSWORD_PROPERTY_ID, "password"); - requestProperties.put(UserResourceProvider.USER_ADMIN_PROPERTY_ID, false); - requestProperties.put(UserResourceProvider.USER_ACTIVE_PROPERTY_ID, true); + // delete the created username + Predicate predicate = new PredicateBuilder() + .property(UserResourceProvider.USER_USERNAME_PROPERTY_ID).equals("abcd").toPredicate(); + requestStatus = userResourceProvider.deleteResources(request, predicate); + assertNotNull(requestStatus); + + // verify that the username was deleted + Request getRequest = PropertyHelper.getReadRequest(new HashSet<>(Arrays.asList("Users"))); + Set<Resource> resources = userResourceProvider.getResources(getRequest, null); + assertEquals(resources.size(), 0); + } + + /** + * Creates a user and retrieves the user using the same username but in lowercase. Verifies + * that the retrieval is successful and that the retrieved username is the same as the one + * that was used during creation. + * + * @throws Exception + */ + @Test + public void getExistingUser() throws Exception { + Authentication authentication = TestAuthenticationFactory.createAdministrator(); + SecurityContextHolder.getContext().setAuthentication(authentication); + + // create a new user viewUser + Map<String, Object> requestProperties = new HashMap<>(); + requestProperties.put(UserResourceProvider.USER_USERNAME_PROPERTY_ID, "viewUser"); + requestProperties.put(UserResourceProvider.USER_PASSWORD_PROPERTY_ID, "password"); + requestProperties.put(UserResourceProvider.USER_ADMIN_PROPERTY_ID, false); + requestProperties.put(UserResourceProvider.USER_ACTIVE_PROPERTY_ID, true); + + Request request = PropertyHelper.getCreateRequest(Collections.singleton(requestProperties), null); + RequestStatus requestStatus = userResourceProvider.createResources(request); + assertNotNull(requestStatus); + + // verify the created username + Request getRequest = PropertyHelper.getReadRequest(new HashSet<>(Arrays.asList("Users"))); + Predicate predicate = new PredicateBuilder() + .property(UserResourceProvider.USER_USERNAME_PROPERTY_ID).equals("viewuser").toPredicate(); + Set<Resource> resources = userResourceProvider.getResources(getRequest, predicate); + assertEquals(resources.size(), 1); + Resource resource = resources.iterator().next(); + + String userName = resource.getPropertyValue(UserResourceProvider.USER_USERNAME_PROPERTY_ID).toString(); + assertEquals("viewuser", userName); + + // delete the created username + requestStatus = userResourceProvider.deleteResources(request, predicate); + assertNotNull(requestStatus); + + // verify that the username was deleted + resources = userResourceProvider.getResources(getRequest, null); + assertEquals(resources.size(), 0); + } + + /** + * Adds an array of users, retrieves the users and verifies that the usernames do not differ + * from the ones that were used during creation. + * + * @throws Exception + */ + @Test + public void getAllUserTest() throws Exception { + Authentication authentication = TestAuthenticationFactory.createAdministrator(); + SecurityContextHolder.getContext().setAuthentication(authentication); + + List<String> userNames = Arrays.asList("user1", "uSer2", "User3", "useR4"); + List<String> lowercaseUserNames = new ArrayList<>(); + + for (String username : userNames) { + lowercaseUserNames.add(username.toLowerCase()); + } - Request request = PropertyHelper.getCreateRequest(Collections.singleton(requestProperties), null); - RequestStatus requestStatus = userResourceProvider.createResources(request); - assertNotNull(requestStatus); + for (String userName : userNames) { + Map<String, Object> requestProperties = new HashMap<>(); + requestProperties.put(UserResourceProvider.USER_USERNAME_PROPERTY_ID, userName); + requestProperties.put(UserResourceProvider.USER_PASSWORD_PROPERTY_ID, "password"); + requestProperties.put(UserResourceProvider.USER_ADMIN_PROPERTY_ID, false); + requestProperties.put(UserResourceProvider.USER_ACTIVE_PROPERTY_ID, true); - /* try with uppercase version of an existing user */ - requestProperties.put(UserResourceProvider.USER_USERNAME_PROPERTY_ID, "ABCD"); - request = PropertyHelper.getCreateRequest(Collections.singleton(requestProperties), null); - try { - requestStatus = userResourceProvider.createResources(request); - assertTrue("Should fail with user exists", false); - } - catch(Exception ex) { - assertTrue(ex.getMessage().contains("User abcd already exists")); - } - - // delete the created username - Predicate predicate = new PredicateBuilder() - .property(UserResourceProvider.USER_USERNAME_PROPERTY_ID).equals("abcd").toPredicate(); - requestStatus = userResourceProvider.deleteResources(request, predicate); - assertNotNull(requestStatus); - - // verify that the username was deleted - Request getRequest = PropertyHelper.getReadRequest(new HashSet<>(Arrays.asList("Users"))); - Set<Resource> resources = userResourceProvider.getResources(getRequest, null); - assertEquals(resources.size(), 0); + Request request = PropertyHelper.getCreateRequest(Collections.singleton(requestProperties), null); + RequestStatus requestStatus = userResourceProvider.createResources(request); + assertNotNull(requestStatus); } - /** - * Creates a user and retrieves the user using the same username but in lowercase. Verifies - * that the retrieval is successful and that the retrieved username is the same as the one - * that was used during creation. - * - * @throws Exception - */ - @Test - public void getExistingUserCaseInsensitiveTest() throws Exception { - Authentication authentication = TestAuthenticationFactory.createAdministrator(); - SecurityContextHolder.getContext().setAuthentication(authentication); - - // create a new user viewUser - Map<String, Object> requestProperties = new HashMap<>(); - requestProperties.put(UserResourceProvider.USER_USERNAME_PROPERTY_ID, "viewUser"); - requestProperties.put(UserResourceProvider.USER_PASSWORD_PROPERTY_ID, "password"); - requestProperties.put(UserResourceProvider.USER_ADMIN_PROPERTY_ID, false); - requestProperties.put(UserResourceProvider.USER_ACTIVE_PROPERTY_ID, true); - - Request request = PropertyHelper.getCreateRequest(Collections.singleton(requestProperties), null); - RequestStatus requestStatus = userResourceProvider.createResources(request); - assertNotNull(requestStatus); - - // verify the created username - Request getRequest = PropertyHelper.getReadRequest(new HashSet<>(Arrays.asList("Users"))); - Predicate predicate = new PredicateBuilder() - .property(UserResourceProvider.USER_USERNAME_PROPERTY_ID).equals("viewuser").toPredicate(); - Set<Resource> resources = userResourceProvider.getResources(getRequest, predicate); - assertEquals(resources.size(), 1); - Resource resource = resources.iterator().next(); - - String userName = resource.getPropertyValue(UserResourceProvider.USER_USERNAME_PROPERTY_ID).toString(); - assertEquals(userName, "viewUser"); - - // delete the created username - requestStatus = userResourceProvider.deleteResources(request, predicate); - assertNotNull(requestStatus); - - // verify that the username was deleted - resources = userResourceProvider.getResources(getRequest, null); - assertEquals(resources.size(), 0); + // verify the created username + Request getRequest = PropertyHelper.getReadRequest(Collections.singleton(("Users"))); + Set<Resource> resources = userResourceProvider.getResources(getRequest, null); + for (Resource resource : resources) { + System.out.println("Resource: " + resource.getPropertyValue(UserResourceProvider.USER_USERNAME_PROPERTY_ID).toString()); + } + for (String s: lowercaseUserNames) { + System.out.println("LC UN: " + s); + } + assertEquals(lowercaseUserNames.size(), resources.size()); + for (Resource resource : resources) { + String userName = resource.getPropertyValue(UserResourceProvider.USER_USERNAME_PROPERTY_ID).toString(); + assertTrue(lowercaseUserNames.contains(userName)); } - /** - * Adds an array of users, retrieves the users and verifies that the usernames do not differ - * from the ones that were used during creation. - * - * @throws Exception - */ - @Test - public void getAllUserTest() throws Exception { - Authentication authentication = TestAuthenticationFactory.createAdministrator(); - SecurityContextHolder.getContext().setAuthentication(authentication); - - List<String> userNames = Arrays.asList("user1", "uSer2", "User3", "useR4"); - - for (String userName : userNames) { - Map<String, Object> requestProperties = new HashMap<>(); - requestProperties.put(UserResourceProvider.USER_USERNAME_PROPERTY_ID, userName); - requestProperties.put(UserResourceProvider.USER_PASSWORD_PROPERTY_ID, "password"); - requestProperties.put(UserResourceProvider.USER_ADMIN_PROPERTY_ID, false); - requestProperties.put(UserResourceProvider.USER_ACTIVE_PROPERTY_ID, true); - - Request request = PropertyHelper.getCreateRequest(Collections.singleton(requestProperties), null); - RequestStatus requestStatus = userResourceProvider.createResources(request); - assertNotNull(requestStatus); - } - - // verify the created username - Request getRequest = PropertyHelper.getReadRequest(new HashSet<>(Arrays.asList("Users"))); - Set<Resource> resources = userResourceProvider.getResources(getRequest, null); - assertEquals(resources.size(), userNames.size()); - for (Resource resource : resources) { - String userName = resource.getPropertyValue(UserResourceProvider.USER_USERNAME_PROPERTY_ID).toString(); - assertTrue(userNames.contains(userName)); - } - - // delete the users - for (String userName : userNames) { - Predicate predicate = new PredicateBuilder() - .property(UserResourceProvider.USER_USERNAME_PROPERTY_ID).equals(userName).toPredicate(); - RequestStatus requestStatus = userResourceProvider.deleteResources(null /* not used */, predicate); - assertNotNull(requestStatus); - } - - // verify that the username was deleted - resources = userResourceProvider.getResources(getRequest, null); - assertEquals(resources.size(), 0); + // delete the users + for (String userName : userNames) { + Predicate predicate = new PredicateBuilder() + .property(UserResourceProvider.USER_USERNAME_PROPERTY_ID).equals(userName).toPredicate(); + RequestStatus requestStatus = userResourceProvider.deleteResources(null /* not used */, predicate); + assertNotNull(requestStatus); } + + // verify that the username was deleted + resources = userResourceProvider.getResources(getRequest, null); + assertEquals(resources.size(), 0); + } }
http://git-wip-us.apache.org/repos/asf/ambari/blob/f76c87a6/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserResourceProviderTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserResourceProviderTest.java index d298b7f..4530d40 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserResourceProviderTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserResourceProviderTest.java @@ -6,9 +6,9 @@ * to you 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> + * + * 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. @@ -55,11 +55,12 @@ import org.apache.ambari.server.metadata.CachedRoleCommandOrderProvider; import org.apache.ambari.server.metadata.RoleCommandOrderProvider; import org.apache.ambari.server.orm.DBAccessor; import org.apache.ambari.server.orm.dao.HostRoleCommandDAO; +import org.apache.ambari.server.orm.entities.MemberEntity; +import org.apache.ambari.server.orm.entities.UserAuthenticationEntity; +import org.apache.ambari.server.orm.entities.UserEntity; import org.apache.ambari.server.scheduler.ExecutionScheduler; import org.apache.ambari.server.security.TestAuthenticationFactory; import org.apache.ambari.server.security.authorization.AuthorizationException; -import org.apache.ambari.server.security.authorization.User; -import org.apache.ambari.server.security.authorization.UserType; import org.apache.ambari.server.security.authorization.Users; import org.apache.ambari.server.security.encryption.CredentialStoreService; import org.apache.ambari.server.security.encryption.CredentialStoreServiceImpl; @@ -266,9 +267,20 @@ public class UserResourceProviderTest extends EasyMockSupport { private void createResourcesTest(Authentication authentication) throws Exception { Injector injector = createInjector(); + UserEntity userEntity100 = createNiceMock(UserEntity.class); + UserEntity userEntity200 = createNiceMock(UserEntity.class); + Users users = injector.getInstance(Users.class); - users.createUser("User100", "password", UserType.LOCAL, (Boolean) null, null); - expectLastCall().atLeastOnce(); + expect(users.createUser("User100", "User100", "User100", null)) + .andReturn(userEntity100) + .once(); + expect(users.createUser("user200", "user200", "user200", null)) + .andReturn(userEntity200) + .once(); + + users.addLocalAuthentication(userEntity100, "password100"); + users.addLocalAuthentication(userEntity200, "password200"); + expectLastCall().once(); // replay replayAll(); @@ -278,19 +290,21 @@ public class UserResourceProviderTest extends EasyMockSupport { AmbariMetaInfo ambariMetaInfo = injector.getInstance(AmbariMetaInfo.class); ambariMetaInfo.init(); - AmbariManagementController managementController = injector.getInstance(AmbariManagementController.class); - - ResourceProvider provider = getResourceProvider(managementController); + ResourceProvider provider = getResourceProvider(injector); // add the property map to a set for the request. add more maps for multiple creates Set<Map<String, Object>> propertySet = new LinkedHashSet<>(); - Map<String, Object> properties = new LinkedHashMap<>(); + Map<String, Object> properties; - // add properties to the request map + properties = new LinkedHashMap<>(); properties.put(UserResourceProvider.USER_USERNAME_PROPERTY_ID, "User100"); - properties.put(UserResourceProvider.USER_PASSWORD_PROPERTY_ID, "password"); + properties.put(UserResourceProvider.USER_PASSWORD_PROPERTY_ID, "password100"); + propertySet.add(properties); + properties = new LinkedHashMap<>(); + properties.put(UserResourceProvider.USER_USERNAME_PROPERTY_ID, "user200"); + properties.put(UserResourceProvider.USER_PASSWORD_PROPERTY_ID, "password200"); propertySet.add(properties); // create the request @@ -308,15 +322,23 @@ public class UserResourceProviderTest extends EasyMockSupport { Users users = injector.getInstance(Users.class); if ("admin".equals(authentication.getName())) { - List<User> allUsers = Arrays.asList( - createMockUser("User1"), - createMockUser("User10"), - createMockUser("User100"), - createMockUser("admin") - ); - expect(users.getAllUsers()).andReturn(allUsers).atLeastOnce(); + UserEntity userEntity1 = createMockUserEntity("User1"); + UserEntity userEntity10 = createMockUserEntity("User10"); + UserEntity userEntity100 = createMockUserEntity("User100"); + UserEntity userEntityAdmin = createMockUserEntity("admin"); + + List<UserEntity> allUsers = Arrays.asList(userEntity1, userEntity10, userEntity100, userEntityAdmin); + + expect(users.getAllUserEntities()).andReturn(allUsers).once(); + expect(users.hasAdminPrivilege(userEntity1)).andReturn(false).once(); + expect(users.hasAdminPrivilege(userEntity10)).andReturn(false).once(); + expect(users.hasAdminPrivilege(userEntity100)).andReturn(false).once(); + expect(users.hasAdminPrivilege(userEntityAdmin)).andReturn(true).once(); } else { - expect(users.getAnyUser("User1")).andReturn(createMockUser("User1")).atLeastOnce(); + + UserEntity userEntity = createMockUserEntity("User1"); + expect(users.getUserEntity("User1")).andReturn(userEntity).once(); + expect(users.hasAdminPrivilege(userEntity)).andReturn(false).once(); } replayAll(); @@ -326,9 +348,7 @@ public class UserResourceProviderTest extends EasyMockSupport { SecurityContextHolder.getContext().setAuthentication(authentication); - AmbariManagementController managementController = injector.getInstance(AmbariManagementController.class); - - ResourceProvider provider = getResourceProvider(managementController); + ResourceProvider provider = getResourceProvider(injector); Set<String> propertyIds = new HashSet<>(); propertyIds.add(UserResourceProvider.USER_USERNAME_PROPERTY_ID); @@ -358,8 +378,11 @@ public class UserResourceProviderTest extends EasyMockSupport { private void getResourceTest(Authentication authentication, String requestedUsername) throws Exception { Injector injector = createInjector(); + UserEntity userEntity = createMockUserEntity(requestedUsername); + Users users = injector.getInstance(Users.class); - expect(users.getAnyUser(requestedUsername)).andReturn(createMockUser(requestedUsername)).atLeastOnce(); + expect(users.getUserEntity(requestedUsername)).andReturn(userEntity).once(); + expect(users.hasAdminPrivilege(userEntity)).andReturn(false).once(); replayAll(); @@ -368,9 +391,7 @@ public class UserResourceProviderTest extends EasyMockSupport { SecurityContextHolder.getContext().setAuthentication(authentication); - AmbariManagementController managementController = injector.getInstance(AmbariManagementController.class); - - ResourceProvider provider = getResourceProvider(managementController); + ResourceProvider provider = getResourceProvider(injector); Set<String> propertyIds = new HashSet<>(); propertyIds.add(UserResourceProvider.USER_USERNAME_PROPERTY_ID); @@ -389,14 +410,16 @@ public class UserResourceProviderTest extends EasyMockSupport { verifyAll(); } - public void updateResources_SetAdmin(Authentication authentication, String requestedUsername) throws Exception { + private void updateResources_SetAdmin(Authentication authentication, String requestedUsername) throws Exception { Injector injector = createInjector(); + UserEntity userEntity = createMockUserEntity(requestedUsername); + Users users = injector.getInstance(Users.class); - expect(users.getAnyUser(requestedUsername)).andReturn(createMockUser(requestedUsername)).once(); + expect(users.getUserEntity(requestedUsername)).andReturn(userEntity).once(); if ("admin".equals(authentication.getName())) { - users.grantAdminPrivilege(requestedUsername.hashCode()); + users.grantAdminPrivilege(userEntity); expectLastCall().once(); } @@ -407,9 +430,7 @@ public class UserResourceProviderTest extends EasyMockSupport { SecurityContextHolder.getContext().setAuthentication(authentication); - AmbariManagementController managementController = injector.getInstance(AmbariManagementController.class); - - ResourceProvider provider = getResourceProvider(managementController); + ResourceProvider provider = getResourceProvider(injector); // add the property map to a set for the request. Map<String, Object> properties = new LinkedHashMap<>(); @@ -423,14 +444,16 @@ public class UserResourceProviderTest extends EasyMockSupport { verifyAll(); } - public void updateResources_SetActive(Authentication authentication, String requestedUsername) throws Exception { + private void updateResources_SetActive(Authentication authentication, String requestedUsername) throws Exception { Injector injector = createInjector(); + UserEntity userEntity = createMockUserEntity(requestedUsername); + Users users = injector.getInstance(Users.class); - expect(users.getAnyUser(requestedUsername)).andReturn(createMockUser(requestedUsername)).once(); + expect(users.getUserEntity(requestedUsername)).andReturn(userEntity).once(); if ("admin".equals(authentication.getName())) { - users.setUserActive(requestedUsername, true); + users.setUserActive(userEntity, true); expectLastCall().once(); } @@ -441,9 +464,7 @@ public class UserResourceProviderTest extends EasyMockSupport { SecurityContextHolder.getContext().setAuthentication(authentication); - AmbariManagementController managementController = injector.getInstance(AmbariManagementController.class); - - ResourceProvider provider = getResourceProvider(managementController); + ResourceProvider provider = getResourceProvider(injector); // add the property map to a set for the request. Map<String, Object> properties = new LinkedHashMap<>(); @@ -456,12 +477,14 @@ public class UserResourceProviderTest extends EasyMockSupport { verifyAll(); } - public void updateResources_SetPassword(Authentication authentication, String requestedUsername) throws Exception { + private void updateResources_SetPassword(Authentication authentication, String requestedUsername) throws Exception { Injector injector = createInjector(); + UserEntity userEntity = createMockUserEntity(requestedUsername); + Users users = injector.getInstance(Users.class); - expect(users.getAnyUser(requestedUsername)).andReturn(createMockUser(requestedUsername)).once(); - users.modifyPassword(requestedUsername, "old_password", "new_password"); + expect(users.getUserEntity(requestedUsername)).andReturn(userEntity).once(); + users.modifyPassword(userEntity, "old_password", "new_password"); expectLastCall().once(); replayAll(); @@ -471,9 +494,7 @@ public class UserResourceProviderTest extends EasyMockSupport { SecurityContextHolder.getContext().setAuthentication(authentication); - AmbariManagementController managementController = injector.getInstance(AmbariManagementController.class); - - ResourceProvider provider = getResourceProvider(managementController); + ResourceProvider provider = getResourceProvider(injector); // add the property map to a set for the request. Map<String, Object> properties = new LinkedHashMap<>(); @@ -491,11 +512,11 @@ public class UserResourceProviderTest extends EasyMockSupport { private void deleteResourcesTest(Authentication authentication, String requestedUsername) throws Exception { Injector injector = createInjector(); - User user = createMockUser(requestedUsername); + UserEntity userEntity = createMockUserEntity(requestedUsername); Users users = injector.getInstance(Users.class); - expect(users.getAnyUser(requestedUsername)).andReturn(user).atLeastOnce(); - users.removeUser(user); + expect(users.getUserEntity(requestedUsername)).andReturn(userEntity).once(); + users.removeUser(userEntity); expectLastCall().atLeastOnce(); // replay @@ -506,9 +527,7 @@ public class UserResourceProviderTest extends EasyMockSupport { SecurityContextHolder.getContext().setAuthentication(authentication); - AmbariManagementController managementController = injector.getInstance(AmbariManagementController.class); - - ResourceProvider provider = getResourceProvider(managementController); + ResourceProvider provider = getResourceProvider(injector); provider.deleteResources(new RequestImpl(null, null, null, null), createPredicate(requestedUsername)); @@ -524,24 +543,23 @@ public class UserResourceProviderTest extends EasyMockSupport { .toPredicate(); } - private User createMockUser(String username) { - User user = createMock(User.class); - expect(user.getUserId()).andReturn(username.hashCode()).anyTimes(); - expect(user.getUserName()).andReturn(username).anyTimes(); - expect(user.getUserType()).andReturn(UserType.LOCAL).anyTimes(); - expect(user.isLdapUser()).andReturn(false).anyTimes(); - expect(user.isActive()).andReturn(true).anyTimes(); - expect(user.isAdmin()).andReturn(false).anyTimes(); - expect(user.getGroups()).andReturn(Collections.<String>emptyList()).anyTimes(); - - return user; + private UserEntity createMockUserEntity(String username) { + UserEntity userEntity = createMock(UserEntity.class); + expect(userEntity.getUserId()).andReturn(username.hashCode()).anyTimes(); + expect(userEntity.getUserName()).andReturn(username).anyTimes(); + expect(userEntity.getActive()).andReturn(true).anyTimes(); + expect(userEntity.getAuthenticationEntities()).andReturn(Collections.<UserAuthenticationEntity>emptyList()).anyTimes(); + expect(userEntity.getMemberEntities()).andReturn(Collections.<MemberEntity>emptySet()).anyTimes(); + return userEntity; } - private ResourceProvider getResourceProvider(AmbariManagementController managementController) { - return AbstractControllerResourceProvider.getResourceProvider( - Resource.Type.User, + private ResourceProvider getResourceProvider(Injector injector) { + UserResourceProvider resourceProvider = new UserResourceProvider( PropertyHelper.getPropertyIds(Resource.Type.User), PropertyHelper.getKeyPropertyIds(Resource.Type.User), - managementController); + injector.getInstance(AmbariManagementController.class)); + + injector.injectMembers(resourceProvider); + return resourceProvider; } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/f76c87a6/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java index 271d536..99cc286 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java @@ -227,8 +227,7 @@ public class OrmTestHelper { PasswordEncoder encoder = injector.getInstance(PasswordEncoder.class); UserEntity admin = new UserEntity(); - admin.setUserName(UserName.fromString("administrator")); - admin.setUserPassword(encoder.encode("admin")); + admin.setUserName(UserName.fromString("administrator").toString()); admin.setPrincipal(principalEntity); Set<UserEntity> users = new HashSet<>(); @@ -242,11 +241,9 @@ public class OrmTestHelper { getEntityManager().persist(principalEntity); UserEntity userWithoutRoles = new UserEntity(); - userWithoutRoles.setUserName(UserName.fromString("userWithoutRoles")); - userWithoutRoles.setUserPassword(encoder.encode("test")); + userWithoutRoles.setUserName(UserName.fromString("userWithoutRoles").toString()); userWithoutRoles.setPrincipal(principalEntity); userDAO.create(userWithoutRoles); - } @Transactional http://git-wip-us.apache.org/repos/asf/ambari/blob/f76c87a6/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/UserDAOTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/UserDAOTest.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/UserDAOTest.java index 05733fa..e3c904d 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/UserDAOTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/UserDAOTest.java @@ -25,9 +25,6 @@ import static org.easymock.EasyMock.createStrictMock; import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.replay; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -import java.util.Arrays; import javax.persistence.EntityManager; import javax.persistence.TypedQuery; @@ -35,7 +32,6 @@ import javax.persistence.TypedQuery; import org.apache.ambari.server.orm.DBAccessor; import org.apache.ambari.server.orm.entities.UserEntity; import org.apache.ambari.server.security.authorization.UserName; -import org.apache.ambari.server.security.authorization.UserType; import org.junit.Test; import com.google.inject.AbstractModule; @@ -52,7 +48,7 @@ public class UserDAOTest { private static String SERVICEOP_USER_NAME = "serviceopuser"; private UserDAO userDAO; - public void init(UserEntity... usersInDB) { + public void init(UserEntity userInDB) { final EntityManager entityManager = createStrictMock(EntityManager.class); final DaoUtils daoUtils = createNiceMock(DaoUtils.class); final DBAccessor dbAccessor = createNiceMock(DBAccessor.class); @@ -68,55 +64,24 @@ public class UserDAOTest { userDAO = mockInjector.getInstance(UserDAO.class); TypedQuery<UserEntity> userQuery = createNiceMock(TypedQuery.class); - expect(userQuery.getResultList()).andReturn(Arrays.asList(usersInDB)); + expect(userQuery.getSingleResult()).andReturn(userInDB); expect(entityManager.createNamedQuery(anyString(), anyObject(Class.class))).andReturn(userQuery); replay(entityManager, daoUtils, dbAccessor, userQuery); } @Test - public void testFindSingleUserByName_NoUsers() { - init(); - assertNull(userDAO.findSingleUserByName(SERVICEOP_USER_NAME)); - } - - @Test - public void testFindSingleUserByName_SingleUser() { - init(user(UserType.PAM)); - assertEquals(UserType.PAM, userDAO.findSingleUserByName(SERVICEOP_USER_NAME).getUserType()); - } - - @Test - public void testFindSingleUserByName_LocalIsFirstPrecedence() { - init(user(UserType.LOCAL), - user(UserType.LDAP), - user(UserType.JWT), - user(UserType.PAM)); - assertEquals(UserType.LOCAL, userDAO.findSingleUserByName(SERVICEOP_USER_NAME).getUserType()); - } - - @Test - public void testFindSingleUserByName_LdapIsSecondPrecedence() { - init(user(UserType.LDAP), - user(UserType.JWT), - user(UserType.PAM)); - assertEquals(UserType.LDAP, userDAO.findSingleUserByName(SERVICEOP_USER_NAME).getUserType()); - } - - @Test - public void testFindSingleUserByName_JwtIsThirdPrecedence() { - init(user(UserType.JWT), - user(UserType.PAM)); - assertEquals(UserType.JWT, userDAO.findSingleUserByName(SERVICEOP_USER_NAME).getUserType()); + public void testUserByName() { + init(user()); + assertEquals(SERVICEOP_USER_NAME, userDAO.findUserByName(SERVICEOP_USER_NAME).getUserName()); } - private static final UserEntity user(UserType type) { - return user(SERVICEOP_USER_NAME, type); + private static final UserEntity user() { + return user(SERVICEOP_USER_NAME); } - private static final UserEntity user(String name, UserType type) { + private static final UserEntity user(String name) { UserEntity userEntity = new UserEntity(); - userEntity.setUserName(UserName.fromString(name)); - userEntity.setUserType(type); + userEntity.setUserName(UserName.fromString(name).toString()); return userEntity; } http://git-wip-us.apache.org/repos/asf/ambari/blob/f76c87a6/ambari-server/src/test/java/org/apache/ambari/server/security/SecurityHelperImplTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/security/SecurityHelperImplTest.java b/ambari-server/src/test/java/org/apache/ambari/server/security/SecurityHelperImplTest.java index f15f2f5..4d6d5a9 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/security/SecurityHelperImplTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/security/SecurityHelperImplTest.java @@ -44,13 +44,14 @@ public class SecurityHelperImplTest { SecurityContext ctx = SecurityContextHolder.getContext(); UserEntity userEntity = new UserEntity(); userEntity.setPrincipal(new PrincipalEntity()); - userEntity.setUserName(UserName.fromString("userName")); + userEntity.setUserName(UserName.fromString("userName").toString()); userEntity.setUserId(1); User user = new User(userEntity); Authentication auth = new AmbariUserAuthentication(null, user, null); ctx.setAuthentication(auth); - Assert.assertEquals("userName", SecurityHelperImpl.getInstance().getCurrentUserName()); + // Username is expected to be lowercase + Assert.assertEquals("username", SecurityHelperImpl.getInstance().getCurrentUserName()); } @Test http://git-wip-us.apache.org/repos/asf/ambari/blob/f76c87a6/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/AmbariJWTAuthenticationFilterTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/AmbariJWTAuthenticationFilterTest.java b/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/AmbariJWTAuthenticationFilterTest.java index de5b768..961e65d 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/AmbariJWTAuthenticationFilterTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/AmbariJWTAuthenticationFilterTest.java @@ -37,10 +37,10 @@ import javax.servlet.http.HttpServletResponse; import org.apache.ambari.server.audit.AuditLogger; import org.apache.ambari.server.configuration.Configuration; +import org.apache.ambari.server.orm.entities.UserAuthenticationEntity; +import org.apache.ambari.server.orm.entities.UserEntity; import org.apache.ambari.server.security.AmbariEntryPoint; import org.apache.ambari.server.security.authorization.PermissionHelper; -import org.apache.ambari.server.security.authorization.User; -import org.apache.ambari.server.security.authorization.UserType; import org.apache.ambari.server.security.authorization.Users; import org.apache.ambari.server.security.authorization.jwt.JwtAuthenticationProperties; import org.easymock.EasyMockSupport; @@ -83,13 +83,11 @@ public class AmbariJWTAuthenticationFilterTest extends EasyMockSupport { Configuration configuration = createMock(Configuration.class); expect(configuration.getJwtProperties()).andReturn(properties).once(); - User user = createMock(User.class); - expect(user.getUserName()).andReturn("test-user").once(); - expect(user.getUserType()).andReturn(UserType.JWT).once(); + UserEntity userEntity = createMock(UserEntity.class); + expect(userEntity.getAuthenticationEntities()).andReturn(Collections.<UserAuthenticationEntity>emptyList()).once(); Users users = createMock(Users.class); - expect(users.getUser("test-user", UserType.JWT)).andReturn(user).once(); - expect(users.getUserAuthorities("test-user", UserType.JWT)).andReturn(null).once(); + expect(users.getUserEntity("test-user")).andReturn(userEntity).once(); AuditLogger auditLogger = createMock(AuditLogger.class); expect(auditLogger.isEnabled()).andReturn(false).times(2); http://git-wip-us.apache.org/repos/asf/ambari/blob/f76c87a6/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/kerberos/AmbariAuthToLocalUserDetailsServiceTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/kerberos/AmbariAuthToLocalUserDetailsServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/kerberos/AmbariAuthToLocalUserDetailsServiceTest.java index 530bf65..c6ee706 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/kerberos/AmbariAuthToLocalUserDetailsServiceTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/kerberos/AmbariAuthToLocalUserDetailsServiceTest.java @@ -24,9 +24,10 @@ import java.util.Collection; import java.util.Collections; import org.apache.ambari.server.configuration.Configuration; +import org.apache.ambari.server.orm.entities.UserAuthenticationEntity; +import org.apache.ambari.server.orm.entities.UserEntity; import org.apache.ambari.server.security.authorization.AmbariGrantedAuthority; -import org.apache.ambari.server.security.authorization.User; -import org.apache.ambari.server.security.authorization.UserType; +import org.apache.ambari.server.security.authorization.UserAuthenticationType; import org.apache.ambari.server.security.authorization.Users; import org.easymock.EasyMockSupport; import org.junit.Before; @@ -53,15 +54,19 @@ public class AmbariAuthToLocalUserDetailsServiceTest extends EasyMockSupport { Configuration configuration = createMock(Configuration.class); expect(configuration.getKerberosAuthenticationProperties()).andReturn(properties).once(); - User user = createMock(User.class); - expect(user.getUserName()).andReturn("user1").once(); - expect(user.getUserType()).andReturn(UserType.LDAP).once(); + UserAuthenticationEntity kerberosAuthenticationEntity = createMock(UserAuthenticationEntity.class); + expect(kerberosAuthenticationEntity.getAuthenticationType()).andReturn(UserAuthenticationType.KERBEROS).anyTimes(); + expect(kerberosAuthenticationEntity.getAuthenticationKey()).andReturn("[email protected]").anyTimes(); + + UserEntity userEntity = createMock(UserEntity.class); + expect(userEntity.getActive()).andReturn(true).once(); + expect(userEntity.getAuthenticationEntities()).andReturn(Collections.singletonList(kerberosAuthenticationEntity)).once(); Collection<AmbariGrantedAuthority> userAuthorities = Collections.singletonList(createNiceMock(AmbariGrantedAuthority.class)); Users users = createMock(Users.class); - expect(users.getUser("user1", UserType.LDAP)).andReturn(user).once(); - expect(users.getUserAuthorities("user1", UserType.LDAP)).andReturn(userAuthorities).once(); + expect(users.getUserEntity("user1")).andReturn(userEntity).atLeastOnce(); + expect(users.getUserAuthorities(userEntity)).andReturn(userAuthorities).atLeastOnce(); replayAll(); @@ -85,8 +90,7 @@ public class AmbariAuthToLocalUserDetailsServiceTest extends EasyMockSupport { expect(configuration.getKerberosAuthenticationProperties()).andReturn(properties).once(); Users users = createMock(Users.class); - expect(users.getUser("user1", UserType.LDAP)).andReturn(null).once(); - expect(users.getUser("user1", UserType.LOCAL)).andReturn(null).once(); + expect(users.getUserEntity("user1")).andReturn(null).times(2); replayAll(); http://git-wip-us.apache.org/repos/asf/ambari/blob/f76c87a6/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/kerberos/AmbariKerberosAuthenticationPropertiesTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/kerberos/AmbariKerberosAuthenticationPropertiesTest.java b/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/kerberos/AmbariKerberosAuthenticationPropertiesTest.java index eb26cd8..bf170fe 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/kerberos/AmbariKerberosAuthenticationPropertiesTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/kerberos/AmbariKerberosAuthenticationPropertiesTest.java @@ -18,11 +18,6 @@ package org.apache.ambari.server.security.authentication.kerberos; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; - -import org.apache.ambari.server.security.authorization.UserType; import org.junit.Assert; import org.junit.Test; @@ -61,17 +56,6 @@ public class AmbariKerberosAuthenticationPropertiesTest { } @Test - public void testOrderedUserTypes() throws Exception { - AmbariKerberosAuthenticationProperties properties = new AmbariKerberosAuthenticationProperties(); - - properties.setOrderedUserTypes(new ArrayList<>(Arrays.asList(UserType.LDAP, UserType.LOCAL))); - Assert.assertEquals(new ArrayList<>(Arrays.asList(UserType.LDAP, UserType.LOCAL)), properties.getOrderedUserTypes()); - - properties.setOrderedUserTypes(Collections.singletonList(UserType.JWT)); - Assert.assertEquals(new ArrayList<>(Collections.singletonList(UserType.JWT)), properties.getOrderedUserTypes()); - } - - @Test public void testAuthToLocalRules() throws Exception { AmbariKerberosAuthenticationProperties properties = new AmbariKerberosAuthenticationProperties(); http://git-wip-us.apache.org/repos/asf/ambari/blob/f76c87a6/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariAuthorizationFilterTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariAuthorizationFilterTest.java b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariAuthorizationFilterTest.java index 15e243e..1d46b89 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariAuthorizationFilterTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariAuthorizationFilterTest.java @@ -317,11 +317,10 @@ public class AmbariAuthorizationFilterTest { User user = EasyMock.createMock(User.class); expect(user.getUserName()).andReturn("user1").anyTimes(); - expect(user.getUserType()).andReturn(UserType.LOCAL).anyTimes(); final Users users = EasyMock.createMock(Users.class); - expect(users.getUser("user1", UserType.LOCAL)).andReturn(user).once(); - expect(users.getUserAuthorities("user1", UserType.LOCAL)).andReturn(Collections.<AmbariGrantedAuthority>emptyList()).once(); + expect(users.getUser("user1")).andReturn(user).once(); + expect(users.getUserAuthorities("user1")).andReturn(Collections.<AmbariGrantedAuthority>emptyList()).once(); replay(request, response, chain, configuration, users, user); http://git-wip-us.apache.org/repos/asf/ambari/blob/f76c87a6/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariAuthorizationProviderDisableUserTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariAuthorizationProviderDisableUserTest.java b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariAuthorizationProviderDisableUserTest.java index 891ab38..33100dd 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariAuthorizationProviderDisableUserTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariAuthorizationProviderDisableUserTest.java @@ -18,10 +18,13 @@ package org.apache.ambari.server.security.authorization; +import java.util.Collections; + import org.apache.ambari.server.orm.dao.MemberDAO; import org.apache.ambari.server.orm.dao.PrivilegeDAO; import org.apache.ambari.server.orm.dao.UserDAO; import org.apache.ambari.server.orm.entities.PrincipalEntity; +import org.apache.ambari.server.orm.entities.UserAuthenticationEntity; import org.apache.ambari.server.orm.entities.UserEntity; import org.junit.Assert; import org.junit.Before; @@ -87,13 +90,18 @@ public class AmbariAuthorizationProviderDisableUserTest { private void createUser(String login, boolean isActive) { PrincipalEntity principalEntity = new PrincipalEntity(); + + UserAuthenticationEntity userAuthenticationEntity = new UserAuthenticationEntity(); + userAuthenticationEntity.setAuthenticationType(UserAuthenticationType.LOCAL); + userAuthenticationEntity.setAuthenticationKey(encoder.encode("pwd")); + UserEntity activeUser = new UserEntity(); activeUser.setUserId(1); activeUser.setActive(isActive); - activeUser.setUserName(UserName.fromString(login)); - activeUser.setUserPassword(encoder.encode("pwd")); + activeUser.setUserName(UserName.fromString(login).toString()); + activeUser.setAuthenticationEntities(Collections.singletonList(userAuthenticationEntity)); activeUser.setPrincipal(principalEntity); - Mockito.when(userDAO.findLocalUserByName(login)).thenReturn(activeUser); - Mockito.when(userDAO.findLdapUserByName(login)).thenReturn(activeUser); + Mockito.when(userDAO.findUserByName(login)).thenReturn(activeUser); + Mockito.when(userDAO.findUserByName(login)).thenReturn(activeUser); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/f76c87a6/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLdapAuthenticationProviderForDNWithSpaceTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLdapAuthenticationProviderForDNWithSpaceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLdapAuthenticationProviderForDNWithSpaceTest.java index 442414f..1bf122e 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLdapAuthenticationProviderForDNWithSpaceTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLdapAuthenticationProviderForDNWithSpaceTest.java @@ -28,6 +28,7 @@ import org.apache.ambari.server.configuration.Configuration; import org.apache.ambari.server.controller.ControllerModule; import org.apache.ambari.server.orm.GuiceJpaInitializer; import org.apache.ambari.server.orm.dao.UserDAO; +import org.apache.ambari.server.orm.entities.UserEntity; import org.apache.ambari.server.security.ClientSecurityType; import org.apache.directory.server.annotations.CreateLdapServer; import org.apache.directory.server.annotations.CreateTransport; @@ -104,8 +105,10 @@ public class AmbariLdapAuthenticationProviderForDNWithSpaceTest extends AmbariLd @Test public void testAuthenticate() throws Exception { - assertNull("User alread exists in DB", userDAO.findLdapUserByName("the allowedUser")); - users.createUser("the allowedUser", "password", UserType.LDAP, true, false); + assertNull("User already exists in DB", userDAO.findUserByName("the allowedUser")); + UserEntity userEntity = users.createUser("the allowedUser", null, null); + users.addLdapAuthentication(userEntity, "some Dn"); + Authentication authentication = new UsernamePasswordAuthenticationToken("the allowedUser", "password"); Authentication result = authenticationProvider.authenticate(authentication); assertTrue(result.isAuthenticated()); http://git-wip-us.apache.org/repos/asf/ambari/blob/f76c87a6/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLdapAuthenticationProviderTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLdapAuthenticationProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLdapAuthenticationProviderTest.java index 4941bc7..d9eb335 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLdapAuthenticationProviderTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLdapAuthenticationProviderTest.java @@ -181,9 +181,11 @@ public class AmbariLdapAuthenticationProviderTest extends AmbariLdapAuthenticati @Test public void testAuthenticate() throws Exception { - assertNull("User alread exists in DB", userDAO.findLdapUserByName("allowedUser")); - users.createUser("allowedUser", "password", UserType.LDAP, true, false); - UserEntity ldapUser = userDAO.findLdapUserByName("allowedUser"); + assertNull("User alread exists in DB", userDAO.findUserByName("allowedUser")); + UserEntity userEntity = users.createUser("allowedUser", null, null); + users.addLdapAuthentication(userEntity, "some dn"); + + UserEntity ldapUser = userDAO.findUserByName("allowedUser"); Authentication authentication = new UsernamePasswordAuthenticationToken("allowedUser", "password"); AmbariAuthentication result = (AmbariAuthentication) authenticationProvider.authenticate(authentication); @@ -206,8 +208,10 @@ public class AmbariLdapAuthenticationProviderTest extends AmbariLdapAuthenticati @Test public void testAuthenticateLoginAlias() throws Exception { // Given - assertNull("User already exists in DB", userDAO.findLdapUserByName("[email protected]")); - users.createUser("[email protected]", "password", UserType.LDAP, true, false); + assertNull("User already exists in DB", userDAO.findUserByName("[email protected]")); + UserEntity userEntity = users.createUser("[email protected]", null, null); + users.addLdapAuthentication(userEntity, "some dn"); + Authentication authentication = new UsernamePasswordAuthenticationToken("[email protected]", "password"); configuration.setProperty(Configuration.LDAP_ALT_USER_SEARCH_ENABLED.getKey(), "true"); @@ -221,7 +225,7 @@ public class AmbariLdapAuthenticationProviderTest extends AmbariLdapAuthenticati @Test(expected = InvalidUsernamePasswordCombinationException.class) public void testBadCredentialsForMissingLoginAlias() throws Exception { // Given - assertNull("User already exists in DB", userDAO.findLdapUserByName("allowedUser")); + assertNull("User already exists in DB", userDAO.findUserByName("allowedUser")); Authentication authentication = new UsernamePasswordAuthenticationToken("[email protected]", "password"); configuration.setProperty(Configuration.LDAP_ALT_USER_SEARCH_ENABLED.getKey(), "true"); @@ -237,7 +241,7 @@ public class AmbariLdapAuthenticationProviderTest extends AmbariLdapAuthenticati @Test(expected = InvalidUsernamePasswordCombinationException.class) public void testBadCredentialsBadPasswordForLoginAlias() throws Exception { // Given - assertNull("User already exists in DB", userDAO.findLdapUserByName("allowedUser")); + assertNull("User already exists in DB", userDAO.findUserByName("allowedUser")); Authentication authentication = new UsernamePasswordAuthenticationToken("[email protected]", "bad_password"); configuration.setProperty(Configuration.LDAP_ALT_USER_SEARCH_ENABLED.getKey(), "true"); http://git-wip-us.apache.org/repos/asf/ambari/blob/f76c87a6/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLocalUserProviderTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLocalUserProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLocalUserProviderTest.java index 2362823..65a5400 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLocalUserProviderTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLocalUserProviderTest.java @@ -25,12 +25,15 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import java.util.Collections; + import org.apache.ambari.server.H2DatabaseCleaner; import org.apache.ambari.server.audit.AuditLoggerModule; import org.apache.ambari.server.orm.GuiceJpaInitializer; import org.apache.ambari.server.orm.OrmTestHelper; import org.apache.ambari.server.orm.dao.UserDAO; import org.apache.ambari.server.orm.entities.PrincipalEntity; +import org.apache.ambari.server.orm.entities.UserAuthenticationEntity; import org.apache.ambari.server.orm.entities.UserEntity; import org.junit.AfterClass; import org.junit.Before; @@ -81,9 +84,9 @@ public class AmbariLocalUserProviderTest { UserEntity userEntity = combineUserEntity(); expect(authentication.getName()).andReturn(TEST_USER_NAME); - expect(userDAO.findLocalUserByName(TEST_USER_NAME)).andReturn(userEntity); + expect(userDAO.findUserByName(TEST_USER_NAME)).andReturn(userEntity); expect(authentication.getCredentials()).andReturn(TEST_USER_PASS).anyTimes(); - expect(users.getUserAuthorities(userEntity.getUserName(), userEntity.getUserType())).andReturn(null); + expect(users.getUserAuthorities(userEntity)).andReturn(null); replay(users, userDAO, authentication); @@ -105,7 +108,7 @@ public class AmbariLocalUserProviderTest { Authentication authentication = createMock(Authentication.class); expect(authentication.getName()).andReturn(TEST_USER_NAME); - expect(userDAO.findLocalUserByName(TEST_USER_NAME)).andReturn(null); + expect(userDAO.findUserByName(TEST_USER_NAME)).andReturn(null); replay(users, userDAO, authentication); @@ -122,7 +125,7 @@ public class AmbariLocalUserProviderTest { UserEntity userEntity = combineUserEntity(); expect(authentication.getName()).andReturn(TEST_USER_NAME); - expect(userDAO.findLocalUserByName(TEST_USER_NAME)).andReturn(userEntity); + expect(userDAO.findUserByName(TEST_USER_NAME)).andReturn(userEntity); expect(authentication.getCredentials()).andReturn(null); replay(users, userDAO, authentication); @@ -140,7 +143,7 @@ public class AmbariLocalUserProviderTest { UserEntity userEntity = combineUserEntity(); expect(authentication.getName()).andReturn(TEST_USER_NAME); - expect(userDAO.findLocalUserByName(TEST_USER_NAME)).andReturn(userEntity); + expect(userDAO.findUserByName(TEST_USER_NAME)).andReturn(userEntity); expect(authentication.getCredentials()).andReturn(TEST_USER_INCORRECT_PASS).anyTimes(); replay(users, userDAO, authentication); @@ -153,13 +156,16 @@ public class AmbariLocalUserProviderTest { private UserEntity combineUserEntity() { PrincipalEntity principalEntity = new PrincipalEntity(); + + UserAuthenticationEntity userAuthenticationEntity = new UserAuthenticationEntity(); + userAuthenticationEntity.setAuthenticationType(UserAuthenticationType.LOCAL); + userAuthenticationEntity.setAuthenticationKey(passwordEncoder.encode(TEST_USER_PASS)); + UserEntity userEntity = new UserEntity(); userEntity.setUserId(1); - userEntity.setUserName(UserName.fromString(TEST_USER_NAME)); - userEntity.setUserPassword(passwordEncoder.encode(TEST_USER_PASS)); - userEntity.setUserType(UserType.LOCAL); + userEntity.setUserName(UserName.fromString(TEST_USER_NAME).toString()); userEntity.setPrincipal(principalEntity); - + userEntity.setAuthenticationEntities(Collections.singletonList(userAuthenticationEntity)); return userEntity; } } http://git-wip-us.apache.org/repos/asf/ambari/blob/f76c87a6/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariPamAuthenticationProviderTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariPamAuthenticationProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariPamAuthenticationProviderTest.java index 8faa6ce..1145954 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariPamAuthenticationProviderTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariPamAuthenticationProviderTest.java @@ -20,10 +20,8 @@ package org.apache.ambari.server.security.authorization; import static org.easymock.EasyMock.createNiceMock; import static org.easymock.EasyMock.expect; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.HashSet; import org.apache.ambari.server.H2DatabaseCleaner; import org.apache.ambari.server.audit.AuditLoggerModule; @@ -31,6 +29,7 @@ import org.apache.ambari.server.configuration.Configuration; import org.apache.ambari.server.orm.GuiceJpaInitializer; import org.apache.ambari.server.orm.dao.UserDAO; import org.apache.ambari.server.orm.entities.PrincipalEntity; +import org.apache.ambari.server.orm.entities.UserAuthenticationEntity; import org.apache.ambari.server.orm.entities.UserEntity; import org.apache.ambari.server.security.ClientSecurityType; import org.easymock.EasyMock; @@ -41,7 +40,6 @@ import org.jvnet.libpam.PAM; import org.jvnet.libpam.UnixUser; import org.springframework.security.core.Authentication; import org.springframework.security.core.AuthenticationException; -import org.springframework.security.crypto.password.PasswordEncoder; import com.google.inject.Guice; import com.google.inject.Inject; @@ -54,15 +52,11 @@ public class AmbariPamAuthenticationProviderTest { private static Injector injector; @Inject - PasswordEncoder passwordEncoder; - @Inject private AmbariPamAuthenticationProvider authenticationProvider; @Inject - Configuration configuration; + private Configuration configuration; private static final String TEST_USER_NAME = "userName"; - private static final String TEST_USER_PASS = "userPass"; - private static final String TEST_USER_INCORRECT_PASS = "userIncorrectPass"; @Before public void setUp() { @@ -91,12 +85,13 @@ public class AmbariPamAuthenticationProviderTest { public void testAuthenticate() throws Exception { PAM pam = createNiceMock(PAM.class); UnixUser unixUser = createNiceMock(UnixUser.class); + expect(unixUser.getUserName()).andReturn(TEST_USER_NAME).atLeastOnce(); UserEntity userEntity = combineUserEntity(); User user = new User(userEntity); UserDAO userDAO = createNiceMock(UserDAO.class); Collection<AmbariGrantedAuthority> userAuthorities = Collections.singletonList(createNiceMock(AmbariGrantedAuthority.class)); expect(pam.authenticate(EasyMock.anyObject(String.class), EasyMock.anyObject(String.class))).andReturn(unixUser).atLeastOnce(); - expect(unixUser.getGroups()).andReturn(new HashSet<>(Arrays.asList("group"))).atLeastOnce(); + expect(unixUser.getGroups()).andReturn(Collections.singleton("group")).atLeastOnce(); EasyMock.replay(unixUser); EasyMock.replay(pam); Authentication authentication = new AmbariUserAuthentication("userPass", user, userAuthorities); @@ -120,12 +115,16 @@ public class AmbariPamAuthenticationProviderTest { private UserEntity combineUserEntity() { PrincipalEntity principalEntity = new PrincipalEntity(); + + UserAuthenticationEntity userAuthenticationEntity = new UserAuthenticationEntity(); + userAuthenticationEntity.setAuthenticationType(UserAuthenticationType.PAM); + userAuthenticationEntity.setAuthenticationKey(TEST_USER_NAME); + UserEntity userEntity = new UserEntity(); userEntity.setUserId(1); - userEntity.setUserName(UserName.fromString(TEST_USER_NAME)); - userEntity.setUserPassword(passwordEncoder.encode(TEST_USER_PASS)); - userEntity.setUserType(UserType.PAM); + userEntity.setUserName(UserName.fromString(TEST_USER_NAME).toString()); userEntity.setPrincipal(principalEntity); + userEntity.setAuthenticationEntities(Collections.singletonList(userAuthenticationEntity)); return userEntity; } http://git-wip-us.apache.org/repos/asf/ambari/blob/f76c87a6/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariUserAuthenticationFilterTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariUserAuthenticationFilterTest.java b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariUserAuthenticationFilterTest.java index 0483b04..7c3a7fd 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariUserAuthenticationFilterTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariUserAuthenticationFilterTest.java @@ -72,10 +72,11 @@ public class AmbariUserAuthenticationFilterTest { expect(tokenStorage.isValidInternalToken(TEST_INTERNAL_TOKEN)).andReturn(true); expect(request.getHeader(ExecutionScheduleManager.USER_ID_HEADER)).andReturn(TEST_USER_ID_HEADER); - User user = combineUser(); + UserEntity userEntity = createUserEntity(); - expect(users.getUser(TEST_USER_ID)).andReturn(user); - expect(users.getUserAuthorities(user.getUserName(), user.getUserType())).andReturn(new HashSet<AmbariGrantedAuthority>()); + expect(users.getUserEntity(TEST_USER_ID)).andReturn(userEntity); + expect(users.getUserAuthorities(userEntity)).andReturn(new HashSet<AmbariGrantedAuthority>()); + expect(users.getUser(userEntity)).andReturn(new User(userEntity)); Capture<String> userHeaderValue = newCapture(); response.setHeader(eq("User"), capture(userHeaderValue)); expectLastCall(); @@ -93,7 +94,7 @@ public class AmbariUserAuthenticationFilterTest { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); assertNotNull(authentication); assertEquals(true, authentication.isAuthenticated()); - assertEquals(TEST_USER_NAME, userHeaderValue.getValue()); + assertEquals(TEST_USER_NAME.toLowerCase(), userHeaderValue.getValue()); } @Test @@ -158,7 +159,7 @@ public class AmbariUserAuthenticationFilterTest { expect(tokenStorage.isValidInternalToken(TEST_INTERNAL_TOKEN)).andReturn(true); expect(request.getHeader(ExecutionScheduleManager.USER_ID_HEADER)).andReturn(TEST_USER_ID_HEADER); - expect(users.getUser(TEST_USER_ID)).andReturn(null); + expect(users.getUserEntity(TEST_USER_ID)).andReturn(null); response.sendError(HttpServletResponse.SC_FORBIDDEN, "Authentication required"); expectLastCall(); @@ -204,15 +205,12 @@ public class AmbariUserAuthenticationFilterTest { assertNull(authentication); } - private User combineUser() { + private UserEntity createUserEntity() { PrincipalEntity principalEntity = new PrincipalEntity(); UserEntity userEntity = new UserEntity(); userEntity.setUserId(TEST_USER_ID); - userEntity.setUserName(UserName.fromString(TEST_USER_NAME)); - userEntity.setUserType(UserType.LOCAL); + userEntity.setUserName(UserName.fromString(TEST_USER_NAME).toString()); userEntity.setPrincipal(principalEntity); - User user = new User(userEntity); - - return user; + return userEntity; } } http://git-wip-us.apache.org/repos/asf/ambari/blob/f76c87a6/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/TestAmbariLdapAuthoritiesPopulator.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/TestAmbariLdapAuthoritiesPopulator.java b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/TestAmbariLdapAuthoritiesPopulator.java index fff39d8..314e8d8 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/TestAmbariLdapAuthoritiesPopulator.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/TestAmbariLdapAuthoritiesPopulator.java @@ -64,7 +64,7 @@ public class TestAmbariLdapAuthoritiesPopulator extends EasyMockSupport { expect(userEntity.getActive()).andReturn(true); expect(users.getUserPrivileges(userEntity)).andReturn(Collections.singletonList(privilegeEntity)); - expect(userDAO.findLdapUserByName(username)).andReturn(userEntity); + expect(userDAO.findUserByName(username)).andReturn(userEntity); replayAll(); populator.getGrantedAuthorities(userData, username); @@ -90,7 +90,7 @@ public class TestAmbariLdapAuthoritiesPopulator extends EasyMockSupport { expect(userEntity.getActive()).andReturn(true); expect(users.getUserPrivileges(userEntity)).andReturn(Collections.singletonList(privilegeEntity)); - expect(userDAO.findLdapUserByName(ambariUserName)).andReturn(userEntity); // user should be looked up by user name instead of login alias + expect(userDAO.findUserByName(ambariUserName)).andReturn(userEntity); // user should be looked up by user name instead of login alias replayAll();
