IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

Propriétés du LDAP


Sujet :

C#

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Inscrit en
    Juillet 2005
    Messages
    69
    Détails du profil
    Informations forums :
    Inscription : Juillet 2005
    Messages : 69
    Par défaut Propriétés du LDAP
    Bonjour,

    J’essaie d’afficher les utilisateurs appartenant à un groupe donnée.
    Je récupère les divers attributs (givenname, sn, c, co, lastLogon…), par contre je n’arrive pas à afficher la valeur du « cn ».
    Est ce que vous savez comment je dois extraire cette valeur car le
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Properties["cn"][0].ToString()
    m'affiche un code qui me sert pas à grand chose "S-1-5-21-1202660629-1767777339-725345543"

    Merci d'avance

  2. #2
    Rédacteur
    Avatar de Thomas Lebrun
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    9 161
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 9 161
    Par défaut
    Là, il t'affiche le SSID. Mais pourquoi tu veux le CN ?

  3. #3
    Membre confirmé
    Inscrit en
    Juillet 2005
    Messages
    69
    Détails du profil
    Informations forums :
    Inscription : Juillet 2005
    Messages : 69
    Par défaut
    Merci pour ta réponse.

    En fait, je veux afficher les principales propriétés des utilisateurs et je crois que le "cn" permet de récupérer le Nom de l'utilisateur.

  4. #4
    Membre éclairé
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    801
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2005
    Messages : 801
    Par défaut
    Oui, moi je récpère le nom d'utilisateur ainsi:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    String name = (String)entry.Properties["cn"].Value;

  5. #5
    Rédacteur
    Avatar de Thomas Lebrun
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    9 161
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 9 161
    Par défaut
    Tu pourrais nous montrer un peu plus de code ?

  6. #6
    Membre éclairé
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    801
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2005
    Messages : 801
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
     
        public void getInfo()
        {
             DirectoryEntry ldap = new DirectoryEntry(_rootEntry, AdAdministrator.username, AdAdministrator.password);
             DirectorySearcher searcher = new DirectorySearcher(ldap);
             searcher.Filter = "(sAMAccountName=" + SGI + ")";
             searcher.SearchScope = SearchScope.Subtree;
             searcher.SearchRoot = ldap;
             SearchResult result = searcher.FindOne();
             DirectoryEntry User = result.GetDirectoryEntry();
             DIRECTORY_ENTRY = User;
             CN = (string)DIRECTORY_ENTRY.Properties["cn"].Value;
             Assistant = (System.DirectoryServices.DirectoryEntry)DIRECTORY_ENTRY.Properties["assistant"].Value;
             BusinessCategory = (string)DIRECTORY_ENTRY.Properties["businessCategory"].Value;
             Co = (string)DIRECTORY_ENTRY.Properties["co"].Value;
             Company = (string)DIRECTORY_ENTRY.Properties["company"].Value;
             CountryCode = (int)DIRECTORY_ENTRY.Properties["countryCode"].Value;
             Department = (string)DIRECTORY_ENTRY.Properties["department"].Value;
             Description = (string)DIRECTORY_ENTRY.Properties["description"].Value;
             DisplayName = (string)DIRECTORY_ENTRY.Properties["displayName"].Value;
             Division = (string)DIRECTORY_ENTRY.Properties["division"].Value;
             EmployeeID = (string)DIRECTORY_ENTRY.Properties["employeeID"].Value;
             FacsimileTelephoneNumber = (string)DIRECTORY_ENTRY.Properties["facsimileTelephoneNumber"].Value;
             GivenName = (string)DIRECTORY_ENTRY.Properties["givenName"].Value;
             HomePhone = (string)DIRECTORY_ENTRY.Properties["homePhone"].Value;
             HomePostalAddress = (string)DIRECTORY_ENTRY.Properties["homePostalAddress"].Value;
             Initials = (string)DIRECTORY_ENTRY.Properties["initials"].Value;
             Info = (string)DIRECTORY_ENTRY.Properties["info"].Value;
             IPPhone = (string)DIRECTORY_ENTRY.Properties["ipPhone"].Value;
             L = (string)DIRECTORY_ENTRY.Properties["l"].Value;
             Mail = (string)DIRECTORY_ENTRY.Properties["mail"].Value;
             Manager = (string)DIRECTORY_ENTRY.Properties["manager"].Value;
             Mobile = (string)DIRECTORY_ENTRY.Properties["mobile"].Value;
             OtherFacsimileTelephoneNumber = (string)DIRECTORY_ENTRY.Properties["otherFacsimileTelephoneNumber"].Value;
             OtherHomePhone = (string)DIRECTORY_ENTRY.Properties["otherHomePhone"].Value;
             OtherIPPhone = (string)DIRECTORY_ENTRY.Properties["otherIpPhone"].Value;
             OtherMailbox = (string)DIRECTORY_ENTRY.Properties["otherMailbox"].Value;
             OtherMobile = (string)DIRECTORY_ENTRY.Properties["otherMobile"].Value;
     
             OtherTelephone = ((string)DIRECTORY_ENTRY.Properties["otherTelephone"].Value!=null)?(string)DIRECTORY_ENTRY.Properties["otherTelephone"].Value:null;
             PostalAddress = (string)DIRECTORY_ENTRY.Properties["postalAddress"].Value;
             PostalCode = (string)DIRECTORY_ENTRY.Properties["postalCode"].Value;
             PostOfficeBox = (string)DIRECTORY_ENTRY.Properties["postOfficeBox"].Value;
             Secretary = (System.DirectoryServices.DirectoryEntry)DIRECTORY_ENTRY.Properties["secretary"].Value;
             SN = (string)DIRECTORY_ENTRY.Properties["sn"].Value;
             ST = (string)DIRECTORY_ENTRY.Properties["st"].Value;
             Street = (string)DIRECTORY_ENTRY.Properties["street"].Value;
             StreetAddress = (string)DIRECTORY_ENTRY.Properties["streetAddress"].Value;
             TelephoneAssistant = (string)DIRECTORY_ENTRY.Properties["telephoneAssistant"].Value;
             TelephoneNumber = (string)DIRECTORY_ENTRY.Properties["telephoneNumber"].Value;
             ThumbnailPhoto = (Byte[])DIRECTORY_ENTRY.Properties["thumbnailPhoto"].Value;
             Title = (string)DIRECTORY_ENTRY.Properties["title"].Value;
     
             ThumbnailLogo = (Byte[])DIRECTORY_ENTRY.Properties["thumbnailLogo"].Value;
             Photo = (Byte[])DIRECTORY_ENTRY.Properties["photo"].Value;
             JpegPhoto = (Byte[])DIRECTORY_ENTRY.Properties["jpegPhoto"].Value;
     
        }

  7. #7
    Membre confirmé
    Inscrit en
    Juillet 2005
    Messages
    69
    Détails du profil
    Informations forums :
    Inscription : Juillet 2005
    Messages : 69
    Par défaut
    j'ai essayé avec le .Value mais ça ne marche pas mieux.
    Par contre j'ai oublié de préciser qu'il s'agit d'un cas 1 peu spécial(peu d'informations sont renséignées).
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
     
    if (userEntry.Properties["givenname"].Count > 0 && userEntry.Properties["sn"].Count > 0 && userEntry.Properties["userPrincipalName"].Count > 0)
                                            {
               string givenName = (string)userEntry.Properties["givenname"][0];
               string lastName = (string)userEntry.Properties["sn"][0];
               string login = (string)userEntry.Properties["userPrincipalName"][0];
               string lastLogon;
               object lastLogonProperty = userEntry.Properties["lastLogon"].Value;
               if (lastLogonProperty == null)
                     lastLogon = "NoLastLogon";
               else
                  {                                                
                li = (LargeIntegerClass)Marshal.CreateWrapperOfType(userEntry.Properties["lastLogon"].Value, typeof(LargeIntegerClass));
    long int64Value = (long)((uint)li.LowPart + (((long)li.HighPart) << 32));
    Marshal.ReleaseComObject(li);
    lastLogon = DateTime.FromFileTimeUtc(int64Value).ToLongDateString();
                   }
    else
    {
               string infos = (String)userEntry.Properties["cn"].Value
    }

  8. #8
    Membre éclairé
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    801
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2005
    Messages : 801
    Par défaut
    Ton code fonctionne ?
    Car je crois que les champs dans l'AD sont case sensitive:

    Tu as écrit:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    if (userEntry.Properties["givenname"].Count ...

    et je crois que c'est
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    if (userEntry.Properties["givenName"].Count ...

  9. #9
    Membre confirmé
    Inscrit en
    Juillet 2005
    Messages
    69
    Détails du profil
    Informations forums :
    Inscription : Juillet 2005
    Messages : 69
    Par défaut
    J'ai essayé les 2 cas(givenName et givenname) et j'ai le même résultat.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    MessageBox.Show((String)userEntry.Properties["cn"].Value + "--" + userEntry.Properties["givenName"].Count + "--" + userEntry.Properties["sn"].Count + "--" + userEntry.Properties["userPrincipalName"].Count);
    Résultat:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    S-1-5-21-1202660629-1767777339-725345543-31797--0--0--0

Discussions similaires

  1. Réponses: 11
    Dernier message: 04/01/2013, 14h56
  2. Java - LDAP - propriété compte actif
    Par mike851 dans le forum Sécurité
    Réponses: 1
    Dernier message: 24/12/2010, 18h50
  3. [ActiveX] Visibilité d'une propriété
    Par paradise dans le forum Composants VCL
    Réponses: 2
    Dernier message: 14/11/2002, 18h33
  4. [controle] propriété read only
    Par Fizgig dans le forum Composants VCL
    Réponses: 6
    Dernier message: 28/08/2002, 10h30
  5. [propriétés]Option Checked
    Par psl dans le forum Composants VCL
    Réponses: 6
    Dernier message: 22/08/2002, 08h07

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo