Exemplo n.º 1
0
 private void UpdateRelationship(ElevateToken token)
 {
     try
     {
         var relationship = new Relationship
         {
             IHaveUnattendedAccess = GwupeClientAppContext.CurrentAppContext.RelationshipManager.GetRelationship(_dataContext.Engagement.SecondParty.Party.Username).IHaveUnattendedAccess
         };
         Dispatcher.Invoke(new Action(() => { relationship.TheyHaveUnattendedAccess = (UnattendedAccessCheckbox.IsChecked == true); }));
         GwupeClientAppContext.CurrentAppContext.RelationshipManager.UpdateRelationship(
             _dataContext.Engagement.SecondParty.Party.Username,
             relationship, token.TokenId, token.SecurityKey);
         _updatedRelationship = true;
     }
     catch (Exception ex)
     {
         Logger.Error("Failed to update the relationship to " + _dataContext.Engagement.SecondParty.Party.Username + " : " + ex.Message, ex);
         UiHelper.Validator.SetError("Failed to save changes to server");
     }
 }
Exemplo n.º 2
0
 private void SaveCurrentUser(ElevateToken token)
 {
     try
     {
         String password = GetPasswordChange();
         _appContext.CurrentUserManager.SaveCurrentUser(token.TokenId, token.SecurityKey, password);
         // save the password if it was changed. (for auto login)
         if (password != null)
         {
             GwupeUserRegistry.getInstance().PasswordHash = Util.getSingleton().hashPassword(password);
         }
         _uiHelper.Validator.SetStatus("Saved changes to server.");
         Dispatcher.Invoke(new Action(() =>
         {
             Password.Password = "";
             PasswordChange.IsChecked = false;
             Password.IsEnabled = false;
         }));
     }
     catch (ElevationException ex)
     {
         _uiHelper.Validator.SetError("Incorrect password, please try again");
     }
     catch (MessageException<UpdateUserRs> ex)
     {
         Logger.Error("Attempt to update user failed : " + ex.Message, ex);
         if ("WILL_NOT_PROCESS_AUTH".Equals(ex.Response.error))
         {
             _uiHelper.Validator.SetError("Incorrect password, please try again");
         }
         else
         {
             _uiHelper.Validator.SetError("Failed to save changes to server");
         }
     }
     catch (Exception ex)
     {
         Logger.Error("Failed to save the current user : "******"Failed to save changes to server");
     }
 }
Exemplo n.º 3
0
 internal ElevateToken Elevate(String message)
 {
     if (CurrentToken == null || CurrentToken.IsExpired())
     {
         Logger.Debug("We don't have an elevation token or it has expired, requesting from server.");
         ElevateTokenRq erq = new ElevateTokenRq();
         try
         {
             String password = UIManager.RequestElevation(message);
             // Make sure password isn't empty and conforms to the current password.
             if (!String.IsNullOrWhiteSpace(password) &&
                 Util.getSingleton().hashPassword(password).Equals(Reg.PasswordHash))
             {
                 ElevateTokenRs ers = ConnectionManager.Connection.Request<ElevateTokenRq, ElevateTokenRs>(erq);
                 CurrentToken = new ElevateToken(ers.tokenId, ers.token, password, ers.expires);
             }
             else
             {
                 Logger.Error("Entered password for elevation is invalid.");
                 CurrentToken = null;
                 throw new ElevationException();
             }
         }
         finally
         {
             UIManager.CompleteElevation();
         }
     }
     else
     {
         Logger.Debug("Reusing elevate token " + CurrentToken.TokenId);
     }
     return CurrentToken;
 }