Ejemplo n.º 1
0
        /// <summary>
        /// Save the token context data.
        /// </summary>
        /// <param name="context">The token data to save.</param>
        private static async void SaveTokenDataAsync(Nequeo.Xml.Authorisation.Token.Data.context context)
        {
            var result = Nequeo.Threading.AsyncOperationResult <int> .
                         RunTask(() => SaveTokenData(context));

            await result;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Load the token context data.
        /// </summary>
        /// <returns>The collection of token data.</returns>
        public static Nequeo.Xml.Authorisation.Token.Data.context LoadTokenData()
        {
            try
            {
                string xmlValidationMessage = string.Empty;

                // Get the xml file location and
                // the xsd file schema.
                string xml = (String.IsNullOrEmpty(TokenReader.TokenXmlPath) ? Helper.TokenXmlPath : TokenReader.TokenXmlPath);
                string xsd = Nequeo.Xml.Authorisation.Properties.Resources.TokenProvider;

                // Validate the filter xml file.
                if (!Validation.IsXmlValidEx(xsd, xml, out xmlValidationMessage))
                {
                    throw new Exception("Xml validation. " + xmlValidationMessage);
                }

                // Deserialise the xml file into
                // the log directory list object
                GeneralSerialisation serial = new GeneralSerialisation();
                Nequeo.Xml.Authorisation.Token.Data.context authData =
                    ((Nequeo.Xml.Authorisation.Token.Data.context)serial.Deserialise(typeof(Nequeo.Xml.Authorisation.Token.Data.context), xml));

                // Return the communication data.
                return(authData);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Save the token context data.
        /// </summary>
        /// <param name="context">The token data to save.</param>
        public static void SaveTokenData(Nequeo.Xml.Authorisation.Token.Data.context context)
        {
            lock (_lockObject)
            {
                try
                {
                    string xmlValidationMessage = string.Empty;

                    // Get the xml file location and
                    // the xsd file schema.
                    string xml = (String.IsNullOrEmpty(TokenReader.TokenXmlPath) ? Helper.TokenXmlPath : TokenReader.TokenXmlPath);
                    string xsd = Nequeo.Xml.Authorisation.Properties.Resources.TokenProvider;

                    // Deserialise the xml file into
                    // the log directory list object
                    GeneralSerialisation serial = new GeneralSerialisation();
                    bool authData = serial.Serialise(context, typeof(Nequeo.Xml.Authorisation.Token.Data.context), xml);

                    // Validate the filter xml file.
                    if (!Validation.IsXmlValidEx(xsd, xml, out xmlValidationMessage))
                    {
                        throw new Exception("Xml validation. " + xmlValidationMessage);
                    }
                }
                catch { }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Delete the token
        /// </summary>
        /// <param name="uniqueIdentifier">The unique client identifier.</param>
        /// <param name="serviceName">The service name the client is connected to.</param>
        /// <param name="context">The communication data.</param>
        /// <returns>True if deleted; else false.</returns>
        /// <exception cref="System.Exception"></exception>
        /// <exception cref="System.ArgumentNullException"></exception>
        public static bool Delete(string uniqueIdentifier, string serviceName, Nequeo.Xml.Authorisation.Token.Data.context context)
        {
            // Validate.
            if (String.IsNullOrEmpty(uniqueIdentifier))
            {
                throw new ArgumentNullException("uniqueIdentifier");
            }
            if (String.IsNullOrEmpty(serviceName))
            {
                throw new ArgumentNullException("serviceName");
            }

            try
            {
                // Find all host unique identifier.
                Token.Data.contextClient client = null;

                try
                {
                    client = context.clients.First(
                        u => (u.uniqueIdentifier.ToString().ToLower() == uniqueIdentifier.ToLower()) &&
                        (u.serviceName.ToLower() == serviceName.ToLower()));
                }
                catch { }

                if (client != null)
                {
                    // Find the index of the client to remove.
                    context.clients = context.clients.Remove(u => u.Equals(client));
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Get the current token.
        /// </summary>
        /// <param name="uniqueIdentifier">The unique client identifier.</param>
        /// <param name="serviceName">The service name the client is connected to.</param>
        /// <param name="context">The communication data.</param>
        /// <returns>The token; else null.</returns>
        /// <exception cref="System.Exception"></exception>
        /// <exception cref="System.ArgumentNullException"></exception>
        public static string Get(string uniqueIdentifier, string serviceName, Nequeo.Xml.Authorisation.Token.Data.context context)
        {
            // Validate.
            if (String.IsNullOrEmpty(uniqueIdentifier))
            {
                throw new ArgumentNullException("uniqueIdentifier");
            }
            if (String.IsNullOrEmpty(serviceName))
            {
                throw new ArgumentNullException("serviceName");
            }

            try
            {
                // Find all host unique identifier.
                Token.Data.contextClient client = null;

                try
                {
                    client = context.clients.First(
                        u => (u.uniqueIdentifier.ToString().ToLower() == uniqueIdentifier.ToLower()) &&
                        (u.serviceName.ToLower() == serviceName.ToLower()));
                }
                catch { }

                if (client != null)
                {
                    return(client.token);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Load provider data from the store.
 /// </summary>
 public void Load()
 {
     // Load the Communication data.
     _tokenData = TokenReader.LoadTokenData();
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Get the client permission.
        /// </summary>
        /// <param name="uniqueIdentifier">The unique client identifier.</param>
        /// <param name="serviceName">The service name the client is connected to.</param>
        /// <param name="context">The communication data.</param>
        /// <returns>The permission.</returns>
        /// <exception cref="System.Exception"></exception>
        /// <exception cref="System.ArgumentNullException"></exception>
        public static Nequeo.Security.IPermission GetPermission(string uniqueIdentifier, string serviceName, Nequeo.Xml.Authorisation.Token.Data.context context)
        {
            // Validate.
            if (String.IsNullOrEmpty(uniqueIdentifier))
            {
                throw new ArgumentNullException("uniqueIdentifier");
            }
            if (String.IsNullOrEmpty(serviceName))
            {
                throw new ArgumentNullException("serviceName");
            }

            try
            {
                // Find all host unique identifier.
                Token.Data.contextClient client = null;

                try
                {
                    client = context.clients.First(
                        u => (u.uniqueIdentifier.ToString().ToLower() == uniqueIdentifier.ToLower()) &&
                        (u.serviceName.ToLower() == serviceName.ToLower()));
                }
                catch { }

                if (client != null)
                {
                    return(new Nequeo.Security.PermissionSource(
                               (Nequeo.Security.PermissionType)Enum.Parse(typeof(Nequeo.Security.PermissionType), client.permission)));
                }
                else
                {
                    return(new Nequeo.Security.PermissionSource(Security.PermissionType.None));
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Update the token
        /// </summary>
        /// <param name="uniqueIdentifier">The unique client identifier.</param>
        /// <param name="serviceName">The service name the client is connected to.</param>
        /// <param name="token">The token that will replace the cuurent token.</param>
        /// <param name="context">The communication data.</param>
        /// <returns>True if updated; else false.</returns>
        /// <exception cref="System.Exception"></exception>
        /// <exception cref="System.ArgumentNullException"></exception>
        public static bool Update(string uniqueIdentifier, string serviceName, string token, Nequeo.Xml.Authorisation.Token.Data.context context)
        {
            // Validate.
            if (String.IsNullOrEmpty(uniqueIdentifier))
            {
                throw new ArgumentNullException("uniqueIdentifier");
            }
            if (String.IsNullOrEmpty(serviceName))
            {
                throw new ArgumentNullException("serviceName");
            }
            if (String.IsNullOrEmpty(token))
            {
                throw new ArgumentNullException("token");
            }

            try
            {
                // Find all host unique identifier.
                Token.Data.contextClient client = null;

                try
                {
                    client = context.clients.First(
                        u => (u.uniqueIdentifier.ToString().ToLower() == uniqueIdentifier.ToLower()) &&
                        (u.serviceName.ToLower() == serviceName.ToLower()) &&
                        (u.token.ToLower() == token.ToLower()));
                }
                catch { }

                if (client != null)
                {
                    // Get the client reference.
                    client.dateAdded = DateTime.Now;
                    client.token     = Guid.NewGuid().ToString();

                    // Save the new data.
                    SaveTokenDataAsync(context);
                    return(true);
                }
                else
                {
                    // Load all the clients into a temp list.
                    List <Token.Data.contextClient> tempClients = new List <Token.Data.contextClient>(context.clients);
                    Token.Data.contextClient        clientData  = new Token.Data.contextClient()
                    {
                        uniqueIdentifier = Int32.Parse(uniqueIdentifier),
                        serviceName      = serviceName,
                        dateAdded        = DateTime.Now,
                        token            = Guid.NewGuid().ToString(),
                        permission       = Nequeo.Security.PermissionType.None.ToString()
                    };

                    // Add the client from the list.
                    tempClients.Add(clientData);

                    // Assign the new client list to the
                    // new context data.
                    context.clients = tempClients.ToArray();
                    return(true);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }