File tree Expand file tree Collapse file tree
app/ldap_protocol/ldap_requests Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44License: https://github.com/MultiDirectoryLab/MultiDirectory/blob/main/LICENSE
55"""
66
7+ import contextlib
78from typing import AsyncGenerator , ClassVar
89
910from pydantic import Field , SecretStr
1718from ldap_protocol .kerberos .exceptions import (
1819 KRBAPIAddPrincipalError ,
1920 KRBAPIConnectionError ,
21+ KRBAPIDeletePrincipalError ,
2022)
2123from ldap_protocol .ldap_codes import LDAPCodes
2224from ldap_protocol .ldap_responses import INVALID_ACCESS_RESPONSE , AddResponse
@@ -453,13 +455,20 @@ async def handle( # noqa: C901
453455 # in case server is not available: raise error and rollback
454456 # stub cannot raise error
455457 if user :
458+ # NOTE: Try to delete existing principal if any
459+ with contextlib .suppress (KRBAPIDeletePrincipalError ):
460+ await ctx .kadmin .del_principal (
461+ user .get_upn_prefix (),
462+ )
463+
456464 pw = (
457465 self .password .get_secret_value ()
458466 if self .password
459467 else None
460468 )
461469 await ctx .kadmin .add_principal (user .get_upn_prefix (), pw )
462- if is_computer :
470+
471+ elif is_computer :
463472 await ctx .kadmin .add_principal (
464473 f"{ new_dir .host_principal } .{ base_dn .name } " ,
465474 None ,
You can’t perform that action at this time.
0 commit comments