1 23 24 package com.sun.enterprise.admin.servermgmt.pe; 25 26 import java.io.File ; 27 import java.io.IOException ; 28 29 import com.sun.enterprise.util.OS; 30 import com.sun.enterprise.util.io.FileUtils; 31 import com.sun.enterprise.util.i18n.StringManager; 32 33 import com.sun.enterprise.admin.servermgmt.DomainException; 34 import com.sun.enterprise.admin.servermgmt.DomainConfig; 35 import com.sun.enterprise.admin.servermgmt.RepositoryConfig; 36 import com.sun.enterprise.admin.servermgmt.RepositoryException; 37 import com.sun.enterprise.admin.servermgmt.DomainsManager; 38 import com.sun.enterprise.admin.servermgmt.InstancesManager; 39 import com.sun.enterprise.admin.servermgmt.DomainConfigValidator; 40 import com.sun.enterprise.admin.servermgmt.StringValidator; 41 import com.sun.enterprise.admin.servermgmt.FileValidator; 42 import com.sun.enterprise.admin.servermgmt.RepositoryNameValidator; 43 import com.sun.enterprise.admin.servermgmt.DomainXmlEventListener; 44 import com.sun.enterprise.admin.servermgmt.RepositoryManager; 45 import com.sun.enterprise.admin.servermgmt.util.DomainXmlSAXParser; 46 47 import com.sun.enterprise.admin.common.Status; 48 49 import com.sun.enterprise.admin.util.TokenValueSet; 50 51 import java.util.HashMap ; 52 import java.util.BitSet ; 53 54 public class PEDomainsManager extends RepositoryManager 55 implements DomainsManager 56 { 57 60 private static final StringManager strMgr = 61 StringManager.getManager(PEDomainsManager.class); 62 63 public PEDomainsManager() 64 { 65 super(); 66 } 67 68 public BitSet getDomainFlags() 71 { 72 BitSet bs = new BitSet (); 73 bs.set(DomainConfig.K_FLAG_START_DOMAIN_NEEDS_ADMIN_USER, false); 74 return bs; 75 } 76 77 public void validateDomain(DomainConfig domainConfig, boolean domainExists) 78 throws DomainException 79 { 80 try { 81 checkRepository(domainConfig, domainExists, domainExists); 82 } catch (RepositoryException ex) { 83 throw new DomainException(ex); 84 } 85 } 86 87 public void validateAdminUserAndPassword(DomainConfig domainConfig) 88 throws DomainException 89 { 90 try { 91 validateAdminUserAndPassword(domainConfig, getDomainUser(domainConfig), 92 getDomainPasswordClear(domainConfig)); 93 } catch (RepositoryException ex) { 94 throw new DomainException(ex); 95 } 96 } 97 98 public void validateMasterPassword(DomainConfig domainConfig) 99 throws DomainException 100 { 101 try { 102 validateMasterPassword(domainConfig, getMasterPasswordClear(domainConfig)); 103 } catch (RepositoryException ex) { 104 throw new DomainException(ex); 105 } 106 } 107 108 public void createDomain(DomainConfig domainConfig) 109 throws DomainException 110 { 111 PEFileLayout layout = getFileLayout(domainConfig); 112 113 try { 114 new RepositoryNameValidator(strMgr.getString("domainsRoot")). 115 checkValidXmlToken( 116 layout.getRepositoryRootDir().getAbsolutePath()); 117 layout.createRepositoryRoot(); 118 new PEDomainConfigValidator().validate(domainConfig); 119 checkRepository(domainConfig, false); 120 } catch (Exception ex) { 121 throw new DomainException(ex); 122 } 123 124 try { 125 String masterPassword = getMasterPasswordClear(domainConfig); 126 layout.createRepositoryDirectories(); 127 createDomainXml(domainConfig); 128 createDomainXmlEvents(domainConfig); 129 createScripts(domainConfig); 130 createServerPolicyFile(domainConfig); 131 createAdminKeyFile(domainConfig, getDomainUser(domainConfig), 132 getDomainPasswordClear(domainConfig)); 133 createKeyFile(domainConfig, getDomainUser(domainConfig), 134 getDomainPasswordClear(domainConfig)); 135 createAppClientContainerXml(domainConfig); 136 createIndexFile(domainConfig); 137 createDefaultWebXml(domainConfig); 138 createLoginConf(domainConfig); 139 createWssServerConfig(domainConfig); 140 createWssServerConfigOld(domainConfig); 141 createSSLCertificateDatabase(domainConfig, masterPassword); 142 changeMasterPasswordInMasterPasswordFile(domainConfig, masterPassword, 143 saveMasterPassword(domainConfig)); 144 createPasswordAliasKeystore(domainConfig, masterPassword); 145 createTimerWal(domainConfig); 146 createTimerDbn(domainConfig); 147 createMQInstance(domainConfig); 148 if (layout.getDerbyEjbTimerSqlFile().exists()) handleDerby(domainConfig); 150 setPermissions(domainConfig); 151 } catch (DomainException de) { 152 FileUtils.liquidate(getDomainDir(domainConfig)); 154 throw de; 155 } catch (Exception ex) { 156 FileUtils.liquidate(getDomainDir(domainConfig)); 158 throw new DomainException(ex); 159 } 160 } 161 162 166 protected void setPermissions(DomainConfig domainConfig) throws DomainException 167 { 168 final PEFileLayout layout = getFileLayout(domainConfig); 169 try { 170 chmod("-R u+x ", layout.getBinDir()); 172 chmod("-R g-rwx,o-rwx ", layout.getConfigRoot()); 173 } catch (Exception e) { 175 throw new DomainException( 176 strMgr.getString("setPermissionError"), e); 177 } 178 } 179 180 public void deleteDomain(DomainConfig domainConfig) 181 throws DomainException 182 { 183 try { 184 deleteRepository(domainConfig); 185 } catch (Exception e) { 186 throw new DomainException(e); 187 } 188 } 189 190 public void startDomain(DomainConfig domainConfig) 191 throws DomainException 192 { 193 try { 194 checkRepository(domainConfig); 195 String [] options = getInteractiveOptions( 196 (String )domainConfig.get(DomainConfig.K_USER), 197 (String )domainConfig.get(DomainConfig.K_PASSWORD), 198 (String )domainConfig.get(DomainConfig.K_MASTER_PASSWORD), 199 (HashMap )domainConfig.get(DomainConfig.K_EXTRA_PASSWORDS)); 200 getInstancesManager(domainConfig).startInstance(options); 201 } catch (Exception e) { 202 throw new DomainException(e); 203 } 204 } 205 206 public void stopDomain(DomainConfig domainConfig) 207 throws DomainException 208 { 209 try { 210 checkRepository(domainConfig); 211 getInstancesManager(domainConfig).stopInstance(); 212 } catch (Exception e) { 213 throw new DomainException(e); 214 } 215 } 216 217 public String [] listDomainsAndStatus(DomainConfig domainConfig) 218 throws DomainException 219 { 220 try { 221 return listDomainsAndStatusAsString(domainConfig); 222 } catch (Exception e) { 223 throw new DomainException(e); 224 } 225 } 226 227 230 public String [] listDomains(DomainConfig domainConfig) 231 throws DomainException 232 { 233 try { 234 return listRepository(domainConfig); 235 } catch (Exception e) { 236 throw new DomainException(e); 237 } 238 } 239 240 241 protected void createDomainXmlEvents(DomainConfig domainConfig) 242 throws DomainException { 243 try { 244 final PEFileLayout layout = getFileLayout(domainConfig); 245 final File domainXml = layout.getDomainConfigFile(); 246 DomainXmlSAXParser parser = new DomainXmlSAXParser(); 247 try { 248 parser.parse(domainXml,layout.getDtdFile()); 249 } 250 catch(Exception e) { 251 throw new DomainException( 252 strMgr.getString("domainXmlNotParsed"), e); 253 } 254 String className = parser.getDomainXmlEventListenerClass(); 255 if(className!=null) { 256 DomainXmlEventListener listener = (DomainXmlEventListener) Class.forName(className).newInstance(); 257 listener.handleCreateEvent(domainConfig); 258 } 259 } 260 catch(Exception e) { 261 throw new DomainException( 262 strMgr.getString("domainXmlEventsNotCreated"), e); 263 } 264 } 265 266 269 protected TokenValueSet getDomainXmlTokens(DomainConfig domainConfig) { 270 return PEDomainXmlTokens.getTokenValueSet(domainConfig); 271 } 272 273 protected void createDomainXml(DomainConfig domainConfig) 274 throws DomainException 275 { 276 try 277 { 278 final PEFileLayout layout = getFileLayout(domainConfig); 279 final File domainXml = layout.getDomainConfigFile(); 280 final File domainXmlTemplate; 281 String templateName = (String )domainConfig.get(DomainConfig.K_TEMPLATE_NAME); 282 if((templateName == null)||(templateName.equals(""))) 283 domainXmlTemplate = layout.getDomainXmlTemplate(); 284 else 285 domainXmlTemplate = layout.getDomainXmlTemplate(templateName); 286 287 TokenValueSet tokens = getDomainXmlTokens(domainConfig); 288 generateFromTemplate(tokens, domainXmlTemplate, domainXml); 289 } 290 catch(Exception e) 291 { 292 throw new DomainException( 293 strMgr.getString("domainXmlNotCreated"), e); 294 } 295 } 296 297 protected void createScripts(DomainConfig domainConfig) 298 throws DomainException 299 { 300 final TokenValueSet tokens = PEScriptsTokens.getTokenValueSet(domainConfig); 301 createStartServ(domainConfig, tokens); 302 createStopServ(domainConfig, tokens); 303 } 304 305 void createStartServ(DomainConfig domainConfig, 306 TokenValueSet tokens) throws DomainException 307 { 308 try 309 { 310 final PEFileLayout layout = getFileLayout(domainConfig); 311 final File startServTemplate = layout.getStartServTemplate(); 312 final File startServ = layout.getStartServ(); 313 generateFromTemplate(tokens, startServTemplate, startServ); 314 } 315 catch (Exception e) 316 { 317 throw new DomainException( 318 strMgr.getString("startServNotCreated"), e); 319 } 320 } 321 322 void createStopServ(DomainConfig domainConfig, 323 TokenValueSet tokens) throws DomainException 324 { 325 try 326 { 327 final PEFileLayout layout = getFileLayout(domainConfig); 328 final File stopServTemplate = layout.getStopServTemplate(); 329 final File stopServ = layout.getStopServ(); 330 generateFromTemplate(tokens, stopServTemplate, stopServ); 331 } 332 catch (Exception e) 333 { 334 throw new DomainException( 335 strMgr.getString("stopServNotCreated"), e); 336 } 337 } 338 339 protected void createAppClientContainerXml( 340 DomainConfig domainConfig) throws DomainException 341 { 342 try 343 { 344 final PEFileLayout layout = getFileLayout(domainConfig); 345 final File accXmlTemplate = 346 layout.getAppClientContainerXmlTemplate(); 347 final File accXml = layout.getAppClientContainerXml(); 348 TokenValueSet tokens = PEAccXmlTokens.getTokenValueSet(domainConfig); 349 generateFromTemplate(tokens, accXmlTemplate, accXml); 350 } 351 catch(Exception e) 352 { 353 throw new DomainException(strMgr.getString("accXmlNotCreated"), e); 354 } 355 } 356 357 protected void createIndexFile( 358 DomainConfig domainConfig) throws DomainException 359 { 360 final PEFileLayout layout = getFileLayout(domainConfig); 361 final File src = layout.getIndexFileTemplate(); 362 final File dest = layout.getIndexFile(); 363 try 364 { 365 FileUtils.copy(src, dest); 366 } 367 catch (IOException ioe) 368 { 369 throw new DomainException( 370 strMgr.getString("indexFileNotCreated"), ioe); 371 } 372 } 373 374 protected void createDefaultWebXml( 375 DomainConfig domainConfig) throws DomainException 376 { 377 final PEFileLayout layout = getFileLayout(domainConfig); 378 final File src = layout.getDefaultWebXmlTemplate(); 379 final File dest = layout.getDefaultWebXml(); 380 try 381 { 382 FileUtils.copy(src, dest); 383 } 384 catch (IOException ioe) 385 { 386 throw new DomainException( 387 strMgr.getString("defaultWebXmlNotCreated"), ioe); 388 } 389 } 390 391 protected void createLoginConf( 392 RepositoryConfig config) throws DomainException 393 { 394 final PEFileLayout layout = getFileLayout(config); 395 final File src = layout.getLoginConfTemplate(); 396 final File dest = layout.getLoginConf(); 397 try 398 { 399 FileUtils.copy(src, dest); 400 } 401 catch (IOException ioe) 402 { 403 throw new DomainException( 404 strMgr.getString("loginConfNotCreated"), ioe); 405 } 406 } 407 408 protected void createWssServerConfigOld(RepositoryConfig config) 409 throws DomainException 410 { 411 final PEFileLayout layout = getFileLayout(config); 412 final File src = layout.getWssServerConfigOldTemplate(); 413 final File dest = layout.getWssServerConfigOld(); 414 try 415 { 416 FileUtils.copy(src, dest); 417 } 418 catch (IOException ioe) 419 { 420 throw new DomainException( 421 strMgr.getString("wssserverconfignotcreated"), ioe); 422 } 423 424 } 425 426 protected void createWssServerConfig(RepositoryConfig config) 427 throws DomainException 428 { 429 final PEFileLayout layout = getFileLayout(config); 430 final File src = layout.getWssServerConfigTemplate(); 431 final File dest = layout.getWssServerConfig(); 432 try 433 { 434 FileUtils.copy(src, dest); 435 } 436 catch (IOException ioe) 437 { 438 throw new DomainException( 439 strMgr.getString("wssserverconfignotcreated"), ioe); 440 } 441 442 } 443 444 protected File getDomainDir(DomainConfig domainConfig) 445 { 446 return getRepositoryDir(domainConfig); 447 } 448 449 protected File getDomainRoot(DomainConfig domainConfig) 450 { 451 return getRepositoryRootDir(domainConfig); 452 } 453 454 String getDefaultInstance() 455 { 456 return PEFileLayout.DEFAULT_INSTANCE_NAME; 457 } 458 459 464 465 protected static String getDomainUser(DomainConfig domainConfig) 466 { 467 return ( (String ) domainConfig.get(DomainConfig.K_USER) ); 468 } 469 470 475 476 protected static String getDomainPasswordClear(DomainConfig domainConfig) 477 { 478 return ( (String ) domainConfig.get(DomainConfig.K_PASSWORD) ); 479 } 480 481 protected static String getMasterPasswordClear(DomainConfig domainConfig) 482 { 483 return ((String )domainConfig.get(DomainConfig.K_MASTER_PASSWORD)); 484 } 485 486 protected static String getNewMasterPasswordClear(DomainConfig domainConfig) 487 { 488 return ((String )domainConfig.get(DomainConfig.K_NEW_MASTER_PASSWORD)); 489 } 490 491 protected static boolean saveMasterPassword(DomainConfig domainConfig) { 492 Boolean b = (Boolean )domainConfig.get(DomainConfig.K_SAVE_MASTER_PASSWORD); 493 return b.booleanValue(); 494 } 495 496 499 public void changeMasterPassword(DomainConfig config) throws DomainException 500 { 501 try { 502 final int status = getInstancesManager(config).getInstanceStatus(); 504 if (status != Status.kInstanceNotRunningCode) { 505 throw new DomainException( 506 strMgr.getString("cannotChangePassword_invalidState", 507 config.getDisplayName(), Status.getStatusString(status))); 508 } 509 510 String oldPass = getMasterPasswordClear(config); 511 String newPass = getNewMasterPasswordClear(config); 512 513 changePasswordAliasKeystorePassword(config, oldPass, newPass); 515 516 changeSSLCertificateDatabasePassword(config, oldPass, newPass); 518 519 changeMasterPasswordInMasterPasswordFile(config, newPass, saveMasterPassword(config)); 522 } catch (Exception ex) { 523 throw new DomainException( 524 strMgr.getString("masterPasswordNotChanged"), ex); 525 } 526 } 527 528 public String [] getExtraPasswordOptions(DomainConfig config) 529 throws DomainException 530 { 531 return null; 532 } 533 } 534 | Popular Tags |