diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/api/APIMessage.java b/src/main/java/ch/ethz/seb/sebserver/gbl/api/APIMessage.java index e47317e4..9c4bafb2 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/api/APIMessage.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/api/APIMessage.java @@ -203,7 +203,7 @@ public class APIMessage implements Serializable { return ErrorMessage.FIELD_VALIDATION.of(fieldName, args); } - public static String toHTML(final String errorMessage, final List messages) { + public static String toHTML(final String errorMessage, final Collection messages) { final StringBuilder builder = new StringBuilder(); builder.append("Failure:").append("

").append(errorMessage).append("

"); builder.append("Detail Messages:

"); @@ -220,7 +220,7 @@ public class APIMessage implements Serializable { * within an Exception and throw. The Exception will be caught a the * APIExceptionHandler endpoint. The APIMessage will be extracted * and send as response. */ - public static class APIMessageException extends RuntimeException { + public static class APIMessageException extends RuntimeException implements APIMessageError { private static final long serialVersionUID = 1453431210820677296L; @@ -246,6 +246,7 @@ public class APIMessage implements Serializable { this.apiMessages = Arrays.asList(errorMessage.of(detail, attributes)); } + @Override public Collection getAPIMessages() { return this.apiMessages; } @@ -283,11 +284,11 @@ public class APIMessage implements Serializable { } public static boolean checkError(final Exception error, final ErrorMessage errorMessage) { - if (!(error instanceof APIMessageException)) { + if (!(error instanceof APIMessageError)) { return false; } - final APIMessageException _error = (APIMessageException) error; + final APIMessageError _error = (APIMessageError) error; return _error.getAPIMessages() .stream() .filter(msg -> errorMessage.messageCode.equals(msg.messageCode)) diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/api/APIMessageError.java b/src/main/java/ch/ethz/seb/sebserver/gbl/api/APIMessageError.java index 8df39117..e6597fd5 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/api/APIMessageError.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/api/APIMessageError.java @@ -8,14 +8,14 @@ package ch.ethz.seb.sebserver.gbl.api; -import java.util.List; +import java.util.Collection; /** Defines an API message error holder that supplies a List of APIMessage if error happened */ public interface APIMessageError { /** Get a List of APIMessage errors if error happened * - * @return a List of APIMessage errors if error happened or empty list of not*/ - List getErrorMessages(); + * @return a List of APIMessage errors if error happened or empty list of not */ + Collection getAPIMessages(); } diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/model/sebconfig/SEBClientConfig.java b/src/main/java/ch/ethz/seb/sebserver/gbl/model/sebconfig/SEBClientConfig.java index 0f292477..b1020d93 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/model/sebconfig/SEBClientConfig.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/model/sebconfig/SEBClientConfig.java @@ -203,10 +203,16 @@ public final class SEBClientConfig implements GrantEntity, Activatable { this.configPurpose = configPurpose; this.sebServerPingTime = sebServerPingTime; - this.vdiType = vdiType; - this.vdiExecutable = vdiExecutable != null ? vdiExecutable : vdiType.defaultExecutable; - this.vdiPath = vdiPath != null ? vdiPath : vdiType.defaultPath; - this.vdiArguments = vdiArguments != null ? vdiArguments : vdiType.defaultArguments; + this.vdiType = vdiType != null ? vdiType : VDIType.NO; + this.vdiExecutable = vdiExecutable != null + ? vdiExecutable + : vdiType != null ? vdiType.defaultExecutable : null; + this.vdiPath = vdiPath != null + ? vdiPath + : vdiType != null ? vdiType.defaultPath : null; + this.vdiArguments = vdiArguments != null + ? vdiArguments + : vdiType != null ? vdiType.defaultArguments : null; this.fallback = fallback; this.fallbackStartURL = fallbackStartURL; diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/CertificateImportPopup.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/CertificateImportPopup.java index b380f98b..f9c98425 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/CertificateImportPopup.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/CertificateImportPopup.java @@ -176,7 +176,7 @@ public class CertificateImportPopup { final Exception error = result.getError(); if (error instanceof RestCallError) { ((RestCallError) error) - .getErrorMessages() + .getAPIMessages() .stream() .findFirst() .ifPresent(message -> { diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/CertificateList.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/CertificateList.java index eebda06e..b68e86c4 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/CertificateList.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/CertificateList.java @@ -75,6 +75,8 @@ public class CertificateList implements TemplateComposer { new LocTextKey("sebserver.certificate.action.import-config.confirm"); static final LocTextKey FORM_ACTION_MESSAGE_IN_USE_TEXT_KEY = new LocTextKey("sebserver.certificate.action.remove.in-use"); + static final LocTextKey FORM_ACTION_MESSAGE_REMOVE_CONFIRM_TEXT_KEY = + new LocTextKey("sebserver.certificate.action.remove.confirm"); private final TableFilterAttribute aliasFilter = new TableFilterAttribute( CriteriaType.TEXT, @@ -155,6 +157,7 @@ public class CertificateList implements TemplateComposer { .publishIf(() -> grantCheck.iw()) .newAction(ActionDefinition.SEB_CERTIFICATE_REMOVE) + .withConfirm(() -> FORM_ACTION_MESSAGE_REMOVE_CONFIRM_TEXT_KEY) .withSelect( table::getSelection, this::removeCertificate, diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/SEBClientConfigForm.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/SEBClientConfigForm.java index 562968dd..bdf96fa5 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/SEBClientConfigForm.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/SEBClientConfigForm.java @@ -16,6 +16,7 @@ import org.eclipse.rap.rwt.RWT; import org.eclipse.rap.rwt.client.service.UrlLauncher; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Listener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -332,14 +333,16 @@ public class SEBClientConfigForm implements TemplateComposer { // VDI .withDefaultSpanInput(2) - .addField(FormBuilder.singleSelection( - SEBClientConfig.ATTR_VDI_TYPE, - VDI_TYPE_TEXT_KEY, - clientConfig.vdiType != null - ? clientConfig.vdiType.name() - : SEBClientConfig.VDIType.NO.name(), - () -> this.pageService.getResourceService().vdiTypeResources()) - .mandatory(!isReadonly)) + .addFieldIf( + () -> false, // TODO skipped for version 1.2 --> 1.3 or 1.4 + () -> FormBuilder.singleSelection( + SEBClientConfig.ATTR_VDI_TYPE, + VDI_TYPE_TEXT_KEY, + clientConfig.vdiType != null + ? clientConfig.vdiType.name() + : SEBClientConfig.VDIType.NO.name(), + () -> this.pageService.getResourceService().vdiTypeResources()) + .mandatory(!isReadonly)) .withDefaultSpanEmptyCell(3); // VDI Attributes @@ -472,10 +475,18 @@ public class SEBClientConfigForm implements TemplateComposer { }; if (!isReadonly) { - formHandleAnchor.formHandle.getForm().getFieldInput(SEBClientConfig.ATTR_FALLBACK) - .addListener(SWT.Selection, selectionListener); - formHandleAnchor.formHandle.getForm().getFieldInput(SEBClientConfig.ATTR_VDI_TYPE) - .addListener(SWT.Selection, selectionListener); + final Control fallbackInput = formHandleAnchor.formHandle + .getForm() + .getFieldInput(SEBClientConfig.ATTR_FALLBACK); + if (fallbackInput != null) { + fallbackInput.addListener(SWT.Selection, selectionListener); + } + final Control vdiInput = formHandleAnchor.formHandle + .getForm() + .getFieldInput(SEBClientConfig.ATTR_VDI_TYPE); + if (vdiInput != null) { + vdiInput.addListener(SWT.Selection, selectionListener); + } } formContent.layout(); diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/SEBExamConfigImportPopup.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/SEBExamConfigImportPopup.java index 04e882bc..e8da2b64 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/SEBExamConfigImportPopup.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/SEBExamConfigImportPopup.java @@ -9,6 +9,7 @@ package ch.ethz.seb.sebserver.gui.content; import java.io.InputStream; +import java.util.Collection; import java.util.List; import java.util.function.Function; import java.util.function.Predicate; @@ -210,7 +211,7 @@ public class SEBExamConfigImportPopup { final Exception error = configuration.getError(); if (error instanceof RestCallError) { ((RestCallError) error) - .getErrorMessages() + .getAPIMessages() .stream() .findFirst() .ifPresent(message -> { @@ -393,8 +394,8 @@ public class SEBExamConfigImportPopup { private static void notifyErrorOnSave(final Exception error, final PageContext context) { if (error instanceof APIMessageError) { try { - final List errorMessages = ((APIMessageError) error).getErrorMessages(); - final APIMessage apiMessage = errorMessages.get(0); + final Collection errorMessages = ((APIMessageError) error).getAPIMessages(); + final APIMessage apiMessage = errorMessages.iterator().next(); if (APIMessage.ErrorMessage.INTEGRITY_VALIDATION.isOf(apiMessage)) { context.publishPageMessage(new PageMessageException(MESSAGE_SAVE_INTEGRITY_VIOLATION)); } else { diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/SEBSettingsForm.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/SEBSettingsForm.java index 16fd1682..439eff48 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/SEBSettingsForm.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/SEBSettingsForm.java @@ -9,6 +9,7 @@ package ch.ethz.seb.sebserver.gui.content; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.function.Function; @@ -324,8 +325,8 @@ public class SEBSettingsForm implements TemplateComposer { public void notifyErrorOnSave(final Exception error, final PageContext context) { if (error instanceof APIMessageError) { try { - final List errorMessages = ((APIMessageError) error).getErrorMessages(); - final APIMessage apiMessage = errorMessages.get(0); + final Collection errorMessages = ((APIMessageError) error).getAPIMessages(); + final APIMessage apiMessage = errorMessages.iterator().next(); if (APIMessage.ErrorMessage.INTEGRITY_VALIDATION.isOf(apiMessage)) { throw new PageMessageException(MESSAGE_SAVE_INTEGRITY_VIOLATION); } else { diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/form/FormHandle.java b/src/main/java/ch/ethz/seb/sebserver/gui/form/FormHandle.java index 54b3b365..3b27f860 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/form/FormHandle.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/form/FormHandle.java @@ -144,13 +144,13 @@ public class FormHandle { if (error instanceof RestCallError) { final List fieldValidationErrors = ((RestCallError) error) - .getErrorMessages() + .getAPIMessages() .stream() .filter(APIMessage.ErrorMessage.FIELD_VALIDATION::isOf) .collect(Collectors.toList()); final List noneFieldValidationErrors = ((RestCallError) error) - .getErrorMessages() + .getAPIMessages() .stream() .filter(message -> !APIMessage.ErrorMessage.FIELD_VALIDATION.isOf(message)) .collect(Collectors.toList()); diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/ExamConfigurationServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/ExamConfigurationServiceImpl.java index 07cad3cf..b27c63cf 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/ExamConfigurationServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/ExamConfigurationServiceImpl.java @@ -390,7 +390,7 @@ public class ExamConfigurationServiceImpl implements ExamConfigurationService { private String verifyErrorMessage(final Exception error) { if (error instanceof RestCallError) { - final List errorMessages = ((RestCallError) error).getErrorMessages(); + final List errorMessages = ((RestCallError) error).getAPIMessages(); if (errorMessages.isEmpty()) { return ""; } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageContextImpl.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageContextImpl.java index 16170cbd..ff12ffb3 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageContextImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageContextImpl.java @@ -9,6 +9,7 @@ package ch.ethz.seb.sebserver.gui.service.page.impl; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -332,7 +333,7 @@ public class PageContextImpl implements PageContext { : error.getMessage(); if (error instanceof APIMessageError) { - final List errorMessages = ((APIMessageError) error).getErrorMessages(); + final Collection errorMessages = ((APIMessageError) error).getAPIMessages(); final MessageBox messageBox = new Message( getShell(), this.i18nSupport.getText("sebserver.error.unexpected"), diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/RestCallError.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/RestCallError.java index ed71d178..1ed226ce 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/RestCallError.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/RestCallError.java @@ -38,7 +38,7 @@ public class RestCallError extends RuntimeException implements APIMessageError { } @Override - public List getErrorMessages() { + public List getAPIMessages() { return this.errors; } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/CertificateDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/CertificateDAOImpl.java index 086877c0..27a15314 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/CertificateDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/CertificateDAOImpl.java @@ -223,12 +223,7 @@ public class CertificateDAOImpl implements CertificateDAO { // dataEncipherment if (keyUsage[2] || keyUsage[3]) { - final String alias = certificates.keyStore.engineGetCertificateAlias(cert); - if (this.cryptor.getPrivateKey(certificates.keyStore, alias).hasValue()) { - result.add(CertificateType.DATA_ENCIPHERMENT_PRIVATE_KEY); - } else { - result.add(CertificateType.DATA_ENCIPHERMENT); - } + result.add(CertificateType.DATA_ENCIPHERMENT); } // keyCertSign @@ -240,6 +235,11 @@ public class CertificateDAOImpl implements CertificateDAO { result.add(CertificateType.UNKNOWN); } + final String alias = certificates.keyStore.engineGetCertificateAlias(cert); + if (this.cryptor.getPrivateKey(certificates.keyStore, alias).hasValue()) { + result.add(CertificateType.DATA_ENCIPHERMENT_PRIVATE_KEY); + } + return result; } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/AbstractCertificateCryptor.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/AbstractCertificateCryptor.java index b709061a..4da634c7 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/AbstractCertificateCryptor.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/AbstractCertificateCryptor.java @@ -85,7 +85,7 @@ public abstract class AbstractCertificateCryptor { final String algorithm = cert.getPublicKey().getAlgorithm(); final Cipher encryptCipher = Cipher.getInstance(algorithm); - encryptCipher.init(Cipher.ENCRYPT_MODE, cert); + encryptCipher.init(Cipher.ENCRYPT_MODE, cert.getPublicKey()); return encryptCipher.doFinal(data, 0, length); } @@ -99,7 +99,7 @@ public abstract class AbstractCertificateCryptor { final String algorithm = cert.getPublicKey().getAlgorithm(); final Cipher encryptCipher = Cipher.getInstance(algorithm); - encryptCipher.init(Cipher.DECRYPT_MODE, cert); + encryptCipher.init(Cipher.DECRYPT_MODE, cert.getPublicKey()); return encryptCipher.doFinal(encryptedData, 0, length); } diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index 8e867285..265bdb92 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -1607,6 +1607,7 @@ sebserver.certificate.action.import.missing-password=The certificate file needs sebserver.certificate.action.import-config.confirm=Certificate(s) successfully imported sebserver.certificate.message.error.file=Unsupported file type sebserver.certificate.action.import-file-select.no=Please select a valid file +sebserver.certificate.action.remove.confirm=Are you sure you want delete the selected Certificate(s)? sebserver.certificate.action.remove.in-use=This certificate is in use and cannot be removed. diff --git a/src/test/java/ch/ethz/seb/sebserver/gui/integration/UseCasesIntegrationTest.java b/src/test/java/ch/ethz/seb/sebserver/gui/integration/UseCasesIntegrationTest.java index 7c87c598..1730d649 100644 --- a/src/test/java/ch/ethz/seb/sebserver/gui/integration/UseCasesIntegrationTest.java +++ b/src/test/java/ch/ethz/seb/sebserver/gui/integration/UseCasesIntegrationTest.java @@ -381,7 +381,7 @@ public class UseCasesIntegrationTest extends GuiIntegrationTest { RestCallError error = (RestCallError) call.getError(); assertEquals( "[APIMessage [messageCode=1001, systemMessage=FORBIDDEN, details=No edit right grant for user: TestInstAdmin, attributes=[]]]", - String.valueOf(error.getErrorMessages())); + String.valueOf(error.getAPIMessages())); // change password final Result passwordChange = restService @@ -400,7 +400,7 @@ public class UseCasesIntegrationTest extends GuiIntegrationTest { error = (RestCallError) instNames.getError(); assertEquals( "UNAUTHORIZED", - String.valueOf(error.getErrorMessages().get(0).getSystemMessage())); + String.valueOf(error.getAPIMessages().get(0).getSystemMessage())); // login again with the new password and check roles restService = createRestServiceForUser( @@ -2339,7 +2339,7 @@ public class UseCasesIntegrationTest extends GuiIntegrationTest { .getOrThrow(); fail("Forbidden error message expected here"); } catch (final RestCallError e) { - final APIMessage apiMessage = e.getErrorMessages().get(0); + final APIMessage apiMessage = e.getAPIMessages().get(0); assertEquals("1001", apiMessage.messageCode); assertEquals("FORBIDDEN", apiMessage.systemMessage); } @@ -2395,7 +2395,7 @@ public class UseCasesIntegrationTest extends GuiIntegrationTest { .getOrThrow(); fail("no resource found exception expected here"); } catch (final RestCallError e) { - final APIMessage apiMessage = e.getErrorMessages().get(0); + final APIMessage apiMessage = e.getAPIMessages().get(0); assertEquals("1002", apiMessage.getMessageCode()); assertEquals("resource not found", apiMessage.getSystemMessage()); } @@ -2408,7 +2408,7 @@ public class UseCasesIntegrationTest extends GuiIntegrationTest { .getOrThrow(); fail("no resource found exception expected here"); } catch (final RestCallError e) { - final APIMessage apiMessage = e.getErrorMessages().get(0); + final APIMessage apiMessage = e.getAPIMessages().get(0); assertEquals("1002", apiMessage.getMessageCode()); assertEquals("resource not found", apiMessage.getSystemMessage()); } @@ -2419,7 +2419,7 @@ public class UseCasesIntegrationTest extends GuiIntegrationTest { .getOrThrow(); fail("no resource found exception expected here"); } catch (final RestCallError e) { - final APIMessage apiMessage = e.getErrorMessages().get(0); + final APIMessage apiMessage = e.getAPIMessages().get(0); assertEquals("1002", apiMessage.getMessageCode()); assertEquals("resource not found", apiMessage.getSystemMessage()); } @@ -2430,7 +2430,7 @@ public class UseCasesIntegrationTest extends GuiIntegrationTest { .getOrThrow(); fail("no resource found exception expected here"); } catch (final RestCallError e) { - final APIMessage apiMessage = e.getErrorMessages().get(0); + final APIMessage apiMessage = e.getAPIMessages().get(0); assertEquals("1002", apiMessage.getMessageCode()); assertEquals("resource not found", apiMessage.getSystemMessage()); } @@ -2441,7 +2441,7 @@ public class UseCasesIntegrationTest extends GuiIntegrationTest { .getOrThrow(); fail("no resource found exception expected here"); } catch (final RestCallError e) { - final APIMessage apiMessage = e.getErrorMessages().get(0); + final APIMessage apiMessage = e.getAPIMessages().get(0); assertEquals("1002", apiMessage.getMessageCode()); assertEquals("resource not found", apiMessage.getSystemMessage()); } @@ -2452,7 +2452,7 @@ public class UseCasesIntegrationTest extends GuiIntegrationTest { .getOrThrow(); fail("no resource found exception expected here"); } catch (final RestCallError e) { - final APIMessage apiMessage = e.getErrorMessages().get(0); + final APIMessage apiMessage = e.getAPIMessages().get(0); assertEquals("1002", apiMessage.getMessageCode()); assertEquals("resource not found", apiMessage.getSystemMessage()); } @@ -2463,7 +2463,7 @@ public class UseCasesIntegrationTest extends GuiIntegrationTest { .getOrThrow(); fail("no resource found exception expected here"); } catch (final RestCallError e) { - final APIMessage apiMessage = e.getErrorMessages().get(0); + final APIMessage apiMessage = e.getAPIMessages().get(0); assertEquals("1002", apiMessage.getMessageCode()); assertEquals("resource not found", apiMessage.getSystemMessage()); }