1 /*
2 * MIT License
3 *
4 * Copyright (c) 2010-2024 The Waffle Project Contributors: https://github.com/Waffle/waffle/graphs/contributors
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
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 * Windows Domain.
32 */
33 public class WindowsDomainImpl implements IWindowsDomain {
34
35 /**
36 * The Enum TrustDirection.
37 */
38 private enum TrustDirection {
39
40 /** The inbound. */
41 INBOUND,
42 /** The outbound. */
43 OUTBOUND,
44 /** The bidirectional. */
45 BIDIRECTIONAL
46 }
47
48 /**
49 * The Enum TrustType.
50 */
51 private enum TrustType {
52
53 /** The tree root. */
54 TREE_ROOT,
55 /** The parent child. */
56 PARENT_CHILD,
57 /** The cross link. */
58 CROSS_LINK,
59 /** The external. */
60 EXTERNAL,
61 /** The forest. */
62 FOREST,
63 /** The kerberos. */
64 KERBEROS,
65 /** The unknown. */
66 UNKNOWN
67 }
68
69 /** The fqn. */
70 private String fqn;
71
72 /** The trust direction. */
73 private TrustDirection trustDirection = TrustDirection.BIDIRECTIONAL;
74
75 /** The trust type. */
76 private TrustType trustType = TrustType.UNKNOWN;
77
78 /**
79 * Instantiates a new windows domain impl.
80 *
81 * @param newFqn
82 * the new fqn
83 */
84 public WindowsDomainImpl(final String newFqn) {
85 this.fqn = newFqn;
86 }
87
88 /**
89 * Instantiates a new windows domain impl.
90 *
91 * @param trust
92 * the trust
93 */
94 public WindowsDomainImpl(final DomainTrust trust) {
95 // fqn
96 this.fqn = trust.DnsDomainName;
97 if (this.fqn == null || this.fqn.length() == 0) {
98 this.fqn = trust.NetbiosDomainName;
99 }
100 // trust direction
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 // trust type
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 }