/*
 * Copyright (c) 2002-2011 JSCAPE
 * 1147 S. 53rd Pl., Mesa, Arizona, 85206, U.S.A.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * JSCAPE. ("Confidential Information").  You shall not disclose such
 * Confidential Information and shall use it only in accordance with
 *  the terms of the license agreement you entered into with JSCAPE.
 */

package com.jscape.util.net.ssl;

import com.jscape.util.ArrayTools;

import javax.net.ssl.SSLEngine;

import static com.jscape.util.Parameters.assertNotNull;

/**
 * @author Alex Usun
 */
public class SslEngineServerParameters {

    public final boolean needClientAuth;
    public final boolean wantClientAuth;
    public final String[] enabledCipherSuites;
    public final String[] enabledProtocols;

    public SslEngineServerParameters(boolean needClientAuth,
                                     boolean wantClientAuth,
                                     String[] enabledCipherSuites,
                                     String[] enabledProtocols) {
        this.needClientAuth = needClientAuth;
        this.wantClientAuth = wantClientAuth;
        this.enabledCipherSuites = enabledCipherSuites;

        assertNotNull(enabledProtocols);
        this.enabledProtocols = enabledProtocols;
    }

    public void setup(SSLEngine engine) {
        engine.setUseClientMode(false);
        engine.setNeedClientAuth(this.needClientAuth);
        engine.setWantClientAuth(this.wantClientAuth);

        if (this.enabledCipherSuites != null && this.enabledCipherSuites.length > 0) {
            engine.setEnabledCipherSuites(this.enabledCipherSuites);
        }

        engine.setEnabledProtocols(this.enabledProtocols);
    }

    @Override
    public String toString() {
        return "SslEngineServerParameters {"
                + "needClientAuth=" + this.needClientAuth
                + ", wantClientAuth=" + this.wantClientAuth
                + ", enabledCipherSuites=" + ArrayTools.toString(this.enabledCipherSuites)
                + ", enabledProtocols=" + ArrayTools.toString(this.enabledProtocols)
                + '}';
    }
}
