Package com.emc.vipr.client.core

Source Code of com.emc.vipr.client.core.Keystore

package com.emc.vipr.client.core;

import static com.emc.vipr.client.core.impl.PathConstants.KEYSTORE_URL;

import com.emc.vipr.client.impl.RestClient;
import com.emc.vipr.model.keystore.CertificateChain;
import com.emc.vipr.model.keystore.KeyAndCertificateChain;
import com.emc.vipr.model.keystore.RotateKeyAndCertParam;

/**
* Keystore resource.
* <p>
* Base URL: <tt>/keystore</tt>
*/
public class Keystore {

    protected final RestClient client;

    public Keystore(RestClient client) {
        this.client = client;
    }

    /**
     * Gets the certificate chain that identifies ViPR.
     * <p>
     * API Call: <tt>GET /keystore</tt>
     *
     * @return The Certificate chain
     */
    public CertificateChain getCertificateChain() {
        return client.get(CertificateChain.class, KEYSTORE_URL);
    }

    /**
     * Sets the key and certificate chain that ViPR uses for SSL communication.
     * <p>
     * API Call: <tt>PUT /vdc/keystore</tt>
     *
     * @param keyAndCert
     *            the new key and certificate
     *
     * @return The Certificate chain
     */
    public CertificateChain setKeyAndCertificateChain(KeyAndCertificateChain keyAndCert) {
        RotateKeyAndCertParam rotateKeyAndCertParam = new RotateKeyAndCertParam();
        rotateKeyAndCertParam.setSystemSelfSigned(false);
        rotateKeyAndCertParam.setKeyCertChain(keyAndCert);
        return client.put(CertificateChain.class, rotateKeyAndCertParam, KEYSTORE_URL);
    }

    /**
     * Makes ViPR generate a key and a self signed certificate to use for SSL
     * communication.
     * <p>
     * API Call: <tt>PUT /vdc/keystore</tt>
     *
     * @return The Certificate chain
     */
    public CertificateChain regenerateKeyAndCertificate() {
        RotateKeyAndCertParam rotateKeyAndCertParam = new RotateKeyAndCertParam();
        rotateKeyAndCertParam.setSystemSelfSigned(true);
        return client.put(CertificateChain.class, rotateKeyAndCertParam, KEYSTORE_URL);
    }

}
TOP

Related Classes of com.emc.vipr.client.core.Keystore

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.