Search in sources :

Example 6 with SamlClient

use of org.keycloak.protocol.saml.SamlClient in project keycloak by keycloak.

the class ModAuthMellonClientInstallation method generateInstallation.

@Override
public Response generateInstallation(KeycloakSession session, RealmModel realm, ClientModel client, URI serverBaseUri) {
    SamlClient samlClient = new SamlClient(client);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ZipOutputStream zip = new ZipOutputStream(baos);
    String idpDescriptor = SamlService.getIDPMetadataDescriptor(session.getContext().getUri(), session, realm);
    String spDescriptor = SamlSPDescriptorClientInstallation.getSPDescriptorForClient(client);
    String clientDirName = client.getClientId().replace('/', '_').replace(' ', '_');
    try {
        zip.putNextEntry(new ZipEntry(clientDirName + "/idp-metadata.xml"));
        zip.write(idpDescriptor.getBytes());
        zip.closeEntry();
        zip.putNextEntry(new ZipEntry(clientDirName + "/sp-metadata.xml"));
        zip.write(spDescriptor.getBytes());
        zip.closeEntry();
        if (samlClient.requiresClientSignature()) {
            if (samlClient.getClientSigningPrivateKey() != null) {
                zip.putNextEntry(new ZipEntry(clientDirName + "/client-private-key.pem"));
                zip.write(samlClient.getClientSigningPrivateKey().getBytes());
                zip.closeEntry();
            }
            if (samlClient.getClientSigningCertificate() != null) {
                zip.putNextEntry(new ZipEntry(clientDirName + "/client-cert.pem"));
                zip.write(samlClient.getClientSigningCertificate().getBytes());
                zip.closeEntry();
            }
        }
        zip.close();
        baos.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return Response.ok(baos.toByteArray(), getMediaType()).build();
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) SamlClient(org.keycloak.protocol.saml.SamlClient)

Example 7 with SamlClient

use of org.keycloak.protocol.saml.SamlClient in project keycloak by keycloak.

the class KeycloakSamlClientInstallation method generateInstallation.

@Override
public Response generateInstallation(KeycloakSession session, RealmModel realm, ClientModel client, URI baseUri) {
    SamlClient samlClient = new SamlClient(client);
    StringBuilder buffer = new StringBuilder();
    buffer.append("<keycloak-saml-adapter>\n");
    baseXml(session, realm, client, baseUri, samlClient, buffer);
    buffer.append("</keycloak-saml-adapter>\n");
    return Response.ok(buffer.toString(), MediaType.TEXT_PLAIN_TYPE).build();
}
Also used : SamlClient(org.keycloak.protocol.saml.SamlClient)

Aggregations

SamlClient (org.keycloak.protocol.saml.SamlClient)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 URI (java.net.URI)1 ZipEntry (java.util.zip.ZipEntry)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 Response (javax.ws.rs.core.Response)1 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)1 EntityDescriptorType (org.keycloak.dom.saml.v2.metadata.EntityDescriptorType)1 ClientSessionContext (org.keycloak.models.ClientSessionContext)1 UserModel (org.keycloak.models.UserModel)1 LoginProtocol (org.keycloak.protocol.LoginProtocol)1 LoginProtocolFactory (org.keycloak.protocol.LoginProtocolFactory)1 TokenExchangeSamlProtocol (org.keycloak.protocol.oidc.endpoints.TokenEndpoint.TokenExchangeSamlProtocol)1 SamlProtocol (org.keycloak.protocol.saml.SamlProtocol)1 SamlService (org.keycloak.protocol.saml.SamlService)1 AccessTokenResponse (org.keycloak.representations.AccessTokenResponse)1 SAMLMetadataWriter (org.keycloak.saml.processing.core.saml.v2.writers.SAMLMetadataWriter)1 CorsErrorResponseException (org.keycloak.services.CorsErrorResponseException)1