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