try {
KeystoreInstance[] keystores = PortletManager.getCurrentServer(actionRequest).getKeystoreManager().getKeystores();
String[] keys = null;
for (int i = 0; i < keystores.length; i++) {
KeystoreInstance keystore = keystores[i];
if(keystore.getKeystoreName().equals(keyStore)) {
keys = keystore.getUnlockedKeys(null);
}
}
if(keys != null && keys.length == 1) {
setProperty(secure, "keyAlias", keys[0]);
} else {
throw new PortletException("Cannot handle keystores with anything but 1 unlocked private key");
}
} catch (KeystoreException e) {
throw new PortletException(e);
}
String trustStore = actionRequest.getParameter("unlockTrustStore");
// "" is a valid trustStore value, which means the parameter should be cleared
setProperty(secure, "trustStore", isValid(trustStore) ? trustStore : null);
} else if (server.equals(WEB_SERVER_TOMCAT)) {
if(isValid(truststoreType)) {setProperty(secure, "truststoreType", truststoreType);}
if(isValid(truststoreFile)) {setProperty(secure, "truststoreFileName", truststoreFile);}
if(isValid(truststorePass)) {setProperty(secure, "truststorePassword", truststorePass);}
} else {
//todo: Handle "should not occur" condition
}
}
// Start the connector
try {
((GeronimoManagedBean)connector).startRecursive();
} catch (Exception e) {
log.error("Unable to start connector", e); //todo: get into rendered page somehow?
}
actionResponse.setRenderParameter("mode", "list");
} else if(mode.equals("save")) { // User just submitted the form to update a connector
// Get submitted values
//todo: lots of validation
String host = actionRequest.getParameter("host");
int port = Integer.parseInt(actionRequest.getParameter("port"));
int maxThreads = Integer.parseInt(actionRequest.getParameter("maxThreads"));
Integer minThreads = getInteger(actionRequest, "minThreads");
String connectorURI = actionRequest.getParameter("connectorURI");
// Identify and update the connector
WebConnector connector = PortletManager.getWebConnector(actionRequest, new AbstractName(URI.create(connectorURI)));
if(connector != null) {
connector.setHost(host);
connector.setPort(port);
connector.setMaxThreads(maxThreads);
if(server.equals(WEB_SERVER_JETTY)) {
if(minThreads != null) {
setProperty(connector,"minThreads",minThreads);
}
else if (server.equals(WEB_SERVER_TOMCAT)) {
//todo: Any Tomcat specific processing?
}
else {
//todo: Handle "should not occur" condition
}
}
if(connector instanceof SecureConnector) {
String keystoreType = actionRequest.getParameter("keystoreType");
String keystoreFile = actionRequest.getParameter("keystoreFile");
String privateKeyPass = actionRequest.getParameter("privateKeyPassword");
String keystorePass = actionRequest.getParameter("keystorePassword");
String secureProtocol = actionRequest.getParameter("secureProtocol");
String algorithm = actionRequest.getParameter("algorithm");
String truststoreType = actionRequest.getParameter("truststoreType");
String truststoreFile = actionRequest.getParameter("truststoreFile");
String truststorePass = actionRequest.getParameter("truststorePassword");
boolean clientAuth = isValid(actionRequest.getParameter("clientAuth"));
SecureConnector secure = (SecureConnector) connector;
if(isValid(keystoreType)) {secure.setKeystoreType(keystoreType);}
if(isValid(keystoreFile)) {secure.setKeystoreFileName(keystoreFile);}
if(isValid(keystorePass)) {secure.setKeystorePassword(keystorePass);}
if(isValid(secureProtocol)) {secure.setSecureProtocol(secureProtocol);}
if(isValid(algorithm)) {secure.setAlgorithm(algorithm);}
secure.setClientAuthRequired(clientAuth);
if(server.equals(WEB_SERVER_JETTY)) {
if(isValid(privateKeyPass)) {setProperty(secure, "keyPassword", privateKeyPass);}
String keyStore = actionRequest.getParameter("unlockKeyStore");
String trustStore = actionRequest.getParameter("unlockTrustStore");
setProperty(secure, "keyStore", keyStore);
try {
KeystoreInstance[] keystores = PortletManager.getCurrentServer(actionRequest).getKeystoreManager().getKeystores();
String[] keys = null;
for (int i = 0; i < keystores.length; i++) {
KeystoreInstance keystore = keystores[i];
if(keystore.getKeystoreName().equals(keyStore)) {
keys = keystore.getUnlockedKeys(null);
}
}
if(keys != null && keys.length == 1) {
setProperty(secure, "keyAlias", keys[0]);
} else {