View Javadoc
1   /*
2    * Copyright 2019 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.bremersee.dccon.config;
18  
19  import java.io.Serializable;
20  import java.util.ArrayList;
21  import java.util.Arrays;
22  import java.util.List;
23  import lombok.EqualsAndHashCode;
24  import lombok.Getter;
25  import lombok.NoArgsConstructor;
26  import lombok.Setter;
27  import lombok.ToString;
28  import lombok.extern.slf4j.Slf4j;
29  import org.ldaptive.SearchScope;
30  import org.springframework.boot.context.properties.ConfigurationProperties;
31  import org.springframework.stereotype.Component;
32  
33  /**
34   * The domain controller properties.
35   *
36   * @author Christian Bremer
37   */
38  @ConfigurationProperties(prefix = "bremersee.domain-controller")
39  @Component
40  @Getter
41  @Setter
42  @ToString
43  @EqualsAndHashCode
44  @Slf4j
45  public class DomainControllerProperties implements Serializable {
46  
47    private static final long serialVersionUID = 2L;
48  
49    private static final String MIN_LENGTH_PLACEHOLDER = "{{MIN_LENGTH}}";
50  
51    private static final String SIMPLE_PASSWORD_REGEX = "^(?=.{" + MIN_LENGTH_PLACEHOLDER
52        + ",75}$).*";
53  
54    private static final String COMPLEX_PASSWORD_REGEX = "(?=^.{" + MIN_LENGTH_PLACEHOLDER + ",75}$)"
55        + "((?=.*\\d)(?=.*[A-Z])(?=.*[a-z])|(?=.*\\d)(?=.*[^A-Za-z0-9])(?=.*[a-z])"
56        + "|(?=.*[^A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z])|(?=.*\\d)(?=.*[A-Z])(?=.*[^A-Za-z0-9]))^.*";
57  
58  
59    private String personalName = "Anna Livia";
60  
61    private String companyName = "example.org";
62  
63    private String companyUrl = "http://example.org";
64  
65  
66    private String groupBaseDn;
67  
68    private String groupRdn = "cn";
69  
70    private String groupFindAllFilter = "(objectClass=group)";
71  
72    private SearchScope groupFindAllSearchScope = SearchScope.ONELEVEL;
73  
74    private String groupFindOneFilter = "(&(objectClass=group)(sAMAccountName={0}))";
75  
76    private SearchScope groupFindOneSearchScope = SearchScope.ONELEVEL;
77  
78  
79    private String userBaseDn;
80  
81    private String userRdn = "cn";
82  
83    private String userFindAllFilter = "(objectClass=user)";
84  
85    private SearchScope userFindAllSearchScope = SearchScope.ONELEVEL;
86  
87    private String userFindOneFilter = "(&(objectClass=user)(sAMAccountName={0}))";
88  
89    private SearchScope userFindOneSearchScope = SearchScope.ONELEVEL;
90  
91  
92    private String defaultSidPrefix = "S-1-5-21-";
93  
94    private int maxSystemSidSuffix = 999;
95  
96  
97    private String dnsZoneBaseDn;
98  
99    private String dnsZoneRdn = "dc";
100 
101   private String dnsZoneFindAllFilter = "(objectClass=dnsZone)";
102 
103   private SearchScope dnsZoneFindAllSearchScope = SearchScope.SUBTREE;
104 
105   private String dnsZoneFindOneFilter = "(&(objectClass=dnsZone)(name={0}))";
106 
107   private SearchScope dnsZoneFindOneSearchScope = SearchScope.SUBTREE;
108 
109 
110   private String defaultZone = "samdom.example.org";
111 
112   private String dnsNodeBaseDn;
113 
114   private String dnsNodeRdn = "dc";
115 
116   private String dnsNodeFindAllFilter = "(objectClass=dnsNode)";
117 
118   private SearchScope dnsNodeFindAllSearchScope = SearchScope.SUBTREE;
119 
120   private String dnsNodeFindOneFilter = "(&(objectClass=dnsNode)(name={0}))";
121 
122   private SearchScope dnsNodeFindOneSearchScope = SearchScope.SUBTREE;
123 
124 
125   private String kinitBinary = "/usr/bin/kinit";
126 
127   private String kinitAdministratorName = "Administrator";
128 
129   private String kinitPasswordFile = "/var/lib/dc-con/dc-pass.txt";
130 
131   private String sudoBinary = "/usr/bin/sudo";
132 
133   private boolean usingSudo = true;
134 
135   private String sambaToolBinary = "/usr/bin/samba-tool";
136 
137   private String sambaToolExecDir = "/tmp";
138 
139   private String loginShell = "/bin/bash";
140 
141   private String homeDirectoryTemplate = "\\\\data\\users\\{}";
142 
143   private String unixHomeDirTemplate = "/home/{}";
144 
145 
146   private String dhcpLeaseListBinary = "/usr/sbin/dhcp-lease-list";
147 
148   private String dhcpLeaseListExecDir = "/tmp";
149 
150 
151   private String nameServerHost = "ns.samdom.example.org";
152 
153   private String reverseZoneSuffixIp4 = ".in-addr.arpa";
154 
155   private String reverseZoneSuffixIp6 = ".ip6.arpa";
156 
157   private List<String> excludedZoneRegexList = new ArrayList<>();
158 
159   private List<String> excludedNodeRegexList = new ArrayList<>();
160 
161 
162   private String ip4Regex = "^(?:[0-9]{1,3}\\.){3}[0-9]{1,3}$";
163 
164   private String macRegex = "^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$";
165 
166 
167   private String gravatarUrl = "https://www.gravatar.com/avatar/{hash}?d={default}&s={size}";
168 
169 
170   private MailWithCredentialsProperties mailWithCredentials = new MailWithCredentialsProperties();
171 
172 
173   /**
174    * Instantiates a new Domain controller properties.
175    */
176   public DomainControllerProperties() {
177     excludedZoneRegexList.add("^_msdcs\\..*$");
178     excludedZoneRegexList.add("RootDNSServers");
179 
180     excludedNodeRegexList.add("^$");
181     excludedNodeRegexList.add("_msdcs");
182     excludedNodeRegexList.add("_sites");
183     excludedNodeRegexList.add("_tcp");
184     excludedNodeRegexList.add("_udp");
185 
186     excludedNodeRegexList.add("@");
187     excludedNodeRegexList.add("_gc\\..*$");
188     excludedNodeRegexList.add("_kerberos\\..*$");
189     excludedNodeRegexList.add("_kpasswd\\..*$");
190     excludedNodeRegexList.add("_ldap\\..*$");
191     excludedNodeRegexList.add("ForestDnsZones");
192   }
193 
194   /**
195    * Gets reverse zone suffix list.
196    *
197    * @return the reverse zone suffix list
198    */
199   public List<String> getReverseZoneSuffixList() {
200     return Arrays.asList(reverseZoneSuffixIp4, reverseZoneSuffixIp6);
201   }
202 
203   /**
204    * Determines whether the given zone is a reverse zone or not.
205    *
206    * @param zoneName the zone name
207    * @return {@code true} if the zone is a reverse zone, otherwise {@code false}
208    */
209   public boolean isReverseZone(final String zoneName) {
210     return zoneName != null && getReverseZoneSuffixList().stream()
211         .anyMatch(suffix -> zoneName.toLowerCase().endsWith(suffix.toLowerCase()));
212   }
213 
214   /**
215    * Build dns node base dn string.
216    *
217    * @param zoneName the zone name
218    * @return the string
219    */
220   public String buildDnsNodeBaseDn(String zoneName) {
221     return dnsNodeBaseDn.replace("{zoneName}", zoneName);
222   }
223 
224   /**
225    * Gets simple password regex.
226    *
227    * @param minLength the min length
228    * @return the simple password regex
229    */
230   public static String getSimplePasswordRegex(int minLength) {
231     return SIMPLE_PASSWORD_REGEX.replace(MIN_LENGTH_PLACEHOLDER, String.valueOf(minLength));
232   }
233 
234   /**
235    * Gets complex password regex.
236    *
237    * @param minLength the min length
238    * @return the complex password regex
239    */
240   public static String getComplexPasswordRegex(int minLength) {
241     return COMPLEX_PASSWORD_REGEX.replace(MIN_LENGTH_PLACEHOLDER, String.valueOf(minLength));
242   }
243 
244   /**
245    * The mail with credentials properties.
246    *
247    * @author Christian Bremer
248    */
249   @Getter
250   @Setter
251   @ToString
252   @EqualsAndHashCode
253   @NoArgsConstructor
254   @SuppressWarnings("WeakerAccess")
255   public static class MailWithCredentialsProperties {
256 
257     private String sender = "no-reply@example.org";
258 
259     private String templateBasename = "personal-mail-with-credentials";
260 
261     private String loginUrl = "http://localhost:4200/change-password";
262 
263     private List<MailInlineAttachment> inlineAttachments = new ArrayList<>();
264   }
265 
266   /**
267    * The mail inline attachment.
268    */
269   @Getter
270   @Setter
271   @ToString
272   @EqualsAndHashCode
273   @NoArgsConstructor
274   public static class MailInlineAttachment {
275 
276     private String contentId;
277 
278     private String location;
279 
280     private String mimeType;
281   }
282 }