View Javadoc
1   /*
2    * SPDX-License-Identifier: MIT
3    * See LICENSE file for details.
4    *
5    * Copyright 2010-2026 The Waffle Project Contributors: https://github.com/Waffle/waffle/graphs/contributors
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   * Windows Domain.
15   */
16  public class WindowsDomainImpl implements IWindowsDomain {
17  
18      /**
19       * The Enum TrustDirection.
20       */
21      private enum TrustDirection {
22  
23          /** The inbound. */
24          INBOUND,
25          /** The outbound. */
26          OUTBOUND,
27          /** The bidirectional. */
28          BIDIRECTIONAL
29      }
30  
31      /**
32       * The Enum TrustType.
33       */
34      private enum TrustType {
35  
36          /** The tree root. */
37          TREE_ROOT,
38          /** The parent child. */
39          PARENT_CHILD,
40          /** The cross link. */
41          CROSS_LINK,
42          /** The external. */
43          EXTERNAL,
44          /** The forest. */
45          FOREST,
46          /** The kerberos. */
47          KERBEROS,
48          /** The unknown. */
49          UNKNOWN
50      }
51  
52      /** The fqn. */
53      private String fqn;
54  
55      /** The trust direction. */
56      private TrustDirection trustDirection = TrustDirection.BIDIRECTIONAL;
57  
58      /** The trust type. */
59      private TrustType trustType = TrustType.UNKNOWN;
60  
61      /**
62       * Instantiates a new windows domain impl.
63       *
64       * @param newFqn
65       *            the new fqn
66       */
67      public WindowsDomainImpl(final String newFqn) {
68          this.fqn = newFqn;
69      }
70  
71      /**
72       * Instantiates a new windows domain impl.
73       *
74       * @param trust
75       *            the trust
76       */
77      public WindowsDomainImpl(final DomainTrust trust) {
78          // fqn
79          this.fqn = trust.DnsDomainName;
80          if (this.fqn == null || this.fqn.length() == 0) {
81              this.fqn = trust.NetbiosDomainName;
82          }
83          // trust direction
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          // trust type
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 }