public static AddRequest GetAddRequest(ILdapUser user, string objectClass) { var addReq = new AddRequest {DistinguishedName = user.GetUserDn()}; addReq.Attributes.Add(new DirectoryAttribute("objectClass", objectClass)); addReq.Attributes.Add(new DirectoryAttribute("cn", user.GetUserCn())); addReq.Attributes.Add(new DirectoryAttribute("sn", user.GetUserSn())); foreach (string attributeName in user.GetUserAttributeKeys()) { foreach (string attributeValue in user.GetUserAttribute(attributeName)) { addReq.Attributes.Add(new DirectoryAttribute(attributeName, attributeValue)); } } return addReq; }
/// <summary> /// LDAP library constructior where all the class variables are initialized /// The variables not specified in definition will be set at default values. /// </summary> /// <param name="adminUser">Admin user</param> /// <param name="adminMode">Admin User</param> /// <param name="ldapServer">LDAP Server with port</param> /// <param name="ldapSearchBaseDn">Base DN where start the search.</param> /// <param name="authType"></param> /// <param name="loggerType">Mode to log</param> /// <param name="logPath">Path of the logger File</param> public LdapManager(ILdapUser adminUser, LDAPAdminMode adminMode, string ldapServer, string ldapSearchBaseDn, AuthType authType, LoggerType loggerType, string logPath ) { _configRepository = LdapConfigRepositoryFactory.GetConfigRepository(); try { _configRepository.BasicLdapConfig(adminUser,adminMode, ldapServer, ldapSearchBaseDn, authType, loggerType, logPath); _logger = LoggerFactory.GetLogger(_configRepository.GetWriteLogFlag(), _configRepository.GetLogPath()); } catch (ArgumentNullException) { _ldapCurrentState = LdapState.LdapLibraryInitError; throw; } _adminModeChecker = new LdapAdminModeChecker(_configRepository); CommonInitOperations(); _ldapCurrentState = LdapState.LdapLibraryInitSuccess; }
/// <summary> /// LDAP library constructior where all the class variables are initialized /// The variables not specified in definition will be set at default values. /// </summary> /// <param name="adminUser">Admin user</param> /// <param name="adminMode">Admin User</param> /// <param name="ldapServer">LDAP Server with port</param> /// <param name="ldapSearchBaseDn">Base DN where start the search.</param> /// <param name="authType"></param> /// <param name="loggerType">Mode to log</param> /// <param name="logPath">Path of the logger File</param> public LdapManager(ILdapUser adminUser, LDAPAdminMode adminMode, string ldapServer, string ldapSearchBaseDn, AuthType authType, LoggerType loggerType, string logPath ) { _configRepository = LdapConfigRepositoryFactory.GetConfigRepository(); try { _configRepository.BasicLdapConfig(adminUser, adminMode, ldapServer, ldapSearchBaseDn, authType, loggerType, logPath); _logger = LoggerFactory.GetLogger(_configRepository.GetWriteLogFlag(), _configRepository.GetLogPath()); } catch (ArgumentNullException) { _ldapCurrentState = LdapState.LdapLibraryInitError; throw; } _adminModeChecker = new LdapAdminModeChecker(_configRepository); CommonInitOperations(); _ldapCurrentState = LdapState.LdapLibraryInitSuccess; }
public static ModifyRequest GetModifyPasswordRequest(ILdapUser user, string newPassword) { var modifyUserPassword = new DirectoryAttributeModification { Operation = DirectoryAttributeOperation.Replace, Name = "userPassword" }; modifyUserPassword.Add(newPassword); return new ModifyRequest(user.GetUserDn(), modifyUserPassword); }
public static ModifyRequest GetModifyPasswordRequest(ILdapUser user, string newPassword) { var modifyUserPassword = new DirectoryAttributeModification { Operation = DirectoryAttributeOperation.Replace, Name = "userPassword" }; modifyUserPassword.Add(newPassword); return(new ModifyRequest(user.GetUserDn(), modifyUserPassword)); }
public void UpdateModel(User user, ILdapUser ldapUser) { user.Guid = ldapUser.Guid; user.Name = ldapUser.Name; user.LdapSid = ldapUser.Sid; user.DisplayName = ldapUser.DisplayName; user.Description = ldapUser.Description; user.Created = ldapUser.Created; user.Updated = ldapUser.Updated; user.EmployeeId = ldapUser.EmployeeId; user.Email = ldapUser.Email; }
/// <summary> /// Delete an LDAPUser /// </summary> /// <param name="user">User to delete</param> /// <returns>Success or Failed</returns> public LdapState DeleteUser(ILdapUser user) { try { _ldapConnection.SendRequest(LdapRequestBuilder.GetDeleteRequest(user)); } catch (Exception e) { _logger.Write(_logger.BuildLogMessage(e.Message, LdapState.LdapDeleteUserError)); return(LdapState.LdapDeleteUserError); } _logger.Write(_logger.BuildLogMessage("Delete User Operation Success", LdapState.LdapUserManipulatorSuccess)); return(LdapState.LdapUserManipulatorSuccess); }
public void BasicLdapConfig(ILdapUser adminUser, LDAPAdminMode adminMode, string server, string searchBaseDn, AuthType authType, LoggerType loggerType, string logPath) { BasicLdapConfigValidator(server, loggerType, logPath,searchBaseDn,adminUser,adminMode); _authType = authType; _searchBaseDn = searchBaseDn; _server = server; _adminUser = adminUser; _loggerType = loggerType; _logPath = logPath; _adminMode = adminMode; StandardLdapInformation(); }
/// <summary> /// Delete an LDAPUser /// </summary> /// <param name="user">User to delete</param> /// <returns>Success or Failed</returns> public LdapState DeleteUser(ILdapUser user) { try { _ldapConnection.SendRequest(LdapRequestBuilder.GetDeleteRequest(user)); } catch (Exception e) { _logger.Write(_logger.BuildLogMessage(e.Message, LdapState.LdapDeleteUserError)); return LdapState.LdapDeleteUserError; } _logger.Write(_logger.BuildLogMessage("Delete User Operation Success", LdapState.LdapUserManipulatorSuccess)); return LdapState.LdapUserManipulatorSuccess; }
/// <summary> /// Create a new LDAPUser /// </summary> /// <param name="newUser">User to create</param> /// <returns> Success or Failed</returns> public LdapState CreateUser(ILdapUser newUser) { try { _ldapConnection.SendRequest(LdapRequestBuilder.GetAddRequest(newUser, _configRepository.GetUserObjectClass())); } catch (Exception e) { _logger.Write(_logger.BuildLogMessage(e.Message, LdapState.LdapCreateUserError)); return LdapState.LdapCreateUserError; } _logger.Write(_logger.BuildLogMessage("Create User Operation Success", LdapState.LdapUserManipulatorSuccess)); return LdapState.LdapUserManipulatorSuccess; }
/// <summary> /// Create a new LDAPUser /// </summary> /// <param name="newUser">User to create</param> /// <returns> Success or Failed</returns> public LdapState CreateUser(ILdapUser newUser) { try { _ldapConnection.SendRequest(LdapRequestBuilder.GetAddRequest(newUser, _configRepository.GetUserObjectClass())); } catch (Exception e) { _logger.Write(_logger.BuildLogMessage(e.Message, LdapState.LdapCreateUserError)); return(LdapState.LdapCreateUserError); } _logger.Write(_logger.BuildLogMessage("Create User Operation Success", LdapState.LdapUserManipulatorSuccess)); return(LdapState.LdapUserManipulatorSuccess); }
public ILdapUser Get(ILdapUser user) { var _identity = GetIdentityType(user); if (_identity != null) { var _context = ldap.GetPrincipalContext(user.Domain); UserPrincipal _user = UserPrincipal.FindByIdentity(_context, _identity.Type, _identity.Value); return _user != null ? Fabric.CastLdapUser(_user) : null; } else { throw new ArgumentNullException("Object identity not defined"); } }
public ILdapUser Create(ILdapUser user, string password, string path = "") { using (PrincipalContext _context = ldap.GetPrincipalContext(user.Domain)) { if (Get(user) == null) { UserPrincipal _newUser = Create(user, password, ldap.GetPrincipalContext(user.Domain, path)); return Fabric.CastLdapUser(_newUser); } else { throw new Exception(string.Format("{0}: {1}.", log.Name, "LDAP user exist")); } } }
public void BasicLdapConfig(ILdapUser adminUser, LDAPAdminMode adminMode, string server, string searchBaseDn, AuthType authType, LoggerType loggerType, string logPath) { _adminMode = adminMode; _loggerType = loggerType; _authType = authType; BasicLdapConfigValidator(server, logPath, searchBaseDn, adminUser); _searchBaseDn = searchBaseDn; _server = server; _adminUser = adminUser; _logPath = logPath; StandardLdapInformation(); }
/// <summary> /// Change an LDAPUser's Password /// </summary> /// <param name="user">LDAPUser to change the password</param> /// <param name="newPwd">New Passowrd</param> /// <returns>Success or Failed</returns> public LdapState ChangeUserPassword(ILdapUser user, string newPwd) { try { _ldapConnection.SendRequest(LdapRequestBuilder.GetModifyPasswordRequest(user, newPwd)); } catch (Exception e) { _logger.Write(_logger.BuildLogMessage(e.Message, LdapState.LdapChangeUserPasswordError)); return(LdapState.LdapChangeUserPasswordError); } user.OverwriteUserAttribute("userPassword", newPwd); _logger.Write(_logger.BuildLogMessage("Change Password Operation Success", LdapState.LdapUserManipulatorSuccess)); return(LdapState.LdapUserManipulatorSuccess); }
public static AddRequest GetAddRequest(ILdapUser user, string objectClass) { var addReq = new AddRequest { DistinguishedName = user.GetUserDn() }; addReq.Attributes.Add(new DirectoryAttribute("objectClass", objectClass)); addReq.Attributes.Add(new DirectoryAttribute("cn", user.GetUserCn())); addReq.Attributes.Add(new DirectoryAttribute("sn", user.GetUserSn())); foreach (string attributeName in user.GetUserAttributeKeys()) { foreach (string attributeValue in user.GetUserAttribute(attributeName)) { addReq.Attributes.Add(new DirectoryAttribute(attributeName, attributeValue)); } } return(addReq); }
/// <summary> /// Modify an LDAPUser Attribute /// </summary> /// <param name="operationType">Operation to execute on the attribute</param> /// <param name="user">LDAPUser's Attribute</param> /// <param name="attributeName">Attribute name</param> /// <param name="attributeValue">Attribute Value</param> /// <returns>Success or Failed</returns> public LdapState ModifyUserAttribute(DirectoryAttributeOperation operationType, ILdapUser user, string attributeName, string attributeValue) { try { _ldapConnection.SendRequest(LdapRequestBuilder.GetModifyRequest(user, operationType, attributeName, attributeValue)); } catch (Exception e) { _logger.Write(_logger.BuildLogMessage(e.Message, LdapState.LdapModifyUserAttributeError)); return LdapState.LdapModifyUserAttributeError; } user.GetUserOperation(operationType, attributeName, attributeValue)(); _logger.Write(_logger.BuildLogMessage("Modify User Attribute Operation Success", LdapState.LdapUserManipulatorSuccess)); return LdapState.LdapUserManipulatorSuccess; }
/// <summary> /// More detailed contructor that user the default constructor and the addictionalLDAPInformation method /// </summary> public LdapManager(ILdapUser adminUser, LDAPAdminMode adminMode, string ldapServer, string ldapSearchBaseDn, AuthType authType, bool secureSocketLayerFlag, bool transportSocketLayerFlag, bool clientCertificateFlag, string clientCertificatePath, LoggerType loggerType, string logPath, string userObjectClass, string matchFieldUsername ) : this(adminUser, adminMode, ldapServer, ldapSearchBaseDn, authType, loggerType, logPath) { try { _configRepository.AdditionalLdapConfig(secureSocketLayerFlag, transportSocketLayerFlag, clientCertificateFlag, clientCertificatePath, userObjectClass, matchFieldUsername); } catch (ArgumentNullException e) { _ldapCurrentState = LdapState.LdapLibraryInitError; _logger.Write(_logger.BuildLogMessage(e.Message, _ldapCurrentState)); throw; } _connector = LdapConnectorFactory.GetLdapConnector(_adminModeChecker, _configRepository, _logger); _manageLdapUser = LdapUserManipulatorFactory.GetUserManipulator(_connector, _logger, _configRepository); _ldapCurrentState = LdapState.LdapLibraryInitSuccess; _logger.Write(_logger.BuildLogMessage("", _ldapCurrentState)); }
/// <summary> /// More detailed contructor that user the default constructor and the addictionalLDAPInformation method /// </summary> public LdapManager(ILdapUser adminUser, LDAPAdminMode adminMode, string ldapServer, string ldapSearchBaseDn, AuthType authType, bool secureSocketLayerFlag, bool transportSocketLayerFlag, bool clientCertificateFlag, string clientCertificatePath, LoggerType loggerType, string logPath, string userObjectClass, string matchFieldUsername, TimeSpan connectionTimeout) : this(adminUser, adminMode, ldapServer, ldapSearchBaseDn, authType, loggerType, logPath) { try { _configRepository.AdditionalLdapConfig(secureSocketLayerFlag, transportSocketLayerFlag, clientCertificateFlag, clientCertificatePath, userObjectClass, matchFieldUsername, connectionTimeout); } catch (ArgumentNullException e) { _ldapCurrentState = LdapState.LdapLibraryInitError; _logger.Write(_logger.BuildLogMessage(e.Message, _ldapCurrentState)); throw; } CommonInitOperations(); _ldapCurrentState = LdapState.LdapLibraryInitSuccess; _logger.Write(_logger.BuildLogMessage("", _ldapCurrentState)); }
public static ModifyRequest GetModifyRequest(ILdapUser user, DirectoryAttributeOperation attributeOperation, string attributeName, string attributeValue) { return(new ModifyRequest(user.GetUserDn(), attributeOperation, attributeName, attributeValue)); }
public static DeleteRequest GetDeleteRequest(ILdapUser user) { return(new DeleteRequest(user.GetUserDn())); }
/// <summary> /// Check the validity of parameters /// /// * Server and searchBaseDn cannot be null or empty /// * logPath cannot be null or empty if the loggerType is set to File /// * Admin cannot be null if there's admin mode /// /// Used in the BasicLdapConfig method /// /// Can throw an ArgumentNullException /// </summary> /// <param name="server">Server URL</param> /// <param name="loggerType"></param> /// <param name="logPath">Path of the log file</param> /// <param name="searchBaseDn">Search Root Node</param> /// <param name="admin">Admin User</param> /// <param name="adminMode">Library Admin Mode</param> private void BasicLdapConfigValidator(string server, string logPath, string searchBaseDn, ILdapUser admin) { if (String.IsNullOrEmpty(server) || (String.IsNullOrEmpty(logPath) && GetWriteLogFlag() == LoggerType.File) || (GetAdminMode() == LDAPAdminMode.Admin && admin == null) || (String.IsNullOrEmpty(searchBaseDn) && GetAdminMode() != LDAPAdminMode.NoAdmin)) { throw new ArgumentNullException(String.Format(BasicConfigNullParametersErrorMessage)); } }
public bool CreateUser(ILdapUser newUser) { _ldapCurrentState = _manageLdapUser.CreateUser(newUser); return(LdapStateUtils.ToBoolean(_ldapCurrentState)); }
public bool ChangeUserPassword(ILdapUser user, string newPwd) { _ldapCurrentState = _manageLdapUser.ChangeUserPassword(user, newPwd); return LdapStateUtils.ToBoolean(_ldapCurrentState); }
public bool ModifyUserAttribute(DirectoryAttributeOperation operationType, ILdapUser user, string attributeName, string attributeValue) { _ldapCurrentState = _manageLdapUser.ModifyUserAttribute(operationType, user, attributeName, attributeValue); return LdapStateUtils.ToBoolean(_ldapCurrentState); }
/// <summary> /// Change an LDAPUser's Password /// </summary> /// <param name="user">LDAPUser to change the password</param> /// <param name="newPwd">New Passowrd</param> /// <returns>Success or Failed</returns> public LdapState ChangeUserPassword(ILdapUser user, string newPwd) { try { _ldapConnection.SendRequest(LdapRequestBuilder.GetModifyPasswordRequest(user, newPwd)); } catch (Exception e) { _logger.Write(_logger.BuildLogMessage(e.Message, LdapState.LdapChangeUserPasswordError)); return LdapState.LdapChangeUserPasswordError; } user.OverwriteUserAttribute("userPassword", newPwd); _logger.Write(_logger.BuildLogMessage("Change Password Operation Success", LdapState.LdapUserManipulatorSuccess)); return LdapState.LdapUserManipulatorSuccess; }
/// <summary> /// Modify an LDAPUser Attribute /// </summary> /// <param name="operationType">Operation to execute on the attribute</param> /// <param name="user">LDAPUser's Attribute</param> /// <param name="attributeName">Attribute name</param> /// <param name="attributeValue">Attribute Value</param> /// <returns>Success or Failed</returns> public LdapState ModifyUserAttribute(DirectoryAttributeOperation operationType, ILdapUser user, string attributeName, string attributeValue) { try { _ldapConnection.SendRequest(LdapRequestBuilder.GetModifyRequest(user, operationType, attributeName, attributeValue)); } catch (Exception e) { _logger.Write(_logger.BuildLogMessage(e.Message, LdapState.LdapModifyUserAttributeError)); return(LdapState.LdapModifyUserAttributeError); } user.GetUserOperation(operationType, attributeName, attributeValue)(); _logger.Write(_logger.BuildLogMessage("Modify User Attribute Operation Success", LdapState.LdapUserManipulatorSuccess)); return(LdapState.LdapUserManipulatorSuccess); }
/// <summary> /// Check the validity of parameters /// /// * Server and searchBaseDn cannot be null or empty /// * logPath cannot be null or empty if the loggerType is set to File /// * Admin cannot be null if there's admin mode /// /// Used in the BasicLdapConfig method /// /// Can throw an ArgumentNullException /// </summary> /// <param name="server">Server URL</param> /// <param name="loggerType"></param> /// <param name="logPath">Path of the log file</param> /// <param name="searchBaseDn">Search Root Node</param> /// <param name="admin">Admin User</param> /// <param name="adminMode">Library Admin Mode</param> private void BasicLdapConfigValidator(string server, string logPath, string searchBaseDn, ILdapUser admin) { if ( String.IsNullOrEmpty(server) || (String.IsNullOrEmpty(logPath) && GetWriteLogFlag() == LoggerType.File) || (GetAdminMode() == LDAPAdminMode.Admin && admin == null) || (String.IsNullOrEmpty(searchBaseDn) && GetAdminMode() != LDAPAdminMode.NoAdmin)) throw new ArgumentNullException(String.Format(BasicConfigNullParametersErrorMessage)); }
public bool ChangeUserPassword(ILdapUser user, string newPwd) { _ldapCurrentState = _manageLdapUser.ChangeUserPassword(user, newPwd); return(LdapStateUtils.ToBoolean(_ldapCurrentState)); }
public static ModifyRequest GetModifyRequest(ILdapUser user, DirectoryAttributeOperation attributeOperation,string attributeName, string attributeValue) { return new ModifyRequest(user.GetUserDn(), attributeOperation, attributeName, attributeValue); }
public ILdapUser Update(ILdapUser user) { throw new NotImplementedException(); }
public bool DeleteUser(ILdapUser user) { _ldapCurrentState = _manageLdapUser.DeleteUser(user); return(LdapStateUtils.ToBoolean(_ldapCurrentState)); }
/// <summary> /// Check the validity of parameters /// /// * Server and searchBaseDn cannot be null or empty /// * logPath cannot be null or empty if the loggerType is set to File /// * Admin cannot be null if there's admin mode /// /// Used in the BasicLdapConfig method /// /// Can throw an ArgumentNullException /// </summary> /// <param name="server">Server URL</param> /// <param name="loggerType"></param> /// <param name="logPath">Path of the log file</param> /// <param name="searchBaseDn">Search Root Node</param> /// <param name="admin">Admin User</param> /// <param name="adminMode">Library Admin Mode</param> private static void BasicLdapConfigValidator(string server, LoggerType loggerType, string logPath, string searchBaseDn, ILdapUser admin, LDAPAdminMode adminMode) { if (LdapParameterChecker.ParametersIsNullOrEmpty(new[] { server, searchBaseDn }) || (LdapParameterChecker.ParametersIsNullOrEmpty(new[] { logPath })) && loggerType == LoggerType.File || (adminMode == LDAPAdminMode.Admin && admin == null)) throw new ArgumentNullException(String.Format(BasicConfigNullParametersErrorMessage)); }
public void SetupTestUser(string testUserDn, string testUserCn, string testUserSn, Dictionary<string, List<string>> testUserOtherAttribute) { TestUser = new LdapUser(testUserDn, testUserCn, testUserSn, testUserOtherAttribute); }
public bool CreateUser(ILdapUser newUser) { _ldapCurrentState = _manageLdapUser.CreateUser(newUser); return LdapStateUtils.ToBoolean(_ldapCurrentState); }
public static DeleteRequest GetDeleteRequest(ILdapUser user) { return new DeleteRequest(user.GetUserDn()); }
public bool DeleteUser(ILdapUser user) { _ldapCurrentState = _manageLdapUser.DeleteUser(user); return LdapStateUtils.ToBoolean(_ldapCurrentState); }
private UserPrincipal Create(ILdapUser user, string password, PrincipalContext context) { try { UserPrincipal _newUser = new UserPrincipal(context, user.SamAccountName, password, true); _newUser.Name = user.Name; _newUser.UserPrincipalName = user.UserPrincipalName; _newUser.GivenName = user.GivenName; _newUser.Surname = user.Surname; _newUser.DisplayName = user.DisplayName; _newUser.Description = user.Description; _newUser.Save(); SetUserProperties(_newUser, user.Properties); return _newUser; } catch(Exception ex) { throw new Exception(ex.Message + ". [" + log.Name + "]"); } }
public bool ModifyUserAttribute(DirectoryAttributeOperation operationType, ILdapUser user, string attributeName, string attributeValue) { _ldapCurrentState = _manageLdapUser.ModifyUserAttribute(operationType, user, attributeName, attributeValue); return(LdapStateUtils.ToBoolean(_ldapCurrentState)); }