C# permissions

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Daxthecon
    New Member
    • Jul 2008
    • 63

    #1

    C# permissions

    Code:
    if (username == "watson_c")
    			{
    				name.Visible = false;
    				changename.Visible = true;
    				changename.Value = "criteria here";
    			}
    The problem here is that I don't want to hardcode usernames... It's ridiculous to do if you are in a large company with poeple changing frequently and an app for almost everything then you are changing stuff in your code when it coulde be the Net admins issue with changing who is manager or whatever in the AD. So to negait this practice I want to query the ad and check to see if the person is a manager and make it so they can see the changename field. I don't know how to google search for this. I've tried "AD username permissions" and all that jazz it just comes up with permissions to ad queries and not queriest to get permissions. Anyone got a better source even a MSDN or a code sample would be great.
  • PRR
    Recognized Expert Contributor
    • Dec 2007
    • 750

    #2
    Are you using a database? How about using Generic Identity and Generic Principal or maybe windows identity and principal? Can you explain further?

    Comment

    • Daxthecon
      New Member
      • Jul 2008
      • 63

      #3
      Ok so right now I have an array catching a few properties from the LDAP(Active Directory). These properties are funneled into one variable and the if statement then tells the variable which property it wants for it's particular needs. What I need is to find anyone with that is a manager(which means they have direct reports) and puts them in to this statement. Basically then this statement just decides based on is the person a manager.

      Comment

      • PRR
        Recognized Expert Contributor
        • Dec 2007
        • 750

        #4
        Originally posted by Daxthecon
        Ok so right now I have an array catching a few properties from the LDAP(Active Directory). These properties are funneled into one variable and the if statement then tells the variable which property it wants for it's particular needs. What I need is to find anyone with that is a manager(which means they have direct reports) and puts them in to this statement. Basically then this statement just decides based on is the person a manager.
        Can you post some code?

        Comment

        • Daxthecon
          New Member
          • Jul 2008
          • 63

          #5
          Sure here is the code as it sits right now and I'll explain why it was done that way and it was meant for in short summary.
          Code:
          DirectoryEntry entry = new DirectoryEntry("LDAP://OU=DAXCON,DC=hq,DC=local");
          
          			DirectorySearcher search = new DirectorySearcher(entry);
          
          			search.Filter = "(samaccountname=" + username + ")";
          			search.PropertiesToLoad.Add("name");
          			search.PropertiesToLoad.Add("distinguishedName");
          			search.PropertiesToLoad.Add("mail");
                      search.PropertiesToLoad.Contains("manager");
          
          			foreach (SearchResult result in search.FindAll())
          			{
          				name.Text = result.Properties["name"][0].ToString();
          				email.Text = result.Properties["mail"][0].ToString();
          
          				string[] pieces = result.Properties["distinguishedName"][0].ToString().Split(',');
          
          				if (pieces[1] == "OU=11")
          				{
          					department.Text = "Bartonville";
          					depthead.Text = "Manager Name";
          					phone1.Text = "###";
          					phone2.Text = "###";
          					phone3.Text = "####";
          				}
          				if (pieces[1] == "OU=12")
          				{
          					department.Text = "Nebraska";
          					depthead.Text = "Manager Name";
          					phone1.Text = "###";
          					phone2.Text = "###";
          					phone3.Text = "####";
          				}
          				if (pieces[1] == "OU=13")
          				{
          					department.Text = "Sterling";
          					depthead.Text = "Manager Name";
          					phone1.Text = "###";
          					phone2.Text = "###";
          					phone3.Text = "####";
          				}
          				if (pieces[1] == "OU=20")
          				{
          					department.Text = "Southfield";
          					depthead.Text = "Manager Name";
          					phone1.Text = "###";
          					phone2.Text = "###";
          					phone3.Text = "####";
          				}
          				if (pieces[1] == "OU=30")
          				{
          					department.Text = "St. Louis";
          					depthead.Text = "Manager Name";
          					phone1.Text = "###";
          					phone2.Text = "###";
          					phone3.Text = "####";
          				}
          				if (pieces[1] == "OU=DAXCON")
          				{
          					department.Text = "No Office Listed";
          					depthead.Text = "None";
          					phone1.Text = "###";
          					phone2.Text = "###";
          					phone3.Text = "####";
          				}
                          if (pieces[1] == "CN=manager")
          			{
          				name.Visible = false;
          				changename.Visible = true;
                          changename.Value = ("distinguishedName");
          			}
          
          			}
          			entry.Close();
          		}
          		item13.Attributes.Add("onchange", "total()");
          		item14.Attributes.Add("onchange", "total()");
          
          
                 
          	}
          What the code does as of right now is hides a combo box full of the names of poeple in the company. If you are not authorized to see this box it shows your distinguishedNa me and then locks it to be uneditable. The code also finds your manager and phone number the cheating way which is something I am going to have to fix as well. But as of right now the array is shooting to a variable and that variable is being used mulitple times and can be used for any of the particular attributes that are loaded in the search filter.

          What I need to do is mak the last if statement go to the manager section and see if they are the manager of someone. If they are then they get permission to see the box. If not then they don't see the box. Simple and complicated. I realized the search would take place in the pieces array but I still am new to the AD and LDAP and don't know how to search it effectively.

          NOTE: Most of this code is from the former programmer as I am filling in his place.

          Comment

          Working...