SEBSERV-135 gui

This commit is contained in:
anhefti 2021-04-30 13:32:22 +02:00
parent 4750a96032
commit 3872e0f725
10 changed files with 58 additions and 50 deletions

View file

@ -48,6 +48,8 @@ public class SEBServerInit {
INIT_LOGGER.info("---->");
INIT_LOGGER.info("----> Active profiles: {}", Arrays.toString(this.environment.getActiveProfiles()));
INIT_LOGGER.info("---->");
INIT_LOGGER.info("----> Context Path: {}", this.environment.getProperty("server.servlet.context-path"));
INIT_LOGGER.info("---->");
this.initialized = true;
}

View file

@ -16,7 +16,10 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import ch.ethz.seb.sebserver.gbl.Constants;
import ch.ethz.seb.sebserver.gbl.api.API;
import ch.ethz.seb.sebserver.gbl.api.EntityType;
import ch.ethz.seb.sebserver.gbl.model.EntityKey;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.CertificateInfo;
import ch.ethz.seb.sebserver.gbl.profile.GuiProfile;
import ch.ethz.seb.sebserver.gui.content.action.ActionDefinition;
@ -28,6 +31,7 @@ import ch.ethz.seb.sebserver.gui.service.page.TemplateComposer;
import ch.ethz.seb.sebserver.gui.service.page.impl.PageAction;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestService;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.cert.GetCertificatePage;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.cert.RemoveCertificate;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.CurrentUser;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.CurrentUser.GrantCheck;
import ch.ethz.seb.sebserver.gui.table.ColumnDefinition;
@ -149,11 +153,26 @@ public class CertificateList implements TemplateComposer {
.newAction(ActionDefinition.SEB_CERTIFICATE_REMOVE)
.withSelect(
table::getSelection,
PageAction::applySingleSelectionAsEntityKey,
this::removeCertificate,
EMPTY_SELECTION_TEXT_KEY)
.publishIf(() -> grantCheck.iw(), false);
}
private PageAction removeCertificate(final PageAction action) {
final String ids = StringUtils.join(
action.getMultiSelection().stream()
.map(EntityKey::getModelId)
.collect(Collectors.toList()),
Constants.LIST_SEPARATOR);
this.restService.getBuilder(RemoveCertificate.class)
.withFormParam(API.CERTIFICATE_ALIAS, ids)
.call()
.onError(erorr -> action.pageContext().notifyRemoveError(EntityType.CERTIFICATE, erorr));
return action;
}
private String getTypeInfo(final CertificateInfo certificateInfo) {
final I18nSupport i18nSupport = this.pageService.getI18nSupport();

View file

@ -8,23 +8,17 @@
package ch.ethz.seb.sebserver.gui.content;
import java.util.ArrayList;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.swt.widgets.Composite;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import ch.ethz.seb.sebserver.gbl.api.API;
import ch.ethz.seb.sebserver.gbl.api.EntityType;
import ch.ethz.seb.sebserver.gbl.model.Domain;
import ch.ethz.seb.sebserver.gbl.model.Entity;
import ch.ethz.seb.sebserver.gbl.model.EntityKey;
import ch.ethz.seb.sebserver.gbl.model.institution.Institution;
import ch.ethz.seb.sebserver.gbl.profile.GuiProfile;
import ch.ethz.seb.sebserver.gbl.util.Result;
import ch.ethz.seb.sebserver.gui.content.action.ActionDefinition;
import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey;
import ch.ethz.seb.sebserver.gui.service.page.PageContext;
@ -34,7 +28,6 @@ import ch.ethz.seb.sebserver.gui.service.page.TemplateComposer;
import ch.ethz.seb.sebserver.gui.service.page.impl.PageAction;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestService;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.institution.GetInstitutionPage;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.cert.RemoveCertificate;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.CurrentUser;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.CurrentUser.GrantCheck;
import ch.ethz.seb.sebserver.gui.table.ColumnDefinition;
@ -152,7 +145,7 @@ public class InstitutionList implements TemplateComposer {
.newAction(ActionDefinition.INSTITUTION_MODIFY_FROM_LIST)
.withSelect(
table::getSelection,
this::removeCertificates,
PageAction::applySingleSelectionAsEntityKey,
EMPTY_SELECTION_TEXT_KEY)
.publishIf(() -> instGrant.m(), false)
@ -162,30 +155,4 @@ public class InstitutionList implements TemplateComposer {
.publishIf(() -> instGrant.m(), false);
}
private PageAction removeCertificates(final PageAction action) {
final Set<EntityKey> multiSelection = action.getMultiSelection();
if (multiSelection != null) {
final ArrayList<Exception> errors = new ArrayList<>();
multiSelection
.stream()
.forEach(key -> {
final Result<Void> call = this.restService.getBuilder(RemoveCertificate.class)
.withURIVariable(
API.CERTIFICATE_ALIAS_VAR_PATH_SEGMENT,
key.modelId)
.call();
if (call.hasError()) {
errors.add(call.getError());
}
});
if (!errors.isEmpty()) {
action.pageContext().notifyRemoveError(
EntityType.CERTIFICATE,
errors.get(0));
}
}
return action;
}
}

View file

@ -8,6 +8,8 @@
package ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.cert;
import java.util.Collection;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
@ -17,21 +19,22 @@ import com.fasterxml.jackson.core.type.TypeReference;
import ch.ethz.seb.sebserver.gbl.api.API;
import ch.ethz.seb.sebserver.gbl.api.EntityType;
import ch.ethz.seb.sebserver.gbl.model.EntityKey;
import ch.ethz.seb.sebserver.gbl.profile.GuiProfile;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestCall;
@Lazy
@Component
@GuiProfile
public class RemoveCertificate extends RestCall<Void> {
public class RemoveCertificate extends RestCall<Collection<EntityKey>> {
public RemoveCertificate() {
super(new TypeKey<>(
CallType.GET_SINGLE,
CallType.DELETE,
EntityType.CERTIFICATE,
new TypeReference<Void>() {
new TypeReference<Collection<EntityKey>>() {
}),
HttpMethod.GET,
HttpMethod.DELETE,
MediaType.APPLICATION_FORM_URLENCODED,
API.CERTIFICATE_ENDPOINT + API.CERTIFICATE_ALIAS_VAR_PATH_SEGMENT);
}

View file

@ -22,6 +22,7 @@ import org.bouncycastle.asn1.x500.style.IETFUtils;
import org.bouncycastle.cert.jcajce.JcaX509CertificateHolder;
import org.joda.time.DateTime;
import ch.ethz.seb.sebserver.gbl.model.EntityKey;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.CertificateInfo;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.CertificateInfo.CertificateType;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.Certificates;
@ -34,7 +35,7 @@ public interface CertificateDAO {
Result<CertificateInfo> addCertificate(Long institutionId, String alias, Certificate certificate);
Result<Certificates> removeCertificate(Long institutionId, String alias);
Result<EntityKey> removeCertificate(Long institutionId, String alias);
static Result<CertificateInfo> getDataFromCertificate(final Certificates certificates, final String alias) {
return Result.tryCatch(() -> {

View file

@ -29,7 +29,9 @@ import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import ch.ethz.seb.sebserver.gbl.Constants;
import ch.ethz.seb.sebserver.gbl.api.APIMessage.FieldValidationException;
import ch.ethz.seb.sebserver.gbl.api.EntityType;
import ch.ethz.seb.sebserver.gbl.model.EntityKey;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.CertificateInfo;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.Certificates;
import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile;
@ -88,11 +90,12 @@ public class CertificateDAOImpl implements CertificateDAO {
@Override
@Transactional
public Result<Certificates> removeCertificate(final Long institutionId, final String alias) {
public Result<EntityKey> removeCertificate(final Long institutionId, final String alias) {
return getCertificatesFromPersistent(institutionId)
.flatMap(record -> removeCertificate(record, alias))
.flatMap(this::storeUpdate)
.map(cert -> new EntityKey(alias, EntityType.CERTIFICATE))
.onError(TransactionHandler::rollback);
}
@ -151,7 +154,8 @@ public class CertificateDAOImpl implements CertificateDAO {
final Certificate certificate) {
if (store.engineContainsAlias(alias)) {
throw new RuntimeException("Alias name already exists: " + alias);
throw new FieldValidationException("name", "institution:name:exists");
//throw new RuntimeException("Alias name already exists: " + alias);
}
Collections.list(store.engineAliases())

View file

@ -27,6 +27,7 @@ import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import ch.ethz.seb.sebserver.gbl.api.API;
import ch.ethz.seb.sebserver.gbl.api.APIMessage.FieldValidationException;
import ch.ethz.seb.sebserver.gbl.api.EntityType;
import ch.ethz.seb.sebserver.gbl.model.EntityDependency;
@ -265,7 +266,9 @@ public class InstitutionDAOImpl implements InstitutionDAO {
.execute();
if (count != null && count > 0) {
throw new FieldValidationException("name", "institution:name:exists");
throw new FieldValidationException(
API.IMPORT_FILE_ATTR_NAME,
"certificate:certificate:exists");
}
}
}

View file

@ -14,6 +14,7 @@ import java.util.function.Predicate;
import org.apache.commons.lang3.StringUtils;
import ch.ethz.seb.sebserver.gbl.model.EntityKey;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.CertificateInfo;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.CertificateInfo.CertificateFileType;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.CertificateInfo.CertificateType;
@ -35,7 +36,7 @@ public interface CertificateService {
String alias,
InputStream in);
Result<Certificates> removeCertificate(Long institutionId, String alias);
Result<EntityKey> removeCertificate(Long institutionId, String alias);
Result<Collection<CertificateInfo>> toCertificateInfo(Certificates certificates);

View file

@ -21,6 +21,7 @@ import java.util.stream.Collectors;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import ch.ethz.seb.sebserver.gbl.model.EntityKey;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.CertificateInfo;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.CertificateInfo.CertificateFileType;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.Certificates;
@ -81,7 +82,7 @@ public class CertificateServiceImpl implements CertificateService {
}
@Override
public Result<Certificates> removeCertificate(final Long institutionId, final String alias) {
public Result<EntityKey> removeCertificate(final Long institutionId, final String alias) {
return this.certificateDAO.removeCertificate(institutionId, alias);
}

View file

@ -10,6 +10,7 @@ package ch.ethz.seb.sebserver.webservice.weblayer.api;
import java.io.BufferedInputStream;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
@ -32,10 +33,12 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import ch.ethz.seb.sebserver.gbl.Constants;
import ch.ethz.seb.sebserver.gbl.api.API;
import ch.ethz.seb.sebserver.gbl.api.EntityType;
import ch.ethz.seb.sebserver.gbl.api.authorization.PrivilegeType;
import ch.ethz.seb.sebserver.gbl.model.Entity;
import ch.ethz.seb.sebserver.gbl.model.EntityKey;
import ch.ethz.seb.sebserver.gbl.model.EntityName;
import ch.ethz.seb.sebserver.gbl.model.Page;
import ch.ethz.seb.sebserver.gbl.model.PageSortOrder;
@ -43,6 +46,7 @@ import ch.ethz.seb.sebserver.gbl.model.sebconfig.CertificateInfo;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.CertificateInfo.CertificateFileType;
import ch.ethz.seb.sebserver.gbl.model.user.UserLogActivityType;
import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile;
import ch.ethz.seb.sebserver.gbl.util.Result;
import ch.ethz.seb.sebserver.webservice.servicelayer.PaginationService;
import ch.ethz.seb.sebserver.webservice.servicelayer.authorization.AuthorizationService;
import ch.ethz.seb.sebserver.webservice.servicelayer.authorization.UserService;
@ -229,18 +233,21 @@ public class CertificateController {
method = RequestMethod.DELETE,
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
public void deleteCertificate(
public Collection<EntityKey> deleteCertificate(
@RequestParam(
name = API.PARAM_INSTITUTION_ID,
required = true,
defaultValue = UserService.USERS_INSTITUTION_AS_DEFAULT) final Long institutionId,
@PathVariable final String alias) {
@RequestParam(name = API.CERTIFICATE_ALIAS, required = true) final String aliases) {
this.checkWritePrivilege(institutionId);
this.certificateService
.removeCertificate(institutionId, alias)
.getOrThrow();
return Arrays.asList(StringUtils.split(aliases, Constants.LIST_SEPARATOR))
.stream()
.map(alias -> this.certificateService
.removeCertificate(institutionId, alias))
.flatMap(Result::onErrorLogAndSkip)
.collect(Collectors.toList());
}
private void checkReadPrivilege(final Long institutionId) {