ZoneAwareIdpMetadataGenerator extends IdpMetadataGenerator { @Override public EntityDescriptor generateMetadata() { EntityDescriptor result = super.generateMetadata(); result.setID(SAMLUtil.getNCNameString(result.getEntityID())); return result; }  @Override boolean isAssertionsSigned(); @Override int getAssertionTimeToLiveSeconds(); @Override IdpExtendedMetadata generateExtendedMetadata(); @Override String getEntityId(); @Override String getEntityBaseURL(); @Override boolean isWantAuthnRequestSigned(); @Override EntityDescriptor generateMetadata();  }
@Test void canGetMetadata() throws Exception { IdentityZoneHolder.set(notUaaZone); assertNotNull(SAMLUtil.getMetadataAsString( mock(MetadataManager.class), keyManager, zoneAwareIdpMetadataGenerator.generateMetadata(), extendedMetadata)); }
@Test void defaultKeys() throws Exception { IdentityZoneHolder.set(notUaaZone); String metadata = SAMLUtil.getMetadataAsString( mock(MetadataManager.class), keyManager, zoneAwareIdpMetadataGenerator.generateMetadata(), extendedMetadata); List<String> encryptionKeys = getCertificates(metadata, "encryption"); assertEquals(1, encryptionKeys.size()); assertEquals(cert1Plain, encryptionKeys.get(0)); List<String> signingVerificationCerts = getCertificates(metadata, "signing"); assertEquals(1, signingVerificationCerts.size()); assertEquals(cert1Plain, signingVerificationCerts.get(0)); }
@Test void multipleKeys() throws Exception { notUaaZoneConfiguration.getSamlConfig().addKey("key2", samlKey2); IdentityZoneHolder.set(notUaaZone); String metadata = SAMLUtil.getMetadataAsString( mock(MetadataManager.class), keyManager, zoneAwareIdpMetadataGenerator.generateMetadata(), extendedMetadata); List<String> encryptionKeys = getCertificates(metadata, "encryption"); assertEquals(1, encryptionKeys.size()); assertEquals(cert1Plain, encryptionKeys.get(0)); List<String> signingVerificationCerts = getCertificates(metadata, "signing"); assertEquals(2, signingVerificationCerts.size()); assertThat(signingVerificationCerts, contains(cert1Plain, cert2Plain)); }
@Test void changeActiveKey() throws Exception { multipleKeys(); notUaaZoneConfiguration.getSamlConfig().addAndActivateKey("key2", samlKey2); IdentityZoneHolder.set(notUaaZone); String metadata = SAMLUtil.getMetadataAsString( mock(MetadataManager.class), keyManager, zoneAwareIdpMetadataGenerator.generateMetadata(), extendedMetadata); List<String> encryptionKeys = getCertificates(metadata, "encryption"); assertEquals(1, encryptionKeys.size()); assertEquals(cert2Plain, encryptionKeys.get(0)); List<String> signingVerificationCerts = getCertificates(metadata, "signing"); assertEquals(2, signingVerificationCerts.size()); assertThat(signingVerificationCerts, contains(cert2Plain, cert1Plain)); }
@Test void removeKey() throws Exception { changeActiveKey(); notUaaZoneConfiguration.getSamlConfig().removeKey("key-1"); IdentityZoneHolder.set(notUaaZone); String metadata = SAMLUtil.getMetadataAsString( mock(MetadataManager.class), keyManager, zoneAwareIdpMetadataGenerator.generateMetadata(), extendedMetadata); List<String> encryptionKeys = getCertificates(metadata, "encryption"); assertEquals(1, encryptionKeys.size()); assertEquals(cert2Plain, encryptionKeys.get(0)); List<String> signingVerificationCerts = getCertificates(metadata, "signing"); assertEquals(1, signingVerificationCerts.size()); assertThat(signingVerificationCerts, contains(cert2Plain)); }