@Test public void metadata() throws Exception { given() .config(newConfig() .xmlConfig(xmlConfig().declareNamespace("md", "urn:oasis:names:tc:SAML:2.0:metadata"))) .header("Content-Type", "application/xml") .get("/metadata") .then() .statusCode(SC_OK) .body( "EntityDescriptor.IDPSSODescriptor.SingleSignOnService.@Location", equalTo(idpBaseUrl + "/SingleSignOnService")); }
@Autowired @RequestMapping(method = RequestMethod.GET, value = "/metadata", produces = "application/xml") public String metadata(@Value("${idp.base_url}") String idpBaseUrl) throws SecurityException, ParserConfigurationException, SignatureException, MarshallingException, TransformerException { EntityDescriptor entityDescriptor = buildSAMLObject(EntityDescriptor.class, EntityDescriptor.DEFAULT_ELEMENT_NAME); entityDescriptor.setEntityID(idpConfiguration.getEntityId()); entityDescriptor.setID(SAMLBuilder.randomSAMLId()); entityDescriptor.setValidUntil(new DateTime().plusMillis(86400000)); Signature signature = buildSAMLObject(Signature.class, Signature.DEFAULT_ELEMENT_NAME); Credential credential = keyManager.resolveSingle(new CriteriaSet(new EntityIDCriteria(idpConfiguration.getEntityId()))); signature.setSigningCredential(credential); signature.setSignatureAlgorithm(SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA256); signature.setCanonicalizationAlgorithm(SignatureConstants.ALGO_ID_C14N_EXCL_OMIT_COMMENTS); entityDescriptor.setSignature(signature); Configuration.getMarshallerFactory().getMarshaller(entityDescriptor).marshall(entityDescriptor); Signer.signObject(signature); IDPSSODescriptor idpssoDescriptor = buildSAMLObject(IDPSSODescriptor.class, IDPSSODescriptor.DEFAULT_ELEMENT_NAME); NameIDFormat nameIDFormat = buildSAMLObject(NameIDFormat.class, NameIDFormat.DEFAULT_ELEMENT_NAME); nameIDFormat.setFormat("urn:oasis:names:tc:SAML:2.0:nameid-format:persistent"); idpssoDescriptor.getNameIDFormats().add(nameIDFormat); idpssoDescriptor.addSupportedProtocol(SAMLConstants.SAML20P_NS); SingleSignOnService singleSignOnService = buildSAMLObject(SingleSignOnService.class, SingleSignOnService.DEFAULT_ELEMENT_NAME); singleSignOnService.setLocation(idpBaseUrl + "/SingleSignOnService"); singleSignOnService.setBinding(SAMLConstants.SAML2_REDIRECT_BINDING_URI); idpssoDescriptor.getSingleSignOnServices().add(singleSignOnService); X509KeyInfoGeneratorFactory keyInfoGeneratorFactory = new X509KeyInfoGeneratorFactory(); keyInfoGeneratorFactory.setEmitEntityCertificate(true); KeyInfoGenerator keyInfoGenerator = keyInfoGeneratorFactory.newInstance(); KeyDescriptor encKeyDescriptor = buildSAMLObject(KeyDescriptor.class, KeyDescriptor.DEFAULT_ELEMENT_NAME); encKeyDescriptor.setUse(UsageType.SIGNING); encKeyDescriptor.setKeyInfo(keyInfoGenerator.generate(credential)); idpssoDescriptor.getKeyDescriptors().add(encKeyDescriptor); entityDescriptor.getRoleDescriptors().add(idpssoDescriptor); return writeEntityDescriptor(entityDescriptor); }
MetadataController { @Autowired @RequestMapping(method = RequestMethod.GET, value = "/metadata", produces = "application/xml") public String metadata(@Value("${idp.base_url}") String idpBaseUrl) throws SecurityException, ParserConfigurationException, SignatureException, MarshallingException, TransformerException { EntityDescriptor entityDescriptor = buildSAMLObject(EntityDescriptor.class, EntityDescriptor.DEFAULT_ELEMENT_NAME); entityDescriptor.setEntityID(idpConfiguration.getEntityId()); entityDescriptor.setID(SAMLBuilder.randomSAMLId()); entityDescriptor.setValidUntil(new DateTime().plusMillis(86400000)); Signature signature = buildSAMLObject(Signature.class, Signature.DEFAULT_ELEMENT_NAME); Credential credential = keyManager.resolveSingle(new CriteriaSet(new EntityIDCriteria(idpConfiguration.getEntityId()))); signature.setSigningCredential(credential); signature.setSignatureAlgorithm(SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA256); signature.setCanonicalizationAlgorithm(SignatureConstants.ALGO_ID_C14N_EXCL_OMIT_COMMENTS); entityDescriptor.setSignature(signature); Configuration.getMarshallerFactory().getMarshaller(entityDescriptor).marshall(entityDescriptor); Signer.signObject(signature); IDPSSODescriptor idpssoDescriptor = buildSAMLObject(IDPSSODescriptor.class, IDPSSODescriptor.DEFAULT_ELEMENT_NAME); NameIDFormat nameIDFormat = buildSAMLObject(NameIDFormat.class, NameIDFormat.DEFAULT_ELEMENT_NAME); nameIDFormat.setFormat("urn:oasis:names:tc:SAML:2.0:nameid-format:persistent"); idpssoDescriptor.getNameIDFormats().add(nameIDFormat); idpssoDescriptor.addSupportedProtocol(SAMLConstants.SAML20P_NS); SingleSignOnService singleSignOnService = buildSAMLObject(SingleSignOnService.class, SingleSignOnService.DEFAULT_ELEMENT_NAME); singleSignOnService.setLocation(idpBaseUrl + "/SingleSignOnService"); singleSignOnService.setBinding(SAMLConstants.SAML2_REDIRECT_BINDING_URI); idpssoDescriptor.getSingleSignOnServices().add(singleSignOnService); X509KeyInfoGeneratorFactory keyInfoGeneratorFactory = new X509KeyInfoGeneratorFactory(); keyInfoGeneratorFactory.setEmitEntityCertificate(true); KeyInfoGenerator keyInfoGenerator = keyInfoGeneratorFactory.newInstance(); KeyDescriptor encKeyDescriptor = buildSAMLObject(KeyDescriptor.class, KeyDescriptor.DEFAULT_ELEMENT_NAME); encKeyDescriptor.setUse(UsageType.SIGNING); encKeyDescriptor.setKeyInfo(keyInfoGenerator.generate(credential)); idpssoDescriptor.getKeyDescriptors().add(encKeyDescriptor); entityDescriptor.getRoleDescriptors().add(idpssoDescriptor); return writeEntityDescriptor(entityDescriptor); } }
MetadataController { @Autowired @RequestMapping(method = RequestMethod.GET, value = "/metadata", produces = "application/xml") public String metadata(@Value("${idp.base_url}") String idpBaseUrl) throws SecurityException, ParserConfigurationException, SignatureException, MarshallingException, TransformerException { EntityDescriptor entityDescriptor = buildSAMLObject(EntityDescriptor.class, EntityDescriptor.DEFAULT_ELEMENT_NAME); entityDescriptor.setEntityID(idpConfiguration.getEntityId()); entityDescriptor.setID(SAMLBuilder.randomSAMLId()); entityDescriptor.setValidUntil(new DateTime().plusMillis(86400000)); Signature signature = buildSAMLObject(Signature.class, Signature.DEFAULT_ELEMENT_NAME); Credential credential = keyManager.resolveSingle(new CriteriaSet(new EntityIDCriteria(idpConfiguration.getEntityId()))); signature.setSigningCredential(credential); signature.setSignatureAlgorithm(SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA256); signature.setCanonicalizationAlgorithm(SignatureConstants.ALGO_ID_C14N_EXCL_OMIT_COMMENTS); entityDescriptor.setSignature(signature); Configuration.getMarshallerFactory().getMarshaller(entityDescriptor).marshall(entityDescriptor); Signer.signObject(signature); IDPSSODescriptor idpssoDescriptor = buildSAMLObject(IDPSSODescriptor.class, IDPSSODescriptor.DEFAULT_ELEMENT_NAME); NameIDFormat nameIDFormat = buildSAMLObject(NameIDFormat.class, NameIDFormat.DEFAULT_ELEMENT_NAME); nameIDFormat.setFormat("urn:oasis:names:tc:SAML:2.0:nameid-format:persistent"); idpssoDescriptor.getNameIDFormats().add(nameIDFormat); idpssoDescriptor.addSupportedProtocol(SAMLConstants.SAML20P_NS); SingleSignOnService singleSignOnService = buildSAMLObject(SingleSignOnService.class, SingleSignOnService.DEFAULT_ELEMENT_NAME); singleSignOnService.setLocation(idpBaseUrl + "/SingleSignOnService"); singleSignOnService.setBinding(SAMLConstants.SAML2_REDIRECT_BINDING_URI); idpssoDescriptor.getSingleSignOnServices().add(singleSignOnService); X509KeyInfoGeneratorFactory keyInfoGeneratorFactory = new X509KeyInfoGeneratorFactory(); keyInfoGeneratorFactory.setEmitEntityCertificate(true); KeyInfoGenerator keyInfoGenerator = keyInfoGeneratorFactory.newInstance(); KeyDescriptor encKeyDescriptor = buildSAMLObject(KeyDescriptor.class, KeyDescriptor.DEFAULT_ELEMENT_NAME); encKeyDescriptor.setUse(UsageType.SIGNING); encKeyDescriptor.setKeyInfo(keyInfoGenerator.generate(credential)); idpssoDescriptor.getKeyDescriptors().add(encKeyDescriptor); entityDescriptor.getRoleDescriptors().add(idpssoDescriptor); return writeEntityDescriptor(entityDescriptor); }  }
MetadataController { @Autowired @RequestMapping(method = RequestMethod.GET, value = "/metadata", produces = "application/xml") public String metadata(@Value("${idp.base_url}") String idpBaseUrl) throws SecurityException, ParserConfigurationException, SignatureException, MarshallingException, TransformerException { EntityDescriptor entityDescriptor = buildSAMLObject(EntityDescriptor.class, EntityDescriptor.DEFAULT_ELEMENT_NAME); entityDescriptor.setEntityID(idpConfiguration.getEntityId()); entityDescriptor.setID(SAMLBuilder.randomSAMLId()); entityDescriptor.setValidUntil(new DateTime().plusMillis(86400000)); Signature signature = buildSAMLObject(Signature.class, Signature.DEFAULT_ELEMENT_NAME); Credential credential = keyManager.resolveSingle(new CriteriaSet(new EntityIDCriteria(idpConfiguration.getEntityId()))); signature.setSigningCredential(credential); signature.setSignatureAlgorithm(SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA256); signature.setCanonicalizationAlgorithm(SignatureConstants.ALGO_ID_C14N_EXCL_OMIT_COMMENTS); entityDescriptor.setSignature(signature); Configuration.getMarshallerFactory().getMarshaller(entityDescriptor).marshall(entityDescriptor); Signer.signObject(signature); IDPSSODescriptor idpssoDescriptor = buildSAMLObject(IDPSSODescriptor.class, IDPSSODescriptor.DEFAULT_ELEMENT_NAME); NameIDFormat nameIDFormat = buildSAMLObject(NameIDFormat.class, NameIDFormat.DEFAULT_ELEMENT_NAME); nameIDFormat.setFormat("urn:oasis:names:tc:SAML:2.0:nameid-format:persistent"); idpssoDescriptor.getNameIDFormats().add(nameIDFormat); idpssoDescriptor.addSupportedProtocol(SAMLConstants.SAML20P_NS); SingleSignOnService singleSignOnService = buildSAMLObject(SingleSignOnService.class, SingleSignOnService.DEFAULT_ELEMENT_NAME); singleSignOnService.setLocation(idpBaseUrl + "/SingleSignOnService"); singleSignOnService.setBinding(SAMLConstants.SAML2_REDIRECT_BINDING_URI); idpssoDescriptor.getSingleSignOnServices().add(singleSignOnService); X509KeyInfoGeneratorFactory keyInfoGeneratorFactory = new X509KeyInfoGeneratorFactory(); keyInfoGeneratorFactory.setEmitEntityCertificate(true); KeyInfoGenerator keyInfoGenerator = keyInfoGeneratorFactory.newInstance(); KeyDescriptor encKeyDescriptor = buildSAMLObject(KeyDescriptor.class, KeyDescriptor.DEFAULT_ELEMENT_NAME); encKeyDescriptor.setUse(UsageType.SIGNING); encKeyDescriptor.setKeyInfo(keyInfoGenerator.generate(credential)); idpssoDescriptor.getKeyDescriptors().add(encKeyDescriptor); entityDescriptor.getRoleDescriptors().add(idpssoDescriptor); return writeEntityDescriptor(entityDescriptor); }  @Autowired @RequestMapping(method = RequestMethod.GET, value = "/metadata", produces = "application/xml") String metadata(@Value("${idp.base_url}") String idpBaseUrl); }
MetadataController { @Autowired @RequestMapping(method = RequestMethod.GET, value = "/metadata", produces = "application/xml") public String metadata(@Value("${idp.base_url}") String idpBaseUrl) throws SecurityException, ParserConfigurationException, SignatureException, MarshallingException, TransformerException { EntityDescriptor entityDescriptor = buildSAMLObject(EntityDescriptor.class, EntityDescriptor.DEFAULT_ELEMENT_NAME); entityDescriptor.setEntityID(idpConfiguration.getEntityId()); entityDescriptor.setID(SAMLBuilder.randomSAMLId()); entityDescriptor.setValidUntil(new DateTime().plusMillis(86400000)); Signature signature = buildSAMLObject(Signature.class, Signature.DEFAULT_ELEMENT_NAME); Credential credential = keyManager.resolveSingle(new CriteriaSet(new EntityIDCriteria(idpConfiguration.getEntityId()))); signature.setSigningCredential(credential); signature.setSignatureAlgorithm(SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA256); signature.setCanonicalizationAlgorithm(SignatureConstants.ALGO_ID_C14N_EXCL_OMIT_COMMENTS); entityDescriptor.setSignature(signature); Configuration.getMarshallerFactory().getMarshaller(entityDescriptor).marshall(entityDescriptor); Signer.signObject(signature); IDPSSODescriptor idpssoDescriptor = buildSAMLObject(IDPSSODescriptor.class, IDPSSODescriptor.DEFAULT_ELEMENT_NAME); NameIDFormat nameIDFormat = buildSAMLObject(NameIDFormat.class, NameIDFormat.DEFAULT_ELEMENT_NAME); nameIDFormat.setFormat("urn:oasis:names:tc:SAML:2.0:nameid-format:persistent"); idpssoDescriptor.getNameIDFormats().add(nameIDFormat); idpssoDescriptor.addSupportedProtocol(SAMLConstants.SAML20P_NS); SingleSignOnService singleSignOnService = buildSAMLObject(SingleSignOnService.class, SingleSignOnService.DEFAULT_ELEMENT_NAME); singleSignOnService.setLocation(idpBaseUrl + "/SingleSignOnService"); singleSignOnService.setBinding(SAMLConstants.SAML2_REDIRECT_BINDING_URI); idpssoDescriptor.getSingleSignOnServices().add(singleSignOnService); X509KeyInfoGeneratorFactory keyInfoGeneratorFactory = new X509KeyInfoGeneratorFactory(); keyInfoGeneratorFactory.setEmitEntityCertificate(true); KeyInfoGenerator keyInfoGenerator = keyInfoGeneratorFactory.newInstance(); KeyDescriptor encKeyDescriptor = buildSAMLObject(KeyDescriptor.class, KeyDescriptor.DEFAULT_ELEMENT_NAME); encKeyDescriptor.setUse(UsageType.SIGNING); encKeyDescriptor.setKeyInfo(keyInfoGenerator.generate(credential)); idpssoDescriptor.getKeyDescriptors().add(encKeyDescriptor); entityDescriptor.getRoleDescriptors().add(idpssoDescriptor); return writeEntityDescriptor(entityDescriptor); }  @Autowired @RequestMapping(method = RequestMethod.GET, value = "/metadata", produces = "application/xml") String metadata(@Value("${idp.base_url}") String idpBaseUrl);  }