Skip to content

Commit

Permalink
Merge pull request #199 from jwlodek/use-all-dcs
Browse files Browse the repository at this point in the history
Update authentication method for sync experiment to be more robust in…
  • Loading branch information
mrakitin authored Oct 29, 2024
2 parents b912a23 + 234f8a5 commit bef88fd
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions nslsii/sync_experiment/sync_experiment.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from ldap3 import Server, Connection, NTLM
from ldap3.core.exceptions import LDAPInvalidCredentialsResult
from ldap3.core.exceptions import LDAPInvalidCredentialsResult, LDAPSocketOpenError

import json
import re
Expand Down Expand Up @@ -88,21 +88,31 @@ def validate_proposal(data_session_value, beamline) -> Dict[str, Any]:

def authenticate(username):

auth_server = Server("dc2.bnl.gov", use_ssl=True)
authenticated = False
for server in ["1", "2", "3"]:
if authenticated:
break
auth_server = Server(f"dc{server}.bnl.gov", use_ssl=True)

try:
connection = Connection(
auth_server,
user=f"BNL\\{username}",
password=getpass("Password : "),
authentication=NTLM,
auto_bind=True,
raise_exceptions=True,
)
print(f"\nAuthenticated as : {connection.extend.standard.who_am_i()}")
authenticated = True

try:
connection = Connection(
auth_server,
user=f"BNL\\{username}",
password=getpass("Password : "),
authentication=NTLM,
auto_bind=True,
raise_exceptions=True,
)
print(f"\nAuthenticated as : {connection.extend.standard.who_am_i()}")
except LDAPInvalidCredentialsResult:
raise RuntimeError(f"Invalid credentials for user '{username}'.") from None
except LDAPSocketOpenError:
print(f"DC{server} server connection failed...")

except LDAPInvalidCredentialsResult:
raise RuntimeError(f"Invalid credentials for user '{username}'.") from None
if not authenticated:
raise RuntimeError("All authentication servers are unavailable.")


def should_they_be_here(username, new_data_session, beamline):
Expand Down

0 comments on commit bef88fd

Please sign in to comment.