Skip to content

Commit

Permalink
unloaded credentials now display a message
Browse files Browse the repository at this point in the history
  • Loading branch information
sparerd committed Aug 6, 2017
1 parent ec554da commit e4f8f96
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 9 deletions.
12 changes: 5 additions & 7 deletions mRemoteV1/Connection/AbstractConnectionRecord.cs
Expand Up @@ -11,7 +11,6 @@
using mRemoteNG.Connection.Protocol.VNC;
using mRemoteNG.Credential;
using mRemoteNG.Tools;
using mRemoteNG.UI.Controls;
using mRemoteNG.UI.Controls.Adapters;

// ReSharper disable ArrangeAccessorOwnerBody
Expand Down Expand Up @@ -148,20 +147,19 @@ public virtual Maybe<Guid> CredentialRecordId
LocalizedAttributes.LocalizedDescription(nameof(Language.strPropertyDescriptionCredential))]
[Editor(typeof(CredentialRecordListAdaptor), typeof(UITypeEditor))]
[TypeConverter(typeof(ExpandableObjectConverter))]
public virtual Maybe<ICredentialRecord> CredentialRecord
public virtual ICredentialRecord CredentialRecord
{
get
{
return CredentialRecordId
var credential = CredentialRecordId
.Select(guid => Runtime.CredentialProviderCatalog.GetCredentialRecord(guid))
.FirstOrDefault()
.Maybe();
.FirstOrDefault();
return credential ?? new PlaceholderCredentialRecord(CredentialRecordId);
}

set
{
foreach (var credentialRecord in value)
CredentialRecordId = credentialRecord.Id.Maybe();
CredentialRecordId = Maybe<Guid>.FromNullable(value?.Id);
}
}

Expand Down
34 changes: 34 additions & 0 deletions mRemoteV1/Credential/PlaceholderCredentialRecord.cs
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Security;

namespace mRemoteNG.Credential
{
public class PlaceholderCredentialRecord : ICredentialRecord
{
public event PropertyChangedEventHandler PropertyChanged;

public Guid Id { get; }

[ReadOnly(true)]
public string Title { get; set; } = Language.CredentialUnavailable;

[ReadOnly(true)]
public string Username { get; set; } = Language.CredentialUnavailable;

[ReadOnly(true)]
public SecureString Password { get; set; } = new SecureString();

[ReadOnly(true)]
public string Domain { get; set; } = Language.CredentialUnavailable;

public PlaceholderCredentialRecord(IEnumerable<Guid> id)
{
Id = id.FirstOrDefault();
}

public override string ToString() => Language.CredentialUnavailable;
}
}
9 changes: 9 additions & 0 deletions mRemoteV1/Resources/Language/Language.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions mRemoteV1/Resources/Language/Language.resx
Expand Up @@ -2567,4 +2567,8 @@ mRemoteNG will now quit and begin with the installation.</value>

This page will walk you through the process of upgrading your connections file or give you a chance to open a different connections file if you do not want to perform the upgrade.</value>
</data>
<data name="CredentialUnavailable" xml:space="preserve">
<value>Credential not available</value>
<comment>Shown when a credential is not loaded/available for use.</comment>
</data>
</root>
7 changes: 7 additions & 0 deletions mRemoteV1/Tools/Maybe.cs
Expand Up @@ -34,5 +34,12 @@ public override string ToString()
{
return _maybe.Any() ? _maybe.First().ToString() : "";
}

public static Maybe<TOut> FromNullable<TOut>(TOut? value) where TOut : struct
{
return value.HasValue
? new Maybe<TOut>(value.Value)
: new Maybe<TOut>();
}
}
}
Expand Up @@ -3,7 +3,6 @@
using System.Drawing.Design;
using System.Windows.Forms.Design;
using mRemoteNG.App;
using mRemoteNG.Tools;

namespace mRemoteNG.UI.Controls.Adapters
{
Expand Down Expand Up @@ -37,7 +36,7 @@ public override object EditValue(ITypeDescriptorContext context, IServiceProvide
//return newCred;
}

return listBox.SelectedItem.Maybe();
return listBox.SelectedItem ?? value;
}

private void ListBoxOnSelectedValueChanged(object sender, EventArgs eventArgs)
Expand Down
1 change: 1 addition & 0 deletions mRemoteV1/mRemoteV1.csproj
Expand Up @@ -232,6 +232,7 @@
<Compile Include="Connection\Protocol\ProtocolFactory.cs" />
<Compile Include="Connection\Protocol\VNC\VNCEnum.cs" />
<Compile Include="Connection\WebHelper.cs" />
<Compile Include="Credential\PlaceholderCredentialRecord.cs" />
<Compile Include="Credential\Repositories\CompositeRepositoryUnlocker.cs" />
<Compile Include="Credential\CredentialChangedEventArgs.cs" />
<Compile Include="Credential\CredentialDeletionMsgBoxConfirmer.cs" />
Expand Down

0 comments on commit e4f8f96

Please sign in to comment.