Example #1
0
 public void SaveAccessKey(AccessKey accessKey, TObjectState state)
 {
     if (accessKey.OrganisationID == 0)
     {
         accessKey.OrganisationID = DataAccessFactory.AccessKeys.GenerateOrganisationID();
     }
     if ((state == TObjectState.Add) && string.IsNullOrEmpty(accessKey.Key))
     {
         byte[] secretkey = new Byte[64];
         System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider();
         Model.AccessKey existingTenantAccessKey;
         do
         {
             rng.GetBytes(secretkey);
             accessKey.Key = StringUtils.Encode(secretkey);
             existingTenantAccessKey = DataAccessFactory.AccessKeys.GetAccessKey(accessKey.Key);
         } while (existingTenantAccessKey != null);
         rng.GetBytes(secretkey);
         accessKey.Secret = StringUtils.Encode(secretkey);
     }
     DataAccessFactory.AccessKeys.SaveAccessKey(accessKey, state);
 }
Example #2
0
 public void SaveAccessKey(AccessKey accessKey, TObjectState state)
 {
     IMongoDatabase database = GetDatabase(DATABASE_NAME, true);
     IMongoCollection<BsonDocument> collection = database.GetCollection<BsonDocument>("AccessKey");
     FilterDefinition<BsonDocument> query = Builders<BsonDocument>.Filter.Eq("_id", accessKey.Key);
     if ((state == TObjectState.Add) || (state == TObjectState.Update))
     {
         BsonDocument doc = new BsonDocument();
         BsonHelper.SetValue(doc, "_id", accessKey.Key);
         BsonHelper.SetValue(doc, "OrganisationID", accessKey.OrganisationID);
         BsonHelper.SetValue(doc, "Name", accessKey.Name);
         BsonHelper.SetValue(doc, "Secret", accessKey.Secret);
         UpdateOptions options = new UpdateOptions();
         options.IsUpsert = true;
         collection.ReplaceOne(query, doc, options);
     }
     else if (state == TObjectState.Delete)
     {
         collection.DeleteOne(query);
     }
     BroadcastTableChange("AccessKey", accessKey.Key);
 }
Example #3
0
 private AccessKey LoadAccessKey(BsonDocument item)
 {
     AccessKey result = new AccessKey();
     result.Key = BsonHelper.GetString(item, "_id");
     result.OrganisationID = BsonHelper.GetInt32(item, "OrganisationID");
     result.Name = BsonHelper.GetString(item, "Name");
     result.Secret = BsonHelper.GetString(item, "Secret");
     return result;
 }