aboutsummaryrefslogtreecommitdiff
path: root/SocketHttpListener/Net/HttpListenerBasicIdentity.cs
blob: 391fc931edea787e036e649b7449044d4d008c5e (plain)
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
using System.Security.Principal;

namespace SocketHttpListener.Net
{
    public class HttpListenerBasicIdentity : GenericIdentity
    {
        string password;

        public HttpListenerBasicIdentity(string username, string password)
            : base(username, "Basic")
        {
            this.password = password;
        }

        public virtual string Password
        {
            get { return password; }
        }
    }

    public class GenericIdentity : IIdentity
    {
        private string m_name;
        private string m_type;

        public GenericIdentity(string name)
        {
            if (name == null)
                throw new System.ArgumentNullException(nameof(name));

            m_name = name;
            m_type = "";
        }

        public GenericIdentity(string name, string type)
        {
            if (name == null)
                throw new System.ArgumentNullException(nameof(name));
            if (type == null)
                throw new System.ArgumentNullException(nameof(type));

            m_name = name;
            m_type = type;
        }

        public virtual string Name
        {
            get
            {
                return m_name;
            }
        }

        public virtual string AuthenticationType
        {
            get
            {
                return m_type;
            }
        }

        public virtual bool IsAuthenticated
        {
            get
            {
                return !m_name.Equals("");
            }
        }
    }
}