1
2
3
4
5
6
7
8
9
10
11
12
13
14 package waffle.windows.auth.impl;
15
16 import waffle.windows.auth.IWindowsDomain;
17
18 import com.sun.jna.platform.win32.Netapi32Util.DomainTrust;
19
20
21
22
23
24
25 public class WindowsDomainImpl implements IWindowsDomain {
26
27
28
29
30 private enum TrustDirection {
31
32
33 INBOUND,
34
35 OUTBOUND,
36
37 BIDIRECTIONAL
38 }
39
40
41
42
43 private enum TrustType {
44
45
46 TREE_ROOT,
47
48 PARENT_CHILD,
49
50 CROSS_LINK,
51
52 EXTERNAL,
53
54 FOREST,
55
56 KERBEROS,
57
58 UNKNOWN
59 }
60
61
62 private String fqn;
63
64
65 private TrustDirection trustDirection = TrustDirection.BIDIRECTIONAL;
66
67
68 private TrustType trustType = TrustType.UNKNOWN;
69
70
71
72
73
74
75
76 public WindowsDomainImpl(final String newFqn) {
77 this.fqn = newFqn;
78 }
79
80
81
82
83
84
85
86 public WindowsDomainImpl(final DomainTrust trust) {
87
88 this.fqn = trust.DnsDomainName;
89 if (this.fqn == null || this.fqn.length() == 0) {
90 this.fqn = trust.NetbiosDomainName;
91 }
92
93 if (trust.isInbound() && trust.isOutbound()) {
94 this.trustDirection = TrustDirection.BIDIRECTIONAL;
95 } else if (trust.isOutbound()) {
96 this.trustDirection = TrustDirection.OUTBOUND;
97 } else if (trust.isInbound()) {
98 this.trustDirection = TrustDirection.INBOUND;
99 }
100
101 if (trust.isInForest()) {
102 this.trustType = TrustType.FOREST;
103 } else if (trust.isRoot()) {
104 this.trustType = TrustType.TREE_ROOT;
105 }
106 }
107
108
109
110
111 @Override
112 public String getFqn() {
113 return this.fqn;
114 }
115
116
117
118
119 @Override
120 public String getTrustDirectionString() {
121 return this.trustDirection.toString();
122 }
123
124
125
126
127 @Override
128 public String getTrustTypeString() {
129 return this.trustType.toString();
130 }
131
132 }