| 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; |
| 21 |
|
| 22 |
|
| 23 |
import java.io.File; |
| 24 |
import java.io.IOException; |
| 25 |
import java.util.ArrayList; |
| 26 |
import java.util.HashMap; |
| 27 |
import java.util.HashSet; |
| 28 |
import java.util.List; |
| 29 |
import java.util.Map; |
| 30 |
import java.util.UUID; |
| 31 |
|
| 32 |
import org.apache.commons.lang.time.DateUtils; |
| 33 |
import org.apache.directory.server.config.ConfigPartitionReader; |
| 34 |
import org.apache.directory.server.config.LdifConfigExtractor; |
| 35 |
import org.apache.directory.server.config.beans.ConfigBean; |
| 36 |
import org.apache.directory.server.config.beans.DirectoryServiceBean; |
| 37 |
import org.apache.directory.server.config.beans.HttpServerBean; |
| 38 |
import org.apache.directory.server.config.beans.KdcServerBean; |
| 39 |
import org.apache.directory.server.config.beans.LdapServerBean; |
| 40 |
import org.apache.directory.server.config.beans.NtpServerBean; |
| 41 |
import org.apache.directory.server.config.builder.ServiceBuilder; |
| 42 |
import org.apache.directory.server.core.api.CoreSession; |
| 43 |
import org.apache.directory.server.core.api.DirectoryService; |
| 44 |
import org.apache.directory.server.core.api.InstanceLayout; |
| 45 |
import org.apache.directory.server.core.api.filtering.EntryFilteringCursor; |
| 46 |
import org.apache.directory.server.core.api.interceptor.context.ModifyOperationContext; |
| 47 |
import org.apache.directory.server.core.api.partition.Partition; |
| 48 |
import org.apache.directory.server.core.api.schema.SchemaPartition; |
| 49 |
import org.apache.directory.server.core.partition.ldif.LdifPartition; |
| 50 |
import org.apache.directory.server.core.partition.ldif.SingleFileLdifPartition; |
| 51 |
import org.apache.directory.server.i18n.I18n; |
| 52 |
import org.apache.directory.server.integration.http.HttpServer; |
| 53 |
import org.apache.directory.server.kerberos.kdc.KdcServer; |
| 54 |
import org.apache.directory.server.ldap.LdapServer; |
| 55 |
import org.apache.directory.server.ntp.NtpServer; |
| 56 |
import org.slf4j.Logger; |
| 57 |
import org.slf4j.LoggerFactory; |
| 58 |
|
| 59 |
|
| 60 |
/** |
| 61 |
* A class used to start various servers in a given {@link InstanceLayout}. |
| 62 |
* |
| 63 |
* @author <a href="mailto:[email protected]">Apache Directory Project</a> |
| 64 |
*/ |
| 65 |
public class ApacheDsService |
| 66 |
{ |
| 67 |
/** A logger for this class */ |
| 68 |
private static final Logger LOG = LoggerFactory.getLogger( ApacheDsService.class ); |
| 69 |
|
| 70 |
/** The LDAP server instance */ |
| 71 |
private LdapServer ldapServer; |
| 72 |
|
| 73 |
/** The NTP server instance */ |
| 74 |
private NtpServer ntpServer; |
| 75 |
|
| 76 |
/** The DNS server instance */ |
| 77 |
// private DnsServer dnsServer; |
| 78 |
|
| 79 |
/** The Change Password server instance * |
| 80 |
private ChangePasswordServer changePwdServer;/ |
| 81 |
|
| 82 |
/** The Kerberos server instance */ |
| 83 |
private KdcServer kdcServer; |
| 84 |
|
| 85 |
/** The started HttpServer */ |
| 86 |
private HttpServer httpServer; |
| 87 |
|
| 88 |
/** The Schema partition */ |
| 89 |
private LdifPartition schemaLdifPartition; |
| 90 |
|
| 91 |
/** The SchemaManager instance */ |
| 92 |
private SchemaManager schemaManager; |
| 93 |
|
| 94 |
/** The configuration partition */ |
| 95 |
private SingleFileLdifPartition configPartition; |
| 96 |
|
| 97 |
/** The configuration reader instance */ |
| 98 |
private ConfigPartitionReader cpReader; |
| 99 |
|
| 100 |
// variables used during the initial startup to update the mandatory operational |
| 101 |
// attributes |
| 102 |
/** The UUID syntax checker instance */ |
| 103 |
private UuidSyntaxChecker uuidChecker = new UuidSyntaxChecker(); |
| 104 |
|
| 105 |
/** The CSN syntax checker instance */ |
| 106 |
private CsnSyntaxChecker csnChecker = new CsnSyntaxChecker(); |
| 107 |
|
| 108 |
private GeneralizedTimeSyntaxChecker timeChecker = new GeneralizedTimeSyntaxChecker(); |
| 109 |
|
| 110 |
private static final Map<String, AttributeTypeOptions> MANDATORY_ENTRY_ATOP_MAP = new HashMap<String, AttributeTypeOptions>(); |
| 111 |
|
| 112 |
private boolean isConfigPartitionFirstExtraction = false; |
| 113 |
|
| 114 |
private boolean isSchemaPartitionFirstExtraction = false; |
| 115 |
|
| 116 |
|
| 117 |
/** |
| 118 |
* starts various services configured according to the |
| 119 |
* configuration present in the given instance's layout |
| 120 |
* |
| 121 |
* @param instanceLayout the on disk location's layout of the intance to be started |
| 122 |
* @throws Exception |
| 123 |
*/ |
| 124 |
public void start( InstanceLayout instanceLayout ) throws Exception |
| 125 |
{ |
| 126 |
File partitionsDir = instanceLayout.getPartitionsDirectory(); |
| 127 |
|
| 128 |
if ( !partitionsDir.exists() ) |
| 129 |
{ |
| 130 |
LOG.info( "partition directory doesn't exist, creating {}", partitionsDir.getAbsolutePath() ); |
| 131 |
if ( !partitionsDir.mkdirs() ) |
| 132 |
{ |
| 133 |
throw new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY, partitionsDir ) ); |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
LOG.info( "using partition dir {}", partitionsDir.getAbsolutePath() ); |
| 138 |
|
| 139 |
initSchemaManager( instanceLayout ); |
| 140 |
initSchemaLdifPartition( instanceLayout ); |
| 141 |
initConfigPartition( instanceLayout ); |
| 142 |
|
| 143 |
// Read the configuration |
| 144 |
cpReader = new ConfigPartitionReader( configPartition ); |
| 145 |
|
| 146 |
ConfigBean configBean = cpReader.readConfig(); |
| 147 |
|
| 148 |
DirectoryServiceBean directoryServiceBean = configBean.getDirectoryServiceBean(); |
| 149 |
|
| 150 |
// Initialize the DirectoryService now |
| 151 |
DirectoryService directoryService = initDirectoryService( instanceLayout, directoryServiceBean ); |
| 152 |
|
| 153 |
// start the LDAP server |
| 154 |
startLdap( directoryServiceBean.getLdapServerBean(), directoryService ); |
| 155 |
|
| 156 |
// start the NTP server |
| 157 |
startNtp( directoryServiceBean.getNtpServerBean(), directoryService ); |
| 158 |
|
| 159 |
// Initialize the DNS server (Not ready yet) |
| 160 |
// initDns( configBean ); |
| 161 |
|
| 162 |
// Initialize the DHCP server (Not ready yet) |
| 163 |
// initDhcp( configBean ); |
| 164 |
|
| 165 |
// start the ChangePwd server (Not ready yet) |
| 166 |
//startChangePwd( directoryServiceBean.getChangePasswordServerBean(), directoryService ); |
| 167 |
|
| 168 |
// start the Kerberos server |
| 169 |
startKerberos( directoryServiceBean.getKdcServerBean(), directoryService ); |
| 170 |
|
| 171 |
// start the jetty http server |
| 172 |
startHttpServer( directoryServiceBean.getHttpServerBean(), directoryService ); |
| 173 |
} |
| 174 |
|
| 175 |
|
| 176 |
/** |
| 177 |
* Initialize the schema Manager by loading the schema LDIF files |
| 178 |
* |
| 179 |
* @param instanceLayout the instance layout |
| 180 |
* @throws Exception in case of any problems while extracting and writing the schema files |
| 181 |
*/ |
| 182 |
private void initSchemaManager( InstanceLayout instanceLayout ) throws Exception |
| 183 |
{ |
| 184 |
File schemaPartitionDirectory = new File( instanceLayout.getPartitionsDirectory(), "schema" ); |
| 185 |
|
| 186 |
// Extract the schema on disk (a brand new one) and load the registries |
| 187 |
if ( schemaPartitionDirectory.exists() ) |
| 188 |
{ |
| 189 |
LOG.info( "schema partition already exists, skipping schema extraction" ); |
| 190 |
} |
| 191 |
else |
| 192 |
{ |
| 193 |
SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( instanceLayout.getPartitionsDirectory() ); |
| 194 |
extractor.extractOrCopy(); |
| 195 |
isSchemaPartitionFirstExtraction = true; |
| 196 |
} |
| 197 |
|
| 198 |
SchemaLoader loader = new LdifSchemaLoader( schemaPartitionDirectory ); |
| 199 |
schemaManager = new DefaultSchemaManager( loader ); |
| 200 |
|
| 201 |
// We have to load the schema now, otherwise we won't be able |
| 202 |
// to initialize the Partitions, as we won't be able to parse |
| 203 |
// and normalize their suffix Dn |
| 204 |
schemaManager.loadAllEnabled(); |
| 205 |
|
| 206 |
List<Throwable> errors = schemaManager.getErrors(); |
| 207 |
|
| 208 |
if ( errors.size() != 0 ) |
| 209 |
{ |
| 210 |
throw new Exception( I18n.err( I18n.ERR_317, Exceptions.printErrors( errors ) ) ); |
| 211 |
} |
| 212 |
} |
| 213 |
|
| 214 |
|
| 215 |
/** |
| 216 |
* Initialize the schema partition |
| 217 |
* |
| 218 |
* @param instanceLayout the instance layout |
| 219 |
* @throws Exception in case of any problems while initializing the SchemaPartition |
| 220 |
*/ |
| 221 |
private void initSchemaLdifPartition( InstanceLayout instanceLayout ) throws Exception |
| 222 |
{ |
| 223 |
File schemaPartitionDirectory = new File( instanceLayout.getPartitionsDirectory(), "schema" ); |
| 224 |
|
| 225 |
// Init the LdifPartition |
| 226 |
schemaLdifPartition = new LdifPartition( schemaManager ); |
| 227 |
schemaLdifPartition.setPartitionPath( schemaPartitionDirectory.toURI() ); |
| 228 |
} |
| 229 |
|
| 230 |
|
| 231 |
/** |
| 232 |
* |
| 233 |
* initializes a LDIF partition for configuration |
| 234 |
* |
| 235 |
* @param instanceLayout the instance layout |
| 236 |
* @throws Exception in case of any issues while extracting the schema |
| 237 |
*/ |
| 238 |
private void initConfigPartition( InstanceLayout instanceLayout ) throws Exception |
| 239 |
{ |
| 240 |
File confFile = new File( instanceLayout.getConfDirectory(), LdifConfigExtractor.LDIF_CONFIG_FILE ); |
| 241 |
|
| 242 |
if ( confFile.exists() ) |
| 243 |
{ |
| 244 |
LOG.info( "config partition already exists, skipping default config extraction" ); |
| 245 |
} |
| 246 |
else |
| 247 |
{ |
| 248 |
LdifConfigExtractor.extractSingleFileConfig( instanceLayout.getConfDirectory(), |
| 249 |
LdifConfigExtractor.LDIF_CONFIG_FILE, true ); |
| 250 |
isConfigPartitionFirstExtraction = true; |
| 251 |
} |
| 252 |
|
| 253 |
configPartition = new SingleFileLdifPartition( schemaManager ); |
| 254 |
configPartition.setId( "config" ); |
| 255 |
configPartition.setPartitionPath( confFile.toURI() ); |
| 256 |
configPartition.setSuffixDn( new Dn( schemaManager, "ou=config" ) ); |
| 257 |
configPartition.setSchemaManager( schemaManager ); |
| 258 |
|
| 259 |
configPartition.initialize(); |
| 260 |
} |
| 261 |
|
| 262 |
|
| 263 |
private DirectoryService initDirectoryService( InstanceLayout instanceLayout, |
| 264 |
DirectoryServiceBean directoryServiceBean ) throws Exception |
| 265 |
{ |
| 266 |
LOG.info( "Initializing the DirectoryService..." ); |
| 267 |
|
| 268 |
long startTime = System.currentTimeMillis(); |
| 269 |
|
| 270 |
DirectoryService directoryService = ServiceBuilder.createDirectoryService( directoryServiceBean, |
| 271 |
instanceLayout, schemaManager ); |
| 272 |
|
| 273 |
// The schema partition |
| 274 |
SchemaPartition schemaPartition = new SchemaPartition( schemaManager ); |
| 275 |
schemaPartition.setWrappedPartition( schemaLdifPartition ); |
| 276 |
directoryService.setSchemaPartition( schemaPartition ); |
| 277 |
|
| 278 |
directoryService.addPartition( configPartition ); |
| 279 |
|
| 280 |
// Store the default directories |
| 281 |
directoryService.setInstanceLayout( instanceLayout ); |
| 282 |
|
| 283 |
directoryService.startup(); |
| 284 |
|
| 285 |
AttributeType ocAt = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.OBJECT_CLASS_AT ); |
| 286 |
MANDATORY_ENTRY_ATOP_MAP.put( ocAt.getName(), new AttributeTypeOptions( ocAt ) ); |
| 287 |
|
| 288 |
AttributeType uuidAt = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.ENTRY_UUID_AT ); |
| 289 |
MANDATORY_ENTRY_ATOP_MAP.put( uuidAt.getName(), new AttributeTypeOptions( uuidAt ) ); |
| 290 |
|
| 291 |
AttributeType csnAt = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.ENTRY_CSN_AT ); |
| 292 |
MANDATORY_ENTRY_ATOP_MAP.put( csnAt.getName(), new AttributeTypeOptions( csnAt ) ); |
| 293 |
|
| 294 |
AttributeType creatorAt = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.CREATORS_NAME_AT ); |
| 295 |
MANDATORY_ENTRY_ATOP_MAP.put( creatorAt.getName(), new AttributeTypeOptions( creatorAt ) ); |
| 296 |
|
| 297 |
AttributeType createdTimeAt = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.CREATE_TIMESTAMP_AT ); |
| 298 |
MANDATORY_ENTRY_ATOP_MAP.put( createdTimeAt.getName(), new AttributeTypeOptions( createdTimeAt ) ); |
| 299 |
|
| 300 |
if ( isConfigPartitionFirstExtraction ) |
| 301 |
{ |
| 302 |
LOG.info( "begining to update config partition LDIF files after modifying manadatory attributes" ); |
| 303 |
|
| 304 |
// disable writes to the disk upon every modification to improve performance |
| 305 |
configPartition.setEnableRewriting( false ); |
| 306 |
|
| 307 |
// perform updates |
| 308 |
updateMandatoryOpAttributes( configPartition, directoryService ); |
| 309 |
|
| 310 |
// enable writes to disk, this will save the partition data first if found dirty |
| 311 |
configPartition.setEnableRewriting( true ); |
| 312 |
|
| 313 |
LOG.info( "config partition data was successfully updated" ); |
| 314 |
} |
| 315 |
|
| 316 |
if ( isSchemaPartitionFirstExtraction ) |
| 317 |
{ |
| 318 |
LOG.info( "begining to update schema partition LDIF files after modifying manadatory attributes" ); |
| 319 |
|
| 320 |
updateMandatoryOpAttributes( schemaLdifPartition, directoryService ); |
| 321 |
|
| 322 |
LOG.info( "schema partition data was successfully updated" ); |
| 323 |
} |
| 324 |
|
| 325 |
LOG.info( "DirectoryService initialized in {} milliseconds", ( System.currentTimeMillis() - startTime ) ); |
| 326 |
|
| 327 |
return directoryService; |
| 328 |
} |
| 329 |
|
| 330 |
|
| 331 |
/** |
| 332 |
* start the LDAP server |
| 333 |
*/ |
| 334 |
private void startLdap( LdapServerBean ldapServerBean, DirectoryService directoryService ) throws Exception |
| 335 |
{ |
| 336 |
LOG.info( "Starting the LDAP server" ); |
| 337 |
long startTime = System.currentTimeMillis(); |
| 338 |
|
| 339 |
ldapServer = ServiceBuilder.createLdapServer( ldapServerBean, directoryService ); |
| 340 |
|
| 341 |
if ( ldapServer == null ) |
| 342 |
{ |
| 343 |
LOG.info( "Cannot find any reference to the LDAP Server in the configuration : the server won't be started" ); |
| 344 |
return; |
| 345 |
} |
| 346 |
|
| 347 |
printBanner( BANNER_LDAP ); |
| 348 |
|
| 349 |
ldapServer.setDirectoryService( directoryService ); |
| 350 |
|
| 351 |
// And start the server now |
| 352 |
try |
| 353 |
{ |
| 354 |
ldapServer.start(); |
| 355 |
} |
| 356 |
catch ( Exception e ) |
| 357 |
{ |
| 358 |
LOG.error( "Cannot start the server : " + e.getMessage() ); |
| 359 |
} |
| 360 |
|
| 361 |
LOG.info( "LDAP server: started in {} milliseconds", ( System.currentTimeMillis() - startTime ) + "" ); |
| 362 |
} |
| 363 |
|
| 364 |
|
| 365 |
/** |
| 366 |
* start the NTP server |
| 367 |
*/ |
| 368 |
private void startNtp( NtpServerBean ntpServerBean, DirectoryService directoryService ) throws Exception |
| 369 |
{ |
| 370 |
LOG.info( "Starting the NTP server" ); |
| 371 |
long startTime = System.currentTimeMillis(); |
| 372 |
|
| 373 |
ntpServer = ServiceBuilder.createNtpServer( ntpServerBean, directoryService ); |
| 374 |
|
| 375 |
if ( ntpServer == null ) |
| 376 |
{ |
| 377 |
LOG.info( "Cannot find any reference to the NTP Server in the configuration : the server won't be started" ); |
| 378 |
return; |
| 379 |
} |
| 380 |
|
| 381 |
printBanner( BANNER_NTP ); |
| 382 |
|
| 383 |
ntpServer.start(); |
| 384 |
|
| 385 |
if ( LOG.isInfoEnabled() ) |
| 386 |
{ |
| 387 |
LOG.info( "NTP server: started in {} milliseconds", ( System.currentTimeMillis() - startTime ) + "" ); |
| 388 |
} |
| 389 |
} |
| 390 |
|
| 391 |
|
| 392 |
/** |
| 393 |
* Initialize the DNS server |
| 394 |
*/ |
| 395 |
// private void initDns( InstanceLayout layout ) throws Exception |
| 396 |
// { |
| 397 |
// if ( factory == null ) |
| 398 |
// { |
| 399 |
// return; |
| 400 |
// } |
| 401 |
// |
| 402 |
// try |
| 403 |
// { |
| 404 |
// dnsServer = ( DnsServer ) factory.getBean( "dnsServer" ); |
| 405 |
// } |
| 406 |
// catch ( Exception e ) |
| 407 |
// { |
| 408 |
// LOG.info( "Cannot find any reference to the DNS Server in the configuration : the server won't be started" ); |
| 409 |
// return; |
| 410 |
// } |
| 411 |
// |
| 412 |
// System.out.println( "Starting the DNS server" ); |
| 413 |
// LOG.info( "Starting the DNS server" ); |
| 414 |
// |
| 415 |
// printBanner( BANNER_DNS ); |
| 416 |
// long startTime = System.currentTimeMillis(); |
| 417 |
// |
| 418 |
// dnsServer.start(); |
| 419 |
// System.out.println( "DNS Server started" ); |
| 420 |
// |
| 421 |
// if ( LOG.isInfoEnabled() ) |
| 422 |
// { |
| 423 |
// LOG.info( "DNS server: started in {} milliseconds", ( System.currentTimeMillis() - startTime ) + "" ); |
| 424 |
// } |
| 425 |
// } |
| 426 |
|
| 427 |
/** |
| 428 |
* start the KERBEROS server |
| 429 |
*/ |
| 430 |
private void startKerberos( KdcServerBean kdcServerBean, DirectoryService directoryService ) throws Exception |
| 431 |
{ |
| 432 |
LOG.info( "Starting the Kerberos server" ); |
| 433 |
long startTime = System.currentTimeMillis(); |
| 434 |
|
| 435 |
kdcServer = ServiceBuilder.createKdcServer( kdcServerBean, directoryService ); |
| 436 |
|
| 437 |
if ( kdcServer == null ) |
| 438 |
{ |
| 439 |
LOG.info( "Cannot find any reference to the Kerberos Server in the configuration : the server won't be started" ); |
| 440 |
return; |
| 441 |
} |
| 442 |
|
| 443 |
getDirectoryService().startup(); |
| 444 |
kdcServer.setDirectoryService( getDirectoryService() ); |
| 445 |
|
| 446 |
printBanner( BANNER_KERBEROS ); |
| 447 |
|
| 448 |
kdcServer.start(); |
| 449 |
|
| 450 |
if ( LOG.isInfoEnabled() ) |
| 451 |
{ |
| 452 |
LOG.info( "Kerberos server: started in {} milliseconds", ( System.currentTimeMillis() - startTime ) + "" ); |
| 453 |
} |
| 454 |
} |
| 455 |
|
| 456 |
|
| 457 |
/** |
| 458 |
* start the Change Password server |
| 459 |
* |
| 460 |
private void startChangePwd( ChangePasswordServerBean changePwdServerBean, DirectoryService directoryService ) throws Exception |
| 461 |
{ |
| 462 |
changePwdServer = ServiceBuilder.createChangePasswordServer( changePwdServerBean, directoryService ); |
| 463 |
|
| 464 |
if ( changePwdServer == null ) |
| 465 |
{ |
| 466 |
LOG.info( "Cannot find any reference to the Change Password Server in the configuration : the server won't be started" ); |
| 467 |
return; |
| 468 |
} |
| 469 |
|
| 470 |
LOG.info( "Starting the Change Password server" ); |
| 471 |
long startTime = System.currentTimeMillis(); |
| 472 |
|
| 473 |
getDirectoryService().startup(); |
| 474 |
changePwdServer.setDirectoryService( getDirectoryService() ); |
| 475 |
|
| 476 |
LOG.info( "Starting the Change Password server" ); |
| 477 |
|
| 478 |
printBanner( BANNER_CHANGE_PWD ); |
| 479 |
|
| 480 |
changePwdServer.start(); |
| 481 |
|
| 482 |
if ( LOG.isInfoEnabled() ) |
| 483 |
{ |
| 484 |
LOG.info( "Change Password server: started in {} milliseconds", ( System.currentTimeMillis() - startTime ) |
| 485 |
+ "" ); |
| 486 |
} |
| 487 |
} |
| 488 |
*/ |
| 489 |
|
| 490 |
/** |
| 491 |
* start the embedded HTTP server |
| 492 |
*/ |
| 493 |
private void startHttpServer( HttpServerBean httpServerBean, DirectoryService directoryService ) throws Exception |
| 494 |
{ |
| 495 |
httpServer = ServiceBuilder.createHttpServer( httpServerBean, directoryService ); |
| 496 |
|
| 497 |
if ( httpServer == null ) |
| 498 |
{ |
| 499 |
LOG.info( "Cannot find any reference to the HTTP Server in the configuration : the server won't be started" ); |
| 500 |
return; |
| 501 |
} |
| 502 |
|
| 503 |
LOG.info( "Starting the Http server" ); |
| 504 |
long startTime = System.currentTimeMillis(); |
| 505 |
|
| 506 |
httpServer.start( getDirectoryService() ); |
| 507 |
|
| 508 |
if ( LOG.isInfoEnabled() ) |
| 509 |
{ |
| 510 |
LOG.info( "Http server: started in {} milliseconds", ( System.currentTimeMillis() - startTime ) |
| 511 |
+ "" ); |
| 512 |
} |
| 513 |
} |
| 514 |
|
| 515 |
|
| 516 |
public DirectoryService getDirectoryService() |
| 517 |
{ |
| 518 |
return ldapServer.getDirectoryService(); |
| 519 |
} |
| 520 |
|
| 521 |
|
| 522 |
public void synch() throws Exception |
| 523 |
{ |
| 524 |
ldapServer.getDirectoryService().sync(); |
| 525 |
} |
| 526 |
|
| 527 |
|
| 528 |
public void stop() throws Exception |
| 529 |
{ |
| 530 |
// Stops the server |
| 531 |
if ( ldapServer != null ) |
| 532 |
{ |
| 533 |
ldapServer.stop(); |
| 534 |
} |
| 535 |
|
| 536 |
if ( kdcServer != null ) |
| 537 |
{ |
| 538 |
kdcServer.stop(); |
| 539 |
} |
| 540 |
|
| 541 |
/*if ( changePwdServer != null ) |
| 542 |
{ |
| 543 |
changePwdServer.stop(); |
| 544 |
}*/ |
| 545 |
|
| 546 |
if ( ntpServer != null ) |
| 547 |
{ |
| 548 |
ntpServer.stop(); |
| 549 |
} |
| 550 |
|
| 551 |
if ( httpServer != null ) |
| 552 |
{ |
| 553 |
httpServer.stop(); |
| 554 |
} |
| 555 |
|
| 556 |
// We now have to stop the underlaying DirectoryService |
| 557 |
if ( ldapServer != null ) |
| 558 |
{ |
| 559 |
ldapServer.getDirectoryService().shutdown(); |
| 560 |
} |
| 561 |
} |
| 562 |
|
| 563 |
private static final String BANNER_LDAP = " _ _ ____ ____ \n" |
| 564 |
+ " / \\ _ __ ___ ___| |__ ___| _ \\/ ___| \n" |
| 565 |
+ " / _ \\ | '_ \\ / _` |/ __| '_ \\ / _ \\ | | \\___ \\ \n" |
| 566 |
+ " / ___ \\| |_) | (_| | (__| | | | __/ |_| |___) | \n" |
| 567 |
+ " /_/ \\_\\ .__/ \\__,_|\\___|_| |_|\\___|____/|____/ \n" |
| 568 |
+ " |_| \n"; |
| 569 |
|
| 570 |
private static final String BANNER_NTP = " _ _ _ _ _____ _ __ \n" |
| 571 |
+ " / \\ _ __ ___ ___| |__ ___| \\ | |_ __| '_ \\ \n" |
| 572 |
+ " / _ \\ | '_ \\ / _` |/ __| '_ \\ / _ \\ .\\| | | | | |_) | \n" |
| 573 |
+ " / ___ \\| |_) | (_| | (__| | | | __/ |\\ | | | | .__/ \n" |
| 574 |
+ " /_/ \\_\\ .__/ \\__,_|\\___|_| |_|\\___|_| \\_| |_| |_| \n" |
| 575 |
+ " |_| \n"; |
| 576 |
|
| 577 |
private static final String BANNER_KERBEROS = " _ _ _ __ ____ ___ \n" |
| 578 |
+ " / \\ _ __ ___ ___| |__ ___| |/ /| _ \\ / __| \n" |
| 579 |
+ " / _ \\ | '_ \\ / _` |/ __| '_ \\ / _ \\ ' / | | | / / \n" |
| 580 |
+ " / ___ \\| |_) | (_| | (__| | | | __/ . \\ | |_| \\ \\__ \n" |
| 581 |
+ " /_/ \\_\\ .__/ \\__,_|\\___|_| |_|\\___|_|\\_\\|____/ \\___| \n" |
| 582 |
+ " |_| \n"; |
| 583 |
|
| 584 |
// private static final String BANNER_DNS = |
| 585 |
// " _ _ ____ _ _ ____ \n" |
| 586 |
// + " / \\ _ __ ___ ___| |__ ___| _ \\| \\ | / ___| \n" |
| 587 |
// + " / _ \\ | '_ \\ / _` |/ __| '_ \\ / _ \\ | | | \\| \\__ \\ \n" |
| 588 |
// + " / ___ \\| |_) | (_| | (__| | | | __/ |_| | . ' |___) | \n" |
| 589 |
// + " /_/ \\_\\ .__/ \\__,_|\\___|_| |_|\\___|____/|_|\\__|____/ \n" |
| 590 |
// + " |_| \n"; |
| 591 |
// |
| 592 |
// |
| 593 |
// private static final String BANNER_DHCP = |
| 594 |
// " _ _ ____ _ _ ___ ____ \n" |
| 595 |
// + " / \\ _ __ ___ ___| |__ ___| _ \\| | | |/ __| _ \\ \n" |
| 596 |
// + " / _ \\ | '_ \\ / _` |/ __| '_ \\ / _ \\ | | | |_| / / | |_) )\n" |
| 597 |
// + " / ___ \\| |_) | (_| | (__| | | | __/ |_| | _ \\ \\__| __/ \n" |
| 598 |
// + " /_/ \\_\\ .__/ \\__,_|\\___|_| |_|\\___|____/|_| |_|\\___|_| \n" |
| 599 |
// + " |_| \n"; |
| 600 |
|
| 601 |
private static final String BANNER_CHANGE_PWD = " ___ ___ __ __ __ ______ \n" |
| 602 |
+ " / __|_ ___ _ __ ____ ___| _ \\ \\ \\ / / / | _ \\ \n" |
| 603 |
+ " / / | |__ / _` | ' \\ / ___\\/ _ \\ |_) \\ \\ / /\\/ /| | | | \n" |
| 604 |
+ " \\ \\__| '_ \\ (_| | |\\ | |___ | __/ __/ \\ ' / / | |_| | \n" |
| 605 |
+ " \\___|_| |_|\\__,_|_| |_|\\__. |\\___| | \\_/ \\_/ |____/ \n" |
| 606 |
+ " |_| |_| \n"; |
| 607 |
|
| 608 |
|
| 609 |
/** |
| 610 |
* Print the banner for a server |
| 611 |
*/ |
| 612 |
public static void printBanner( String bannerConstant ) |
| 613 |
{ |
| 614 |
System.out.println( bannerConstant ); |
| 615 |
} |
| 616 |
|
| 617 |
|
| 618 |
/** |
| 619 |
* |
| 620 |
* adds mandatory operational attributes {@link #MANDATORY_ENTRY_ATOP_MAP} and updates all the LDIF files. |
| 621 |
* WARN: this method is only called for the first time when schema and config files are bootstrapped |
| 622 |
* afterwards it is the responsibility of the user to ensure correctness of LDIF files if modified |
| 623 |
* by hand |
| 624 |
* |
| 625 |
* Note: we do these modifications explicitly cause we have no idea if each entry's LDIF file has the |
| 626 |
* correct values for all these mandatory attributes |
| 627 |
* |
| 628 |
* @param partition instance of the partition Note: should only be those which are loaded before starting the DirectoryService |
| 629 |
* @param dirService the DirectoryService instance |
| 630 |
* @throws Exception |
| 631 |
*/ |
| 632 |
public void updateMandatoryOpAttributes( Partition partition, DirectoryService dirService ) throws Exception |
| 633 |
{ |
| 634 |
CoreSession session = dirService.getAdminSession(); |
| 635 |
|
| 636 |
String adminDn = session.getEffectivePrincipal().getName(); |
| 637 |
|
| 638 |
ExprNode filter = new PresenceNode( SchemaConstants.OBJECT_CLASS_AT ); |
| 639 |
|
| 640 |
EntryFilteringCursor cursor = session.search( partition.getSuffixDn(), SearchScope.SUBTREE, filter, |
| 641 |
AliasDerefMode.NEVER_DEREF_ALIASES, new HashSet<AttributeTypeOptions>( MANDATORY_ENTRY_ATOP_MAP.values() ) ); |
| 642 |
cursor.beforeFirst(); |
| 643 |
|
| 644 |
List<Modification> mods = new ArrayList<Modification>(); |
| 645 |
|
| 646 |
while ( cursor.next() ) |
| 647 |
{ |
| 648 |
Entry entry = cursor.get(); |
| 649 |
|
| 650 |
AttributeType atType = MANDATORY_ENTRY_ATOP_MAP.get( SchemaConstants.ENTRY_UUID_AT ).getAttributeType(); |
| 651 |
|
| 652 |
Attribute uuidAt = entry.get( atType ); |
| 653 |
String uuid = ( uuidAt == null ? null : uuidAt.getString() ); |
| 654 |
|
| 655 |
if ( !uuidChecker.isValidSyntax( uuid ) ) |
| 656 |
{ |
| 657 |
uuidAt = new DefaultAttribute( atType, UUID.randomUUID().toString() ); |
| 658 |
} |
| 659 |
|
| 660 |
Modification uuidMod = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, uuidAt ); |
| 661 |
mods.add( uuidMod ); |
| 662 |
|
| 663 |
atType = MANDATORY_ENTRY_ATOP_MAP.get( SchemaConstants.ENTRY_CSN_AT ).getAttributeType(); |
| 664 |
Attribute csnAt = entry.get( atType ); |
| 665 |
String csn = ( csnAt == null ? null : csnAt.getString() ); |
| 666 |
|
| 667 |
if ( !csnChecker.isValidSyntax( csn ) ) |
| 668 |
{ |
| 669 |
csnAt = new DefaultAttribute( atType, dirService.getCSN().toString() ); |
| 670 |
} |
| 671 |
|
| 672 |
Modification csnMod = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, csnAt ); |
| 673 |
mods.add( csnMod ); |
| 674 |
|
| 675 |
atType = MANDATORY_ENTRY_ATOP_MAP.get( SchemaConstants.CREATORS_NAME_AT ).getAttributeType(); |
| 676 |
Attribute creatorAt = entry.get( atType ); |
| 677 |
String creator = ( creatorAt == null ? "" : creatorAt.getString().trim() ); |
| 678 |
|
| 679 |
if ( ( creator.length() == 0 ) || ( !Dn.isValid( creator ) ) ) |
| 680 |
{ |
| 681 |
creatorAt = new DefaultAttribute( atType, adminDn ); |
| 682 |
} |
| 683 |
|
| 684 |
Modification creatorMod = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, creatorAt ); |
| 685 |
mods.add( creatorMod ); |
| 686 |
|
| 687 |
atType = MANDATORY_ENTRY_ATOP_MAP.get( SchemaConstants.CREATE_TIMESTAMP_AT ).getAttributeType(); |
| 688 |
Attribute createdTimeAt = entry.get( atType ); |
| 689 |
String createdTime = ( createdTimeAt == null ? null : createdTimeAt.getString() ); |
| 690 |
|
| 691 |
if ( !timeChecker.isValidSyntax( createdTime ) ) |
| 692 |
{ |
| 693 |
createdTimeAt = new DefaultAttribute( atType, DateUtils.getGeneralizedTime() ); |
| 694 |
} |
| 695 |
|
| 696 |
Modification createdMod = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, createdTimeAt ); |
| 697 |
mods.add( createdMod ); |
| 698 |
|
| 699 |
if ( !mods.isEmpty() ) |
| 700 |
{ |
| 701 |
LOG.debug( "modifying the entry {} after adding missing manadatory operational attributes", |
| 702 |
entry.getDn() ); |
| 703 |
ModifyOperationContext modifyContext = new ModifyOperationContext( session ); |
| 704 |
modifyContext.setEntry( entry ); |
| 705 |
modifyContext.setDn( entry.getDn() ); |
| 706 |
modifyContext.setModItems( mods ); |
| 707 |
partition.modify( modifyContext ); |
| 708 |
} |
| 709 |
|
| 710 |
mods.clear(); |
| 711 |
} |
| 712 |
|
| 713 |
cursor.close(); |
| 714 |
} |
| 715 |
|
| 716 |
} |