@ ShellMethod ( key = "generate-idp-metadata" , value = "Generate SAML2 IdP Metadata" ) public void generate ( @ ShellOption ( value = { "metadataLocation" } , help = "Directory location to hold metadata and relevant keys/certificates" , defaultValue = "/etc/cas/saml" ) final String metadataLocation , @ ShellOption ( value = { "entityId" } , help = "Entity ID to use for the generated metadata" , defaultValue = "cas.example.org" ) final String entityId , @ ShellOption ( value = { "hostName" } , help = "CAS server prefix to be used at the IdP host name when generating metadata" , defaultValue = "https://cas.example.org/cas" ) final String serverPrefix , @ ShellOption ( value = { "scope" } , help = "Scope to use when generating metadata" , defaultValue = "example.org" ) final String scope , @ ShellOption ( value = { "force" } , help = "Force metadata generation, disregarding anything that might already be available at the specified location" ) final boolean force ) { val locator = new FileSystemSamlIdPMetadataLocator ( new File ( metadataLocation ) ) ; val writer = new DefaultSamlIdPCertificateAndKeyWriter ( ) ; val context = SamlIdPMetadataGeneratorConfigurationContext . builder ( ) . samlIdPMetadataLocator ( locator ) . samlIdPCertificateAndKeyWriter ( writer ) . entityId ( entityId ) . resourceLoader ( resourceLoader ) . casServerPrefix ( serverPrefix ) . scope ( scope ) . metadataCipherExecutor ( CipherExecutor . noOpOfStringToString ( ) ) . build ( ) ; val generator = new FileSystemSamlIdPMetadataGenerator ( context ) ; val generateMetadata = FunctionUtils . doIf ( locator . exists ( ) , ( ) -> Boolean . TRUE , ( ) -> { LOGGER . warn ( "Metadata artifacts are available at the specified location: [{}]" , metadataLocation ) ; return force ; } ) . get ( ) ; if ( generateMetadata ) { generator . initialize ( ) ; generator . generate ( ) ; LOGGER . info ( "Generated metadata is available at [{}]" , locator . getMetadata ( ) ) ; } else { LOGGER . info ( "No metadata was generated; it might already exist at the specified path" ) ; } }
Generate saml2 idp metadata at the specified location .