1 /**
2 * Waffle (https://github.com/dblock/waffle)
3 *
4 * Copyright (c) 2010 - 2015 Application Security, Inc.
5 *
6 * All rights reserved. This program and the accompanying materials
7 * are made available under the terms of the Eclipse Public License v1.0
8 * which accompanies this distribution, and is available at
9 * http://www.eclipse.org/legal/epl-v10.html
10 *
11 * Contributors:
12 * Application Security, Inc.
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 * Windows Domain.
22 *
23 * @author dblock[at]dblock[dot]org
24 */
25 public class WindowsDomainImpl implements IWindowsDomain {
26
27 /**
28 * The Enum TrustDirection.
29 */
30 private enum TrustDirection {
31
32 /** The inbound. */
33 INBOUND,
34 /** The outbound. */
35 OUTBOUND,
36 /** The bidirectional. */
37 BIDIRECTIONAL
38 }
39
40 /**
41 * The Enum TrustType.
42 */
43 private enum TrustType {
44
45 /** The tree root. */
46 TREE_ROOT,
47 /** The parent child. */
48 PARENT_CHILD,
49 /** The cross link. */
50 CROSS_LINK,
51 /** The external. */
52 EXTERNAL,
53 /** The forest. */
54 FOREST,
55 /** The kerberos. */
56 KERBEROS,
57 /** The unknown. */
58 UNKNOWN
59 }
60
61 /** The fqn. */
62 private String fqn;
63
64 /** The trust direction. */
65 private TrustDirection trustDirection = TrustDirection.BIDIRECTIONAL;
66
67 /** The trust type. */
68 private TrustType trustType = TrustType.UNKNOWN;
69
70 /**
71 * Instantiates a new windows domain impl.
72 *
73 * @param newFqn
74 * the new fqn
75 */
76 public WindowsDomainImpl(final String newFqn) {
77 this.fqn = newFqn;
78 }
79
80 /**
81 * Instantiates a new windows domain impl.
82 *
83 * @param trust
84 * the trust
85 */
86 public WindowsDomainImpl(final DomainTrust trust) {
87 // fqn
88 this.fqn = trust.DnsDomainName;
89 if (this.fqn == null || this.fqn.length() == 0) {
90 this.fqn = trust.NetbiosDomainName;
91 }
92 // trust direction
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 // trust type
101 if (trust.isInForest()) {
102 this.trustType = TrustType.FOREST;
103 } else if (trust.isRoot()) {
104 this.trustType = TrustType.TREE_ROOT;
105 }
106 }
107
108 /* (non-Javadoc)
109 * @see waffle.windows.auth.IWindowsDomain#getFqn()
110 */
111 @Override
112 public String getFqn() {
113 return this.fqn;
114 }
115
116 /* (non-Javadoc)
117 * @see waffle.windows.auth.IWindowsDomain#getTrustDirectionString()
118 */
119 @Override
120 public String getTrustDirectionString() {
121 return this.trustDirection.toString();
122 }
123
124 /* (non-Javadoc)
125 * @see waffle.windows.auth.IWindowsDomain#getTrustTypeString()
126 */
127 @Override
128 public String getTrustTypeString() {
129 return this.trustType.toString();
130 }
131
132 }