public static boolean isUserLocked(Long value, Map<String, String> mapConnectorParams) { ALNTLogger.debug(LDAPUtility.class.getName(), "isUserLocked()", "entered for value : " + value); boolean accountLocked = false; int UF_ACCOUNTDISABLE = 0x0002; String encodePwd = LDAPUtility.getLdapColumnName( mapConnectorParams, CommonConstants.LDAP_PWD_ENCODING_COLUMN_NAME); boolean pwdEncodeEnabled = true; if (StringUtils.isNotNullOrNotEmpty(encodePwd) && encodePwd.equalsIgnoreCase("No")) { pwdEncodeEnabled = false; } else { pwdEncodeEnabled = true; } if (pwdEncodeEnabled) { if (value != null && ((value & UF_ACCOUNTDISABLE) == UF_ACCOUNTDISABLE)) { accountLocked = true; } } else { if (value != null && (value.intValue() == 1)) accountLocked = true; else accountLocked = false; } ALNTLogger.debug( LDAPUtility.class.getName(), "isUserLocked()", "accountLocked : " + accountLocked); return accountLocked; }
public static Long getUserAccessValue( String userId, LDAPConnectorService ldapConnection, Map<String, String> mapConnectorParams) throws ALNTApplicationException { ALNTLogger.debug( LDAPUtility.class.getName(), "getUserAccessValue()", "entered for userId : " + userId); Long userAccessValue = null; String encodePwd = LDAPUtility.getLdapColumnName( mapConnectorParams, CommonConstants.LDAP_PWD_ENCODING_COLUMN_NAME); String accountControlColumnName = LDAPUtility.getLdapColumnName( mapConnectorParams, CommonConstants.LDAP_ACCOUNT_CONTROL_COLUMN_NAME); boolean pwdEncodeEnabled = true; if (StringUtils.isNotNullOrNotEmpty(encodePwd) && encodePwd.equalsIgnoreCase("No")) { pwdEncodeEnabled = false; } else { pwdEncodeEnabled = true; } try { DirContext dirContext = ldapConnection.getDirContext(); SearchControls ctls = new SearchControls(); ctls.setSearchScope(SearchControls.SUBTREE_SCOPE); String searchObjClass = ldapConnection.getObjectClass(); if (searchObjClass == null || searchObjClass.trim().length() == 0) { searchObjClass = "user"; } ALNTLogger.debug( LDAPUtility.class.getName(), "getUserAccessValue()", "Search object class: " + searchObjClass); String userIdColumnName = (String) mapConnectorParams.get("userIdColumnName"); if (StringUtils.isNullOrEmpty(userIdColumnName)) { userIdColumnName = "sAMAccountName"; } NamingEnumeration attrs = dirContext.search( ldapConnection.getCompleteBaseDns(), "(&(objectClass=" + searchObjClass + ")(" + userIdColumnName + "=" + userId + "))", ctls); while (attrs.hasMoreElements()) { SearchResult result = (SearchResult) attrs.next(); Attributes userAttrs = result.getAttributes(); if (userAttrs != null) { Attribute userAccess = userAttrs // .get(LDAPConstants.LDAP_ATTR_UserAccntControl); .get(accountControlColumnName); if (!pwdEncodeEnabled) { if (userAccess == null) userAccessValue = Long.parseLong("0"); else { String status = userAccess.get().toString(); if (status.equalsIgnoreCase("true")) userAccessValue = Long.parseLong("1"); else userAccessValue = Long.parseLong("0"); } } else { if (userAccess != null && !"".equals(userAccess.get().toString())) { // accountLocked = isAccountDisable(Integer.parseInt(userAccess.get().toString())); userAccessValue = Long.parseLong(userAccess.get().toString()); } } } } } catch (Exception e) { ALNTLogger.error( LDAPUtility.class.getName(), "getUserAccessValue(): Error finding user locked: ", e); } ALNTLogger.debug( LDAPUtility.class.getName(), "getUserAccessValue()", "returning userAccessValue : " + userAccessValue); return userAccessValue; }