Added a function to extract possible match names from cert, fixed bug in altName...
[java-idp.git] / build.xml
index 256cb9d..50da28a 100755 (executable)
--- a/build.xml
+++ b/build.xml
@@ -3,7 +3,6 @@
 <project name="Shibboleth" default="install" basedir=".">
 
     <!-- Set global properties for this build -->
-    <property name="distname" value="shibboleth-idp" />
     <property name="distnameWayf" value="shibboleth-wayf" />
     <property name="root" value="." />
     <property name="src" value="${root}/src/" />
     <target name="init">
         <mkdir dir="${build}" />
         <mkdir dir="${dist}" />
+
+        <if>
+            <not> <available file="build.properties" /> </not>
+            <then>
+                <copy file="conf/default.build.properties" tofile="build.properties" />
+            </then>
+        </if>
+
         <property file="build.properties" />
     </target>
 
         <jar jarfile="${distlibs}/shib-util.jar" basedir="${build}" />
     </target>
 
-    
     <!-- Cleanup after the build, test, and distribution processes -->
     <target name="clean" depends="clean-all" />
     <target name="clean-all" depends="clean-build, clean-dist, clean-test, clean-javadocs, clean-util" />
             </fileset>
         </delete>
     </target>
+       <!-- For IDE development, run this target first to delete all
+                directories generated by the install process before
+                recreating and reinstalling everything. -->
+       <target name="clean-install" depends="init" 
+               description="Delete old configuration and Tomcat webapp directories.">
+               <delete dir="${shib.home}" />
+               <delete dir="${shibsp.home}" />
+               <delete dir="${tomcat.home}/webapps/${shib.webapp.name}" />
+               <delete dir="${tomcat.home}/webapps/${shibsp.webapp.name}" />
+       </target>
 
 
        <!-- Add to the classpath for unit tests -->
        </target>
     
     <target name="tomcat.start" depends="setupTomcatTasks" description="Start a deployed webapp using Tomcat manager">
-        <tomcatStart url="${tomcat.url}" username="${tomcat.username}" password="${tomcat.password}" path="/${distname}"/>
+        <tomcatStart url="${tomcat.url}" username="${tomcat.username}" password="${tomcat.password}" path="/${shib.webapp.name}"/>
     </target>
 
     <target name="tomcat.stop" depends="setupTomcatTasks" description="Stop a deployed webapp using Tomcat manager">
-        <tomcatStop url="${tomcat.url}" username="${tomcat.username}" password="${tomcat.password}" path="/${distname}"/>
+        <tomcatStop url="${tomcat.url}" username="${tomcat.username}" password="${tomcat.password}" path="/${shib.webapp.name}"/>
     </target>
 
     <target name="tomcat.deploy" depends="setupTomcatTasks" description="Upload and deploy using Tomcat manager">
-        <tomcatDeploy url="${tomcat.url}" username="${tomcat.username}" password="${tomcat.password}" path="/${distname}"
-               war="file:${basedir}/${dist}/${distname}.war"/>
+        <tomcatDeploy url="${tomcat.url}" username="${tomcat.username}" password="${tomcat.password}" path="/${shib.webapp.name}"
+               war="file:${basedir}/${dist}/${shib.webapp.name}.war"/>
     </target>
 
     <target name="tomcat.undeploy" depends="setupTomcatTasks" description="Undeploy using Tomcat manager">
-        <tomcatUndeploy url="${tomcat.url}" username="${tomcat.username}" password="${tomcat.password}" path="/${distname}"/>
+        <tomcatUndeploy url="${tomcat.url}" username="${tomcat.username}" password="${tomcat.password}" path="/${shib.webapp.name}"/>
     </target>
        
     
         <genSalt keyStorePath="${appconfig}/persistent.jks" keyStorePassword="shibhs" keyStoreKeyAlias="handleKey" keyStoreKeyPassword="shibhs" />
     </target>
        
-       <target name="exampleCertificate">
+       <target name="exampleCertificates">
+               <!--
+               This target provides an example of the generation of
+               self-signed Certificates for the IdP and SP. You may
+               change the cn= and use it to generate new identities
+               when you want to replace "example.org" with your real
+               organization dns. However,the generated key and 
+               certificate also have to be defined to the Credentials
+               of the IdP and SP config files and added to the Metadata.
+               -->
+               <genkey alias="tomcat" storepass="exampleorg"
+                       keystore="${tomcat.home}/conf/idp-example.jks"
+                       keyalg="RSA" validity="365"
+                       dname="cn=idp.example.org, o=example.org, c=US"
+               />
                <genkey alias="tomcat" storepass="exampleorg"
-                       keystore="${tomcat.home}/conf/example.jks"
+                       keystore="${tomcat.home}/conf/sp-example.jks"
                        keyalg="RSA" validity="365"
-                       dname="cn=shibboleth.example.org, o=example.org, c=US"
+                       dname="cn=sp.example.org, o=example.org, c=US"
                />
        </target>
 
 
     <!-- Install Shibboleth -->
     <target name="install.init">
-       <taskdef name="xinput" classname="edu.internet2.middleware.shibboleth.utils.ant.XInput" classpath="${build}"/>
-       <typedef name="xoption" classname="edu.internet2.middleware.shibboleth.utils.ant.XInputOption" classpath="${build}"/>
+        <taskdef name="xinput" classname="edu.internet2.middleware.shibboleth.utils.ant.XInput" classpath="${build}" />
+        <typedef name="xoption" classname="edu.internet2.middleware.shibboleth.utils.ant.XInputOption" classpath="${build}" />
+    </target>
+
+    <target name="install.url">
+               <taskdef name="urlconvert" classname="edu.internet2.middleware.shibboleth.utils.ant.URLConvert" classpath="${build}"/>
+               <urlconvert path="${shib.home}" addProperty="shib.home.url"/>
+               <urlconvert path="${shibsp.home}" addProperty="shibsp.home.url"/>
     </target>
 
     <target name="install" depends="init, install.init" description="Install Shibboleth">
        <target name="install.idp" depends="init, install.init">
         <xinput message="Deploying the java web application.  Do you want to install it directly onto the filesystem or use the tomcat manager application?" 
             addproperty="idp.install-type.input" type="menu" casesensitive="no" defaultValue="${idp.install-type}">
-            <xoption>filesystem</xoption>
+            <xoption value="filesystem.prompt">filesystem</xoption>
             <xoption>manager</xoption>
         </xinput>
         <var name="idp.install-type" value="${idp.install-type.input}" />
         <antcall target="install.idp.${idp.install-type}" />
     </target>
 
-    <target name="install.idp.filesystem" depends="init, install.init, build-util">
+    <!-- Prompt user for filesystem installation options and save them to build.properties -->
+    <target name="install.idp.filesystem.prompt" depends="init, install.init">
         <input message="Select an installation base for the Shibboleth Identity Provider [default: ${shib.home}]"
             addproperty="shib.home.input" defaultvalue="${shib.home}" />
         <var name="shib.home" value="${shib.home.input}" />
-
         <input message="Enter tomcat home directory [default: ${tomcat.home}]"
             addproperty="tomcat.home.input" defaultvalue="${tomcat.home}" />
         <var name="tomcat.home" value="${tomcat.home.input}" />
         
-        <copy file="${configroot}/idp.xml.dist" tofile="${configroot}/idp.xml" overwrite="true" />
-        <replace file="${configroot}/idp.xml" token="$SHIB_HOME$" value="${shib.home}" />
-        <war warfile="${dist}/${distname}.war" webxml="${configroot}/idp.xml" basedir="${approot}" update="no" />
-               <delete file="${configroot}/idp.xml"/>
-        <copy file="${dist}/${distname}.war" tofile="${tomcat.home}/webapps/${shib.webapp.name}.war" />
-
         <if>
                        <available file="${shib.home}/etc" />
             <then>
-                <if>
-                    <xinput type="confirm">WARNING!! The directory `${shib.home}/etc` already exists.  Do you want to overwrite the existing configuration?</xinput>
-                    <then>
-                        <delete dir="${shib.home}/etc" />
-                        <antcall target="install.idp.filesystem.config" />
-                    </then>
-                </if>
+                <xinput type="confirm" addproperty="copy-idp-conf">WARNING!! The directory `${shib.home}/etc` already exists.  Do you want to overwrite the existing configuration?</xinput>
             </then>
             <else>
-                <antcall target="install.idp.filesystem.config" />
+                <property name="copy-idp-conf" value="y" />
             </else>
         </if>
 
+        <antcall target="install.idp.filesystem" />
+        <antcall target="savePropertyFile" />
+    </target>
+
+    <!-- Install Shibboleth IdP to filesystem using the properties in build.properties -->
+    <target name="install.idp.filesystem" depends="init, install.init, build-util, install.url" 
+        description="Install Shibboleth IdP to filesystem using the properties in build.properties">
+
+        <!-- copy values to deployment descriptor and create war -->
+        <copy file="${configroot}/dist.idp.xml" tofile="${configroot}/idp.xml" overwrite="true" />
+        <replace file="${configroot}/idp.xml" token="$SHIB_HOME$" value="${shib.home.url}" />
+        <war warfile="${dist}/${shib.webapp.name}.war" webxml="${configroot}/idp.xml" basedir="${approot}" update="no" />
+               <delete file="${configroot}/idp.xml"/>
+        <copy file="${dist}/${shib.webapp.name}.war" tofile="${tomcat.home}/webapps/${shib.webapp.name}.war" />
+
+        <!-- copy IdP jars and utilities -->
         <copy todir="${shib.home}/lib">
             <fileset dir="lib" includesfile="conf/idp-lib.include" />
         </copy>
 
         <mkdir dir="${shib.home}/logs" />
 
-        <antcall target="savePropertyFile" />
+        <!-- copy IdP configuration -->
+        <if>
+            <or>
+                <equals arg1="${copy-idp-conf}" arg2="y" />
+                <not> <available file="${shib.home}/etc" /> </not>
+            </or>
+            <then>
+                <delete dir="${shib.home}/etc" />
+                <antcall target="install.idp.filesystem.config" />
+            </then>
+        </if>
     </target>
 
-       <target name="install.idp.filesystem.config" depends="init, install.init">
+    <!-- Install Shibboleth SP to filesystem using the properties in build.properties -->
+    <target name="install.sp.filesystem" depends="init, install.init, build-util, install.url" 
+        description="Install Shibboleth SP to filesystem using the properties in build.properties">
+
+        <!-- copy values to deployment descriptor and create war -->
+        <copy file="${configroot}/dist.sp.xml" tofile="${configroot}/sp.xml" overwrite="true" />
+        <replace file="${configroot}/sp.xml" token="$SHIB_HOME$" value="${shibsp.home.url}" />
+        <war warfile="${dist}/${shibsp.webapp.name}.war" webxml="${configroot}/sp.xml" basedir="${approot}" update="no" />
+               <delete file="${configroot}/sp.xml"/>
+        <copy file="${dist}/${shibsp.webapp.name}.war" tofile="${tomcat.home}/webapps/${shibsp.webapp.name}.war" />
+
+        <!-- copy sp jars and utilities -->
+        <copy todir="${shibsp.home}/lib">
+            <fileset dir="lib" includesfile="conf/idp-lib.include" />
+        </copy>
+
+        <copy todir="${shibsp.home}/bin">
+            <fileset dir="bin"/>
+        </copy>
+               <chmod dir="${shibsp.home}/bin" perm="ug+rx" includes="**/*"/>
+
+        <mkdir dir="${shibsp.home}/logs" />
+
+        <!-- copy sp configuration -->
+        <if>
+            <or>
+                <equals arg1="${copy-sp-conf}" arg2="y" />
+                <not> <available file="${shibsp.home}/etc" /> </not>
+            </or>
+            <then>
+                <delete dir="${shibsp.home}/etc" />
+                <antcall target="install.sp.filesystem.config" />
+            </then>
+        </if>
+    </target>
+       
+       
+    <!-- copy shibboleth configuration to $SHIB_HOME/etc, overwriting any existing configuration -->
+       <target name="install.idp.filesystem.config" depends="init, install.init, install.url">
         <mkdir dir="${shib.home}/etc" />
         <copy todir="${shib.home}/etc" overwrite="true">
             <fileset dir="${src}/conf" includesfile="conf/idp-conf.include"/>
         </copy>
-               <copy file="${shib.home}/etc/idp.xml.dist" tofile="${shib.home}/etc/idp.xml" overwrite="true" />
-               <delete file="${shib.home}/etc/idp.xml.dist"/>
-        <replace file="${shib.home}/etc/idp.xml" token="$SHIB_HOME$" value="${shib.home}" />
+               <move file="${shib.home}/etc/dist.idp.xml" tofile="${shib.home}/etc/idp.xml" overwrite="true" />
+        <replace file="${shib.home}/etc/idp.xml" token="$SHIB_HOME$" value="${shib.home.url}" />
+    </target>
+       
+    <!-- copy SP configuration to $SHIB_HOME$/etc, overwriting any existing configuration -->
+       <target name="install.sp.filesystem.config" depends="init, install.init">
+        <mkdir dir="${shibsp.home}/etc" />
+        <copy todir="${shibsp.home}/etc" overwrite="true">
+            <fileset dir="${src}/conf" includesfile="conf/sp-conf.include"/>
+        </copy>
+               <move file="${shibsp.home}/etc/dist.sp.xml" tofile="${shibsp.home}/etc/sp.xml" overwrite="true" />
+        <replace file="${shibsp.home}/etc/sp.xml" token="$SHIB_HOME$" value="${shibsp.home.url}" />
     </target>
 
+    <!-- install Shibboleth-IdP war using tomcat's manager app -->
        <target name="install.idp.manager" depends="init, install.init">
         <antcall target="setupTomcatTasks" />
         
         <antcall target="savePropertyFile" />
     </target>
 
+    <!-- save configuration to build.properties -->
     <target name="savePropertyFile">
         <propertyfile file="build.properties">
             <entry key="shib.home" value="${shib.home}" />
+            <entry key="shibsp.home" value="${shibsp.home}" />
             <entry key="shib.webapp.name" value="${shib.webapp.name}" />
+            <entry key="shibsp.webapp.name" value="${shibsp.webapp.name}" />
             <entry key="idp.install-type" value="${idp.install-type}" />
             <entry key="tomcat.home" value="${tomcat.home}" />
             <entry key="tomcat.url" value="${tomcat.url}" />
         </propertyfile>
     </target>
 
-
-       <!-- Create an IdP war and copy it to the pre-configured tomcat directory -->
-       <target name="copy-IdP" depends="compile" description="Copy shibboleth.war to {tomcat.home}/webapps (Tomcat must be stopped first)">
-               <!-- This task assumes that a pre-existing properties file has the correct path information -->
-        <copy file="${configroot}/idp.xml.dist" tofile="${configroot}/idp.xml" overwrite="true" />
-        <replace file="${configroot}/idp.xml" token="$SHIB_HOME$" value="${shib.home}" />
-        <war warfile="${dist}/${distname}.war" webxml="${configroot}/idp.xml" basedir="${approot}" update="no" />
-        <copy file="${dist}/${distname}.war" tofile="${tomcat.home}/webapps/${shib.webapp.name}.war" />
-               <delete dir="${tomcat.home}/webapps/${distname}" quiet="yes" />
-       </target>
-
-
     <!-- Create WAYF and move it to ${dist} -->
-    <target name="package-wayf" depends="compile, clean-build">
+    <target name="package-wayf" depends="compile">
         <war warfile="${dist}/${distnameWayf}.war" webxml="${configroot}/wayf.xml" basedir="${approot}" update="no" />
     </target>