Commit cc7c6b27 authored by Malo Toudic's avatar Malo Toudic
Browse files
parent ab035da8
......@@ -21,4 +21,6 @@ INSERT INTO app_configuration (id, variable, value) VALUES (nextval('app_configu
INSERT INTO app_configuration (id, variable, value) VALUES (nextval('app_configuration_id_seq'), 'project_directory', '/opt/gazelle-webservice-tester/projects/');
INSERT INTO app_configuration (id, variable, value) VALUES (nextval('app_configuration_id_seq'), 'tm_url', 'https://ehealthsuisse.ihe-europe.net/gazelle/');
INSERT INTO app_configuration (id, variable, value) VALUES (nextval('app_configuration_id_seq'), 'keystore_directory', '/opt/gazelle-webservice-tester/keystores/');
INSERT INTO app_configuration (id, variable, value) VALUES (nextval('app_configuration_id_seq'), 'logs_directory', '/opt/gazelle-webservice-tester/logs/');
\ No newline at end of file
INSERT INTO app_configuration (id, variable, value) VALUES (nextval('app_configuration_id_seq'), 'logs_directory', '/opt/gazelle-webservice-tester/logs/');
INSERT INTO app_configuration (id, variable, value)
VALUES (nextval('app_configuration_id_seq'), 'ehealthsuisse', 'false');
\ No newline at end of file
......@@ -57,3 +57,6 @@ ALTER TABLE gwt_test_component
UPDATE gwt_test_component
SET disable = FALSE;
INSERT INTO app_configuration (id, variable, value)
VALUES (nextval('app_configuration_id_seq'), 'ehealthsuisse', 'false');
......@@ -191,7 +191,6 @@
<groupId>net.ihe.gazelle.maven</groupId>
<artifactId>GazelleTRMClient</artifactId>
<version>1.1.0-SNAPSHOT</version>
</dependency>
<dependency>
......
package net.ihe.gazelle.wstester.action;
import net.ihe.gazelle.wstester.dao.KeystoreDao;
import net.ihe.gazelle.wstester.model.Keystore;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.faces.Converter;
import org.jboss.seam.annotations.intercept.BypassInterceptors;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
@Name("keystoreConverter")
@BypassInterceptors
@Converter(forClass = Keystore.class)
public class KeystoreConverter implements javax.faces.convert.Converter {
@Override
public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String s) {
return KeystoreDao.getKeystoreByLabel(s);
}
@Override
public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object o) {
if (o instanceof Keystore) {
Keystore keystore = (Keystore) o;
return keystore.getLabel();
} else {
return null;
}
}
}
package net.ihe.gazelle.wstester.action;
import net.ihe.gazelle.common.filter.Filter;
import net.ihe.gazelle.common.filter.FilterDataModel;
import net.ihe.gazelle.hql.criterion.HQLCriterionsForFilter;
import net.ihe.gazelle.hql.providers.EntityManagerService;
import net.ihe.gazelle.preferences.PreferenceService;
import net.ihe.gazelle.wstester.dao.KeystoreDao;
import net.ihe.gazelle.wstester.model.Keystore;
import net.ihe.gazelle.wstester.model.KeystoreQuery;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.faces.FacesMessages;
import org.jboss.seam.international.StatusMessage;
import org.richfaces.event.FileUploadEvent;
import org.richfaces.model.UploadedFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.faces.context.FacesContext;
import javax.persistence.EntityManager;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@Name("keystoreManager")
@Scope(ScopeType.PAGE)
public class KeystoreManager {
private static final Logger LOG = LoggerFactory.getLogger(KeystoreManager.class);
boolean addKeystore = false;
Keystore newKeystore = null;
Keystore keystoreToDelete = null;
private FilterDataModel<Keystore> keystores;
private Filter<Keystore> filter;
public FilterDataModel<Keystore> getKeystores() {
return new FilterDataModel<Keystore>(getFilter()) {
@Override
protected Object getId(Keystore keystore) {
return keystore.getId();
}
};
}
public Filter<Keystore> getFilter() {
if (filter == null) {
Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
this.filter = new Filter(this.getHqlCriterions(), params);
}
return this.filter;
}
private HQLCriterionsForFilter getHqlCriterions() {
KeystoreQuery query = new KeystoreQuery();
HQLCriterionsForFilter criterion = query.getHQLCriterionsForFilter();
criterion.addPath("label", query.label());
criterion.addPath("path", query.path());
criterion.addPath("password", query.password());
return criterion;
}
public boolean isAddKeystore() {
return addKeystore;
}
public void setAddKeystore(boolean addKeystore) {
this.addKeystore = addKeystore;
}
public Keystore getNewKeystore() {
return newKeystore;
}
public void setNewKeystore(Keystore newKeystore) {
this.newKeystore = newKeystore;
}
public void merge() {
merge(newKeystore);
cancel();
}
public void merge(Keystore keystoreToMerge) {
List<Keystore> keystoreList = KeystoreDao.getAllKeystores();
if (keystoreList != null) {
for (Keystore callingTool : keystoreList) {
if (keystoreToMerge.getLabel().equals(callingTool.getLabel()) && keystoreToMerge.getId() != callingTool.getId()) {
FacesMessages.instance().add(StatusMessage.Severity.ERROR, "There is already a keystore with this name");
return;
}
}
}
keystoreToMerge.save();
}
public void uploadEventListener(final FileUploadEvent event) {
FileOutputStream fos = null;
try {
final UploadedFile item = event.getUploadedFile();
if (PreferenceService.getString("keystore_directory") != null) {
newKeystore = new Keystore(item.getName(), PreferenceService.getString("keystore_directory") + UUID.randomUUID() + item.getName());
newKeystore.setDefaultKeystore(false);
File uploadedFile = new File(newKeystore.getPath());
uploadedFile.getParentFile().mkdirs();
if (uploadedFile.getParentFile().exists()) {
if (uploadedFile.createNewFile()) {
if (item.getData() != null && item.getData().length > 0) {
fos = new FileOutputStream(uploadedFile);
fos.write(item.getData());
} else {
newKeystore.setPath(null);
}
} else {
LOG.error("uploadEventListener() : file " + newKeystore.getPath() + " couldn't be created");
}
} else {
LOG.error("uploadEventListener() : directory " + newKeystore.getPath() + " couldn't be created");
}
} else {
LOG.error("The app preference project_directory is not set");
FacesMessages.instance().add(StatusMessage.Severity.ERROR, "The property project_directory is not set in the application configuration");
}
} catch (final IOException e) {
LOG.error(e.getMessage());
} catch (Exception e) {
LOG.error(e.getMessage());
} finally {
if (fos != null) {
try {
fos.close();
} catch (final IOException e) {
LOG.error("not able to close the FOS", e);
}
}
}
}
public void setDefault(Keystore keystoreToDefault) {
List<Keystore> keystoreList = KeystoreDao.getAllKeystores();
for (Keystore keystore : keystoreList) {
if (keystore.equals(keystoreToDefault)) {
keystore.setDefaultKeystore(true);
} else {
keystore.setDefaultKeystore(false);
}
}
}
public Keystore getKeystoreToDelete() {
return keystoreToDelete;
}
public void setKeystoreToDelete(Keystore keystoreToDelete) {
this.keystoreToDelete = keystoreToDelete;
}
public void delete() {
EntityManager entityManager = EntityManagerService.provideEntityManager();
entityManager.remove(entityManager.contains(keystoreToDelete) ? keystoreToDelete : entityManager.merge(keystoreToDelete));
entityManager.flush();
}
public void cancel() {
newKeystore = null;
addKeystore = false;
}
public void addNewKeystore() {
newKeystore = new Keystore();
addKeystore = true;
}
public void setMessageInvalidFileType() {
FacesMessages.instance().add(StatusMessage.Severity.ERROR, "Invalid file type. Expected file type is jks");
}
public void reset() {
if (this.filter != null) {
this.filter.clear();
}
}
}
......@@ -3,8 +3,6 @@ package net.ihe.gazelle.wstester.action;
import com.eviware.soapui.SoapUI;
import com.eviware.soapui.impl.wsdl.WsdlProject;
import com.eviware.soapui.impl.wsdl.WsdlTestSuite;
import com.eviware.soapui.impl.wsdl.support.wss.WssCrypto;
import com.eviware.soapui.impl.wsdl.support.wss.crypto.KeyMaterialWssCrypto;
import com.eviware.soapui.impl.wsdl.testcase.WsdlProjectRunner;
import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase;
import com.eviware.soapui.impl.wsdl.teststeps.WsdlMessageExchangeTestStepResult;
......@@ -26,6 +24,7 @@ import net.ihe.gazelle.ws.client.GazelleTRMServiceStub;
import net.ihe.gazelle.wstester.dao.ExecutionDao;
import net.ihe.gazelle.wstester.dao.GwtTestStepDao;
import net.ihe.gazelle.wstester.dao.GwtTestSuiteDao;
import net.ihe.gazelle.wstester.dao.KeystoreDao;
import net.ihe.gazelle.wstester.model.*;
import net.ihe.gazelle.wstester.util.Application;
import net.ihe.gazelle.wstester.util.WsClient;
......@@ -141,7 +140,7 @@ public class RunInstanceAction {
prepareExecution();
if (PreferenceService.getString("keystore_directory") != null) {
componentToExecute = execution.getTestInstanceResult().getTestSuite();
WsdlProject wsdlProject = createProjectWithKeyStore("soapui.jks", PreferenceService.getString("keystore_directory"));
WsdlProject wsdlProject = createWsdlProject();
List<TestCaseRunner> testCaseRunnerList = (List<TestCaseRunner>) (List<?>) startExecution(wsdlProject);
if (!testCaseRunnerList.isEmpty()) {
List<GwtTestStepResult> gwtTestStepResultList = iterateThroughTestCaseRunnerList(testCaseRunnerList);
......@@ -158,8 +157,7 @@ public class RunInstanceAction {
public Execution run() {
prepareExecution();
WsdlProject wsdlProject = createProjectWithKeyStore("soapui.jks", PreferenceService.getString("keystore_directory"));
//WsdlProject wsdlProject = createWsdlProject();
WsdlProject wsdlProject = createWsdlProject();
List<TestRunner> testRunners = startExecution(wsdlProject);
if (!testRunners.isEmpty()) {
List<GwtTestStepResult> gwtTestStepResultList;
......@@ -179,7 +177,11 @@ public class RunInstanceAction {
List<TestRunner> listResult = new ArrayList<>();
if (project != null) {
setCustomPropertiesInSoapUi(project);
addKeystores(execution.getKeystores());
if (currentProject.getKeystore() != null) {
addKeystore(currentProject.getKeystore());
} else if (KeystoreDao.getDefaultKeystore() != null) {
addKeystore(KeystoreDao.getDefaultKeystore());
}
project.getSettings().setBoolean(HttpSettings.RESPONSE_COMPRESSION, false);
if (componentToExecute instanceof GwtProject) {
project.setAbortOnError(false);
......@@ -550,28 +552,11 @@ public class RunInstanceAction {
}
}
public WsdlProject createProjectWithKeyStore(String keystore, String PathToKeystore) {
WsdlProject project = createWsdlProject();
if (project != null) {
List<WssCrypto> listCrypto = project.getWssContainer().getCryptoList();
for (WssCrypto crypto : listCrypto) {
if (crypto.getLabel().equals(keystore)) {
KeyMaterialWssCrypto cryptoAccess = (KeyMaterialWssCrypto) crypto;
cryptoAccess.setSource(PathToKeystore + keystore);
}
}
}
return project;
}
public void addKeystores(List<Keystore> keystoreList) {
if (keystoreList != null) {
for (Keystore keystore : keystoreList) {
SoapUI.getSettings().setString(SSLSettings.KEYSTORE, keystore.getPath());
if (keystore.getPassword() != null) {
SoapUI.getSettings().setString(SSLSettings.KEYSTORE_PASSWORD, keystore.getPassword());
}
public void addKeystore(Keystore keystore) {
if (keystore != null) {
SoapUI.getSettings().setString(SSLSettings.KEYSTORE, keystore.getPath());
if (keystore.getPassword() != null) {
SoapUI.getSettings().setString(SSLSettings.KEYSTORE_PASSWORD, keystore.getPassword());
}
SoapUI.getSettings().setBoolean(HttpSettings.AUTHENTICATE_PREEMPTIVELY, true);
}
......
......@@ -7,6 +7,7 @@ import com.eviware.soapui.model.testsuite.TestStep;
import com.eviware.soapui.model.testsuite.TestSuite;
import net.ihe.gazelle.common.tree.GazelleTreeNodeImpl;
import net.ihe.gazelle.preferences.PreferenceService;
import net.ihe.gazelle.wstester.dao.KeystoreDao;
import net.ihe.gazelle.wstester.dao.SoapuiProjectDao;
import net.ihe.gazelle.wstester.model.*;
import net.ihe.gazelle.wstester.util.Application;
......@@ -204,7 +205,7 @@ public class UploadProject implements Serializable {
private void moveTmpFile() {
soapuiProject = SoapuiProjectDao.mergeSoapuiProject(soapuiProject);
String target = PreferenceService.getString("project_directory") + soapuiProject.getId() + soapuiProject.getLabel();
String target = PreferenceService.getString("project_directory") + soapuiProject.getId() + soapuiProject.getLabel() + ".xml";
try {
Files.move(Paths.get(soapuiProject.getXmlFilePath()), Paths.get(target));
soapuiProject.setXmlFilePath(target);
......@@ -229,6 +230,10 @@ public class UploadProject implements Serializable {
this.uploadedFile = null;
}
public List<Keystore> getAllKeystore() {
return KeystoreDao.getAllKeystores();
}
public void setMessageInvalidFileType() {
FacesMessages.instance().add(StatusMessage.Severity.ERROR, "Invalid file type. Expected file type is xml");
}
......
package net.ihe.gazelle.wstester.bean;
import net.ihe.gazelle.common.tree.GazelleTreeNodeImpl;
import net.ihe.gazelle.preferences.PreferenceService;
import net.ihe.gazelle.wstester.action.RunInstanceAction;
import net.ihe.gazelle.wstester.dao.SoapuiProjectDao;
import net.ihe.gazelle.wstester.model.Execution;
import net.ihe.gazelle.wstester.model.Keystore;
import net.ihe.gazelle.wstester.model.SoapuiProject;
import net.ihe.gazelle.wstester.model.TestComponent;
import net.ihe.gazelle.wstester.util.Tree;
......@@ -13,21 +11,13 @@ import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.faces.FacesMessages;
import org.jboss.seam.international.StatusMessage;
import org.richfaces.event.FileUploadEvent;
import org.richfaces.event.TreeSelectionChangeEvent;
import org.richfaces.model.UploadedFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.faces.event.AjaxBehaviorEvent;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.Serializable;
import java.util.List;
import java.util.UUID;
@Name("runSoapui")
@Scope(ScopeType.PAGE)
......@@ -112,13 +102,17 @@ public class RunInstanceBean implements Serializable {
public void reset() {
runInstance = false;
runInstanceAction = new RunInstanceAction();
setExecution(new Execution());
setExecution(null);
}
public void softReset(AjaxBehaviorEvent event) {
runInstance = false;
setComponentToExecute(null);
setExecution(new Execution());
setExecution(null);
}
public boolean isEhealthsuisse() {
return true;
}
public void getAllInfo() {
......@@ -138,52 +132,6 @@ public class RunInstanceBean implements Serializable {
}
}
public void uploadEventListener(final FileUploadEvent event) {
FileOutputStream fos = null;
try {
final UploadedFile item = event.getUploadedFile();
if (PreferenceService.getString("keystore_directory") != null) {
Keystore keystore = new Keystore(item.getName(), PreferenceService.getString("keystore_directory") + UUID.randomUUID() + item.getName(), getCurrentProject(), getExecution());
File uploadedFile = new File(keystore.getPath());
uploadedFile.getParentFile().mkdirs();
if (uploadedFile.getParentFile().exists()) {
if (uploadedFile.createNewFile()) {
if (item.getData() != null && item.getData().length > 0) {
fos = new FileOutputStream(uploadedFile);
fos.write(item.getData());
} else {
keystore.setPath(null);
}
getExecution().addKeystore(keystore);
} else {
LOG.error("uploadEventListener() : file " + keystore.getPath() + " couldn't be created");
}
} else {
LOG.error("uploadEventListener() : directory " + keystore.getPath() + " couldn't be created");
}
} else {
LOG.error("The app preference project_directory is not set");
FacesMessages.instance().add(StatusMessage.Severity.ERROR, "The property project_directory is not set in the application configuration");
}
} catch (final IOException e) {
LOG.error(e.getMessage());
} catch (Exception e) {
LOG.error(e.getMessage());
} finally {
if (fos != null) {
try {
fos.close();
} catch (final IOException e) {
LOG.error("not able to close the FOS", e);
}
}
}
}
public void setMessageInvalidFileType() {
FacesMessages.instance().add(StatusMessage.Severity.ERROR, "Invalid file type. Expected file type is jks");
}
public String redirectToResult() {
Execution execution = runInstanceAction.runTestInstance();
return "/executionResult.seam?id=" + execution.getId();
......
package net.ihe.gazelle.wstester.dao;
import net.ihe.gazelle.hql.providers.EntityManagerService;
import net.ihe.gazelle.wstester.model.Keystore;
import net.ihe.gazelle.wstester.model.KeystoreQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.persistence.EntityManager;
import java.util.List;
public class KeystoreDao {
private static final Logger LOG = LoggerFactory.getLogger(KeystoreDao.class);
public static Keystore merge(Keystore keystore) {
final EntityManager em = EntityManagerService.provideEntityManager();
Keystore keystore1 = em.merge(keystore);
em.flush();
return keystore1;
}
public static List<Keystore> getAllKeystores() {
KeystoreQuery query = new KeystoreQuery();
query.getList();
return query.getListNullIfEmpty();
}
public static Keystore getKeystoreByLabel(String label) {
KeystoreQuery query = new KeystoreQuery();
query.label().eq(label);
return query.getUniqueResult();
}
public static Keystore getDefaultKeystore() {
KeystoreQuery query = new KeystoreQuery();
query.defaultKeystore().eq(true);
return query.getUniqueResult();
}
}
......@@ -16,7 +16,8 @@ public enum Pages implements Page {
ADMINISTRATION("/administration/configure.seam", null, "Admin Configuration", Authorizations.ADMIN),
CALLING_TOOL("/administration/callingTools.seam", null, "Manager calling tools", Authorizations.ADMIN),
ERROR("/error.seam", null, "Error", Authorizations.ALL),
ERROR_EXPIRED("/errorExpired.seam", null, "Error Expired", Authorizations.ALL);
ERROR_EXPIRED("/errorExpired.seam", null, "Error Expired", Authorizations.ALL),
KEYSTORE("/administration/keystore.seam", null, "Keystore Manager", Authorizations.ADMIN);
private String link;
......
......@@ -6,7 +6,6 @@ import org.hibernate.annotations.FetchMode;
import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
......@@ -62,14 +61,6 @@ public class Execution implements Serializable {
@JoinColumn(name = "execution")
private TestInstanceResult testInstanceResult;
@OneToMany(
targetEntity = Keystore.class,
mappedBy = "execution",
cascade = CascadeType.ALL,
orphanRemoval = true
)
private List<Keystore> keystores;
public Execution() {
super();
}
......@@ -152,14 +143,6 @@ public class Execution implements Serializable {
this.company = company;
}
public List<Keystore> getKeystores() {
return keystores;
}
public void setKeystores(List<Keystore> keystores) {
this.keystores = keystores;
}
public String getGlobalStatus() {
for (GwtTestStepResult testStepResult : testStepResults) {
if (testStepResult.getStatus().equals("FAILED")) {
......@@ -184,17 +167,6 @@ public class Execution implements Serializable {
return "/executionResult.seam?id=" + runner.getExecution().getId();
}