public static Document produceMetadataDocument ( final CasConfigurationProperties config ) { try { val wsfedIdp = config . getAuthn ( ) . getWsfedIdp ( ) ; val sts = wsfedIdp . getSts ( ) ; val prop = CryptoUtils . getSecurityProperties ( sts . getRealm ( ) . getKeystoreFile ( ) , sts . getRealm ( ) . getKeystorePassword ( ) , sts . getRealm ( ) . getKeystoreAlias ( ) ) ; val crypto = CryptoFactory . getInstance ( prop ) ; val writer = new W3CDOMStreamWriter ( ) ; writer . writeStartDocument ( StandardCharsets . UTF_8 . name ( ) , "1.0" ) ; val referenceID = IDGenerator . generateID ( "_" ) ; writer . writeStartElement ( "md" , "EntityDescriptor" , SAML2_METADATA_NS ) ; writer . writeAttribute ( "ID" , referenceID ) ; val idpEntityId = config . getServer ( ) . getPrefix ( ) . concat ( WSFederationConstants . ENDPOINT_FEDERATION_REQUEST ) ; writer . writeAttribute ( "entityID" , idpEntityId ) ; writer . writeNamespace ( "md" , SAML2_METADATA_NS ) ; writer . writeNamespace ( "fed" , WS_FEDERATION_NS ) ; writer . writeNamespace ( "wsa" , WS_ADDRESSING_NS ) ; writer . writeNamespace ( "auth" , WS_FEDERATION_NS ) ; writer . writeNamespace ( "xsi" , SCHEMA_INSTANCE_NS ) ; val stsUrl = config . getServer ( ) . getPrefix ( ) . concat ( WSFederationConstants . ENDPOINT_STS ) . concat ( wsfedIdp . getIdp ( ) . getRealmName ( ) ) ; writeFederationMetadata ( writer , idpEntityId , stsUrl , crypto ) ; writer . writeEndElement ( ) ; writer . writeEndDocument ( ) ; writer . close ( ) ; val out = DOM2Writer . nodeToString ( writer . getDocument ( ) ) ; LOGGER . trace ( out ) ; val result = SignatureUtils . signMetaInfo ( crypto , null , sts . getRealm ( ) . getKeyPassword ( ) , writer . getDocument ( ) , referenceID ) ; if ( result != null ) { return result ; } throw new IllegalArgumentException ( "Failed to sign the metadata document" ) ; } catch ( final Exception e ) { throw new IllegalArgumentException ( "Error creating service metadata information: " + e . getMessage ( ) , e ) ; } }
Produce metadata document .