Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop cleanup ldap et al #2371

Merged
merged 3 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 4 additions & 16 deletions roles/middleware/files/FWO.Middleware.Server/Ldap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ private LdapConnection Connect()
}

/// <summary>
/// try an ldap bind
/// decrypting pwd before bind
/// try an ldap bind, decrypting pwd before bind; using pwd as is if it cannot be decrypted
/// false if bind fails
/// </summary>
private bool TryBind(LdapConnection connection, string user, string password)
Expand Down Expand Up @@ -150,9 +149,6 @@ private string getGroupSearchFilter(string searchPattern)
// Connecting to Ldap
using (LdapConnection connection = Connect())
{
// Authenticate as search user
// connection.Bind(SearchUser, AesEnc.Decrypt(SearchUserPwd, AesEnc.GetMainKey()));
// connection.Bind(SearchUser, SearchUserPwd);
TryBind(connection, SearchUser, SearchUserPwd);

LdapSearchConstraints cons = connection.SearchConstraints;
Expand Down Expand Up @@ -227,10 +223,7 @@ private bool CredentialsValid(LdapConnection connection, string dn, string passw
Log.WriteDebug("User Validation", $"Trying to validate user with distinguished name: \"{dn}\" ...");

// Try to authenticate as user with given password
connection.Bind(dn, password);

// If authentication was successful (user is bound)
if (connection.Bound)
if (TryBind(connection, dn, password))
{
// Return ldap dn
Log.WriteDebug("User Validation", $"\"{dn}\" successfully authenticated in {Address}:{Port}.");
Expand Down Expand Up @@ -301,9 +294,7 @@ public string ChangePassword(string userDn, string oldPassword, string newPasswo
using (LdapConnection connection = Connect())
{
// Try to authenticate as user with old password
connection.Bind(userDn, oldPassword);

if (connection.Bound)
if (TryBind(connection, userDn, oldPassword))
{
// authentication was successful (user is bound): set new password
LdapAttribute attribute = new LdapAttribute("userPassword", newPassword);
Expand Down Expand Up @@ -336,9 +327,6 @@ public string SetPassword(string userDn, string newPassword)
// Connecting to Ldap
using (LdapConnection connection = Connect())
{
// Authenticate as write user
// connection.Bind(WriteUser, WriteUserPwd);
// if (connection.Bound)
if (TryBind(connection, WriteUser, WriteUserPwd))
{
// authentication was successful: set new password
Expand Down Expand Up @@ -455,7 +443,7 @@ public List<RoleGetReturnParameters> GetAllRoles()
using (LdapConnection connection = Connect())
{
// Authenticate as search user
connection.Bind(SearchUser, SearchUserPwd);
TryBind(connection, SearchUser, SearchUserPwd);

// Search for Ldap roles in given directory
int searchScope = LdapConnection.ScopeSub; // TODO: Correct search scope?
Expand Down
4 changes: 0 additions & 4 deletions scripts/customizing/customizeFwoSampleScript.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# library for FWORCH API calls
from asyncio.log import logger
import re
import traceback
from sqlite3 import Timestamp
from textwrap import indent
import requests.packages
import requests
import json
Expand Down