1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 * 19 */ 20 package org.apache.directory.server.core; 21 22 23 import org.apache.directory.server.core.authn.LdapPrincipal; 24 import org.apache.directory.server.core.changelog.ChangeLog; 25 import org.apache.directory.server.core.entry.ServerEntry; 26 import org.apache.directory.server.core.entry.ServerEntryFactory; 27 import org.apache.directory.server.core.event.EventService; 28 import org.apache.directory.server.core.interceptor.Interceptor; 29 import org.apache.directory.server.core.interceptor.InterceptorChain; 30 import org.apache.directory.server.core.partition.Partition; 31 import org.apache.directory.server.core.partition.PartitionNexus; 32 import org.apache.directory.server.core.schema.SchemaService; 33 import org.apache.directory.server.schema.registries.Registries; 34 import org.apache.directory.shared.ldap.ldif.LdifEntry; 35 import org.apache.directory.shared.ldap.name.LdapDN; 36 37 import java.io.File; 38 import java.util.List; 39 import java.util.Set; 40 41 42 /** 43 * Provides JNDI service to {@link AbstractContextFactory}. 44 * 45 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 46 * @version $Rev: 679219 $, $Date: 2008-07-24 00:45:05 +0200 (Do, 24 Jul 2008) $ 47 */ 48 public interface DirectoryService extends ServerEntryFactory 49 { 50 String JNDI_KEY = DirectoryService.class.getName(); 51 52 /** 53 * Reverts the server's state to an earlier revision. Note that the revsion number 54 * still increases to revert back even though the state reverted to is the same. 55 * Note that implementations may lock the server from making changes or searching 56 * the directory until this operation has completed. 57 * 58 * @param revision the revision number to revert to 59 * @return the new revision reached by applying all changes needed to revert to the 60 * original state 61 * @throws Exception if there are problems reverting back to the earlier state 62 * @throws IllegalArgumentException if the revision provided is greater than the current 63 * revision or less than 0 64 * @throws UnsupportedOperationException if this feature is not supported by the 65 * change log 66 */ 67 long revert( long revision ) throws Exception; 68 69 70 /** 71 * Reverts the server's state to the latest tagged snapshot if one was taken. If 72 * there is no tag a illegal state exception will result. If the latest revision 73 * is not earlier than the current revision (both are same), then no changes were 74 * made to the directory to be reverted. In this case we return the current 75 * revision and do nothiig loggin the fact that we ignored the request to revert. 76 * 77 * @return the new revision reached by applying all changes needed to revert 78 * to the new state or the same version before this call if no revert actually 79 * took place 80 * @throws Exception if there are problems reverting back to the earlier state 81 * @throws UnsupportedOperationException if this feature is not supported by the 82 * change log 83 */ 84 long revert() throws Exception; 85 86 87 PartitionNexus getPartitionNexus(); 88 89 90 InterceptorChain getInterceptorChain(); 91 92 93 void addPartition( Partition partition ) throws Exception; 94 95 96 void removePartition( Partition partition ) throws Exception; 97 98 99 Registries getRegistries(); 100 101 102 void setRegistries( Registries registries ); 103 104 105 SchemaService getSchemaService(); 106 107 108 void setSchemaService( SchemaService schemaService ); 109 110 111 EventService getEventService(); 112 113 114 void setEventService( EventService eventService ); 115 116 117 /** 118 * Starts up this service. 119 * 120 * @throws Exception if failed to start up 121 */ 122 void startup() throws Exception; 123 124 125 /** 126 * Shuts down this service. 127 * 128 * @throws Exception if failed to shut down 129 */ 130 void shutdown() throws Exception; 131 132 133 /** 134 * Calls {@link Partition#sync()} for all registered {@link Partition}s. 135 * @throws Exception if synchronization failed 136 */ 137 void sync() throws Exception; 138 139 140 /** 141 * Returns <tt>true</tt> if this service is started. 142 * @return true if the service has started, false otherwise 143 */ 144 boolean isStarted(); 145 146 147 CoreSession getAdminSession() throws Exception; 148 149 150 /** 151 * Gets a logical session to perform operations on this DirectoryService 152 * as the anonymous user. This bypasses authentication without 153 * propagating a bind operation into the core. 154 * 155 * @return a logical session as the anonymous user 156 */ 157 CoreSession getSession() throws Exception; 158 159 160 /** 161 * Gets a logical session to perform operations on this DirectoryService 162 * as a specific user. This bypasses authentication without propagating 163 * a bind operation into the core. 164 * 165 * @return a logical session as a specific user 166 */ 167 CoreSession getSession( LdapPrincipal principal ) throws Exception; 168 169 170 /** 171 * Gets a logical session to perform operations on this DirectoryService 172 * as a specific user with a separate authorization principal. This 173 * bypasses authentication without propagating a bind operation into the 174 * core. 175 * 176 * @return a logical session as a specific user 177 */ 178 CoreSession getSession( LdapDN principalDn, byte[] credentials ) throws Exception; 179 180 181 /** 182 * Gets a logical session to perform operations on this DirectoryService 183 * as a specific user with a separate authorization principal. This 184 * bypasses authentication without propagating a bind operation into the 185 * core. 186 * 187 * @return a logical session as a specific user 188 */ 189 CoreSession getSession( LdapDN principalDn, byte[] credentials, String saslMechanism, String saslAuthId ) 190 throws Exception; 191 192 193 void setInstanceId( String instanceId ); 194 195 196 String getInstanceId(); 197 198 199 /** 200 * Gets the {@link Partition}s used by this DirectoryService. 201 * 202 * @return the set of partitions used 203 */ 204 Set<? extends Partition> getPartitions(); 205 206 207 /** 208 * Sets {@link Partition}s used by this DirectoryService. 209 * 210 * @param partitions the partitions to used 211 */ 212 void setPartitions( Set<? extends Partition> partitions ); 213 214 215 /** 216 * Returns <tt>true</tt> if access control checks are enabled. 217 * 218 * @return true if access control checks are enabled, false otherwise 219 */ 220 boolean isAccessControlEnabled(); 221 222 223 /** 224 * Sets whether to enable basic access control checks or not. 225 * 226 * @param accessControlEnabled true to enable access control checks, false otherwise 227 */ 228 void setAccessControlEnabled( boolean accessControlEnabled ); 229 230 231 /** 232 * Returns <tt>true</tt> if anonymous access is allowed on entries besides the RootDSE. 233 * If the access control subsystem is enabled then access to some entries may not be 234 * allowed even when full anonymous access is enabled. 235 * 236 * @return true if anonymous access is allowed on entries besides the RootDSE, false 237 * if anonymous access is allowed to all entries. 238 */ 239 boolean isAllowAnonymousAccess(); 240 241 242 /** 243 * Sets whether to allow anonymous access to entries other than the RootDSE. If the 244 * access control subsystem is enabled then access to some entries may not be allowed 245 * even when full anonymous access is enabled. 246 * 247 * @param enableAnonymousAccess true to enable anonymous access, false to disable it 248 */ 249 void setAllowAnonymousAccess( boolean enableAnonymousAccess ); 250 251 252 /** 253 * Returns interceptors in the server. 254 * 255 * @return the interceptors in the server. 256 */ 257 List<Interceptor> getInterceptors(); 258 259 260 /** 261 * Sets the interceptors in the server. 262 * 263 * @param interceptors the interceptors to be used in the server. 264 */ 265 void setInterceptors( List<Interceptor> interceptors ); 266 267 268 /** 269 * Returns test directory entries({@link LdifEntry}) to be loaded while 270 * bootstrapping. 271 * 272 * @return test entries to load during bootstrapping 273 */ 274 List<LdifEntry> getTestEntries(); 275 276 277 /** 278 * Sets test directory entries({@link Attributes}) to be loaded while 279 * bootstrapping. 280 * 281 * @param testEntries the test entries to load while bootstrapping 282 */ 283 void setTestEntries( List<? extends LdifEntry> testEntries ); 284 285 286 /** 287 * Returns working directory (counterpart of <tt>var/lib</tt>) where partitions are 288 * stored by default. 289 * 290 * @return the directory where partition's are stored. 291 */ 292 File getWorkingDirectory(); 293 294 295 /** 296 * Sets working directory (counterpart of <tt>var/lib</tt>) where partitions are stored 297 * by default. 298 * 299 * @param workingDirectory the directory where the server's partitions are stored by default. 300 */ 301 void setWorkingDirectory( File workingDirectory ); 302 303 304 /** 305 * Sets the shutdown hook flag which controls whether or not this DirectoryService 306 * registers a JVM shutdown hook to flush caches and synchronize to disk safely. This is 307 * enabled by default. 308 * 309 * @param shutdownHookEnabled true to enable the shutdown hook, false to disable 310 */ 311 void setShutdownHookEnabled( boolean shutdownHookEnabled ); 312 313 314 /** 315 * Checks to see if this DirectoryService has registered a JVM shutdown hook 316 * to flush caches and synchronize to disk safely. This is enabled by default. 317 * 318 * @return true if a shutdown hook is registered, false if it is not 319 */ 320 boolean isShutdownHookEnabled(); 321 322 323 void setExitVmOnShutdown( boolean exitVmOnShutdown ); 324 325 326 boolean isExitVmOnShutdown(); 327 328 329 void setMaxSizeLimit( int maxSizeLimit ); 330 331 332 int getMaxSizeLimit(); 333 334 335 void setMaxTimeLimit( int maxTimeLimit ); 336 337 338 int getMaxTimeLimit(); 339 340 341 void setSystemPartition( Partition systemPartition ); 342 343 344 Partition getSystemPartition(); 345 346 347 boolean isDenormalizeOpAttrsEnabled(); 348 349 350 void setDenormalizeOpAttrsEnabled( boolean denormalizeOpAttrsEnabled ); 351 352 353 /** 354 * Gets the ChangeLog service for this DirectoryService used for tracking 355 * changes (revisions) to the server and using them to revert the server 356 * to earier revisions. 357 * 358 * @return the change log service 359 */ 360 ChangeLog getChangeLog(); 361 362 363 /** 364 * Sets the ChangeLog service for this DirectoryService used for tracking 365 * changes (revisions) to the server and using them to revert the server 366 * to earier revisions. 367 * 368 * @param changeLog the change log service to set 369 */ 370 void setChangeLog( ChangeLog changeLog ); 371 372 373 /** 374 * Create a new ServerEntry. 375 * 376 * @param ldif the String representing the attributes, in LDIF format 377 * @param dn the DN for this new entry 378 */ 379 ServerEntry newEntry( String ldif, String dn ); 380 381 382 /** 383 * Gets the operation manager. 384 */ 385 OperationManager getOperationManager(); 386 }