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