Пример #1
0
        public void ResetPassword(String domainAndUserName)
        {
            // Create Anonymouse RmPerson and set ObjectID to Domain\User
            // The ObjectID attribute will become ResourceReferenceProperty in the message header
            RmPerson    user = new RmPerson();
            RmReference domainAndUsernameReference = new RmReference();

            domainAndUsernameReference.DomainAndUserNameValue = domainAndUserName;
            user.ObjectID = domainAndUsernameReference;
            PutResponse putResponse;

            putResponse = new PutResponse();
            string STSEndpoint = String.Empty;

            // Set ResetPassword to true
            // Need a transaction to watch changes to the user
            using (RmResourceChanges transaction = new RmResourceChanges(user)) {
                transaction.BeginChanges();
                user.ResetPassword = "******";
                try {
                    // We commit the change to the server
                    Put(transaction, true, out putResponse, null, null);
                } catch (FaultException <AnonymousInteractionRequiredFault> exc) {
                    // Now we must set the new password in the endpoint contained
                    // in the exception
                    string endpoint = exc.Detail.AnonymousInteractionEndpointAddress;
#warning "MUST ADD A CREATE MESSAGE WITH THE NEW PASSWORD."
                }
            }
        }
Пример #2
0
        public async Task <PutResponse> Put(int id, [FromBody] Comments comments)
        {
            var pr = new PutResponse()
            {
                Success = false
            };

            try
            {
                if (comments.Id > 0 && comments.ItemId > 0 && comments.UserId > 0 && comments.CommentBody.Length > 0 && comments.CommentTitle.Length > 0 && comments.Rating > 0)
                {
                    var oldComments = await context.Comments.SingleOrDefaultAsync(s => s.Id == id);

                    if (oldComments != null)
                    {
                        oldComments.ItemId       = comments.ItemId;
                        oldComments.UserId       = comments.UserId;
                        oldComments.CommentBody  = comments.CommentBody;
                        oldComments.CommentTitle = comments.CommentTitle;
                        oldComments.Rating       = comments.Rating;


                        await context.SaveChangesAsync();

                        pr.Success = true;
                    }
                }
            }
            catch { }

            return(pr);
        }
Пример #3
0
        public IPutResponse MarkMessageAsReadOrUnRead(String userId, int messageId, int Read)
        {
            if (String.IsNullOrWhiteSpace(userId))
            {
                throw new ArgumentNullException("userId");
            }
            if (messageId == 0)
            {
                throw new ArgumentNullException("assetId");
            }

            var message = this.Context.Shares
                          .Where(s => s.Id == messageId)
                          .Where(s => s.ToUserId == userId)
                          .FirstOrDefault();

            PutResponse response = new PutResponse();

            if (message != null)
            {
                if (Read == 1)
                {
                    message.ReadDt = DateTime.UtcNow;
                }
                else
                {
                    message.ReadDt = null;
                }

                response.AffectedRecords = this.Context.SaveChanges();
            }

            return(response);
        }
Пример #4
0
        public async Task <PutResponse> Put(int id, [FromBody] Order order)
        {
            var pr = new PutResponse()
            {
                Success = false
            };

            try
            {
                if (order.Id > 0 && order.UserId > 0 && order.GrandTotal > 0)
                {
                    var oldOrder = await context.Order.SingleOrDefaultAsync(s => s.Id == id);

                    if (oldOrder != null)
                    {
                        oldOrder.UserId     = order.UserId;
                        oldOrder.GrandTotal = order.GrandTotal;


                        await context.SaveChangesAsync();

                        pr.Success = true;
                    }
                }
            }
            catch { }

            return(pr);
        }
        public async Task <PutResponse> Put(int id, [FromBody] Addresses addresses)
        {
            var pr = new PutResponse()
            {
                Success = false
            };

            try
            {
                if (addresses.Id > 0 && addresses.UserId > 0 && addresses.City.Length > 0 && addresses.Country.Length > 0 && addresses.Line1.Length > 0 && addresses.Line2.Length > 0 && addresses.Phone > 0 && addresses.PostalCode.Length > 0)
                {
                    var oldAddress = await context.Addresses.SingleOrDefaultAsync(s => s.Id == id);

                    if (oldAddress != null)
                    {
                        oldAddress.UserId     = addresses.UserId;
                        oldAddress.City       = addresses.City;
                        oldAddress.Country    = addresses.Country;
                        oldAddress.Line1      = addresses.Line1;
                        oldAddress.Line2      = addresses.Line2;
                        oldAddress.Phone      = addresses.Phone;
                        oldAddress.PostalCode = addresses.PostalCode;

                        await context.SaveChangesAsync();

                        pr.Success = true;
                    }
                }
            }
            catch { }

            return(pr);
        }
Пример #6
0
        public async Task <PutResponse> Put(int id, [FromBody] Orderitems orderitems)
        {
            var pr = new PutResponse()
            {
                Success = false
            };

            try
            {
                if (orderitems.Id > 0 && orderitems.ItemId > 0 && orderitems.OrderId > 0 && orderitems.Quantity > 0)
                {
                    var oldOrderItems = await context.Orderitems.SingleOrDefaultAsync(s => s.Id == id);

                    if (oldOrderItems != null)
                    {
                        oldOrderItems.ItemId = orderitems.ItemId;

                        oldOrderItems.OrderId = orderitems.OrderId;

                        oldOrderItems.Quantity = orderitems.Quantity;


                        await context.SaveChangesAsync();

                        pr.Success = true;
                    }
                }
            }
            catch { }

            return(pr);
        }
Пример #7
0
        public async Task <PutResponse> Put(int id, [FromBody] Items items)
        {
            var pr = new PutResponse()
            {
                Success = false
            };

            try
            {
                if (items.Id > 0 && items.Name.Length > 0 && items.Price > 0)
                {
                    var oldItems = await context.Items.SingleOrDefaultAsync(s => s.Id == id);

                    if (oldItems != null)
                    {
                        oldItems.Name  = items.Name;
                        oldItems.Price = items.Price;

                        await context.SaveChangesAsync();

                        pr.Success = true;
                    }
                }
            }
            catch { }

            return(pr);
        }
Пример #8
0
        /// <summary>
        /// Sets the key value in etcd in async
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <PutResponse> PutAsync(PutRequest request, Metadata headers = null)
        {
            PutResponse response   = new PutResponse();
            bool        success    = false;
            int         retryCount = 0;

            while (!success)
            {
                try
                {
                    response = await _balancer.GetConnection().kvClient.PutAsync(request, headers);

                    success = true;
                }
                catch (RpcException ex) when(ex.StatusCode == StatusCode.Unavailable)
                {
                    retryCount++;
                    if (retryCount >= _balancer._numNodes)
                    {
                        throw ex;
                    }
                }
            }
            return(response);
        }
Пример #9
0
        public async Task <PutResponse> Put(int id, [FromBody] Users users)
        {
            var pr = new PutResponse()
            {
                Success = false
            };

            try
            {
                if (users.Id > 0 && users.Email.Length > 0 && users.FirstName.Length > 0 && users.LastName.Length > 0 && users.Password.Length > 0)
                {
                    var oldUser = await context.Users.SingleOrDefaultAsync(s => s.Id == id);

                    if (oldUser != null)
                    {
                        oldUser.Email     = users.Email;
                        oldUser.FirstName = users.FirstName;
                        oldUser.LastName  = users.LastName;
                        oldUser.Password  = oldUser.Password;


                        await context.SaveChangesAsync();

                        pr.Success = true;
                    }
                }
            }
            catch { }

            return(pr);
        }
Пример #10
0
        /// <summary>
        /// Sets the key value in etcd in async
        /// </summary>
        /// <param name="request">The request to send to the server.</param>
        /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param>
        /// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param>
        /// <param name="cancellationToken">An optional token for canceling the call.</param>
        /// <returns>The response received from the server.</returns>
        public async Task <PutResponse> PutAsync(PutRequest request, Grpc.Core.Metadata headers = null,
                                                 DateTime?deadline = null,
                                                 CancellationToken cancellationToken = default)
        {
            PutResponse response   = new PutResponse();
            bool        success    = false;
            int         retryCount = 0;

            while (!success)
            {
                try
                {
                    response = await _balancer.GetConnection().kvClient
                               .PutAsync(request, headers, deadline, cancellationToken);

                    success = true;
                }
                catch (RpcException ex) when(ex.StatusCode == StatusCode.Unavailable)
                {
                    retryCount++;
                    if (retryCount >= _balancer._numNodes)
                    {
                        throw;
                    }
                }
            }

            return(response);
        }
Пример #11
0
 public static Entity.PutResponse FromProto(this PutResponse response)
 {
     return(new Entity.PutResponse()
     {
         Header = response.Header.FromProto(),
         PrevKv = response.PrevKv.FromProto()
     });
 }
Пример #12
0
     private static void ProcessError(PutResponse response)
     {
         if (response.Error != null)
         {
             InternalLogger.WriteLine(@"JD Cloud Log Service call failed:
 Request Id   : {0}
 Error Code   : {1}
 Error Message: {2}",
                                      response.RequestId, response.Error.Code, response.Error.Message);
         }
     }
Пример #13
0
        /// <summary> </summary>
        JsonResult IDriver.Put(string target, string content)
        {
            FullPath    fullPath = ParsePath(target);
            PutResponse answer   = new PutResponse();

            using (StreamWriter writer = new StreamWriter(fullPath.File.FullName, false)) {
                writer.Write(content);
            }
            answer.changed.Add((FileDTO)DTOBase.Create(fullPath.File, fullPath.Root));
            return(Json(answer));
        }
Пример #14
0
        //internal IEnumerable<HttpResponseMessage> GetLroPUTResponse(int pollingResponseCount, bool includeAsyncOperationHeader,
        //    bool includeLocationHeader, bool includeFinalResponse,
        //    HttpStatusCode finalResponseStatusCode)
        //{
        //    HttpResponseMessage res = null;

        //    #region Initial Response
        //    res = new HttpResponseMessage(HttpStatusCode.Created)
        //    {
        //        Content = new StringContent(AsyncOperationHeader.InitialResponse)
        //    };
        //    res.Headers.Add(LroAsyncHeaderName, LroAsyncHeaderValue);
        //    #endregion

        //    #region polling
        //    for (int i = 0; i <= pollingResponseCount - 1; i++)
        //    {
        //        if (includeAsyncOperationHeader == true)
        //        {
        //            res = new HttpResponseMessage(HttpStatusCode.Created)
        //            {
        //                Content = new StringContent(AsyncOperationHeader.IntrimPollingResponse)
        //            };
        //            res.Headers.Add(LroAsyncHeaderName, LroAsyncHeaderValue);
        //        }

        //        if (includeLocationHeader == true)
        //        {
        //            res.Headers.Add(LroLocationHeaderName, LroLocationHeaderValue);
        //        }

        //        yield return res;
        //    }

        //    res = new HttpResponseMessage(HttpStatusCode.OK)
        //    {
        //        Content = new StringContent(AsyncOperationHeader.PollingCompletedResponse)
        //    };
        //    yield return res;
        //    #endregion

        //    #region Final Response


        //    #endregion

        //    res = new HttpResponseMessage(HttpStatusCode.OK)
        //    {
        //        Content = new StringContent(AsyncOperationHeader.AsyncOperationHeaderFinalResource)
        //    };
        //    yield return res;
        //}


        internal IEnumerable <HttpResponseMessage> PutLroResponse(int pollingCount, LroHeaders header)
        {
            List <HttpResponseMessage> lroResList = new List <HttpResponseMessage>();

            lroResList.Add(PutResponse.GetResponse(PutResponse.EmptyInitialResponse, HttpStatusCode.Created, header));

            var lroResponses = PutResponse.PollingResponse(header, pollingCount, HttpStatusCode.Created);

            lroResList.AddRange(lroResponses);

            //lroResList.Add(PutResponse.PostPollingResponse(header, HttpStatusCode.OK));
            return(lroResList);
        }
Пример #15
0
        public override async Task <PutResponse> Put(PutRequest request, ServerCallContext context)
        {
            var channel = channels.GetChannel(request.Channel);
            var message = new Message()
            {
                Timestamp = request.Timestamp,
                Content   = request.Message.ToByteArray()
            };
            await channel.Put(message);

            var response = new PutResponse()
            {
                ResponseStatus = ResponseHelpers.CreateOkStatus()
            };

            return(response);
        }
Пример #16
0
        public void Update_User()
        {
            var jObj = new User()
            {
                name = "morpheus",
                job  = "zion resident"
            };

            var json         = JsonConvert.SerializeObject(jObj);
            var httpResponse = HttpRequest.Put("https://reqres.in/api/users/2", json);

            PutResponse result = JsonConvert.DeserializeObject <PutResponse>(httpResponse);

            Assert.IsTrue(result.name == null);
            Assert.IsTrue(result.job == null);
            Assert.IsTrue(result.updatedAt < DateTime.Now);
        }
Пример #17
0
        public PutResponse Put(ByteSequence key, ByteSequence value,
                               PutOption option)
        {
            Etcdserverpb.PutRequest request = new Etcdserverpb.PutRequest();
            request.Key    = key.GetByteString();
            request.Value  = value.GetByteString();
            request.Lease  = option.LeaseId;
            request.PrevKv = option.PrevKV;
            var         rsp      = kVClient.Put(request);
            PutResponse response = new PutResponse(rsp);

            return(response);
            //return Util.ToCompletableFutureWithRetry(
            //     stub.Put(request),
            //     new FunctionResponse<Etcdserverpb.PutRequest, PutResponse>(),
            //     Util.IsRetriable
            //);
        }
Пример #18
0
 public IHttpResponse Visit(PutResponse response, HttpRequest restReq)
 {
     return(VisitWithBody(response, restReq));
 }
Пример #19
0
 public HttpServerResponse Visit(PutResponse response, RestServerRequest restReq)
 {
     return(GetDefaultContentResponse(response, restReq));
 }
Пример #20
0
        public static void OTPReset(string domain, string username, ContextualSecurityToken authNSecurityToken, ContextMessageProperty contextMessageProperty)
        {
            // Create Anonymouse RmPerson and set ObjectID to Domain\User
            // The ObjectID attribute will become ResourceReferenceProperty in the message header
            RmPerson    user = new RmPerson();
            RmReference domainAndUsernameReference = new RmReference();

            domainAndUsernameReference.DomainAndUserNameValue = domain + '\\' + username;
            user.ObjectID = domainAndUsernameReference;
            PutResponse putResponse;

            putResponse = new PutResponse();
            string STSEndpoint = String.Empty;
            bool   putSuccess  = false; //This should always stay false with these calls unless no password reset workflow or qa authn workflow is attached.

            var          alternateClient = new AlternateClient();
            var          mexClient       = new MexClient();
            XmlSchemaSet metadata        = mexClient.Get();
            var          requestFactory  = new RmRequestFactory(metadata);

            // Set ResetPassword to true
            // Need a transaction to watch changes to the user
            using (RmResourceChanges transaction = new RmResourceChanges(user))
            {
                transaction.BeginChanges();

                user.ResetPassword = "******";

                try
                {
                    if (transaction.RmObject.ObjectID.Value.Split('\\').Length != 2)
                    {
                        throw new ArgumentException("User Identity must be specified by netbios domain in this format: Domain name\\user name.");
                    }

                    PutRequest alternateEPrequest = requestFactory.CreatePutRequest(transaction);

                    try
                    {
                        alternateClient.Put(alternateEPrequest, out putResponse, authNSecurityToken, contextMessageProperty);
                        putSuccess = true;
                    }
                    catch (System.ServiceModel.FaultException <Microsoft.ResourceManagement.Client.Faults.AuthenticationRequiredFault> authNFault)
                    {
                        Microsoft.ResourceManagement.WebServices.WSResourceManagement.AuthenticationRequiredFault msAuthNFault =
                            new Microsoft.ResourceManagement.WebServices.WSResourceManagement.AuthenticationRequiredFault(authNFault.Detail.SecurityTokenServiceAddress,
                                                                                                                          authNFault.Detail.UserRegistered.GetValueOrDefault(),
                                                                                                                          authNFault.Detail.UserLockedOut.GetValueOrDefault());

                        ContextMessageProperty responseContext;

                        if (ContextMessageProperty.TryGet(putResponse.Message, out responseContext) == false)
                        {
                            throw new InvalidOperationException("Could not retrieve security context message property even though we received an AuthN Fault. Something is fundamentally broken. Ensure assembly versions are correct and upgrades did not change protocol.");
                        }

                        throw new AuthenticationRequiredException(authNFault.Reason.ToString(),
                                                                  msAuthNFault,
                                                                  responseContext);
                    }
                }
                finally
                {
                    if (putSuccess == true)
                    {
                        transaction.AcceptChanges();
                    }
                    else
                    {
                        transaction.DiscardChanges();
                    }
                }
            }
        }
Пример #21
0
 private static void ModifyResource(RmResourceChanges changes)
 {
     PutRequest  putRequest  = requestFactory.CreatePutRequest(changes);
     PutResponse putResponse = transferClient.Put(putRequest);
 }
Пример #22
0
        public bool Put(RmResourceChanges transaction, bool useAlternateEndpoint, out PutResponse response, SecurityToken token, ContextMessageProperty context)
        {
            response = null;
            if (transaction == null)
            {
                throw new ArgumentNullException("transaction");
            }

            if (!useAlternateEndpoint)
            {
                PutRequest resourceEPrequest = this.requestFactory.CreatePutRequest(transaction);
                try {
                    this.wsTransferClient.Put(resourceEPrequest, out response);
                }
                //catch AuthN Fault here so we have the original transaction so we can re-submit later
                catch (System.ServiceModel.FaultException <Microsoft.ResourceManagement.Client.Faults.AuthenticationRequiredFault> authNFault) {
                    String STSEndpoinAddresst = authNFault.Detail.SecurityTokenServiceAddress;
                    ContextMessageProperty responseContext;
                    //TODO: Add AuthNLogicHere. For now, only support QA gates on the Authernate Endpoint
                }

                if (response == null)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                //TODO:Verify that the ObjectID is in the form Domain\User.
                PutRequest alternateEPrequest = this.requestFactory.CreatePutRequest(transaction);
                response = null;

                try {
                    this.alternateClient.Put(alternateEPrequest, out response, token, context);
                } catch (System.ServiceModel.FaultException <Microsoft.ResourceManagement.Client.Faults.AuthenticationRequiredFault> authNFault) {
                    String STSEndpointAddress = authNFault.Detail.SecurityTokenServiceAddress;
                    ContextMessageProperty responseContext;

                    if (ContextMessageProperty.TryGet(response.Message, out responseContext))
                    {
                        ContextualSecurityToken userToken = HandleAuthNFault(STSEndpointAddress, responseContext);
                        Put(transaction, true, out response, userToken, responseContext);
                    }
                    else
                    {
                        throw new Exception("Could not get security context from Put.");
                    }
                }

                if (response == null)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
        }