Esempio n. 1
0
 private void HandleCreateIdp(string filename)
 {
     if (!_fileToEntity.ContainsKey(filename))
     {
         var metadataDoc = ParseFile(filename);
         var endp        = FindEndPoint(metadataDoc.EntityId);
         if (endp == null) // If the endpoint does not exist, create it.
         {
             endp = new IDPEndPoint()
             {
                 Id       = metadataDoc.EntityId,
                 Name     = metadataDoc.EntityId,
                 metadata = metadataDoc
             };
             IDPEndPoints.Add(endp);
             _fileToEntity.Add(filename, endp.Id);
         }
         else
         {
             HandleUpdateIdp(filename);
         }
     }
     else
     {
         HandleUpdateIdp(filename);
     }
 }
        public static IDPEndPoint ParseIDPEndPoint(Saml20MetadataDocument metadataDoc)
        {
            var endp = new IDPEndPoint()
            {
                Id       = metadataDoc.EntityId,
                Name     = metadataDoc.EntityId,
                metadata = metadataDoc
            };

            return(endp);
        }
Esempio n. 3
0
        /// <summary>
        /// Refreshes the information retrieved from the directory containing metadata files.
        /// </summary>
        public void Refresh()
        {
            if (metadataLocation == null)
            {
                return;
            }

            if (!Directory.Exists(metadataLocation))
            {
                throw new DirectoryNotFoundException(Resources.MetadataLocationNotFoundFormat(metadataLocation));
            }

            // Start by removing information on files that are no long in the directory.
            List <string> keys = new List <string>(_fileInfo.Keys.Count);

            keys.AddRange(_fileInfo.Keys);
            foreach (string file in keys)
            {
                if (!File.Exists(file))
                {
                    _fileInfo.Remove(file);
                    if (_fileToEntity.ContainsKey(file))
                    {
                        IDPEndPoint endp = FindEndPoint(_fileToEntity[file]);
                        if (endp != null)
                        {
                            endp.metadata = null;
                        }
                        _fileToEntity.Remove(file);
                    }
                }
            }

            // Detect added classes
            string[] files = Directory.GetFiles(metadataLocation);
            foreach (string file in files)
            {
                Saml20MetadataDocument metadataDoc;
                if (_fileInfo.ContainsKey(file))
                {
                    if (_fileInfo[file] != File.GetLastWriteTime(file))
                    {
                        metadataDoc = ParseFile(file);
                    }
                    else
                    {
                        continue;
                    }
                }
                else
                {
                    metadataDoc = ParseFile(file);
                }

                if (metadataDoc != null)
                {
                    IDPEndPoint endp = FindEndPoint(metadataDoc.EntityId);
                    if (endp == null) // If the endpoint does not exist, create it.
                    {
                        endp = new IDPEndPoint();
                        IDPEndPoints.Add(endp);
                    }

                    endp.Id       = endp.Name = metadataDoc.EntityId; // Set some default valuDes.
                    endp.metadata = metadataDoc;

                    if (_fileToEntity.ContainsKey(file))
                    {
                        _fileToEntity.Remove(file);
                    }

                    _fileToEntity.Add(file, metadataDoc.EntityId);
                }
            }
        }