public IWebApiCredentials CredentialsShallowCopy()
    {
      var result = new SecureStringPasswordProvider();
      result.providerImpl = this.providerImpl.PasswordProviderCopy();

      return result;
    }
Beispiel #2
0
        public IWebApiCredentials CredentialsShallowCopy()
        {
            var result = new SecureStringPasswordProvider();

            result.providerImpl = this.providerImpl.PasswordProviderCopy();

            return(result);
        }
    public void TestPasswordStorageAllowsWhitespaceLogin()
    {
      const string login = "******";
      const string password = "******";

      using (var passwordStorage = new SecureStringPasswordProvider(login, password))
      {
        Assert.AreEqual(login, passwordStorage.Username);
        Assert.AreEqual(password, passwordStorage.Password);
      }
    }
    public void TestPasswordStorageReturnsSameValues()
    {
      const string login = "******";
      const string password = "******";

      using (var passwordStorage = new SecureStringPasswordProvider(login, password))
      {
        Assert.AreEqual(login, passwordStorage.Username);
        Assert.AreEqual(password, passwordStorage.Password);
      }
    }
    private async void Authenticate()
    {
      var instanceUrl = this.instanceUrlField.Text;
      var login = this.loginField.Text;
      var password = this.passwordField.Text;
      var site = this.siteField.Text;

      if (string.IsNullOrEmpty(instanceUrl))
      {
        Toast.MakeText(this, "Please provide instance url", ToastLength.Long).Show();
        return;
      }

      if (string.IsNullOrEmpty(login) && string.IsNullOrEmpty(password))
      {
        Toast.MakeText(this, "Please provide both login and password", ToastLength.Long).Show();
        return;
      }

      try
      {
        using (var credentials = new SecureStringPasswordProvider(login, password))
          using (var session = SitecoreWebApiSessionBuilder.AuthenticatedSessionWithHost(instanceUrl)
            .Credentials(credentials)
            .Site(site)
            .BuildReadonlySession())
          {
            this.SetProgressBarIndeterminateVisibility(true);

            bool response = await session.AuthenticateAsync();

            this.SetProgressBarIndeterminateVisibility(false);
            if (response)
            {
              DialogHelper.ShowSimpleDialog(this, "Success", "This user exists");
            }
            else
            {
              DialogHelper.ShowSimpleDialog(this, "Failed", "This user doesn't exist");
            }
          }
      }
      catch (System.Exception exception)
      {
        this.SetProgressBarIndeterminateVisibility(false);

        var title = this.GetString(Resource.String.text_error);
        DialogHelper.ShowSimpleDialog(this, title, exception.Message);
      }
    }
    public void TestPasswordStorageCopyReturnsSameValues()
    {
      const string login = "******";
      const string password = "******";

      using (var passwordStorage = new SecureStringPasswordProvider(login, password))
      {
        Assert.AreEqual(login, passwordStorage.Username);
        Assert.AreEqual(password, passwordStorage.Password);

        using (var passwordStorageCopy = passwordStorage.CredentialsShallowCopy())
        {
          Assert.AreNotSame(passwordStorage, passwordStorageCopy);

          Assert.AreEqual(login, passwordStorageCopy.Username);
          Assert.AreEqual(password, passwordStorageCopy.Password);
        }
      }
    }
    protected async override void OnCreate(Bundle bundle)
    {
      base.OnCreate(bundle);

      string instanceUrl = "http://my.site.com";

      using (var credentials = new SecureStringPasswordProvider("login", "password"))
      using (
        var session =
          SitecoreWebApiSessionBuilder.AuthenticatedSessionWithHost(instanceUrl)
          .Credentials(credentials)
          .DefaultDatabase("web")
          .DefaultLanguage("en")
          .MediaLibraryRoot("/sitecore/media library")
          .MediaPrefix("~/media/")
          .DefaultMediaResourceExtension("ashx")
          .BuildReadonlySession())
      {
        var request =
          ItemWebApiRequestBuilder.ReadItemsRequestWithPath("/sitecore/content/home")
            .AddScope(ScopeType.Self)
            .Payload(PayloadType.Content)
            .Build();

        ScItemsResponse items = await session.ReadItemAsync(request);
        string fieldContent = items[0]["Text"].RawValue;

        string itemName = "Home Item Text";

        var dialogBuilder = new AlertDialog.Builder(this);
        dialogBuilder.SetTitle(itemName);
        dialogBuilder.SetMessage(fieldContent);
        dialogBuilder.SetPositiveButton("OK", (object sender, DialogClickEventArgs e) =>
          {
          });

        dialogBuilder.Create().Show();
      }
    }
    public void TestPasswordStorageAllowsNullPassword()
    {
      const string login = "******";
      const string password = null;

      using (var passwordStorage = new SecureStringPasswordProvider(login, password))
      {
        Assert.AreEqual(login, passwordStorage.Username);
        Assert.AreEqual(password, passwordStorage.Password);
      }
    }