/
AuthenticationBackendType.cs
246 lines (221 loc) · 7.45 KB
/
AuthenticationBackendType.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
using System;
using Newtonsoft.Json;
using VaultSharp.Infrastructure.JsonConverters;
using VaultSharp.Infrastructure.Validation;
namespace VaultSharp.Backends.Authentication.Models
{
/// <summary>
/// A helper class for retrieving and comparing Authentication Backend types.
/// </summary>
[JsonConverter(typeof(AuthenticationBackendTypeJsonConverter))]
public class AuthenticationBackendType : IEquatable<AuthenticationBackendType>
{
/// <summary>
/// The application identifier type
/// </summary>
private static readonly AuthenticationBackendType AppIdType = new AuthenticationBackendType("app-id");
/// <summary>
/// The git hub type
/// </summary>
private static readonly AuthenticationBackendType GitHubType = new AuthenticationBackendType("github");
/// <summary>
/// The LDAP type
/// </summary>
private static readonly AuthenticationBackendType LDAPType = new AuthenticationBackendType("ldap");
/// <summary>
/// The certificate type
/// </summary>
private static readonly AuthenticationBackendType CertificateType = new AuthenticationBackendType("cert");
/// <summary>
/// The token type
/// </summary>
private static readonly AuthenticationBackendType TokenType = new AuthenticationBackendType("token");
/// <summary>
/// The username password type
/// </summary>
private static readonly AuthenticationBackendType UsernamePasswordType = new AuthenticationBackendType("userpass");
/// <summary>
/// The _type
/// </summary>
private readonly string _type;
/// <summary>
/// Gets the application identifier type.
/// </summary>
/// <value>
/// The application identifier.
/// </value>
[Obsolete("The AppId Authentication backend in Vault is now deprecated with the addition " +
"of the new AppRole backend. There are no plans to remove it, but we encourage " +
"using AppRole whenever possible, as it offers enhanced functionality " +
"and can accommodate many more types of authentication paradigms.")]
public static AuthenticationBackendType AppId
{
get
{
return AppIdType;
}
}
/// <summary>
/// Gets the git hub type.
/// </summary>
/// <value>
/// The git hub.
/// </value>
public static AuthenticationBackendType GitHub
{
get
{
return GitHubType;
}
}
/// <summary>
/// Gets the LDAP type.
/// </summary>
/// <value>
/// The LDAP.
/// </value>
public static AuthenticationBackendType LDAP
{
get
{
return LDAPType;
}
}
/// <summary>
/// Gets the certificate type.
/// </summary>
/// <value>
/// The certificate.
/// </value>
public static AuthenticationBackendType Certificate
{
get
{
return CertificateType;
}
}
/// <summary>
/// Gets the token type.
/// </summary>
/// <value>
/// The token.
/// </value>
public static AuthenticationBackendType Token
{
get
{
return TokenType;
}
}
/// <summary>
/// Gets the generic type.
/// </summary>
/// <value>
/// The generic.
/// </value>
public static AuthenticationBackendType UsernamePassword
{
get
{
return UsernamePasswordType;
}
}
/// <summary>
/// Gets the type type.
/// </summary>
/// <value>
/// The type.
/// </value>
public string Type
{
get { return _type; }
}
/// <summary>
/// Initializes a new instance of the <see cref="AuthenticationBackendType" /> class.
/// </summary>
/// <param name="type">The type.</param>
public AuthenticationBackendType(string type)
{
Checker.NotNull(type, "type");
_type = type;
}
/// <summary>
/// Implements the operator ==.
/// </summary>
/// <param name="left">The left.</param>
/// <param name="right">The right.</param>
/// <returns>
/// The result of the operator.
/// </returns>
public static bool operator ==(AuthenticationBackendType left, AuthenticationBackendType right)
{
// If both are null, or both are same instance, return true.
if (ReferenceEquals(left, right))
{
return true;
}
// If one is null, but not both, return false.
if (((object)left == null) || ((object)right == null))
{
return false;
}
return string.Equals(left.Type, right.Type, StringComparison.OrdinalIgnoreCase);
}
/// <summary>
/// Implements the operator !=.
/// </summary>
/// <param name="left">The left.</param>
/// <param name="right">The right.</param>
/// <returns>
/// The result of the operator.
/// </returns>
public static bool operator !=(AuthenticationBackendType left, AuthenticationBackendType right)
{
return !(left == right);
}
/// <summary>
/// Indicates whether the current object is equal to another object of the same type.
/// </summary>
/// <param name="other">An object to compare with this object.</param>
/// <returns>
/// true if the current object is equal to the <paramref name="other" /> parameter; otherwise, false.
/// </returns>
public bool Equals(AuthenticationBackendType other)
{
if ((object)other == null)
return false;
return string.Compare(_type, other._type, StringComparison.OrdinalIgnoreCase) == 0;
}
/// <summary>
/// Determines whether the specified <see cref="object" />, is equal to this instance.
/// </summary>
/// <param name="obj">The <see cref="object" /> to compare with this instance.</param>
/// <returns>
/// <c>true</c> if the specified <see cref="object" /> is equal to this instance; otherwise, <c>false</c>.
/// </returns>
public override bool Equals(object obj)
{
return Equals(obj as AuthenticationBackendType);
}
/// <summary>
/// Returns a hash code for this instance.
/// </summary>
/// <returns>
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
/// </returns>
public override int GetHashCode()
{
return _type.ToUpperInvariant().GetHashCode();
}
/// <summary>
/// Returns a <see cref="string" /> that represents this instance.
/// </summary>
/// <returns>
/// A <see cref="string" /> that represents this instance.
/// </returns>
public override string ToString()
{
return _type;
}
}
}