Fix sonar cloud code smells

This commit is contained in:
nvazquez 2022-08-15 12:47:53 -03:00
parent 2763218ce1
commit 92dc9a332a
No known key found for this signature in database
GPG Key ID: 656E1BCC8CB54F84
14 changed files with 107 additions and 86 deletions

View File

@ -23,15 +23,16 @@ import org.apache.cloudstack.framework.config.Configurable;
public interface ConsoleAccessManager extends Manager, Configurable {
ConfigKey<String> ConsoleProxySchema = new ConfigKey<>("Advanced", String.class,
ConfigKey<String> ConsoleProxySchema = new ConfigKey<>(ConfigKey.CATEGORY_ADVANCED, String.class,
"consoleproxy.schema", "http",
"The http/https schema to be used by the console proxy URLs", true);
ConfigKey<Boolean> ConsoleProxyExtraSecurityHeaderEnabled = new ConfigKey<>("Advanced", Boolean.class,
ConfigKey<Boolean> ConsoleProxyExtraSecurityHeaderEnabled = new ConfigKey<>(ConfigKey.CATEGORY_ADVANCED, Boolean.class,
"consoleproxy.extra.security.header.enabled", "false",
"Enable/disable extra security validation for console proxy using client header", true);
ConfigKey<String> ConsoleProxyExtraSecurityHeaderName = new ConfigKey<>("Advanced", String.class,
ConfigKey<String> ConsoleProxyExtraSecurityHeaderName = new ConfigKey<>(ConfigKey.CATEGORY_ADVANCED, String.class,
"consoleproxy.extra.security.header.name", "SECURITY_TOKEN",
"A client header for extra security validation when using the console proxy", true);

View File

@ -26,8 +26,16 @@ public class ConsoleProxyConnectionInfo {
public String tag;
public long createTime;
public long lastUsedTime;
public String sessionUuid;
protected String sessionUuid;
public ConsoleProxyConnectionInfo() {
}
public String getSessionUuid() {
return sessionUuid;
}
public void setSessionUuid(String sessionUuid) {
this.sessionUuid = sessionUuid;
}
}

View File

@ -42,18 +42,18 @@ public interface CapacityManager {
static final String StorageAllocatedCapacityDisableThresholdCK = "pool.storage.allocated.capacity.disablethreshold";
static final String VmwareCreateCloneFullCK = "vmware.create.full.clone";
static final ConfigKey<Float> CpuOverprovisioningFactor = new ConfigKey<Float>(Float.class, CpuOverprovisioningFactorCK, "Advanced", "1.0",
static final ConfigKey<Float> CpuOverprovisioningFactor = new ConfigKey<Float>(Float.class, CpuOverprovisioningFactorCK, ConfigKey.CATEGORY_ADVANCED, "1.0",
"Used for CPU overprovisioning calculation; available CPU will be (actualCpuCapacity * cpu.overprovisioning.factor)", true, ConfigKey.Scope.Cluster, null);
static final ConfigKey<Float> MemOverprovisioningFactor = new ConfigKey<Float>(Float.class, MemOverprovisioningFactorCK, "Advanced", "1.0",
static final ConfigKey<Float> MemOverprovisioningFactor = new ConfigKey<Float>(Float.class, MemOverprovisioningFactorCK, ConfigKey.CATEGORY_ADVANCED, "1.0",
"Used for memory overprovisioning calculation", true, ConfigKey.Scope.Cluster, null);
static final ConfigKey<Double> StorageCapacityDisableThreshold = new ConfigKey<Double>("Alert", Double.class, StorageCapacityDisableThresholdCK, "0.85",
static final ConfigKey<Double> StorageCapacityDisableThreshold = new ConfigKey<Double>(ConfigKey.CATEGORY_ALERT, Double.class, StorageCapacityDisableThresholdCK, "0.85",
"Percentage (as a value between 0 and 1) of storage utilization above which allocators will disable using the pool for low storage available.", true,
ConfigKey.Scope.Zone);
static final ConfigKey<Double> StorageOverprovisioningFactor = new ConfigKey<Double>("Storage", Double.class, StorageOverprovisioningFactorCK, "2",
"Used for storage overprovisioning calculation; available storage will be (actualStorageSize * storage.overprovisioning.factor)", true, ConfigKey.Scope.StoragePool);
static final ConfigKey<Double> StorageAllocatedCapacityDisableThreshold =
new ConfigKey<Double>(
"Alert",
ConfigKey.CATEGORY_ALERT,
Double.class,
StorageAllocatedCapacityDisableThresholdCK,
"0.85",
@ -63,7 +63,7 @@ public interface CapacityManager {
new ConfigKey<Boolean>(
Boolean.class,
"cluster.storage.operations.exclude",
"Advanced",
ConfigKey.CATEGORY_ADVANCED,
"false",
"Exclude cluster from storage operations",
true,
@ -82,14 +82,14 @@ public interface CapacityManager {
new ConfigKey<String>(
String.class,
"secstorage.nfs.version",
"Advanced",
ConfigKey.CATEGORY_ADVANCED,
null,
"Enforces specific NFS version when mounting Secondary Storage. If NULL default selection is performed",
true,
ConfigKey.Scope.ImageStore,
null);
static final ConfigKey<Float> SecondaryStorageCapacityThreshold = new ConfigKey<Float>("Advanced", Float.class, "secondary.storage.capacity.threshold", "0.90",
static final ConfigKey<Float> SecondaryStorageCapacityThreshold = new ConfigKey<Float>(ConfigKey.CATEGORY_ADVANCED, Float.class, "secondary.storage.capacity.threshold", "0.90",
"Percentage (as a value between 0 and 1) of secondary storage capacity threshold.", true);
public boolean releaseVmCapacity(VirtualMachine vm, boolean moveFromReserved, boolean moveToReservered, Long hostId);

View File

@ -30,6 +30,9 @@ import com.cloud.utils.exception.CloudRuntimeException;
*/
public class ConfigKey<T> {
public static final String CATEGORY_ADVANCED = "Advanced";
public static final String CATEGORY_ALERT = "Alert";
public static enum Scope {
Global, Zone, Cluster, StoragePool, Account, ManagementServer, ImageStore, Domain
}

View File

@ -49,9 +49,9 @@ import com.cloud.utils.ssh.SshHelper;
public final class LibvirtStartCommandWrapper extends CommandWrapper<StartCommand, Answer, LibvirtComputingResource> {
private static final Logger s_logger = Logger.getLogger(LibvirtStartCommandWrapper.class);
private static final int sshPort = Integer.parseInt(LibvirtComputingResource.DEFAULTDOMRSSHPORT);
private static final File pemFile = new File(LibvirtComputingResource.SSHPRVKEYPATH);
private static final String vncConfFileLocation = "/root/vncport";
private static final int SSH_PORT = Integer.parseInt(LibvirtComputingResource.DEFAULTDOMRSSHPORT);
private static final File PEM_FILE = new File(LibvirtComputingResource.SSHPRVKEYPATH);
private static final String VNC_CONF_FILE_LOCATION = "/root/vncport";
@Override
public Answer execute(final StartCommand command, final LibvirtComputingResource libvirtComputingResource) {
@ -113,14 +113,7 @@ public final class LibvirtStartCommandWrapper extends CommandWrapper<StartComman
}
if (vmSpec.getType() == VirtualMachine.Type.ConsoleProxy && vmSpec.getVncPort() != null) {
String novncPort = vmSpec.getVncPort();
try {
String addCmd = "echo " + novncPort + " > " + vncConfFileLocation;
SshHelper.sshExecute(controlIp, sshPort, "root",
pemFile, null, addCmd, 20000, 20000, 600000);
} catch (Exception e) {
s_logger.error("Could not set the noVNC port " + novncPort + " to the CPVM", e);
}
configureVncPortOnCpvm(vmSpec.getVncPort(), controlIp);
}
final VirtualRoutingResource virtRouterResource = libvirtComputingResource.getVirtRouterResource();
@ -161,6 +154,16 @@ public final class LibvirtStartCommandWrapper extends CommandWrapper<StartComman
}
}
private void configureVncPortOnCpvm(String novncPort, String controlIp) {
try {
String addCmd = "echo " + novncPort + " > " + VNC_CONF_FILE_LOCATION;
SshHelper.sshExecute(controlIp, SSH_PORT, "root",
LibvirtStartCommandWrapper.PEM_FILE, null, addCmd, 20000, 20000, 600000);
} catch (Exception e) {
s_logger.error("Could not set the noVNC port " + novncPort + " to the CPVM", e);
}
}
private void performAgentStartHook(String vmName, LibvirtComputingResource libvirtComputingResource) {
try {
LibvirtKvmAgentHook onStartHook = libvirtComputingResource.getStartHook();

View File

@ -46,6 +46,7 @@ import org.apache.cloudstack.consoleproxy.ConsoleAccessManager;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.managed.context.ManagedContext;
import org.apache.cloudstack.utils.consoleproxy.ConsoleAccessUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
@ -325,7 +326,7 @@ public class ApiServlet extends HttpServlet {
InetAddress addr = getClientAddress(req);
String clientAddress = addr != null ? addr.getHostAddress() : null;
params.put(ConsoleAccessUtils.CLIENT_INET_ADDRESS_KEY, new String[]{clientAddress});
if (ConsoleAccessManager.ConsoleProxyExtraSecurityHeaderEnabled.value()) {
if (BooleanUtils.isTrue(ConsoleAccessManager.ConsoleProxyExtraSecurityHeaderEnabled.value())) {
String clientSecurityToken = req.getHeader(ConsoleAccessManager.ConsoleProxyExtraSecurityHeaderName.value());
params.put(ConsoleAccessUtils.CLIENT_SECURITY_HEADER_PARAM_KEY, new String[]{clientSecurityToken});
}

View File

@ -71,7 +71,7 @@ public abstract class AgentHookBase implements AgentHook {
KeysManager _keysMgr;
ConsoleAccessManager consoleAccessManager;
public AgentHookBase(VMInstanceDao instanceDao, HostDao hostDao, ConfigurationDao cfgDao, KeystoreManager ksMgr,
protected AgentHookBase(VMInstanceDao instanceDao, HostDao hostDao, ConfigurationDao cfgDao, KeystoreManager ksMgr,
AgentManager agentMgr, KeysManager keysMgr, ConsoleAccessManager consoleAccessMgr) {
_instanceDao = instanceDao;
_hostDao = hostDao;

View File

@ -67,22 +67,22 @@ import java.util.UUID;
public class ConsoleAccessManagerImpl extends ManagerBase implements ConsoleAccessManager {
@Inject
private AccountManager _accountMgr;
private AccountManager accountManager;
@Inject
private VirtualMachineManager _vmMgr;
private VirtualMachineManager virtualMachineManager;
@Inject
private ManagementServer _ms;
private ManagementServer managementServer;
@Inject
private EntityManager _entityMgr;
private EntityManager entityManager;
@Inject
private UserVmDetailsDao _userVmDetailsDao;
private UserVmDetailsDao userVmDetailsDao;
@Inject
private KeysManager _keysMgr;
private KeysManager keysManager;
@Inject
private AgentManager agentManager;
private static KeysManager s_keysMgr;
private final Gson _gson = new GsonBuilder().create();
private static KeysManager secretKeysManager;
private final Gson gson = new GsonBuilder().create();
public static final Logger s_logger = Logger.getLogger(ConsoleAccessManagerImpl.class.getName());
@ -90,19 +90,19 @@ public class ConsoleAccessManagerImpl extends ManagerBase implements ConsoleAcce
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
s_keysMgr = _keysMgr;
allowedSessions = new HashSet<>();
ConsoleAccessManagerImpl.secretKeysManager = keysManager;
ConsoleAccessManagerImpl.allowedSessions = new HashSet<>();
return super.configure(name, params);
}
@Override
public ConsoleEndpoint generateConsoleEndpoint(Long vmId, String clientSecurityToken, String clientAddress) {
try {
if (_accountMgr == null || _vmMgr == null || _ms == null) {
if (accountManager == null || virtualMachineManager == null || managementServer == null) {
return new ConsoleEndpoint(false, null,"Console service is not ready");
}
if (_keysMgr.getHashKey() == null) {
if (keysManager.getHashKey() == null) {
String msg = "Console access denied. Ticket service is not ready yet";
s_logger.debug(msg);
return new ConsoleEndpoint(false, null, msg);
@ -116,7 +116,7 @@ public class ConsoleAccessManagerImpl extends ManagerBase implements ConsoleAcce
return new ConsoleEndpoint(false, null,"Access denied. Invalid or inconsistent account is found");
}
VirtualMachine vm = _entityMgr.findById(VirtualMachine.class, vmId);
VirtualMachine vm = entityManager.findById(VirtualMachine.class, vmId);
if (vm == null) {
s_logger.info("Invalid console servlet command parameter: " + vmId);
return new ConsoleEndpoint(false, null, "Cannot find VM with ID " + vmId);
@ -128,8 +128,8 @@ public class ConsoleAccessManagerImpl extends ManagerBase implements ConsoleAcce
String sessionToken = UUID.randomUUID().toString();
return generateAccessEndpoint(vmId, sessionToken, clientSecurityToken, clientAddress);
} catch (Throwable e) {
s_logger.error("Unexepected exception in ConsoleProxyServlet", e);
} catch (Exception e) {
s_logger.error("Unexepected exception in ConsoleAccessManager", e);
return new ConsoleEndpoint(false, null, "Server Internal Error: " + e.getMessage());
}
}
@ -147,26 +147,24 @@ public class ConsoleAccessManagerImpl extends ManagerBase implements ConsoleAcce
}
private boolean checkSessionPermision(VirtualMachine vm, Account account) {
if (_accountMgr.isRootAdmin(account.getId())) {
if (accountManager.isRootAdmin(account.getId())) {
return true;
}
switch (vm.getType()) {
case User:
try {
_accountMgr.checkAccess(account, null, true, vm);
accountManager.checkAccess(account, null, true, vm);
} catch (PermissionDeniedException ex) {
if (_accountMgr.isNormalUser(account.getId())) {
if (accountManager.isNormalUser(account.getId())) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("VM access is denied. VM owner account " + vm.getAccountId() + " does not match the account id in session " +
account.getId() + " and caller is a normal user");
}
} else if (_accountMgr.isDomainAdmin(account.getId())
|| account.getType() == Account.Type.READ_ONLY_ADMIN) {
if(s_logger.isDebugEnabled()) {
s_logger.debug("VM access is denied. VM owner account " + vm.getAccountId()
+ " does not match the account id in session " + account.getId() + " and the domain-admin caller does not manage the target domain");
}
} else if ((accountManager.isDomainAdmin(account.getId())
|| account.getType() == Account.Type.READ_ONLY_ADMIN) && s_logger.isDebugEnabled()) {
s_logger.debug("VM access is denied. VM owner account " + vm.getAccountId()
+ " does not match the account id in session " + account.getId() + " and the domain-admin caller does not manage the target domain");
}
return false;
}
@ -186,7 +184,7 @@ public class ConsoleAccessManagerImpl extends ManagerBase implements ConsoleAcce
}
private ConsoleEndpoint generateAccessEndpoint(Long vmId, String sessionToken, String clientSecurityToken, String clientAddress) {
VirtualMachine vm = _vmMgr.findById(vmId);
VirtualMachine vm = virtualMachineManager.findById(vmId);
String msg;
if (vm == null) {
msg = "VM " + vmId + " does not exist, sending blank response for console access request";
@ -200,7 +198,7 @@ public class ConsoleAccessManagerImpl extends ManagerBase implements ConsoleAcce
throw new CloudRuntimeException(msg);
}
HostVO host = _ms.getHostBy(vm.getHostId());
HostVO host = managementServer.getHostBy(vm.getHostId());
if (host == null) {
msg = "VM " + vmId + "'s host does not exist, sending blank response for console access request";
s_logger.warn(msg);
@ -211,7 +209,7 @@ public class ConsoleAccessManagerImpl extends ManagerBase implements ConsoleAcce
throw new CloudRuntimeException("Console access is not supported for LXC");
}
String rootUrl = _ms.getConsoleAccessUrlRoot(vmId);
String rootUrl = managementServer.getConsoleAccessUrlRoot(vmId);
if (rootUrl == null) {
throw new CloudRuntimeException("Console access will be ready in a few minutes. Please try it again later.");
}
@ -223,15 +221,15 @@ public class ConsoleAccessManagerImpl extends ManagerBase implements ConsoleAcce
private ConsoleEndpoint composeConsoleAccessEndpoint(String rootUrl, VirtualMachine vm, HostVO hostVo, String addr,
String sessionUuid, String clientSecurityToken) {
StringBuffer sb = new StringBuffer(rootUrl);
StringBuilder sb = new StringBuilder(rootUrl);
String host = hostVo.getPrivateIpAddress();
Pair<String, Integer> portInfo = null;
if (hostVo.getHypervisorType() == Hypervisor.HypervisorType.KVM &&
(hostVo.getResourceState().equals(ResourceState.ErrorInMaintenance) ||
hostVo.getResourceState().equals(ResourceState.ErrorInPrepareForMaintenance))) {
UserVmDetailVO detailAddress = _userVmDetailsDao.findDetail(vm.getId(), VmDetailConstants.KVM_VNC_ADDRESS);
UserVmDetailVO detailPort = _userVmDetailsDao.findDetail(vm.getId(), VmDetailConstants.KVM_VNC_PORT);
UserVmDetailVO detailAddress = userVmDetailsDao.findDetail(vm.getId(), VmDetailConstants.KVM_VNC_ADDRESS);
UserVmDetailVO detailPort = userVmDetailsDao.findDetail(vm.getId(), VmDetailConstants.KVM_VNC_PORT);
if (detailAddress != null && detailPort != null) {
portInfo = new Pair<>(detailAddress.getValue(), Integer.valueOf(detailPort.getValue()));
} else {
@ -241,7 +239,7 @@ public class ConsoleAccessManagerImpl extends ManagerBase implements ConsoleAcce
}
if (portInfo == null) {
portInfo = _ms.getVncPort(vm);
portInfo = managementServer.getVncPort(vm);
}
if (s_logger.isDebugEnabled())
@ -252,13 +250,13 @@ public class ConsoleAccessManagerImpl extends ManagerBase implements ConsoleAcce
int port = -1;
if (portInfo.second() == -9) {
//for hyperv
port = Integer.parseInt(_ms.findDetail(hostVo.getId(), "rdp.server.port").getValue());
port = Integer.parseInt(managementServer.findDetail(hostVo.getId(), "rdp.server.port").getValue());
} else {
port = portInfo.second();
}
String sid = vm.getVncPassword();
UserVmDetailVO details = _userVmDetailsDao.findDetail(vm.getId(), VmDetailConstants.KEYBOARD);
UserVmDetailVO details = userVmDetailsDao.findDetail(vm.getId(), VmDetailConstants.KEYBOARD);
String tag = vm.getUuid();
@ -290,8 +288,8 @@ public class ConsoleAccessManagerImpl extends ManagerBase implements ConsoleAcce
if (portInfo.second() == -9) {
//For Hyperv Clinet Host Address will send Instance id
param.setHypervHost(host);
param.setUsername(_ms.findDetail(hostVo.getId(), "username").getValue());
param.setPassword(_ms.findDetail(hostVo.getId(), "password").getValue());
param.setUsername(managementServer.findDetail(hostVo.getId(), "username").getValue());
param.setPassword(managementServer.findDetail(hostVo.getId(), "password").getValue());
}
if (parsedHostInfo.second() != null && parsedHostInfo.third() != null) {
param.setClientTunnelUrl(parsedHostInfo.second());
@ -310,7 +308,7 @@ public class ConsoleAccessManagerImpl extends ManagerBase implements ConsoleAcce
// for console access, we need guest OS type to help implement keyboard
long guestOs = vm.getGuestOSId();
GuestOSVO guestOsVo = _ms.getGuestOs(guestOs);
GuestOSVO guestOsVo = managementServer.getGuestOs(guestOs);
if (guestOsVo.getCategoryId() == 6)
sb.append("&guest=windows");
@ -323,7 +321,7 @@ public class ConsoleAccessManagerImpl extends ManagerBase implements ConsoleAcce
return new ConsoleEndpoint(true, url);
}
static public Ternary<String, String, String> parseHostInfo(String hostInfo) {
public static Ternary<String, String, String> parseHostInfo(String hostInfo) {
String host = null;
String tunnelUrl = null;
String tunnelSession = null;
@ -332,7 +330,7 @@ public class ConsoleAccessManagerImpl extends ManagerBase implements ConsoleAcce
if (hostInfo != null) {
if (hostInfo.startsWith("consoleurl")) {
String tokens[] = hostInfo.split("&");
String[] tokens = hostInfo.split("&");
if (hostInfo.length() > 19 && hostInfo.indexOf('/', 19) > 19) {
host = hostInfo.substring(19, hostInfo.indexOf('/', 19)).trim();
@ -350,7 +348,7 @@ public class ConsoleAccessManagerImpl extends ManagerBase implements ConsoleAcce
host = hostInfo;
}
return new Ternary<String, String, String>(host, tunnelUrl, tunnelSession);
return new Ternary<>(host, tunnelUrl, tunnelSession);
}
/**
@ -373,7 +371,7 @@ public class ConsoleAccessManagerImpl extends ManagerBase implements ConsoleAcce
long ts = normalizedHashTime.getTime();
ts = ts / 60000; // round up to 1 minute
String secretKey = s_keysMgr.getHashKey();
String secretKey = secretKeysManager.getHashKey();
SecretKeySpec keySpec = new SecretKeySpec(secretKey.getBytes(), mac.getAlgorithm());
mac.init(keySpec);
@ -390,11 +388,11 @@ public class ConsoleAccessManagerImpl extends ManagerBase implements ConsoleAcce
}
private String getEncryptorPassword() {
String key = _keysMgr.getEncryptionKey();
String iv = _keysMgr.getEncryptionIV();
String key = keysManager.getEncryptionKey();
String iv = keysManager.getEncryptionIV();
ConsoleProxyPasswordBasedEncryptor.KeyIVPair keyIvPair = new ConsoleProxyPasswordBasedEncryptor.KeyIVPair(key, iv);
return _gson.toJson(keyIvPair);
return gson.toJson(keyIvPair);
}
/**

View File

@ -36,13 +36,13 @@ public interface ConsoleProxyManager extends Manager, ConsoleProxyService {
String ALERT_SUBJECT = "proxy-alert";
String CERTIFICATE_NAME = "CPVMCertificate";
ConfigKey<Boolean> NoVncConsoleDefault = new ConfigKey<Boolean>("Advanced", Boolean.class, "novnc.console.default", "true",
ConfigKey<Boolean> NoVncConsoleDefault = new ConfigKey<>(ConfigKey.CATEGORY_ADVANCED, Boolean.class, "novnc.console.default", "true",
"If true, noVNC console will be default console for virtual machines", true);
ConfigKey<Boolean> NoVncConsoleSourceIpCheckEnabled = new ConfigKey<Boolean>("Advanced", Boolean.class, "novnc.console.sourceip.check.enabled", "false",
ConfigKey<Boolean> NoVncConsoleSourceIpCheckEnabled = new ConfigKey<>(ConfigKey.CATEGORY_ADVANCED, Boolean.class, "novnc.console.sourceip.check.enabled", "false",
"If true, The source IP to access novnc console must be same as the IP in request to management server for console URL. Needs to reconnect CPVM to management server when this changes (via restart CPVM, or management server, or cloud service in CPVM)", false);
ConfigKey<Integer> NoVncConsolePort = new ConfigKey<>("Advanced", Integer.class, "novnc.console.port",
ConfigKey<Integer> NoVncConsolePort = new ConfigKey<>(ConfigKey.CATEGORY_ADVANCED, Integer.class, "novnc.console.port",
"8080", "The listen port for noVNC console", true);
void setManagementState(ConsoleProxyManagementState state);

View File

@ -977,7 +977,7 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy
}
});
}
} catch (Throwable e) {
} catch (Exception e) {
s_logger.error(String.format("Unable to set console proxy management state to [%s] due to [%s].", state, e.getMessage()), e);
}
}
@ -1012,7 +1012,7 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy
if (lastState != state) {
configurationDao.update(Config.ConsoleProxyManagementState.key(), Config.ConsoleProxyManagementState.getCategory(), lastState.toString());
}
} catch (Throwable e) {
} catch (Exception e) {
s_logger.error(String.format("Unable to resume last management state due to [%s].", e.getMessage()), e);
}
}

View File

@ -179,7 +179,7 @@ public class ConsoleProxyServlet extends HttpServlet {
} else {
handleAuthRequest(req, resp, vmId);
}
} catch (Throwable e) {
} catch (Exception e) {
s_logger.error("Unexepected exception in ConsoleProxyServlet", e);
sendResponse(resp, "Server Internal Error");
}

View File

@ -74,7 +74,7 @@ public class ConsoleProxyClientStatsCollector {
conn.tag = client.getClientTag();
conn.createTime = client.getClientCreateTime();
conn.lastUsedTime = client.getClientLastFrontEndActivityTime();
conn.sessionUuid = client.getSessionUuid();
conn.setSessionUuid(client.getSessionUuid());
conns.add(conn);
}
}
@ -89,7 +89,15 @@ public class ConsoleProxyClientStatsCollector {
public String tag;
public long createTime;
public long lastUsedTime;
public String sessionUuid;
protected String sessionUuid;
public String getSessionUuid() {
return sessionUuid;
}
public void setSessionUuid(String sessionUuid) {
this.sessionUuid = sessionUuid;
}
public ConsoleProxyConnection() {
}

View File

@ -34,7 +34,7 @@ import org.eclipse.jetty.util.ssl.SslContextFactory;
public class ConsoleProxyNoVNCServer {
private static final Logger s_logger = Logger.getLogger(ConsoleProxyNoVNCServer.class);
private static int wsPort = 8080;
private static int WS_PORT = 8080;
private static final String vncConfFileLocation = "/root/vncport";
private Server server;
@ -42,8 +42,8 @@ public class ConsoleProxyNoVNCServer {
private void init() {
try {
String portStr = Files.readString(Path.of(vncConfFileLocation)).trim();
wsPort = Integer.parseInt(portStr);
s_logger.info("Setting port to: " + wsPort);
ConsoleProxyNoVNCServer.WS_PORT = Integer.parseInt(portStr);
s_logger.info("Setting port to: " + WS_PORT);
} catch (Exception e) {
s_logger.error("Error loading properties from " + vncConfFileLocation, e);
}
@ -51,7 +51,7 @@ public class ConsoleProxyNoVNCServer {
public ConsoleProxyNoVNCServer() {
init();
this.server = new Server(wsPort);
this.server = new Server(WS_PORT);
ConsoleProxyNoVNCHandler handler = new ConsoleProxyNoVNCHandler();
this.server.setHandler(handler);
}
@ -65,7 +65,7 @@ public class ConsoleProxyNoVNCServer {
try {
final HttpConfiguration httpConfig = new HttpConfiguration();
httpConfig.setSecureScheme("https");
httpConfig.setSecurePort(wsPort);
httpConfig.setSecurePort(WS_PORT);
final HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig);
httpsConfig.addCustomizer(new SecureRequestCustomizer());
@ -81,7 +81,7 @@ public class ConsoleProxyNoVNCServer {
final ServerConnector sslConnector = new ServerConnector(server,
new SslConnectionFactory(sslContextFactory, "http/1.1"),
new HttpConnectionFactory(httpsConfig));
sslConnector.setPort(wsPort);
sslConnector.setPort(WS_PORT);
server.addConnector(sslConnector);
} catch (Exception e) {
s_logger.error("Unable to secure server due to exception ", e);

View File

@ -16,12 +16,11 @@
// under the License.
package org.apache.cloudstack.utils.consoleproxy;
import org.apache.log4j.Logger;
public class ConsoleAccessUtils {
public static final Logger s_logger = Logger.getLogger(ConsoleAccessUtils.class.getName());
private ConsoleAccessUtils() {
}
public static String CLIENT_SECURITY_HEADER_PARAM_KEY = "client-security-token";
public static String CLIENT_INET_ADDRESS_KEY = "client-inet-address";
public static final String CLIENT_SECURITY_HEADER_PARAM_KEY = "client-security-token";
public static final String CLIENT_INET_ADDRESS_KEY = "client-inet-address";
}