001/*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License").  You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
010 * or http://forgerock.org/license/CDDLv1.0.html.
011 * See the License for the specific language governing permissions
012 * and limitations under the License.
013 *
014 * When distributing Covered Code, include this CDDL HEADER in each
015 * file and include the License file at legal-notices/CDDLv1_0.txt.
016 * If applicable, add the following below this CDDL HEADER, with the
017 * fields enclosed by brackets "[]" replaced with your own identifying
018 * information:
019 *      Portions Copyright [yyyy] [name of copyright owner]
020 *
021 * CDDL HEADER END
022 *
023 *
024 *      Copyright 2008 Sun Microsystems, Inc.
025 */
026
027package org.opends.guitools.controlpanel.datamodel;
028
029
030 /**
031  * Policy to follow to choose the protocol to be used.
032  *
033  * */
034public enum ConnectionProtocolPolicy
035{
036  /**
037   * Force to use Start TLS.
038   */
039  USE_STARTTLS,
040  /**
041   * Force to use LDAP.
042   */
043  USE_LDAP,
044  /**
045   * Force to use LDAPs.
046   */
047  USE_LDAPS,
048  /**
049   * Force to use the Administration Connector.
050   */
051  USE_ADMIN,
052  /**
053   * Use the most secure available (LDAPs, StartTLS and finally LDAP).
054   */
055  USE_MOST_SECURE_AVAILABLE,
056  /**
057   * Use the less secure available (LDAP, and then LDAPs).
058   */
059  USE_LESS_SECURE_AVAILABLE;
060
061  /**
062   * Returns the ConnectionProtocolPolicy to be used with the parameters
063   * provided by the user.
064   * @param useSSL whether the user asked to use SSL or not.
065   * @param useStartTLS whether the user asked to use Start TLS or not.
066   * @return the ConnectionProtocolPolicy to be used with the parameters
067   * provided by the user.
068   */
069  public static ConnectionProtocolPolicy getConnectionPolicy(boolean useSSL,
070      boolean useStartTLS)
071  {
072    ConnectionProtocolPolicy policy;
073    if (useStartTLS)
074    {
075      policy = ConnectionProtocolPolicy.USE_STARTTLS;
076    }
077    else if (useSSL)
078    {
079      policy = ConnectionProtocolPolicy.USE_LDAPS;
080    }
081    else
082    {
083      policy = ConnectionProtocolPolicy.USE_LESS_SECURE_AVAILABLE;
084    }
085    return policy;
086  }
087}