async Task <HandlerReply> IRequestHandler <BindRequest> .Handle(ClientContext context, LdapEvents eventListener, BindRequest operation) { Dictionary <string, List <string> > rdn = RdnParser.ParseRdnString(operation.Name); AuthenticationEvent authEvent = new AuthenticationEvent(rdn, operation.Authentication); bool success = await eventListener.OnAuthenticationRequest(context, authEvent); if (success) { context.IsAuthenticated = true; context.Rdn = rdn; LdapResult ldapResult = new LdapResult(LdapResult.ResultCodeEnum.Success, null, null); BindResponse bindResponse = new BindResponse(ldapResult); return(new HandlerReply(new List <IProtocolOp> { bindResponse })); } else { context.IsAuthenticated = false; context.Rdn = new Dictionary <string, List <string> >(); LdapResult ldapResult = new LdapResult(LdapResult.ResultCodeEnum.InappropriateAuthentication, null, null); BindResponse bindResponse = new BindResponse(ldapResult); return(new HandlerReply(new List <IProtocolOp> { bindResponse })); } }
private static IEnumerable <LdapResult> Sync(Ldap ldap, string pattern) { logger.Info(nameof(LdapSyncTester), $"processing... sync pattern ={pattern}"); var directorySearcher = DirectorySearcher( ldap.LdapSyncUser, ldap.LdapSyncPassword, ldap); directorySearcher.Filter = pattern; directorySearcher.PageSize = 1000; var results = directorySearcher.FindAll(); foreach (SearchResult result in results) { DirectoryEntry entry = result.Entry( ldap.LdapSyncUser, ldap.LdapSyncPassword); string loginId = entry.Property(ldap.LdapSearchProperty); logger.Info(nameof(LdapSyncTester), $"processing...({loginId})"); var ldapResult = new LdapResult() { LoginId = entry.Property(ldap.LdapSearchProperty), Name = Name(loginId, entry, ldap: ldap), Enabled = Enabled(entry, ldap)?"True":"False", MailAddress = entry.Property(ldap.LdapMailAddress, ldap.LdapMailAddressPattern), UserCode = entry.Property(ldap.LdapUserCode, ldap.LdapUserCodePattern), DeptCode = entry.Property(ldap.LdapDeptCode, ldap.LdapDeptCodePattern), DeptName = entry.Property(ldap.LdapDeptName, ldap.LdapDeptNamePattern), ExtendedAttributes = string.Join(", ", ldap.LdapExtendedAttributes?.Select(attr => entry.Property(attr.Name, attr.Pattern)) ?? new string[0]), }; yield return(ldapResult); } }
async Task <HandlerReply> IRequestHandler <SearchRequest> .Handle(ClientContext context, LdapEvents eventListener, SearchRequest operation) { SearchEvent searchEvent = new SearchEvent { SearchRequest = operation, }; List <SearchResultReply> replies = await eventListener.OnSearchRequest(context, searchEvent); List <IProtocolOp> opReply = new List <IProtocolOp>(); foreach (SearchResultReply reply in replies) { SearchResultEntry entry = new SearchResultEntry(reply); opReply.Add(entry); } var resultCode = (replies.Count > 0) ? LdapResult.ResultCodeEnum.Success : LdapResult.ResultCodeEnum.NoSuchObject; LdapResult ldapResult = new LdapResult(resultCode, null, null); SearchResultDone searchResultDone = new SearchResultDone(ldapResult); opReply.Add(searchResultDone); return(new HandlerReply(opReply)); }
/// <summary> /// Create a new Ldap packet with message id /// </summary> /// <param name="messageId"></param> public LdapResultAttribute(LdapOperation operation, LdapResult result, String matchedDN = "", String diagnosticMessage = "") : base(operation) { ChildAttributes.Add(new LdapAttribute(UniversalDataType.Enumerated, (Byte)result)); ChildAttributes.Add(new LdapAttribute(UniversalDataType.OctetString, matchedDN)); ChildAttributes.Add(new LdapAttribute(UniversalDataType.OctetString, diagnosticMessage)); // todo add referral if needed // todo bindresponse can contain more child attributes... }
async Task <HandlerReply> IRequestHandler <ExtendedRequest> .Handle(ClientContext context, LdapEvents eventListener, ExtendedRequest operation) { if (operation.RequestName == StartTLS && SingletonContainer.GetCertificate() != null) { context.HasEncryptedConnection = true; return(new HandlerReply(new List <IProtocolOp> { new ExtendedOperationResponse( new LdapResult(LdapResult.ResultCodeEnum.Success, null, null), StartTLS, null ), })); } LdapResult ldapResult = new LdapResult(LdapResult.ResultCodeEnum.ProtocolError, null, null); BindResponse bindResponse = new BindResponse(ldapResult); return(new HandlerReply(new List <IProtocolOp> { bindResponse })); }
internal BindResponse(LdapResult ldapResult) { LdapResult = ldapResult; }
internal SearchResultDone(LdapResult ldapResult) { LdapResult = ldapResult; }
internal ExtendedOperationResponse(LdapResult ldapResult, string?responseName, string?responseValue) { LdapResult = ldapResult; ResponseName = responseName; ResponseValue = responseValue; }