Skip to content

Commit

Permalink
#37 AttributeStep fixed. AuthForm configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmajirsky committed Dec 10, 2020
1 parent d32d2a3 commit d3f971d
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -95,13 +96,13 @@ private class AttributeStepSecond implements WizardStep<NewEntityWizardDataStora
this.steps = steps;
if (attrType.equals(AUTH_ATTR)) {
authForm = new AuthForm<AuthenticationDto, AuthenticationAttributeDto>(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, AuthorizationAttributeDto>(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());
}

Expand Down Expand Up @@ -144,12 +145,12 @@ private class AttributeStepThird implements WizardStep<NewEntityWizardDataStorag
this.attrType = attrType;
if (attrType.equals(AUTH_ATTR)) {
authForm = new AuthForm<AuthenticationDto, AuthenticationAttributeDto>(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, AuthorizationAttributeDto>(AuthorizationDto.class,
radiusUserService, true, false, (AuthorizationAttributeDto) attribute,
null, null);
radiusUserService, new AuthFormConfiguration(false, false, false, true, null),
(AuthorizationAttributeDto) attribute, null, null);
}

contentLayout.add(authForm);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -134,7 +135,6 @@ private class UserStepSecond implements WizardStep<NewEntityWizardDataStorage> {

@Override
public Component getContent() {
steps.add(new UserStepThird());
return contentLayout;
}

Expand All @@ -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<NewEntityWizardDataStorage> {

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,23 @@
public abstract class AttributeAssignmentDialog<T extends AuthDto, U extends AttributeDto> extends Dialog {

private final RadiusUserService userService;
private final AuthFormConfiguration formConfig;
private final CreationListener<Void> creationListener;

private AuthForm<T, U> authForm;

public AttributeAssignmentDialog(RadiusUserService userService,
AuthFormConfiguration formConfig,
CreationListener<Void> creationListener) {
this.formConfig = formConfig;
this.userService = userService;
this.creationListener = creationListener;
}

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"))),
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public interface AttributeCounter {
}

private final Binder<T> binder;
private final AuthFormConfiguration formConfig;
@Getter
private final ComboBox<RadiusUserDto> username;
@Getter
Expand All @@ -66,12 +67,12 @@ public interface AttributeCounter {

public AuthForm(@NonNull Class<T> clazz,
@NonNull RadiusUserService userService,
boolean showForWizard,
boolean nameAuthTarget,
AuthFormConfiguration formConfig,
U attributeItem,
AttributePager<U> attributePager,
AttributeCounter attributeCounter) {

this.formConfig = formConfig;
binder = new BeanValidationBinder<>(clazz);
try {
binder.setBean(clazz.newInstance());
Expand Down Expand Up @@ -125,15 +126,15 @@ public AuthForm(@NonNull Class<T> clazz,
HorizontalLayout attrConfigLayout = new HorizontalLayout();
ComboBox<U> attribute = new ComboBox<>("Attribute");
attribute.setItemLabelGenerator(AttributeDto::getName);
if (!showForWizard) {
if (formConfig.isShowFullForm() || formConfig.isPredefinedUser()) {
attribute.setDataProvider((ComboBox.FetchItemsCallback<U>)
(searchText, offset, limit) -> attributePager.pageAttributes(searchText, offset, limit)
.stream(),
(SerializableFunction<String, Integer>) searchText ->
(int) attributeCounter.countAttributes(new AttributeFilter(searchText, true,
false)));
} else {
// attribute.setItems(attributeItem);
attribute.setItems(attributeItem);
List<AttributeDto> list = new ArrayList<>();
list.add(attributeItem);
attribute.setDataProvider((ListDataProvider<U>) new ListDataProvider<>(list));
Expand Down Expand Up @@ -171,25 +172,33 @@ public AuthForm(@NonNull Class<T> 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);
add(new VHorizontalLayout()
.withComponents(authTargetConfigLayout)
.withComponents(opSelect)
.withComponents(value));
} else {
attrConfigLayout.add(attribute, opSelect, value);
add(new VVerticalLayout()
.withComponents(authTargetConfigLayout)
.withComponents(attrConfigLayout));
}

}

private AbstractSinglePropertyField<? extends AbstractField<?, ?>, String> buildTextValueField() {
Expand All @@ -214,7 +223,7 @@ public boolean isValid() {
return binder.validate().isOk();
}

public AuthDto getBean() {
public T getBean() {
return binder.getBean();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ public class AuthenticationAttributeAssigmentDialog
public AuthenticationAttributeAssigmentDialog(AuthService authService,
AttributeService attributeService,
RadiusUserService userService,
AuthFormConfiguration formConfig,
CreationListener<Void> creationListener) {
super(userService, creationListener);
super(userService, formConfig, creationListener);
this.authService = authService;
this.attributeService = attributeService;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ public class AuthenticationGrid extends AuthGrid<AuthenticationsDto, Authenticat
public AuthenticationGrid(@NonNull AuthService authService,
@NonNull AttributeService attributeService,
@NonNull RadiusUserService radiusUserService,
@NonNull SecurityService securityService) {
@NonNull SecurityService securityService,
@NonNull AuthFormConfiguration formConfig) {
super(securityService);
this.authService = authService;
this.assigmentDialog = new AuthenticationAttributeAssigmentDialog(authService, attributeService,
radiusUserService, (source, bean) -> refreshGrid());
radiusUserService, formConfig, (source, bean) -> refreshGrid());
refreshGrid();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ public class AuthorizationAttributeAssigmentDialog
public AuthorizationAttributeAssigmentDialog(AuthService authService,
AttributeService attributeService,
RadiusUserService userService,
AuthFormConfiguration formConfig,
CreationListener<Void> creationListener) {
super(userService, creationListener);
super(userService, formConfig, creationListener);
this.authService = authService;
this.attributeService = attributeService;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ public class AuthorizationGrid extends AuthGrid<AuthorizationsDto, Authorization
public AuthorizationGrid(@NonNull AuthService authService,
@NonNull AttributeService attributeService,
@NonNull RadiusUserService userService,
@NonNull SecurityService securityService) {
@NonNull SecurityService securityService,
@NonNull AuthFormConfiguration formConfig) {
super(securityService);
this.authService = authService;
assigmentDialog = new AuthorizationAttributeAssigmentDialog(authService, attributeService, userService,
assigmentDialog = new AuthorizationAttributeAssigmentDialog(authService, attributeService, userService, formConfig,
(source, bean) -> refreshGrid());
refreshGrid();
}
Expand Down

0 comments on commit d3f971d

Please sign in to comment.