ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gau...@apache.org
Subject [4/4] incubator-ranger git commit: RANGER-899: Problem Changing/Updating emailAddress of logged in user using API
Date Mon, 30 May 2016 12:28:52 GMT
RANGER-899: Problem Changing/Updating emailAddress of logged in user using API

Signed-off-by: Gautam Borad <gautam@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/incubator-ranger/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ranger/commit/ced7c3b7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ranger/tree/ced7c3b7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ranger/diff/ced7c3b7

Branch: refs/heads/master
Commit: ced7c3b7af823614c2fbc5a0858e8954aed42f51
Parents: 14f8c11
Author: pradeep <pradeep.agrawal@freestoneinfotech.com>
Authored: Wed May 25 10:24:56 2016 +0530
Committer: Gautam Borad <gautam@apache.org>
Committed: Mon May 30 17:58:24 2016 +0530

----------------------------------------------------------------------
 .../audit/provider/AuditProviderFactory.java    |   6 +-
 .../java/org/apache/ranger/biz/UserMgr.java     |  12 +-
 .../org/apache/ranger/audit/TestAuditQueue.java |   2 +-
 .../java/org/apache/ranger/biz/TestUserMgr.java | 119 +++++++++++--------
 .../org/apache/ranger/common/TestDateUtil.java  |   9 +-
 .../apache/ranger/common/TestStringUtil.java    |   2 +-
 6 files changed, 76 insertions(+), 74 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ced7c3b7/agents-audit/src/main/java/org/apache/ranger/audit/provider/AuditProviderFactory.java
----------------------------------------------------------------------
diff --git a/agents-audit/src/main/java/org/apache/ranger/audit/provider/AuditProviderFactory.java
b/agents-audit/src/main/java/org/apache/ranger/audit/provider/AuditProviderFactory.java
index b95e2a9..e3e818c 100644
--- a/agents-audit/src/main/java/org/apache/ranger/audit/provider/AuditProviderFactory.java
+++ b/agents-audit/src/main/java/org/apache/ranger/audit/provider/AuditProviderFactory.java
@@ -107,11 +107,7 @@ public class AuditProviderFactory {
 		LOG.info("AuditProviderFactory: initializing..");
 
 		if (mInitDone) {
-			LOG.warn(
-					"AuditProviderFactory.init(): already initialized! Will try to re-initialize",
-					new Exception());
-
-			// return;
+			LOG.warn("AuditProviderFactory.init(): already initialized! Will try to re-initialize");
 		}
 		mInitDone = true;
 		componentAppType = appType;

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ced7c3b7/security-admin/src/main/java/org/apache/ranger/biz/UserMgr.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/biz/UserMgr.java b/security-admin/src/main/java/org/apache/ranger/biz/UserMgr.java
index 0e042fe..d3befbe 100644
--- a/security-admin/src/main/java/org/apache/ranger/biz/UserMgr.java
+++ b/security-admin/src/main/java/org/apache/ranger/biz/UserMgr.java
@@ -26,6 +26,7 @@ import java.util.List;
 
 import javax.persistence.Query;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
 import org.apache.ranger.common.AppConstants;
 import org.apache.ranger.common.ContextUtil;
@@ -468,11 +469,11 @@ public class UserMgr {
 	public VXPortalUser changeEmailAddress(XXPortalUser gjUser,
 			VXPasswordChange changeEmail) {
 		checkAccess(gjUser);
-		if (gjUser.getEmailAddress() != null) {
+		if (StringUtils.isEmpty(changeEmail.getEmailAddress())) {
 			throw restErrorUtil.createRESTException(
-					"serverMsg.userMgrEmailChange",
-					MessageEnums.OPER_NO_PERMISSION, null, null, ""
-							+ changeEmail);
+					"serverMsg.userMgrInvalidEmail",
+					MessageEnums.INVALID_INPUT_DATA, changeEmail.getId(),
+					"emailAddress", changeEmail.toString());
 		}
 
 		String encryptedOldPwd = encrypt(gjUser.getLoginId(),
@@ -501,9 +502,6 @@ public class UserMgr {
 		gjUser.setEmailAddress(stringUtil.normalizeEmail(changeEmail
 				.getEmailAddress()));
 
-		// loginId
-		gjUser.setLoginId(gjUser.getEmailAddress());
-
 		String saltEncodedpasswd = encrypt(gjUser.getLoginId(),
 				changeEmail.getOldPassword());
 

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ced7c3b7/security-admin/src/test/java/org/apache/ranger/audit/TestAuditQueue.java
----------------------------------------------------------------------
diff --git a/security-admin/src/test/java/org/apache/ranger/audit/TestAuditQueue.java b/security-admin/src/test/java/org/apache/ranger/audit/TestAuditQueue.java
index 3fe6246..637e43f 100644
--- a/security-admin/src/test/java/org/apache/ranger/audit/TestAuditQueue.java
+++ b/security-admin/src/test/java/org/apache/ranger/audit/TestAuditQueue.java
@@ -174,7 +174,7 @@ public class TestAuditQueue {
 		assertEquals(messageToSend, testConsumer.getSumTotal());
 		assertEquals(countToCheck, testConsumer.getCountTotal());
 	}
-	@Ignore("Junit breakage: RANGER-630") // TODO
+
 	@Test
 	public void testAuditSummaryByInfra() {
 		logger.debug("testAuditSummaryByInfra()...");

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ced7c3b7/security-admin/src/test/java/org/apache/ranger/biz/TestUserMgr.java
----------------------------------------------------------------------
diff --git a/security-admin/src/test/java/org/apache/ranger/biz/TestUserMgr.java b/security-admin/src/test/java/org/apache/ranger/biz/TestUserMgr.java
index 2506c03..701ec4f 100644
--- a/security-admin/src/test/java/org/apache/ranger/biz/TestUserMgr.java
+++ b/security-admin/src/test/java/org/apache/ranger/biz/TestUserMgr.java
@@ -282,8 +282,14 @@ public class TestUserMgr {
 	}
 
 	@Test
-	public void test16GetEmailAddress() {
+	public void test16ChangeEmailAddress() {
 		setup();
+		XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
+		XXPortalUserRoleDao roleDao = Mockito.mock(XXPortalUserRoleDao.class);
+		XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
+		XXGroupPermissionDao xGroupPermissionDao = Mockito.mock(XXGroupPermissionDao.class);
+		XXModuleDefDao xModuleDefDao = Mockito.mock(XXModuleDefDao.class);
+		XXModuleDef xModuleDef = Mockito.mock(XXModuleDef.class);
 		VXPortalUser userProfile = userProfile();
 
 		XXPortalUser user = new XXPortalUser();
@@ -291,65 +297,79 @@ public class TestUserMgr {
 		user.setFirstName(userProfile.getFirstName());
 		user.setLastName(userProfile.getLastName());
 		user.setLoginId(userProfile.getLoginId());
-		user.setPassword(userProfile.getPassword());
+		String encryptedPwd = userMgr.encrypt(userProfile.getLoginId(),userProfile.getPassword());
+		user.setPassword(encryptedPwd);
 		user.setUserSource(userProfile.getUserSource());
 		user.setPublicScreenName(userProfile.getPublicScreenName());
 		user.setId(userProfile.getId());
 
 		VXPasswordChange changeEmail = new VXPasswordChange();
-		changeEmail.setEmailAddress(user.getEmailAddress());
+		changeEmail.setEmailAddress("testuser@test.com");
 		changeEmail.setId(user.getId());
 		changeEmail.setLoginId(user.getLoginId());
+		changeEmail.setOldPassword(userProfile.getPassword());
 
-		Mockito.when(
-				restErrorUtil.createRESTException(
-						"serverMsg.userMgrEmailChange",
-						MessageEnums.OPER_NO_PERMISSION, null, null, ""
-								+ changeEmail)).thenThrow(
-				new WebApplicationException());
-		thrown.expect(WebApplicationException.class);
-
-		VXPortalUser dbVXPortalUser = userMgr.changeEmailAddress(user,
-				changeEmail);
-		Assert.assertNotNull(dbVXPortalUser);
-		Assert.assertEquals(userId, dbVXPortalUser.getId());
-		Assert.assertEquals(userProfile.getLastName(),
-				dbVXPortalUser.getLastName());
-		Assert.assertEquals(changeEmail.getLoginId(),
-				dbVXPortalUser.getLoginId());
-		Assert.assertEquals(changeEmail.getEmailAddress(),
-				dbVXPortalUser.getEmailAddress());
+		XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
+		XXPortalUserRole.setId(userId);
+		XXPortalUserRole.setUserRole("ROLE_USER");
+		List<XXPortalUserRole> list = new ArrayList<XXPortalUserRole>();
+		list.add(XXPortalUserRole);
 
-		Mockito.verify(restErrorUtil).createRESTException(
-				"serverMsg.userMgrEmailChange",
-				MessageEnums.OPER_NO_PERMISSION, null, null, "" + changeEmail);
-	}
+		List<XXUserPermission> xUserPermissionsList = new ArrayList<XXUserPermission>();
+		XXUserPermission xUserPermissionObj = new XXUserPermission();
+		xUserPermissionObj.setAddedByUserId(userId);
+		xUserPermissionObj.setCreateTime(new Date());
+		xUserPermissionObj.setId(userId);
+		xUserPermissionObj.setIsAllowed(1);
+		xUserPermissionObj.setModuleId(1L);
+		xUserPermissionObj.setUpdatedByUserId(userId);
+		xUserPermissionObj.setUpdateTime(new Date());
+		xUserPermissionObj.setUserId(userId);
+		xUserPermissionsList.add(xUserPermissionObj);
 
-	@Test
-	public void test17ValidateEmailAddress() {
-		setup();
-		VXPortalUser userProfile = userProfile();
+		List<XXGroupPermission> xGroupPermissionList = new ArrayList<XXGroupPermission>();
+		XXGroupPermission xGroupPermissionObj = new XXGroupPermission();
+		xGroupPermissionObj.setAddedByUserId(userId);
+		xGroupPermissionObj.setCreateTime(new Date());
+		xGroupPermissionObj.setId(userId);
+		xGroupPermissionObj.setIsAllowed(1);
+		xGroupPermissionObj.setModuleId(1L);
+		xGroupPermissionObj.setUpdatedByUserId(userId);
+		xGroupPermissionObj.setUpdateTime(new Date());
+		xGroupPermissionObj.setGroupId(userId);
+		xGroupPermissionList.add(xGroupPermissionObj);
 
-		XXPortalUser user = new XXPortalUser();
-		user.setFirstName(userProfile.getFirstName());
-		user.setLastName(userProfile.getLastName());
-		user.setLoginId(userProfile.getLoginId());
-		user.setPassword(userProfile.getPassword());
-		user.setUserSource(userProfile.getUserSource());
-		user.setPublicScreenName(userProfile.getPublicScreenName());
-		user.setId(userProfile.getId());
+		VXUserPermission userPermission = new VXUserPermission();
+		userPermission.setId(1L);
+		userPermission.setIsAllowed(1);
+		userPermission.setModuleId(1L);
+		userPermission.setUserId(userId);
+		userPermission.setUserName("xyz");
+		userPermission.setOwner("admin");
 
-		VXPasswordChange changeEmail = new VXPasswordChange();
-		changeEmail.setId(user.getId());
-		changeEmail.setLoginId(user.getLoginId());
+		VXGroupPermission groupPermission = new VXGroupPermission();
+		groupPermission.setId(1L);
+		groupPermission.setIsAllowed(1);
+		groupPermission.setModuleId(1L);
+		groupPermission.setGroupId(userId);
+		groupPermission.setGroupName("xyz");
+		groupPermission.setOwner("admin");
 
-		Mockito.when(
-				restErrorUtil.createRESTException(
-						"serverMsg.userMgrInvalidEmail",
-						MessageEnums.INVALID_INPUT_DATA, changeEmail.getId(),
-						"emailAddress", changeEmail.toString())).thenThrow(
-				new WebApplicationException());
-		thrown.expect(WebApplicationException.class);
+		Mockito.when(stringUtil.validateEmail(Mockito.anyString())).thenReturn(true);
+		Mockito.when(stringUtil.equals(Mockito.anyString(), Mockito.anyString())).thenReturn(true);
+		Mockito.when(stringUtil.normalizeEmail(Mockito.anyString())).thenReturn(changeEmail.getEmailAddress());
+		Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
+		Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(roleDao);
+		Mockito.when(userDao.update(user)).thenReturn(user);
+		Mockito.when(roleDao.findByParentId(Mockito.anyLong())).thenReturn(list);
+		Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermissionDao);
+		Mockito.when(daoManager.getXXGroupPermission()).thenReturn(xGroupPermissionDao);
+		Mockito.when(xUserPermissionDao.findByUserPermissionIdAndIsAllowed(userProfile.getId())).thenReturn(xUserPermissionsList);
+		Mockito.when(xGroupPermissionDao.findbyVXPortalUserId(userProfile.getId())).thenReturn(xGroupPermissionList);
+		Mockito.when(xGroupPermissionService.populateViewBean(xGroupPermissionObj)).thenReturn(groupPermission);
+		Mockito.when(xUserPermissionService.populateViewBean(xUserPermissionObj)).thenReturn(userPermission);
+		Mockito.when(daoManager.getXXModuleDef()).thenReturn(xModuleDefDao);
+		Mockito.when(xModuleDefDao.findByModuleId(Mockito.anyLong())).thenReturn(xModuleDef);
 
 		VXPortalUser dbVXPortalUser = userMgr.changeEmailAddress(user,
 				changeEmail);
@@ -361,11 +381,6 @@ public class TestUserMgr {
 				dbVXPortalUser.getLoginId());
 		Assert.assertEquals(changeEmail.getEmailAddress(),
 				dbVXPortalUser.getEmailAddress());
-
-		Mockito.verify(restErrorUtil).createRESTException(
-				"serverMsg.userMgrInvalidEmail",
-				MessageEnums.INVALID_INPUT_DATA, changeEmail.getId(),
-				"emailAddress", changeEmail.toString());
 	}
 
 	@Test

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ced7c3b7/security-admin/src/test/java/org/apache/ranger/common/TestDateUtil.java
----------------------------------------------------------------------
diff --git a/security-admin/src/test/java/org/apache/ranger/common/TestDateUtil.java b/security-admin/src/test/java/org/apache/ranger/common/TestDateUtil.java
index a55bbdf..1673f6f 100644
--- a/security-admin/src/test/java/org/apache/ranger/common/TestDateUtil.java
+++ b/security-admin/src/test/java/org/apache/ranger/common/TestDateUtil.java
@@ -71,12 +71,5 @@ public class TestDateUtil {
 		Assert.assertEquals(currentDate.getDate(),date.getDate());
 		Assert.assertEquals(currentDate.getMinutes(),mins);
 	}
-	
-	@Ignore("test to be reviewed")
-	@Test
-	public void testGetUTCDate1(){
-		Date date=new Date();
-		Date userdate=DateUtil.getUTCDate();
-		Assert.assertEquals(userdate.getDate(),date.getDate());
-	}
+
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ced7c3b7/security-admin/src/test/java/org/apache/ranger/common/TestStringUtil.java
----------------------------------------------------------------------
diff --git a/security-admin/src/test/java/org/apache/ranger/common/TestStringUtil.java b/security-admin/src/test/java/org/apache/ranger/common/TestStringUtil.java
index 044aebb..1dfedb4 100644
--- a/security-admin/src/test/java/org/apache/ranger/common/TestStringUtil.java
+++ b/security-admin/src/test/java/org/apache/ranger/common/TestStringUtil.java
@@ -128,7 +128,7 @@ public class TestStringUtil {
 	
 	@Test
 	public void testValidateEmailId(){
-		String email="jitendra.sonkar@freestoneinfotech.com";				
+		String email="rangerqa@apache.org";
 		boolean value=stringUtil.validateEmail(email);
 		Assert.assertTrue(email.length() < 128);
 		Assert.assertTrue(value);


Mime
View raw message