Esempio n. 1
0
    /// <summary>
    /// Adds actions to the page header.
    /// </summary>
    protected void InitializeHeaderActions()
    {
        AddHeaderActions(new HeaderAction
        {
            Text                   = GetString("general.apply"),
            CommandName            = "save",
            RegisterShortcutScript = true
        });

        AddHeaderActions(new HeaderAction
        {
            Text          = GetString("general.search"),
            OnClientClick = CreateSearchActionClientScript(),
            CommandName   = "search",
            ButtonStyle   = ButtonStyle.Default,
        });

        AddHeaderActions(new HeaderAction
        {
            Text = string.Format(GetString("datacom.logout"), credentialProvider.GetCredential().UserName),
            GenerateSeparatorBeforeAction = true,
            CommandName   = "logout",
            OnClientClick = "return confirm('" + GetString("datacom.automation.confirmlogout") + "')",
            ButtonStyle   = ButtonStyle.Default,
        });

        HeaderActions.ActionPerformed += HeaderActions_ActionPerformed;
    }
    private DirectoryEntry GetOrCreateConnection(string domain, string baseDn)
    {
        DomainConnectionInfo info;

        if (!connectionsInfo.TryGetValue(domain, out info))
        {
            var credential = _credentialProvider.GetCredential(domain);
            var dc         = DomainController.FindOne(new DirectoryContext(DirectoryContextType.Domain, credential.UserName, credential.Password));
            info = new DomainConnectionInfo(dc.Name, credential);
            // mantaining a connection to rootDse object to make all ldap queries use this single connection under the hood. Increasing performance
            var entry = new DirectoryEntry(string.Format("LDAP://{0}/RootDSE", dc.Name));
            entry.RefreshCache();
            connections.Add(domain, entry);
        }
        return(new DirectoryEntry(string.Format("LDAP://{0}/{1}", info.Server, baseDn), info.Credential.UserName, info.Credential.Password));
    }
Esempio n. 3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Do not check login if it's a CallBack - search button was pressed (see CreateSearchActionClientScript method)
        if (!RequestHelper.IsCallback())
        {
            bool validCredential = false;
            try
            {
                validCredential = CheckCredential();
            }
            catch (Exception ex)
            {
                HandleException(ex);
                return;
            }

            if (!validCredential)
            {
                URLHelper.Redirect(UrlResolver.ResolveUrl(LoginPageUrl));
            }
        }

        try
        {
            if (!String.IsNullOrEmpty(ContactHiddenField.Value))
            {
                JsonSerializer serializer   = new JsonSerializer();
                Contact        freshContact = serializer.Unserialize <Contact>(ContactHiddenField.Value);
                if (Contact == null)
                {
                    ContactForm.MergeHint = true;
                }
                else
                {
                    if (Contact.ContactId != freshContact.ContactId)
                    {
                        ContactForm.MergeHint = true;
                    }
                    else if (String.IsNullOrEmpty(Contact.Phone) && String.IsNullOrEmpty(Contact.Email) && (!String.IsNullOrEmpty(freshContact.Phone) || !String.IsNullOrEmpty(freshContact.Email)))
                    {
                        ContactForm.MergeHint           = true;
                        ContactForm.MergeHintAttributes = new string[] { "Phone", "Email" };
                    }
                }
                Contact = freshContact;
            }
            ContactInfo     contactInfo = EditedObject as ContactInfo;
            ContactIdentity identity    = DataComHelper.CreateContactIdentity(contactInfo);
            Filter = identity.CreateFilter();
            // Do not search for contact if it's a CallBack - search button was pressed (see CreateSearchActionClientScript method)
            if (Contact == null && !RequestHelper.IsCallback())
            {
                DataComClient    client   = DataComHelper.CreateClient();
                IContactProvider provider = DataComHelper.CreateContactProvider(client, credentialProvider.GetCredential());
                ContactFinder    finder   = DataComHelper.CreateContactFinder(provider);
                Contact          match    = finder.Find(identity);
                if (match != null)
                {
                    ShowInformation(GetString("datacom.contactmatch"));
                    Contact = match;
                    ContactForm.MergeHint = true;
                }
                else
                {
                    ShowInformation(GetString("datacom.nocontactmatch"));
                }
            }
            InitializeHeaderActions();
            InitializeDataComForm();
        }
        catch (Exception exception)
        {
            HandleException(exception);
        }
    }
Esempio n. 4
0
 /// <summary>
 /// Creates a new caching dectorator.
 /// </summary>
 /// <param name="inner">The inner <see cref="ICredentialProvider"/> to wrap.</param>
 public CachedCredentialProvider([NotNull] ICredentialProvider inner)
 {
     _inner = inner ?? throw new ArgumentNullException(nameof(inner));
     _cache = new TransparentCache <Uri, NetworkCredential>(uri => inner.GetCredential(uri, null));
 }