Exemple #1
0
        /// <summary>
        /// Loads all the settings from a file.
        /// </summary>
        /// <param name="fileName"></param>
        private void LoadFile(string fileName)
        {
            XmlDocument sourceDocument = new XmlDocument();

            sourceDocument.Load(executionEnvironment.EnsurePathIsRooted(fileName));

            foreach (XmlElement setting in sourceDocument.DocumentElement.SelectNodes("*"))
            {
                object loadedItem = reflectionReader.Read(setting);

                IPermission permission = loadedItem as IPermission;
                if (permission != null)
                {
                    permission.Manager = this;
                    string identifier = permission.Identifier.ToLower(CultureInfo.InvariantCulture);
                    if (loadedPermissions.ContainsKey(identifier))
                    {
                        loadedPermissions.Remove(identifier);
                    }
                    loadedPermissions.Add(identifier, permission);
                    LinkIdentifierWithFile(fileName, identifier);
                }
                else
                {
                    IAuthentication authentication = loadedItem as IAuthentication;
                    if (authentication != null)
                    {
                        authentication.Manager = this;
                        string identifier = authentication.Identifier.ToLower(CultureInfo.InvariantCulture);
                        if (loadedUsers.ContainsKey(identifier))
                        {
                            loadedUsers.Remove(identifier);
                        }
                        if (authentication.Identifier.Contains("*"))
                        {
                            wildCardUsers.Add(authentication);
                        }
                        else
                        {
                            loadedUsers.Add(identifier, authentication);
                        }
                        LinkIdentifierWithFile(fileName, identifier);
                    }
                    else
                    {
                        throw new CruiseControlException("Unknown security item: " + setting.OuterXml);
                    }
                }
            }
        }
        /// <summary>
        /// Performs the actual logging of a security event
        /// </summary>
        /// <param name="projectName">The name of the project.</param>
        /// <param name="userName">The name of the user.</param>
        /// <param name="eventType">The type of event.</param>
        /// <param name="eventRight">The right of the event.</param>
        /// <param name="message">Any security message.</param>
        protected override void DoLogEvent(string projectName, string userName, SecurityEvent eventType, SecurityRight eventRight, string message)
        {
            // Generate the log entry
            XmlDocument auditXml = new XmlDocument();
            XmlElement  xmlRoot  = auditXml.CreateElement("event");

            auditXml.AppendChild(xmlRoot);
            AddXmlElement(auditXml, xmlRoot, "dateTime", DateTime.Now.ToString("o", CultureInfo.CurrentCulture));
            if (!string.IsNullOrEmpty(projectName))
            {
                AddXmlElement(auditXml, xmlRoot, "project", projectName);
            }
            if (!string.IsNullOrEmpty(userName))
            {
                AddXmlElement(auditXml, xmlRoot, "user", userName);
            }
            AddXmlElement(auditXml, xmlRoot, "type", eventType.ToString());
            if (eventRight != SecurityRight.Inherit)
            {
                AddXmlElement(auditXml, xmlRoot, "outcome", eventRight.ToString());
            }
            if (!string.IsNullOrEmpty(message))
            {
                AddXmlElement(auditXml, xmlRoot, "message", message);
            }

            // Write the entry
            string auditLog = executionEnvironment.EnsurePathIsRooted(this.auditFile);

            lock (this)
            {
                File.AppendAllText(auditLog, auditXml.OuterXml.Replace(Environment.NewLine, " ") + Environment.NewLine);
            }
        }
Exemple #3
0
        /// <summary>
        /// Loads the lines from the audit file.
        /// </summary>
        /// <returns></returns>
        private string[] LoadAuditLines()
        {
            string auditLog = executionEnvironment.EnsurePathIsRooted(this.auditFile);

            Stream       inputStream = File.Open(auditLog, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            StreamReader reader      = new StreamReader(inputStream);
            string       fileData;

            try
            {
                fileData = reader.ReadToEnd();
            }
            finally
            {
                try
                {
                    reader.Close();
                }
                finally
                {
                    inputStream.Close();
                }
            }

            return(fileData.Split('\r', '\n'));
        }