Tagging 2.4RC1 release.
[shibboleth/sp.git] / configs / metagen.sh
index 281fa5f..e460240 100755 (executable)
@@ -1,5 +1,7 @@
 #! /bin/sh
 
+DECLS=1
+
 SAML1=0
 SAML2=0
 ARTIFACT=0
@@ -21,30 +23,33 @@ SAML20PAOS="urn:oasis:names:tc:SAML:2.0:bindings:PAOS"
 SAML1POST="urn:oasis:names:tc:SAML:1.0:profiles:browser-post"
 SAML1ART="urn:oasis:names:tc:SAML:1.0:profiles:artifact-01"
 
-while getopts a:c:e:h:n:o:s:t:12ADLN c
+while getopts a:c:e:f:h:n:o:s:t:u:12ADLNO c
      do
          case $c in
            c)   CERTS[${#CERTS[*]}]=$OPTARG;;
            e)   ENTITYID=$OPTARG;;
+           f)   FORMATS[${#FORMATS[*]}]=$OPTARG;;
            h)   HOSTS[${#HOSTS[*]}]=$OPTARG;;
            n)   NAKEDHOSTS[${#NAKEDHOSTS[*]}]=$OPTARG;;
            o)   ORGNAME=$OPTARG;;
            a)   ADMIN[${#ADMIN[*]}]=$OPTARG;;
            s)   SUP[${#SUP[*]}]=$OPTARG;;
            t)   TECH[${#TECH[*]}]=$OPTARG;;
+           u)   URL=$OPTARG;;
            1)   SAML1=1;;
            2)   SAML2=1;;
            A)   ARTIFACT=1;;
            D)   DS=1;;
            L)   LOGOUT=1;;
            N)   NAMEIDMGMT=1;;
-           \?)  echo metagen [-12ADLN] -c cert1 [-c cert2 ...] -h host1 [-h host2 ...] [-e entityID]
+           O)   DECLS=0;;
+           \?)  echo metagen [-12ADLNO] -c cert1 [-c cert2 ...] -h host1 [-h host2 ...] [-e entityID]
                 exit 1;;
          esac
      done
 
 if [ ${#HOSTS[*]} -eq 0 -a ${#NAKEDHOSTS[*]} -eq 0 ] ; then
-    echo metagen -c cert1 [-c cert2 ...] -h host1 [-h host2 ...] [-e entityID]
+    echo metagen [-12ADLN] -c cert1 [-c cert2 ...] -h host1 [-h host2 ...] [-e entityID]
     exit 1
 fi
 
@@ -61,7 +66,11 @@ do
 done
 
 if [ -z $ENTITYID ] ; then
-    ENTITYID=https://${HOSTS[0]}/shibboleth
+    if [ ${#HOSTS[*]} -eq 0 ] ; then
+        ENTITYID=https://${NAKEDHOSTS[0]}/shibboleth
+    else
+        ENTITYID=https://${HOSTS[0]}/shibboleth
+    fi
 fi
 
 # Establish protocols and bindings.
@@ -86,9 +95,9 @@ if [ $LOGOUT -eq 1 -o $NAMEIDMGMT -eq 1 ] ; then
 fi
 
 if [ $SAML1 -eq 1 -a $SAML2 -eq 1 ] ; then
-    PROTENUM="$SAML20PROT $SAML11PROT $SAML10PROT"
+    PROTENUM="$SAML20PROT $SAML11PROT"
 elif [ $SAML1 -eq 1 ] ; then
-    PROTENUM="$SAML11PROT $SAML10PROT"
+    PROTENUM="$SAML11PROT"
 else
     PROTENUM="$SAML20PROT"
 fi
@@ -120,8 +129,17 @@ if [ $SAML2 -eq 1 ] ; then
     ACSLOC[${#ACSLOC[*]}]="SAML2/ECP"
 fi
 
+if [ $DECLS -eq 1 ] ; then
+    DECLS="xmlns:md=\"urn:oasis:names:tc:SAML:2.0:metadata\" xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\" "
+    if [ $DS -eq 1 ] ; then
+        DECLS="${DECLS}xmlns:disco=\"urn:oasis:names:tc:SAML:profiles:SSO:idp-discovery-protocol\" "
+    fi
+else
+    DECLS=""
+fi
+
 cat <<EOF
-<md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" entityID="${ENTITYID}">
+<md:EntityDescriptor ${DECLS}entityID="${ENTITYID}">
   <md:SPSSODescriptor protocolSupportEnumeration="${PROTENUM}">
 EOF
 
@@ -136,7 +154,7 @@ count=1
 for h in ${HOSTS[@]}
 do
   cat << EOF
-      <DiscoveryResponse xmlns="urn:oasis:names:tc:SAML:profiles:SSO:idp-discovery-protocol" Binding="urn:oasis:names:tc:SAML:profiles:SSO:idp-discovery-protocol" Location="https://$h/Shibboleth.sso/DS" index="$count"/>
+      <disco:DiscoveryResponse Binding="urn:oasis:names:tc:SAML:profiles:SSO:idp-discovery-protocol" Location="https://$h/Shibboleth.sso/DS" index="$count"/>
 EOF
   let "count++"
 done
@@ -144,7 +162,7 @@ done
 for h in ${NAKEDHOSTS[@]}
 do
   cat << EOF
-      <DiscoveryResponse xmlns="urn:oasis:names:tc:SAML:profiles:SSO:idp-discovery-protocol" Binding="urn:oasis:names:tc:SAML:profiles:SSO:idp-discovery-protocol" Location="http://$h/Shibboleth.sso/DS" index="$count"/>
+      <disco:DiscoveryResponse xmlns="urn:oasis:names:tc:SAML:profiles:SSO:idp-discovery-protocol" Binding="urn:oasis:names:tc:SAML:profiles:SSO:idp-discovery-protocol" Location="http://$h/Shibboleth.sso/DS" index="$count"/>
 EOF
   let "count++"
 done
@@ -173,6 +191,13 @@ cat << EOF
 EOF
 done
 
+for f in ${FORMATS[@]}
+do
+cat << EOF
+    <md:NameIDFormat>$f</md:NameIDFormat>
+EOF
+done
+
 # Logout BEGIN
 if [ $LOGOUT -eq 1 ] ; then
 
@@ -265,18 +290,22 @@ cat <<EOF
 EOF
 
 if [ -n "$ORGNAME" ] ; then
+  if [ -z "$URL" ] ; then
+    URL=$ENTITYID
+  fi
   cat <<EOF
   <md:Organization>
     <md:OrganizationName xml:lang="en">$ORGNAME</md:OrganizationName>
     <md:OrganizationDisplayName xml:lang="en">$ORGNAME</md:OrganizationDisplayName>
-    <md:OrganizationURL xml:lang="en">$ENTITYID</md:OrganizationURL>
+    <md:OrganizationURL xml:lang="en">$URL</md:OrganizationURL>
   </md:Organization>
 EOF
 fi
 
-for c in ${ADMIN[@]}
+count=${#ADMIN[*]}
+for (( i=0; i<count; i++ ))
 do
-  c=(${c//\// })
+  IFS="/"; declare -a c=(${ADMIN[$i]})
   cat <<EOF
   <md:ContactPerson contactType="administrative">
     <md:GivenName>${c[0]}</md:GivenName>
@@ -286,9 +315,10 @@ do
 EOF
 done
 
-for c in ${SUP[@]}
+count=${#SUP[*]}
+for (( i=0; i<count; i++ ))
 do
-  c=(${c//\// })
+  IFS="/"; declare -a c=(${SUP[$i]})
   cat <<EOF
   <md:ContactPerson contactType="support">
     <md:GivenName>${c[0]}</md:GivenName>
@@ -298,9 +328,10 @@ do
 EOF
 done
 
-for c in ${TECH[@]}
+count=${#TECH[*]}
+for (( i=0; i<count; i++ ))
 do
-  c=(${c//\// })
+  IFS="/"; declare -a c=(${TECH[$i]})
   cat <<EOF
   <md:ContactPerson contactType="technical">
     <md:GivenName>${c[0]}</md:GivenName>
@@ -312,4 +343,5 @@ done
 
 cat <<EOF 
 </md:EntityDescriptor>
+
 EOF