<!DOCTYPE project [
    <!ENTITY importExternalLogs SYSTEM "file:./scripts/importExternalLogs.xml">
]>
<project name="generateKeysForSingleProfile" default="generateKeysForSingleProfile" basedir="."> 
     
    <taskdef name="wscmtlog" 
        classname="com.ibm.ws.install.configmanager.actionengine.ant.utils.AntTaskToLogToConfigManagersLogFiles"/> 
 	
 		<taskdef name="wsadmin" classname="com.ibm.websphere.ant.tasks.WsAdminInProcess"/>
  	&importExternalLogs; 
    <target name="setGenerateKeysForSingleProfileOptions" 
            description="Set up the command string to send to the key generation task."> 
            
        <wscmtlog>Setting up the command options</wscmtlog> 
        <property name="baseOptions" value="-cellName ${cellName} -nodeName ${nodeName}"/>
        
        <condition property="defaultCertDN" value="${baseOptions} -defaultCertDN {${personalCertDN}}">
                <and>
	                <isset property="personalCertDN"/>
		</and>
        </condition>
        <condition property="defaultCertDN" value="${baseOptions}">
                <and>
                <not>
	                <isset property="personalCertDN"/>
                </not>
		</and>
        </condition>
        
        <condition property="defaultCertValidityPeriod" value="${defaultCertDN} -defaultCertValidityPeriod {${personalCertValidityPeriod}}">
                <and>
	                <isset property="personalCertValidityPeriod"/>
		</and>
        </condition>
        <condition property="defaultCertValidityPeriod" value="${defaultCertDN}">
                <and>
                <not>
	                <isset property="personalCertValidityPeriod"/>
                </not>
		</and>
        </condition>
        
        <condition property="rootCertValidityPeriod" value="${defaultCertValidityPeriod} -rootCertValidityPeriod {${signingCertValidityPeriod}}">
                <and>
	                <isset property="signingCertValidityPeriod"/>
		</and>
        </condition>
        <condition property="rootCertValidityPeriod" value="${defaultCertValidityPeriod}">
                <and>
                <not>
	                <isset property="signingCertValidityPeriod"/>
                </not>
		</and>
        </condition>
        
        <condition property="rootCertDN" value="${rootCertValidityPeriod} -rootCertDN {${signingCertDN}}">
                <and>
	                <isset property="signingCertDN"/>
		</and>
        </condition>
        <condition property="rootCertDN" value="${rootCertValidityPeriod}">
                <and>
                <not>
	                <isset property="signingCertDN"/>
		</not>
                </and>
        </condition>
        
        <condition property="importDefaultCertKS" value="${rootCertDN} -importDefaultCertKS {${importPersonalCertKS}}">
                <and>
	                <isset property="importPersonalCertKS"/>
		</and>
        </condition>
        <condition property="importDefaultCertKS" value="${rootCertDN}">
                <and>
                <not>
	                <isset property="importPersonalCertKS"/>
                </not>
		</and>
        </condition>
        
        <condition property="importDefaultCertKSType" value="${importDefaultCertKS} -importDefaultCertKSType {${importPersonalCertKSType}}">
                <and>
	                <isset property="importPersonalCertKSType"/>
		</and>
        </condition>
        <condition property="importDefaultCertKSType" value="${importDefaultCertKS}">
                <and>
                <not>
	                <isset property="importPersonalCertKSType"/>
                </not>
		</and>
        </condition>
        
        <condition property="importDefaultCertKSPassword" value="${importDefaultCertKSType} -importDefaultCertKSPassword {${importPersonalCertKSPassword}}">
                <and>
	                <isset property="importPersonalCertKSPassword"/>
		</and>
        </condition>
        <condition property="importDefaultCertKSPassword" value="${importDefaultCertKSType}">
                <and>
                <not>
	                <isset property="importPersonalCertKSPassword"/>
		</not>
                </and>
        </condition>
        
        <condition property="importDefaultCertAlias" value="${importDefaultCertKSPassword} -importDefaultCertAlias {${importPersonalCertKSAlias}}">
                <and>
	                <isset property="importPersonalCertKSAlias"/>
		</and>
        </condition>
        <condition property="importDefaultCertAlias" value="${importDefaultCertKSPassword}">
                <and>
                <not>
	                <isset property="importPersonalCertKSAlias"/>
                </not>
		</and>
        </condition>
        
        <condition property="importRootCertKS" value="${importDefaultCertAlias} -importRootCertKS {${importSigningCertKS}}">
                <and>
	                <isset property="importSigningCertKS"/>
		</and>
        </condition>
        <condition property="importRootCertKS" value="${importDefaultCertAlias}">
                <and>
                <not>
	                <isset property="importSigningCertKS"/>
                </not>
		</and>
        </condition>
        
        <condition property="importRootCertKSPassword" value="${importRootCertKS} -importRootCertKSPassword {${importSigningCertKSPassword}}">
                <and>
	                <isset property="importSigningCertKSPassword"/>
		</and>
        </condition>
        <condition property="importRootCertKSPassword" value="${importRootCertKS}">
                <and>
		<not>
	                <isset property="importSigningCertKSPassword"/>
		</not>
		</and>
        </condition>

        <condition property="importRootCertKSType" value="${importRootCertKSPassword} -importRootCertKSType {${importSigningCertKSType}}">
                <and>
	                <isset property="importSigningCertKSType"/>
		</and>
        </condition>
        <condition property="importRootCertKSType" value="${importRootCertKSPassword}">
                <and>
		<not>
	                <isset property="importSigningCertKSType"/>
		</not>
		</and>
        </condition>
        
        <condition property="importRootCertAlias" value="${importRootCertKSType} -importRootCertAlias {${importSigningCertKSAlias}}">
                <and>
	                <isset property="importSigningCertKSAlias"/>
		</and>
        </condition>
        <condition property="importRootCertAlias" value="${importRootCertKSType}">
                <and>
		<not>
	                <isset property="importSigningCertKSAlias"/>
		</not>
		</and>
        </condition>
        
        <condition property="genSingleProfileKeyOptions" value="${importRootCertAlias} -keyStorePassword {${keyStorePassword}}">
                <and>
	                <isset property="keyStorePassword"/>
		</and>
        </condition>
        <condition property="genSingleProfileKeyOptions" value="${importRootCertAlias}">
                <and>
                <not>
	                <isset property="keyStorePassword"/>
		</not>
                </and>
        </condition>
        
    </target> 

 
    <target name="runPrepareKeysForSingleProfile" 
            description="Runs the prepareKeysForSingleProfile task to create keys and keystores."> 
             
        <wscmtlog>Setting the security settings in the default security template, the output will be recorded in: ${WS_CMT_LOG_HOME}/${profileName}/keyGeneration.log</wscmtlog>  
        <wscmtlog>${templatePath}</wscmtlog>
         <!-- fail on error was true, but changed to false to accomodate F69142-65189 -->        
        <wsadmin conntype="none"
                  lang="jacl"
                  failonerror="false"
                  returnproperty="rcProperty"
                  tracefile="${WS_CMT_LOG_HOME}/${profileName}/keyGeneration.log"
                  wasHome="${WAS_HOME}"
                  wasInstallRoot="${WAS_HOME}"
                  wasRepositoryRoot="${profilePath}/config"
                  userInstallRoot="${profilePath}"
                  localCell="${cellName}"
                  localNode="${nodeName}"
                  wsadminProps="${profilePath}/properties/wsadmin.properties"
                  ipcFilename="${profilePath}/temp/wsadmin"
                  >
                  <command value="$AdminTask prepareKeysForSingleProfile {-profileRoot {${profilePath}} ${genSingleProfileKeyOptions}}"/>
                  <command value="$$AdminConfig save"/>
          </wsadmin>
         <antcall target="importLogsToMain" >
            <param name="logfile" value="${WS_CMT_LOG_HOME}/${profileName}/keyGeneration.log" />
            <param name="description" value="Setting the security settings in the default security template" />
            <param name="precondition" value="foetrue" />
          </antcall>	           
          <wscmtlog>finished executing wsadmin</wscmtlog>
    </target> 
 
    <target name="generateKeysForSingleProfile"
        description="Starts the tasks."           
        depends="setGenerateKeysForSingleProfileOptions,
                 runPrepareKeysForSingleProfile">
    </target>

</project>

