1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.michaelo.tomcat.pac;
17
18 import java.nio.charset.StandardCharsets;
19 import java.util.Objects;
20
21 import net.sf.michaelo.tomcat.realm.Sid;
22
23
24
25
26
27
28 public class UpnDnsInfo {
29
30 public static final long UPN_CONSTRUCTED_FLAG = 0x00000001L;
31 public static final long SAM_NAME_AND_SID_FLAG = 0x00000002L;
32
33 private final String upn;
34 private final String dnsDomainName;
35
36 private final long flags;
37
38 private String samName;
39 private Sid sid;
40
41
42
43
44
45
46
47
48 public UpnDnsInfo(byte[] infoBytes) {
49 Objects.requireNonNull(infoBytes, "infoBytes cannot be null");
50 if (infoBytes.length == 0) throw new IllegalArgumentException("infoBytes cannot be empty");
51
52 PacDataBuffer buf = new PacDataBuffer(infoBytes);
53
54
55 int upnLength = buf.getUnsignedShort();
56
57 int upnOffset = buf.getUnsignedShort();
58
59 int dnsDomainNameLength = buf.getUnsignedShort();
60
61 int dnsDomainNameOffset = buf.getUnsignedShort();
62
63
64
65
66
67
68
69
70 this.flags = buf.getUnsignedInt();
71
72 int pos = buf.position();
73 buf.position(upnOffset);
74 this.upn = getUnicodeString(buf, upnLength);
75 buf.position(dnsDomainNameOffset);
76 this.dnsDomainName = getUnicodeString(buf, dnsDomainNameLength);
77 buf.position(pos);
78
79 if ((flags & SAM_NAME_AND_SID_FLAG) != 0L) {
80
81 int samNameLength = buf.getUnsignedShort();
82
83 int samNameOffset = buf.getUnsignedShort();
84
85 int sidLength = buf.getUnsignedShort();
86
87 int sidOffset = buf.getUnsignedShort();
88
89 pos = buf.position();
90 buf.position(samNameOffset);
91 this.samName = getUnicodeString(buf, samNameLength);
92 byte[] dst = new byte[sidLength];
93 buf.position(sidOffset);
94 buf.get(dst);
95 this.sid = new Sid(dst);
96 }
97 }
98
99 public String getUpn() {
100 return upn;
101 }
102
103 public String getDnsDomainName() {
104 return dnsDomainName;
105 }
106
107 public long getFlags() {
108 return flags;
109 }
110
111 public String getSamName() {
112 return samName;
113 }
114
115 public Sid getSid() {
116 return sid;
117 }
118
119 private String getUnicodeString(PacDataBuffer buf, int length) {
120 byte[] dst = new byte[length];
121 buf.get(dst);
122 return new String(dst, StandardCharsets.UTF_16LE);
123 }
124 }