View Javadoc
1   /*
2    * Copyright 2008-2016 Brian Thomas Matthews
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 com.btmatthews.maven.plugins.ldap;
18  
19  import com.btmatthews.utils.monitor.AbstractServer;
20  import com.btmatthews.utils.monitor.Logger;
21  
22  import java.io.File;
23  
24  /**
25   * Abstract base class for {@link LDAPServer} implementations.
26   *
27   * @author <a href="mailto:brian@btmatthews.com">Brian Matthews</a>
28   * @since 1.1.1
29   */
30  public abstract class AbstractLDAPServer extends AbstractServer implements LDAPServer {
31  
32      /**
33       * The root DN of the LDAP directory.
34       */
35      private String root;
36      /**
37       * The object classes used for the root DN.
38       */
39      private String[] objectClasses;
40      /**
41       * The distinguished name of the admin account.
42       */
43      private String authDn;
44      /**
45       * The password for the admin account.
46       */
47      private String passwd;
48      /**
49       * The working directory used by the LDAP directory service to store directory data.
50       */
51      private File workingDirectory;
52      /**
53       * The LDIF file used to seed the LDAP directory.
54       */
55      private File ldifFile;
56      /**
57       * The TCP port on which the server is listening for LDAP traffic.
58       */
59      private int serverPort;
60  
61      /**
62       * Used to configure the root DN of the LDAP directory, the working directory used by the directory service to
63       * store the directory data, the LDIF file used to seed the directory or the TCP port number on which the server
64       * will listening for LDAP traffic.
65       *
66       * @param name   The name of the property to configure.
67       * @param value  The value of the property being configured.
68       * @param logger Used to log error and information messages.
69       */
70      @Override
71      public void configure(final String name, final Object value, final Logger logger) {
72          if (ROOT.equals(name)) {
73              if (value instanceof String) {
74                  root = (String) value;
75                  logger.logInfo("Configured root DN for directory server: " + root);
76              }
77          } else if (OBJECT_CLASSES.equals(name)) {
78              if (value instanceof String[]) {
79                  objectClasses = (String[]) value;
80                  logger.logInfo("Configured object classes for root DN: " + objectClasses);
81              }
82          } else if (AUTH_DN.equals(name)) {
83              if (value instanceof String) {
84                  authDn = (String) value;
85                  logger.logInfo("Configured admin identity for directory server: " + authDn);
86              }
87          } else if (PASSWD.equals(name)) {
88              if (value instanceof String) {
89                  passwd = (String) value;
90                  logger.logInfo("Configured admin credentials for directory server: " + passwd);
91              }
92          } else if (WORK_DIR.equals(name)) {
93              if (value instanceof File) {
94                  workingDirectory = (File) value;
95                  logger.logInfo("Configured working directory for directory server: " + workingDirectory);
96              }
97          } else if (LDIF_FILE.equals(name)) {
98              if (value instanceof File) {
99                  ldifFile = (File) value;
100                 logger.logInfo("Configured LDIF seed data source for directory server: " + ldifFile);
101             }
102         } else if (LDAP_PORT.equals(name)) {
103             if (value instanceof Integer) {
104                 serverPort = (Integer) value;
105                 logger.logInfo("Configured TCP port for directory server: " + serverPort);
106             }
107         }
108     }
109 
110     /**
111      * Get the configured directory root.
112      *
113      * @return The directory root.
114      */
115     public final String getRoot() {
116         return root;
117     }
118 
119     /**
120      * Get the object classes used to create the directory root.
121      *
122      * @return The object classes.
123      */
124     public final String[] getObjectClasses() {
125         return objectClasses;
126     }
127 
128     /**
129      * Get the distinguished name of the admin account.
130      *
131      * @return The distinguished name of the admin account.
132      */
133     public final String getAuthDn() {
134         return authDn;
135     }
136 
137     /**
138      * Get the password for the admin account.
139      *
140      * @return The password for the admin account.
141      */
142     public final String getPasswd() {
143         return passwd;
144     }
145 
146     /**
147      * Get the working directory used to create temporary files.
148      *
149      * @return The working directory.
150      */
151     public final File getWorkingDirectory() {
152         return workingDirectory;
153     }
154 
155     /**
156      * Get the LDIF file that contains the data used to seed the directory.
157      *
158      * @return The LDIF file.
159      */
160     public final File getLdifFile() {
161         return ldifFile;
162     }
163 
164     /**
165      * Get the port on which the LDAP server is listening.
166      *
167      * @return The port.
168      */
169     public final int getServerPort() {
170         return serverPort;
171     }
172 }