001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.site; 029 030import org.opencms.main.OpenCms; 031import org.opencms.ui.CmsVaadinUtils; 032 033import java.util.ArrayList; 034import java.util.List; 035 036/** 037 * Enumeration for different SSL Modes of sites.<p> 038 */ 039public enum CmsSSLMode { 040 041 /**No encryption. */ 042 NO("no", Messages.GUI_SSL_MODE_NOSSL_0), 043 /**Manual ssl configuration of server. */ 044 MANUAL("manual", Messages.GUI_SSL_MODE_MANUAL_0), 045 /**Manual ssl configuration of server with endpoint termination. */ 046 MANUAL_EP_TERMINATION("manual-ep-termination", Messages.GUI_SSL_MODE_MANUAL_EP_0), 047 /**Encryption via Let's encrypt. */ 048 LETS_ENCRYPT("lets-encrypt", Messages.GUI_SSL_MODE_LETS_ENCRYPT_0), 049 /**Encryption via secure server (the old OpenCms way). */ 050 SECURE_SERVER("secure-server", Messages.GUI_SSL_MODE_SECURE_SERVER_0); 051 052 /**Message key for label. */ 053 private String m_message; 054 055 /**XML value representing mode. */ 056 private String m_xmlValue; 057 058 /** 059 * Constructor.<p> 060 * 061 * @param xmlValue xmlValue 062 * @param message Message 063 */ 064 CmsSSLMode(String xmlValue, String message) { 065 066 m_xmlValue = xmlValue; 067 m_message = message; 068 } 069 070 /** 071 * List of all available modes.<p> 072 * 073 * @param includeOldStyle include old Secure Server Styles? 074 * @param includeLetsEncrypt if true, include the LETS_ENCRYPT mode in the result 075 * 076 * @return List<CmsSSLMode> -- the list of available modes 077 */ 078 public static List<CmsSSLMode> availableModes(boolean includeOldStyle, boolean includeLetsEncrypt) { 079 080 includeOldStyle = includeOldStyle & OpenCms.getSiteManager().isOldStyleSecureServerAllowed(); 081 List<CmsSSLMode> res = new ArrayList<CmsSSLMode>(); 082 for (CmsSSLMode mode : values()) { 083 switch (mode) { 084 case SECURE_SERVER: 085 if (includeOldStyle) { 086 res.add(mode); 087 } 088 break; 089 case LETS_ENCRYPT: 090 if (includeLetsEncrypt) { 091 res.add(mode); 092 } 093 break; 094 default: 095 res.add(mode); 096 } 097 } 098 return res; 099 } 100 101 /** 102 * The default SSL Mode.<p> 103 * 104 * @return CmsSSLMode 105 */ 106 public static CmsSSLMode getDefault() { 107 108 if (OpenCms.getSiteManager().isOldStyleSecureServerAllowed()) { 109 return SECURE_SERVER; 110 } 111 return NO; 112 } 113 114 /** 115 * Gets CmsSSLMode from given XML value.<p> 116 * 117 * @param xmlValue to get CmsSSLMode for 118 * @return CmsSSLMode 119 */ 120 public static CmsSSLMode getModeFromXML(String xmlValue) { 121 122 for (CmsSSLMode mode : values()) { 123 if (mode.getXMLValue().equals(xmlValue)) { 124 return mode; 125 } 126 } 127 return SECURE_SERVER; 128 } 129 130 /** 131 * Gets localized message.<p> 132 * 133 * @return localized message 134 */ 135 public String getLocalizedMessage() { 136 137 return CmsVaadinUtils.getMessageText(m_message); 138 } 139 140 /** 141 * Gets the XML value.<p> 142 * 143 * @return the XML value 144 */ 145 public String getXMLValue() { 146 147 return m_xmlValue; 148 } 149 150 /** 151 * Returns if SSL Mode is secure.<p> 152 * 153 * @return true if secure 154 */ 155 public boolean isSecure() { 156 157 return this.equals(MANUAL_EP_TERMINATION) || this.equals(MANUAL) || this.equals(LETS_ENCRYPT); 158 } 159}