From d3f971d7550144d5a6e93ce3f8880dc0f4338847 Mon Sep 17 00:00:00 2001 From: daniel Date: Thu, 10 Dec 2020 14:55:27 +0100 Subject: [PATCH] #37 AttributeStep fixed. AuthForm configuration. --- .../component/wizard/demo/AttributeStep.java | 17 +++++---- .../ui/component/wizard/demo/UserStep.java | 14 +++++-- .../netcore/radman/ui/view/auth/AuthView.java | 7 +++- .../widget/AttributeAssignmentDialog.java | 6 ++- .../radman/ui/view/auth/widget/AuthForm.java | 37 ++++++++++++------- .../auth/widget/AuthFormConfiguration.java | 21 +++++++++++ ...uthenticationAttributeAssigmentDialog.java | 3 +- .../view/auth/widget/AuthenticationGrid.java | 5 ++- ...AuthorizationAttributeAssigmentDialog.java | 3 +- .../view/auth/widget/AuthorizationGrid.java | 5 ++- 10 files changed, 83 insertions(+), 35 deletions(-) create mode 100644 src/main/java/software/netcore/radman/ui/view/auth/widget/AuthFormConfiguration.java diff --git a/src/main/java/software/netcore/radman/ui/component/wizard/demo/AttributeStep.java b/src/main/java/software/netcore/radman/ui/component/wizard/demo/AttributeStep.java index 55a0e4e..f424669 100644 --- a/src/main/java/software/netcore/radman/ui/component/wizard/demo/AttributeStep.java +++ b/src/main/java/software/netcore/radman/ui/component/wizard/demo/AttributeStep.java @@ -14,6 +14,7 @@ import software.netcore.radman.ui.component.wizard.WizardStep; import software.netcore.radman.ui.view.attributes.widget.AttributeForm; import software.netcore.radman.ui.view.auth.widget.AuthForm; +import software.netcore.radman.ui.view.auth.widget.AuthFormConfiguration; import java.util.List; @@ -95,13 +96,13 @@ private class AttributeStepSecond implements WizardStep(AuthenticationDto.class, - radiusUserService, true, true, (AuthenticationAttributeDto) attribute, - null, null); + radiusUserService, new AuthFormConfiguration(false, false, true, false, null), + (AuthenticationAttributeDto) attribute, null, null); // authForm.setBean(new AuthenticationDto()); } else if (attrType.equals(AUTZ_ATTR)) { authForm = new AuthForm(AuthorizationDto.class, - radiusUserService, true, true, (AuthorizationAttributeDto) attribute, - null, null); + radiusUserService, new AuthFormConfiguration(false, false, true, false, null), + (AuthorizationAttributeDto) attribute, null, null); // authForm.setBean(new AuthorizationDto()); } @@ -144,12 +145,12 @@ private class AttributeStepThird implements WizardStep(AuthenticationDto.class, - radiusUserService, true, false, (AuthenticationAttributeDto) attribute, - null, null); + radiusUserService, new AuthFormConfiguration(false, false, false, true, null), + (AuthenticationAttributeDto) attribute, null, null); } else if (attrType.equals(AUTZ_ATTR)) { authForm = new AuthForm(AuthorizationDto.class, - radiusUserService, true, false, (AuthorizationAttributeDto) attribute, - null, null); + radiusUserService, new AuthFormConfiguration(false, false, false, true, null), + (AuthorizationAttributeDto) attribute, null, null); } contentLayout.add(authForm); diff --git a/src/main/java/software/netcore/radman/ui/component/wizard/demo/UserStep.java b/src/main/java/software/netcore/radman/ui/component/wizard/demo/UserStep.java index 0581d21..147cc86 100644 --- a/src/main/java/software/netcore/radman/ui/component/wizard/demo/UserStep.java +++ b/src/main/java/software/netcore/radman/ui/component/wizard/demo/UserStep.java @@ -18,6 +18,7 @@ import software.netcore.radman.buisness.service.user.radius.dto.RadiusUserToGroupDto; import software.netcore.radman.buisness.service.user.system.dto.RoleDto; import software.netcore.radman.ui.component.wizard.WizardStep; +import software.netcore.radman.ui.view.auth.widget.AuthFormConfiguration; import software.netcore.radman.ui.view.auth.widget.AuthenticationGrid; import software.netcore.radman.ui.view.auth.widget.AuthorizationGrid; import software.netcore.radman.ui.view.radius_users.widget.RadiusUserForm; @@ -134,7 +135,6 @@ private class UserStepSecond implements WizardStep { @Override public Component getContent() { - steps.add(new UserStepThird()); return contentLayout; } @@ -149,15 +149,21 @@ public void writeDataToStorage(@NonNull NewEntityWizardDataStorage dataStorage) dataStorage.setRadiusGroupDtos(radiusGroupDtoSet); } + @Override + public void onTransition() { + steps.add(new UserStepThird(userForm.getBean())); + } + } private class UserStepThird implements WizardStep { private final VVerticalLayout contentLayout = new VVerticalLayout(); - UserStepThird() { - AuthenticationGrid authGrid = new AuthenticationGrid(authService, attributeService, radiusUserService, securityService); - AuthorizationGrid autzGrid = new AuthorizationGrid(authService, attributeService, radiusUserService, securityService); + UserStepThird(RadiusUserDto radiusUserDto) { + AuthFormConfiguration formConfig = new AuthFormConfiguration(false, true, false, false, radiusUserDto); + AuthenticationGrid authGrid = new AuthenticationGrid(authService, attributeService, radiusUserService, securityService, formConfig); + AuthorizationGrid autzGrid = new AuthorizationGrid(authService, attributeService, radiusUserService, securityService, formConfig); contentLayout.withComponent(authGrid) .withComponent(autzGrid); diff --git a/src/main/java/software/netcore/radman/ui/view/auth/AuthView.java b/src/main/java/software/netcore/radman/ui/view/auth/AuthView.java index 06aff31..60b21d0 100644 --- a/src/main/java/software/netcore/radman/ui/view/auth/AuthView.java +++ b/src/main/java/software/netcore/radman/ui/view/auth/AuthView.java @@ -12,6 +12,7 @@ import software.netcore.radman.buisness.service.security.SecurityService; import software.netcore.radman.buisness.service.user.radius.RadiusUserService; import software.netcore.radman.ui.menu.MenuTemplate; +import software.netcore.radman.ui.view.auth.widget.AuthFormConfiguration; import software.netcore.radman.ui.view.auth.widget.AuthenticationGrid; import software.netcore.radman.ui.view.auth.widget.AuthorizationGrid; @@ -43,8 +44,10 @@ public AuthView(AuthService authService, RadiusUserService userService, private void buildView() { setSpacing(false); add(new H4("Data from Radius DB - \"radcheck\", \"radgroupcheck\", \"radreply\", \"radgroupreply\" tables")); - add(new AuthenticationGrid(authService, attributeService, userService, securityService)); - add(new AuthorizationGrid(authService, attributeService, userService, securityService)); + + AuthFormConfiguration formConfig = new AuthFormConfiguration(true, false, false, false, null); + add(new AuthenticationGrid(authService, attributeService, userService, securityService, formConfig)); + add(new AuthorizationGrid(authService, attributeService, userService, securityService, formConfig)); } } diff --git a/src/main/java/software/netcore/radman/ui/view/auth/widget/AttributeAssignmentDialog.java b/src/main/java/software/netcore/radman/ui/view/auth/widget/AttributeAssignmentDialog.java index 4f2facf..c286424 100644 --- a/src/main/java/software/netcore/radman/ui/view/auth/widget/AttributeAssignmentDialog.java +++ b/src/main/java/software/netcore/radman/ui/view/auth/widget/AttributeAssignmentDialog.java @@ -23,12 +23,15 @@ public abstract class AttributeAssignmentDialog extends Dialog { private final RadiusUserService userService; + private final AuthFormConfiguration formConfig; private final CreationListener creationListener; private AuthForm authForm; public AttributeAssignmentDialog(RadiusUserService userService, + AuthFormConfiguration formConfig, CreationListener creationListener) { + this.formConfig = formConfig; this.userService = userService; this.creationListener = creationListener; } @@ -36,7 +39,7 @@ public AttributeAssignmentDialog(RadiusUserService userService, private void build() { removeAll(); - authForm = new AuthForm<>(getClazz(), userService, false, false, null, + authForm = new AuthForm<>(getClazz(), userService, formConfig, null, (searchText, offset, limit) -> pageAttributes(new AttributeFilter(searchText, true, false), PageRequest.of(offset, limit, new Sort(Sort.Direction.ASC, "id"))), @@ -47,6 +50,7 @@ private void build() { T dto = getNewBeanInstance(); if (authForm.isValid()) { try { + dto = authForm.getBean(); assignAuth(dto); creationListener.onCreated(this, null); setOpened(false); diff --git a/src/main/java/software/netcore/radman/ui/view/auth/widget/AuthForm.java b/src/main/java/software/netcore/radman/ui/view/auth/widget/AuthForm.java index 350fa16..9a587d8 100644 --- a/src/main/java/software/netcore/radman/ui/view/auth/widget/AuthForm.java +++ b/src/main/java/software/netcore/radman/ui/view/auth/widget/AuthForm.java @@ -55,6 +55,7 @@ public interface AttributeCounter { } private final Binder binder; + private final AuthFormConfiguration formConfig; @Getter private final ComboBox username; @Getter @@ -66,12 +67,12 @@ public interface AttributeCounter { public AuthForm(@NonNull Class clazz, @NonNull RadiusUserService userService, - boolean showForWizard, - boolean nameAuthTarget, + AuthFormConfiguration formConfig, U attributeItem, AttributePager attributePager, AttributeCounter attributeCounter) { + this.formConfig = formConfig; binder = new BeanValidationBinder<>(clazz); try { binder.setBean(clazz.newInstance()); @@ -125,7 +126,7 @@ public AuthForm(@NonNull Class clazz, HorizontalLayout attrConfigLayout = new HorizontalLayout(); ComboBox attribute = new ComboBox<>("Attribute"); attribute.setItemLabelGenerator(AttributeDto::getName); - if (!showForWizard) { + if (formConfig.isShowFullForm() || formConfig.isPredefinedUser()) { attribute.setDataProvider((ComboBox.FetchItemsCallback) (searchText, offset, limit) -> attributePager.pageAttributes(searchText, offset, limit) .stream(), @@ -133,7 +134,7 @@ public AuthForm(@NonNull Class clazz, (int) attributeCounter.countAttributes(new AttributeFilter(searchText, true, false))); } else { -// attribute.setItems(attributeItem); + attribute.setItems(attributeItem); List list = new ArrayList<>(); list.add(attributeItem); attribute.setDataProvider((ListDataProvider) new ListDataProvider<>(list)); @@ -171,11 +172,25 @@ public AuthForm(@NonNull Class clazz, .bind("attribute"); binder.bind(opSelect, "op"); - if (showForWizard) { - if (nameAuthTarget) { + if (formConfig.isShowFullForm()) { + authTargetSelect.setValue(AuthTarget.RADIUS_USER); + attrConfigLayout.add(attribute, opSelect, value); + add(new VVerticalLayout() + .withComponents(authTargetConfigLayout) + .withComponents(attrConfigLayout)); + } else if (formConfig.isPredefinedUser()) { + username.setValue(formConfig.getPredefinedUserDto()); + authTargetSelect.setValue(AuthTarget.RADIUS_USER); + attrConfigLayout.add(attribute, opSelect, value); + add(new VVerticalLayout() + .withComponents(attrConfigLayout)); + } else { + if (formConfig.isPredefinedAttrTargetAsUser()) { authTargetSelect.setValue(AuthTarget.RADIUS_USER); - } else { + attribute.setValue(attributeItem); + } else if (formConfig.isPredefinedAttrTargetAsGroup()) { authTargetSelect.setValue(AuthTarget.RADIUS_GROUP); + attribute.setValue(attributeItem); } authTargetConfigLayout.remove(authTargetSelect); @@ -183,13 +198,7 @@ public AuthForm(@NonNull Class clazz, .withComponents(authTargetConfigLayout) .withComponents(opSelect) .withComponents(value)); - } else { - attrConfigLayout.add(attribute, opSelect, value); - add(new VVerticalLayout() - .withComponents(authTargetConfigLayout) - .withComponents(attrConfigLayout)); } - } private AbstractSinglePropertyField, String> buildTextValueField() { @@ -214,7 +223,7 @@ public boolean isValid() { return binder.validate().isOk(); } - public AuthDto getBean() { + public T getBean() { return binder.getBean(); } diff --git a/src/main/java/software/netcore/radman/ui/view/auth/widget/AuthFormConfiguration.java b/src/main/java/software/netcore/radman/ui/view/auth/widget/AuthFormConfiguration.java new file mode 100644 index 0000000..de2a972 --- /dev/null +++ b/src/main/java/software/netcore/radman/ui/view/auth/widget/AuthFormConfiguration.java @@ -0,0 +1,21 @@ +package software.netcore.radman.ui.view.auth.widget; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import software.netcore.radman.buisness.service.user.radius.dto.RadiusUserDto; + +@Getter +@AllArgsConstructor +public class AuthFormConfiguration { + + private final boolean showFullForm; + + private final boolean predefinedUser; + + private final boolean predefinedAttrTargetAsUser; + + private final boolean predefinedAttrTargetAsGroup; + + private final RadiusUserDto predefinedUserDto; + +} diff --git a/src/main/java/software/netcore/radman/ui/view/auth/widget/AuthenticationAttributeAssigmentDialog.java b/src/main/java/software/netcore/radman/ui/view/auth/widget/AuthenticationAttributeAssigmentDialog.java index b5ec409..c72383a 100644 --- a/src/main/java/software/netcore/radman/ui/view/auth/widget/AuthenticationAttributeAssigmentDialog.java +++ b/src/main/java/software/netcore/radman/ui/view/auth/widget/AuthenticationAttributeAssigmentDialog.java @@ -19,8 +19,9 @@ public class AuthenticationAttributeAssigmentDialog public AuthenticationAttributeAssigmentDialog(AuthService authService, AttributeService attributeService, RadiusUserService userService, + AuthFormConfiguration formConfig, CreationListener creationListener) { - super(userService, creationListener); + super(userService, formConfig, creationListener); this.authService = authService; this.attributeService = attributeService; } diff --git a/src/main/java/software/netcore/radman/ui/view/auth/widget/AuthenticationGrid.java b/src/main/java/software/netcore/radman/ui/view/auth/widget/AuthenticationGrid.java index d1ffa3b..f08c988 100644 --- a/src/main/java/software/netcore/radman/ui/view/auth/widget/AuthenticationGrid.java +++ b/src/main/java/software/netcore/radman/ui/view/auth/widget/AuthenticationGrid.java @@ -18,11 +18,12 @@ public class AuthenticationGrid extends AuthGrid refreshGrid()); + radiusUserService, formConfig, (source, bean) -> refreshGrid()); refreshGrid(); } diff --git a/src/main/java/software/netcore/radman/ui/view/auth/widget/AuthorizationAttributeAssigmentDialog.java b/src/main/java/software/netcore/radman/ui/view/auth/widget/AuthorizationAttributeAssigmentDialog.java index 2e34e64..f717b92 100644 --- a/src/main/java/software/netcore/radman/ui/view/auth/widget/AuthorizationAttributeAssigmentDialog.java +++ b/src/main/java/software/netcore/radman/ui/view/auth/widget/AuthorizationAttributeAssigmentDialog.java @@ -19,8 +19,9 @@ public class AuthorizationAttributeAssigmentDialog public AuthorizationAttributeAssigmentDialog(AuthService authService, AttributeService attributeService, RadiusUserService userService, + AuthFormConfiguration formConfig, CreationListener creationListener) { - super(userService, creationListener); + super(userService, formConfig, creationListener); this.authService = authService; this.attributeService = attributeService; } diff --git a/src/main/java/software/netcore/radman/ui/view/auth/widget/AuthorizationGrid.java b/src/main/java/software/netcore/radman/ui/view/auth/widget/AuthorizationGrid.java index f7bc753..45cbfa9 100644 --- a/src/main/java/software/netcore/radman/ui/view/auth/widget/AuthorizationGrid.java +++ b/src/main/java/software/netcore/radman/ui/view/auth/widget/AuthorizationGrid.java @@ -18,10 +18,11 @@ public class AuthorizationGrid extends AuthGrid refreshGrid()); refreshGrid(); }