/// <summary> /// Is the token valid /// </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 to validate.</param> /// <param name="context">The communication data.</param> /// <returns>True if valid; else false.</returns> /// <exception cref="System.Exception"></exception> /// <exception cref="System.ArgumentNullException"></exception> public static bool IsValid(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) { return(true); } else { return(false); } } catch (Exception) { throw; } }
/// <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; } }
/// <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; } }