ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gau...@apache.org
Subject ranger git commit: RANGER-1638 : Improve the password validation from Ranger API
Date Mon, 10 Jul 2017 08:58:24 GMT
Repository: ranger
Updated Branches:
  refs/heads/master 324a8e872 -> 8d32649f9


RANGER-1638 : Improve the password validation from Ranger API


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

Branch: refs/heads/master
Commit: 8d32649f935fc0ade400db94c20d909fa1f767e1
Parents: 324a8e8
Author: Gautam Borad <gautam@apache.org>
Authored: Fri Jun 23 13:50:18 2017 +0530
Committer: Gautam Borad <gautam@apache.org>
Committed: Mon Jul 10 14:23:15 2017 +0530

----------------------------------------------------------------------
 .../java/org/apache/ranger/biz/XUserMgr.java    | 27 +++++++++++++++++---
 .../org/apache/ranger/biz/TestXUserMgr.java     |  3 ++-
 2 files changed, 26 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ranger/blob/8d32649f/security-admin/src/main/java/org/apache/ranger/biz/XUserMgr.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/biz/XUserMgr.java b/security-admin/src/main/java/org/apache/ranger/biz/XUserMgr.java
index cd1de9f..b973b9a 100644
--- a/security-admin/src/main/java/org/apache/ranger/biz/XUserMgr.java
+++ b/security-admin/src/main/java/org/apache/ranger/biz/XUserMgr.java
@@ -180,6 +180,7 @@ public class XUserMgr extends XUserMgrBase {
 
 	public VXUser createXUser(VXUser vXUser) {
 		checkAdminAccess();
+                validatePassword(vXUser);
 		String userName = vXUser.getName();
 		if (userName == null || "null".equalsIgnoreCase(userName)
 				|| userName.trim().isEmpty()) {
@@ -382,8 +383,10 @@ public class XUserMgr extends XUserMgrBase {
 				&& password.equals(hiddenPasswordString)) {
 			vXPortalUser.setPassword(oldUserProfile.getPassword());
 		}
-		vXPortalUser.setPassword(password);
-
+                else if(password != null){
+                        validatePassword(vXUser);
+                        vXPortalUser.setPassword(password);
+                }
 		Collection<Long> groupIdList = vXUser.getGroupIdList();
 		XXPortalUser xXPortalUser = new XXPortalUser();
 		xXPortalUser = userMgr.updateUserWithPass(vXPortalUser);
@@ -514,6 +517,9 @@ public class XUserMgr extends XUserMgrBase {
 	public VXUserGroupInfo createXUserGroupFromMap(
 			VXUserGroupInfo vXUserGroupInfo) {
 		checkAdminAccess();
+                if(vXUserGroupInfo.getXuserInfo() != null) {
+                        validatePassword(vXUserGroupInfo.getXuserInfo());
+                }
 		VXUserGroupInfo vxUGInfo = new VXUserGroupInfo();
 
 		VXUser vXUser = vXUserGroupInfo.getXuserInfo();
@@ -614,6 +620,7 @@ public class XUserMgr extends XUserMgrBase {
 
 	public VXUser createXUserWithOutLogin(VXUser vXUser) {
 		checkAdminAccess();
+                validatePassword(vXUser);
 		return xUserService.createXUserWithOutLogin(vXUser);
 	}
 
@@ -2145,5 +2152,19 @@ public class XUserMgr extends XUserMgrBase {
 			}
 		}
 		return createdXUser;
-}
+        }
+        private void validatePassword(VXUser vXUser) {
+                if (vXUser.getPassword() != null && !vXUser.getPassword().isEmpty())
{
+                        boolean checkPassword = false;
+                        String pattern = "(?=.*[0-9])(?=.*[a-zA-Z]).{8,}";
+                        checkPassword = vXUser.getPassword().trim().matches(pattern);
+                        if (!checkPassword) {
+                                logger.warn("validatePassword(). Password should be minimum
8 characters with min one alphabet and one numeric.");
+                                throw restErrorUtil.createRESTException("serverMsg.xuserMgrValidatePassword",
MessageEnums.INVALID_PASSWORD, null, "Password should be minimum 8 characters with min one
alphabet and one numeric", null);
+                        }
+                } else {
+                        logger.warn("validatePassword(). Password cannot be blank/null.");
+                        throw restErrorUtil.createRESTException("serverMsg.xuserMgrValidatePassword",
MessageEnums.INVALID_PASSWORD, null, "Password cannot be blank/null", null);
+                }
+        }
 }

http://git-wip-us.apache.org/repos/asf/ranger/blob/8d32649f/security-admin/src/test/java/org/apache/ranger/biz/TestXUserMgr.java
----------------------------------------------------------------------
diff --git a/security-admin/src/test/java/org/apache/ranger/biz/TestXUserMgr.java b/security-admin/src/test/java/org/apache/ranger/biz/TestXUserMgr.java
index 30525b3..9846f67 100644
--- a/security-admin/src/test/java/org/apache/ranger/biz/TestXUserMgr.java
+++ b/security-admin/src/test/java/org/apache/ranger/biz/TestXUserMgr.java
@@ -185,6 +185,7 @@ public class TestXUserMgr {
 		vxUser.setName("grouptest");
 		vxUser.setUserRoleList(userRoleList);
 		vxUser.setGroupNameList(groupNameList);
+                vxUser.setPassword("usertest123");
 		return vxUser;
 	}
 
@@ -789,7 +790,7 @@ public class TestXUserMgr {
 		VXUser vXUser = new VXUser();
 		vXUser.setName("user1");
 		vXUser.setDescription("testuser1 -added for unit testing");
-
+                vXUser.setPassword("usertest123");
 		List<VXGroupUser> vXGroupUserList = new ArrayList<VXGroupUser>();
 		List<VXGroup> vXGroupList = new ArrayList<VXGroup>();
 


Mime
View raw message