Java Code Examples for org.opensaml.saml.saml2.metadata.KeyDescriptor#setKeyInfo()
The following examples show how to use
org.opensaml.saml.saml2.metadata.KeyDescriptor#setKeyInfo() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MockSamlIdpServer.java From deprecated-security-advanced-modules with Apache License 2.0 | 4 votes |
private String createMetadata() { try { EntityDescriptor idpEntityDescriptor = createSamlElement(EntityDescriptor.class); idpEntityDescriptor.setEntityID(idpEntityId); IDPSSODescriptor idpSsoDescriptor = createSamlElement(IDPSSODescriptor.class); idpEntityDescriptor.getRoleDescriptors().add(idpSsoDescriptor); idpSsoDescriptor.setWantAuthnRequestsSigned(wantAuthnRequestsSigned); idpSsoDescriptor.addSupportedProtocol(SAMLConstants.SAML20P_NS); SingleLogoutService redirectSingleLogoutService = createSamlElement(SingleLogoutService.class); idpSsoDescriptor.getSingleLogoutServices().add(redirectSingleLogoutService); redirectSingleLogoutService.setBinding("urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect"); redirectSingleLogoutService.setLocation(getSamlSloUri()); idpSsoDescriptor.getNameIDFormats() .add(createNameIDFormat("urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified")); SingleSignOnService redirectSingleSignOnService = createSamlElement(SingleSignOnService.class); idpSsoDescriptor.getSingleSignOnServices().add(redirectSingleSignOnService); redirectSingleSignOnService.setBinding("urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect"); redirectSingleSignOnService.setLocation(getSamlSsoUri()); X509KeyInfoGeneratorFactory keyInfoGeneratorFactory = new X509KeyInfoGeneratorFactory(); keyInfoGeneratorFactory.setEmitEntityCertificate(true); KeyInfoGenerator keyInfoGenerator = keyInfoGeneratorFactory.newInstance(); KeyDescriptor signingKeyDescriptor = createSamlElement(KeyDescriptor.class); idpSsoDescriptor.getKeyDescriptors().add(signingKeyDescriptor); signingKeyDescriptor.setUse(UsageType.SIGNING); signingKeyDescriptor .setKeyInfo(keyInfoGenerator.generate(new BasicX509Credential(this.signingCertificate))); return marshallSamlXml(idpEntityDescriptor); } catch (org.opensaml.security.SecurityException e) { throw new RuntimeException(e); } }
Example 2
Source File: SamlMetadataServiceFunction.java From armeria with Apache License 2.0 | 4 votes |
private static KeyDescriptor buildKeyDescriptorElement(UsageType type, @Nullable KeyInfo key) { final KeyDescriptor descriptor = build(KeyDescriptor.DEFAULT_ELEMENT_NAME); descriptor.setUse(type); descriptor.setKeyInfo(key); return descriptor; }
Example 3
Source File: SAML2SPLogic.java From syncope with Apache License 2.0 | 4 votes |
@PreAuthorize("isAuthenticated()") public void getMetadata(final String spEntityID, final String urlContext, final OutputStream os) { check(); try { EntityDescriptor spEntityDescriptor = new EntityDescriptorBuilder().buildObject(); spEntityDescriptor.setEntityID(spEntityID); SPSSODescriptor spSSODescriptor = new SPSSODescriptorBuilder().buildObject(); spSSODescriptor.setWantAssertionsSigned(true); spSSODescriptor.setAuthnRequestsSigned(true); spSSODescriptor.addSupportedProtocol(SAMLConstants.SAML20P_NS); X509KeyInfoGeneratorFactory keyInfoGeneratorFactory = new X509KeyInfoGeneratorFactory(); keyInfoGeneratorFactory.setEmitEntityCertificate(true); KeyInfoGenerator keyInfoGenerator = keyInfoGeneratorFactory.newInstance(); keyInfoGenerator.generate(loader.getCredential()); KeyDescriptor keyDescriptor = new KeyDescriptorBuilder().buildObject(); keyDescriptor.setKeyInfo(keyInfoGenerator.generate(loader.getCredential())); spSSODescriptor.getKeyDescriptors().add(keyDescriptor); NameIDFormat nameIDFormat = new NameIDFormatBuilder().buildObject(); nameIDFormat.setFormat(NameIDType.PERSISTENT); spSSODescriptor.getNameIDFormats().add(nameIDFormat); nameIDFormat = new NameIDFormatBuilder().buildObject(); nameIDFormat.setFormat(NameIDType.TRANSIENT); spSSODescriptor.getNameIDFormats().add(nameIDFormat); for (SAML2BindingType bindingType : SAML2BindingType.values()) { AssertionConsumerService assertionConsumerService = new AssertionConsumerServiceBuilder().buildObject(); assertionConsumerService.setIndex(bindingType.ordinal()); assertionConsumerService.setBinding(bindingType.getUri()); assertionConsumerService.setLocation(getAssertionConsumerURL(spEntityID, urlContext)); spSSODescriptor.getAssertionConsumerServices().add(assertionConsumerService); spEntityDescriptor.getRoleDescriptors().add(spSSODescriptor); String sloUrl = spEntityID + urlContext + "/logout"; validateUrl(sloUrl); SingleLogoutService singleLogoutService = new SingleLogoutServiceBuilder().buildObject(); singleLogoutService.setBinding(bindingType.getUri()); singleLogoutService.setLocation(sloUrl); singleLogoutService.setResponseLocation(sloUrl); spSSODescriptor.getSingleLogoutServices().add(singleLogoutService); } spEntityDescriptor.getRoleDescriptors().add(spSSODescriptor); saml2rw.sign(spEntityDescriptor); SAML2ReaderWriter.write(new OutputStreamWriter(os), spEntityDescriptor, true); } catch (Exception e) { LOG.error("While getting SP metadata", e); SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.Unknown); sce.getElements().add(e.getMessage()); throw sce; } }