RedirectController into auto config as default and null pointer fix. (#621)

* Vaadin patch and redirect controller to auto config.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Fix potential null pointer.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* revert Vaadin update.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Conditional on missing bean.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Fix on permission checks.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Fix permission checks.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Fix nested cascade on delete.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
Kai Zimmermann
2018-01-19 11:23:41 +01:00
committed by GitHub
parent df41fc0e4e
commit 722c5ad2c2
23 changed files with 173 additions and 98 deletions

View File

@@ -31,7 +31,7 @@ import org.vaadin.spring.security.annotation.EnableVaadinSecurity;
import com.vaadin.spring.annotation.UIScope; import com.vaadin.spring.annotation.UIScope;
/** /**
* The hawkbit-ui autoconfiguration. * The Management UI auto configuration.
*/ */
@Configuration @Configuration
@EnableVaadinSecurity @EnableVaadinSecurity
@@ -41,13 +41,19 @@ import com.vaadin.spring.annotation.UIScope;
@Import(MgmtUiConfiguration.class) @Import(MgmtUiConfiguration.class)
public class MgmtUiAutoConfiguration { public class MgmtUiAutoConfiguration {
@Bean
@ConditionalOnMissingBean
RedirectController uiRedirectController() {
return new RedirectController();
}
/** /**
* A message source bean to add distributed message sources. * A message source bean to add distributed message sources.
* *
* @return the message bean. * @return the message bean.
*/ */
@Bean(name = "messageSource") @Bean(name = "messageSource")
public DistributedResourceBundleMessageSource messageSource() { DistributedResourceBundleMessageSource messageSource() {
return new DistributedResourceBundleMessageSource(); return new DistributedResourceBundleMessageSource();
} }
@@ -58,7 +64,7 @@ public class MgmtUiAutoConfiguration {
*/ */
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
public UIEventProvider eventProvider() { UIEventProvider eventProvider() {
return new HawkbitEventProvider(); return new HawkbitEventProvider();
} }
@@ -81,7 +87,7 @@ public class MgmtUiAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@UIScope @UIScope
public EventPushStrategy eventPushStrategy(final ConfigurableApplicationContext applicationContext, EventPushStrategy eventPushStrategy(final ConfigurableApplicationContext applicationContext,
final ScheduledExecutorService executorService, final UIEventBus eventBus, final ScheduledExecutorService executorService, final UIEventBus eventBus,
final UIEventProvider eventProvider, final UiProperties uiProperties) { final UIEventProvider eventProvider, final UiProperties uiProperties) {
final DelayedEventBusPushStrategy delayedEventBusPushStrategy = new DelayedEventBusPushStrategy(executorService, final DelayedEventBusPushStrategy delayedEventBusPushStrategy = new DelayedEventBusPushStrategy(executorService,

View File

@@ -6,15 +6,15 @@
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
*/ */
package org.eclipse.hawkbit.app; package org.eclipse.hawkbit.autoconfigure.mgmt.ui;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
/** /**
* Redirects for convenience of the example apps users. hawkBit's management UI * Redirects for convenience. hawkBit's management UI is by default not
* is by default not listening on / but on /UI. * listening on / but on /UI.
* *
*/ */
@Controller @Controller

View File

@@ -121,8 +121,9 @@ public abstract class AbstractJpaBaseEntity implements BaseEntity {
} }
private boolean isController() { private boolean isController() {
return SecurityContextHolder.getContext().getAuthentication() return SecurityContextHolder.getContext().getAuthentication() != null
.getDetails() instanceof TenantAwareAuthenticationDetails && SecurityContextHolder.getContext().getAuthentication()
.getDetails() instanceof TenantAwareAuthenticationDetails
&& ((TenantAwareAuthenticationDetails) SecurityContextHolder.getContext().getAuthentication() && ((TenantAwareAuthenticationDetails) SecurityContextHolder.getContext().getAuthentication()
.getDetails()).isController(); .getDetails()).isController();
} }

View File

@@ -72,8 +72,9 @@ public class JpaRolloutGroup extends AbstractJpaNamedEntity implements RolloutGr
CascadeType.PERSIST }, targetEntity = RolloutTargetGroup.class) CascadeType.PERSIST }, targetEntity = RolloutTargetGroup.class)
private List<RolloutTargetGroup> rolloutTargetGroup; private List<RolloutTargetGroup> rolloutTargetGroup;
@ManyToOne(fetch = FetchType.LAZY) // No foreign key to avoid to many nested cascades on delete which some DBs cannot handle
@JoinColumn(name = "parent_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_rolloutgroup_rolloutgroup")) @ManyToOne(fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST })
@JoinColumn(name = "parent_id")
private JpaRolloutGroup parent; private JpaRolloutGroup parent;
@Column(name = "success_condition", nullable = false) @Column(name = "success_condition", nullable = false)

View File

@@ -0,0 +1 @@
alter table sp_rolloutgroup drop constraint fk_rolloutgroup_rolloutgroup;

View File

@@ -0,0 +1 @@
alter table sp_rolloutgroup drop FOREIGN KEY fk_rolloutgroup_rolloutgroup;

View File

@@ -61,6 +61,6 @@ public class UploadArtifactViewMenuItem extends AbstractDashboardMenuItemNotific
@Override @Override
public List<String> getPermissions() { public List<String> getPermissions() {
return Arrays.asList(SpPermission.CREATE_REPOSITORY, SpPermission.READ_REPOSITORY); return Arrays.asList(SpPermission.READ_REPOSITORY);
} }
} }

View File

@@ -8,6 +8,7 @@
*/ */
package org.eclipse.hawkbit.ui.common.table; package org.eclipse.hawkbit.ui.common.table;
import java.util.Collections;
import java.util.List; import java.util.List;
import org.eclipse.hawkbit.repository.model.NamedVersionedEntity; import org.eclipse.hawkbit.repository.model.NamedVersionedEntity;
@@ -66,8 +67,8 @@ public abstract class AbstractNamedVersionTable<E extends NamedVersionedEntity>
} }
@Override @Override
protected boolean hasDropPermission() { protected List<String> hasMissingPermissionsForDrop() {
return true; return Collections.emptyList();
} }
@Override @Override

View File

@@ -431,8 +431,9 @@ public abstract class AbstractTable<E extends NamedEntity> extends Table impleme
final Transferable transferable = dragEvent.getTransferable(); final Transferable transferable = dragEvent.getTransferable();
final Component compsource = transferable.getSourceComponent(); final Component compsource = transferable.getSourceComponent();
if (!hasDropPermission()) { final List<String> missingPermissions = hasMissingPermissionsForDrop();
notification.displayValidationError(i18n.getMessage("message.permission.insufficient")); if (!missingPermissions.isEmpty()) {
notification.displayValidationError(i18n.getMessage("message.permission.insufficient", missingPermissions));
return false; return false;
} }
@@ -487,7 +488,7 @@ public abstract class AbstractTable<E extends NamedEntity> extends Table impleme
publishSelectedEntityEvent(entity); publishSelectedEntityEvent(entity);
} }
protected abstract boolean hasDropPermission(); protected abstract List<String> hasMissingPermissionsForDrop();
protected abstract boolean validateDragAndDropWrapper(final DragAndDropWrapper wrapperSource); protected abstract boolean validateDragAndDropWrapper(final DragAndDropWrapper wrapperSource);

View File

@@ -59,8 +59,7 @@ public class DistributionsViewMenuItem extends AbstractDashboardMenuItemNotifica
@Override @Override
public List<String> getPermissions() { public List<String> getPermissions() {
return Arrays.asList(SpPermission.CREATE_REPOSITORY, SpPermission.READ_REPOSITORY, return Arrays.asList(SpPermission.READ_REPOSITORY);
SpPermission.UPDATE_REPOSITORY);
} }
} }

View File

@@ -8,6 +8,8 @@
*/ */
package org.eclipse.hawkbit.ui.distributions.dstable; package org.eclipse.hawkbit.ui.distributions.dstable;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@@ -17,6 +19,7 @@ import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import org.eclipse.hawkbit.im.authentication.SpPermission;
import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.SoftwareModuleManagement; import org.eclipse.hawkbit.repository.SoftwareModuleManagement;
import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.TargetManagement;
@@ -238,8 +241,7 @@ public class DistributionSetTable extends AbstractNamedVersionTable<Distribution
} }
private void handleDropEvent(final Table source, final Set<Long> softwareModulesIdList, final Object distId) { private void handleDropEvent(final Table source, final Set<Long> softwareModulesIdList, final Object distId) {
final Optional<DistributionSet> distributionSet = distributionSetManagement final Optional<DistributionSet> distributionSet = distributionSetManagement.get((Long) distId);
.get((Long) distId);
if (!distributionSet.isPresent()) { if (!distributionSet.isPresent()) {
notification.displayWarning(i18n.getMessage("distributionset.not.exists")); notification.displayWarning(i18n.getMessage("distributionset.not.exists"));
@@ -261,8 +263,7 @@ public class DistributionSetTable extends AbstractNamedVersionTable<Distribution
final String name = (String) softwareItem.getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue(); final String name = (String) softwareItem.getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue();
final String swVersion = (String) softwareItem.getItemProperty(SPUILabelDefinitions.VAR_VERSION).getValue(); final String swVersion = (String) softwareItem.getItemProperty(SPUILabelDefinitions.VAR_VERSION).getValue();
final Optional<SoftwareModule> softwareModule = softwareModuleManagement final Optional<SoftwareModule> softwareModule = softwareModuleManagement.get(softwareModuleId);
.get(softwareModuleId);
if (softwareModule.isPresent() && validSoftwareModule((Long) distId, softwareModule.get())) { if (softwareModule.isPresent() && validSoftwareModule((Long) distId, softwareModule.get())) {
final SoftwareModuleIdName softwareModuleIdName = new SoftwareModuleIdName(softwareModuleId, final SoftwareModuleIdName softwareModuleIdName = new SoftwareModuleIdName(softwareModuleId,
@@ -384,8 +385,9 @@ public class DistributionSetTable extends AbstractNamedVersionTable<Distribution
} }
@Override @Override
protected boolean hasDropPermission() { protected List<String> hasMissingPermissionsForDrop() {
return permissionChecker.hasUpdateRepositoryPermission(); return permissionChecker.hasUpdateRepositoryPermission() ? Collections.emptyList()
: Arrays.asList(SpPermission.UPDATE_REPOSITORY);
} }
private void addTableStyleGenerator() { private void addTableStyleGenerator() {

View File

@@ -73,7 +73,7 @@ public class FilterManagementView extends VerticalLayout implements View {
final TargetManagement targetManagement) { final TargetManagement targetManagement) {
this.targetFilterHeader = new TargetFilterHeader(eventBus, filterManagementUIState, permissionChecker); this.targetFilterHeader = new TargetFilterHeader(eventBus, filterManagementUIState, permissionChecker);
this.targetFilterTable = new TargetFilterTable(i18n, notification, eventBus, filterManagementUIState, this.targetFilterTable = new TargetFilterTable(i18n, notification, eventBus, filterManagementUIState,
targetFilterQueryManagement, manageDistUIState, targetManagement); targetFilterQueryManagement, manageDistUIState, targetManagement, permissionChecker);
this.createNewFilterHeader = new CreateOrUpdateFilterHeader(i18n, eventBus, filterManagementUIState, this.createNewFilterHeader = new CreateOrUpdateFilterHeader(i18n, eventBus, filterManagementUIState,
targetFilterQueryManagement, permissionChecker, notification, uiProperties, entityFactory, targetFilterQueryManagement, permissionChecker, notification, uiProperties, entityFactory,
queryTextField); queryTextField);

View File

@@ -59,7 +59,7 @@ public class FilterManagementViewMenuItem extends AbstractDashboardMenuItemNotif
@Override @Override
public List<String> getPermissions() { public List<String> getPermissions() {
return Arrays.asList(SpPermission.CREATE_TARGET, SpPermission.READ_TARGET); return Arrays.asList(SpPermission.READ_TARGET);
} }
} }

View File

@@ -13,8 +13,10 @@ import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.eclipse.hawkbit.im.authentication.SpPermission;
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.ui.SpPermissionChecker;
import org.eclipse.hawkbit.ui.common.ConfirmationDialog; import org.eclipse.hawkbit.ui.common.ConfirmationDialog;
import org.eclipse.hawkbit.ui.components.ProxyDistribution; import org.eclipse.hawkbit.ui.components.ProxyDistribution;
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
@@ -67,19 +69,23 @@ public class TargetFilterTable extends Table {
private final DistributionSetSelectWindow dsSelectWindow; private final DistributionSetSelectWindow dsSelectWindow;
private final SpPermissionChecker permChecker;
private Container container; private Container container;
private static final int PROPERTY_DEPT = 3; private static final int PROPERTY_DEPT = 3;
public TargetFilterTable(final VaadinMessageSource i18n, final UINotification notification, final UIEventBus eventBus, public TargetFilterTable(final VaadinMessageSource i18n, final UINotification notification,
final FilterManagementUIState filterManagementUIState, final UIEventBus eventBus, final FilterManagementUIState filterManagementUIState,
final TargetFilterQueryManagement targetFilterQueryManagement, final ManageDistUIState manageDistUIState, final TargetFilterQueryManagement targetFilterQueryManagement, final ManageDistUIState manageDistUIState,
final TargetManagement targetManagement) { final TargetManagement targetManagement, final SpPermissionChecker permChecker) {
this.i18n = i18n; this.i18n = i18n;
this.notification = notification; this.notification = notification;
this.eventBus = eventBus; this.eventBus = eventBus;
this.filterManagementUIState = filterManagementUIState; this.filterManagementUIState = filterManagementUIState;
this.targetFilterQueryManagement = targetFilterQueryManagement; this.targetFilterQueryManagement = targetFilterQueryManagement;
this.permChecker = permChecker;
this.dsSelectWindow = new DistributionSetSelectWindow(i18n, eventBus, targetManagement, this.dsSelectWindow = new DistributionSetSelectWindow(i18n, eventBus, targetManagement,
targetFilterQueryManagement, manageDistUIState); targetFilterQueryManagement, manageDistUIState);
@@ -141,10 +147,14 @@ public class TargetFilterTable extends Table {
private List<TableColumn> getVisbleColumns() { private List<TableColumn> getVisbleColumns() {
final List<TableColumn> columnList = new ArrayList<>(7); final List<TableColumn> columnList = new ArrayList<>(7);
columnList.add(new TableColumn(SPUILabelDefinitions.NAME, i18n.getMessage("header.name"), 0.2F)); columnList.add(new TableColumn(SPUILabelDefinitions.NAME, i18n.getMessage("header.name"), 0.2F));
columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_USER, i18n.getMessage("header.createdBy"), 0.1F)); columnList
columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_DATE, i18n.getMessage("header.createdDate"), 0.2F)); .add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_USER, i18n.getMessage("header.createdBy"), 0.1F));
columnList.add(new TableColumn(SPUILabelDefinitions.VAR_MODIFIED_BY, i18n.getMessage("header.modifiedBy"), 0.1F)); columnList.add(
columnList.add(new TableColumn(SPUILabelDefinitions.VAR_MODIFIED_DATE, i18n.getMessage("header.modifiedDate"), 0.2F)); new TableColumn(SPUILabelDefinitions.VAR_CREATED_DATE, i18n.getMessage("header.createdDate"), 0.2F));
columnList
.add(new TableColumn(SPUILabelDefinitions.VAR_MODIFIED_BY, i18n.getMessage("header.modifiedBy"), 0.1F));
columnList.add(
new TableColumn(SPUILabelDefinitions.VAR_MODIFIED_DATE, i18n.getMessage("header.modifiedDate"), 0.2F));
columnList.add(new TableColumn(SPUILabelDefinitions.AUTO_ASSIGN_DISTRIBUTION_SET, columnList.add(new TableColumn(SPUILabelDefinitions.AUTO_ASSIGN_DISTRIBUTION_SET,
i18n.getMessage("header.auto.assignment.ds"), 0.1F)); i18n.getMessage("header.auto.assignment.ds"), 0.1F));
columnList.add(new TableColumn(SPUIDefinitions.CUSTOM_FILTER_DELETE, i18n.getMessage("header.delete"), 0.1F)); columnList.add(new TableColumn(SPUIDefinitions.CUSTOM_FILTER_DELETE, i18n.getMessage("header.delete"), 0.1F));
@@ -175,12 +185,12 @@ public class TargetFilterTable extends Table {
private void onDelete(final ClickEvent event) { private void onDelete(final ClickEvent event) {
/* Display the confirmation */ /* Display the confirmation */
final ConfirmationDialog confirmDialog = new ConfirmationDialog(i18n.getMessage("caption.filter.delete.confirmbox"), final ConfirmationDialog confirmDialog = new ConfirmationDialog(
i18n.getMessage("message.delete.filter.confirm"), i18n.getMessage("button.ok"), i18n.getMessage("button.cancel"), ok -> { i18n.getMessage("caption.filter.delete.confirmbox"), i18n.getMessage("message.delete.filter.confirm"),
i18n.getMessage("button.ok"), i18n.getMessage("button.cancel"), ok -> {
if (ok) { if (ok) {
final Long rowId = (Long) ((Button) event.getComponent()).getData(); final Long rowId = (Long) ((Button) event.getComponent()).getData();
final String deletedFilterName = targetFilterQueryManagement.get(rowId) final String deletedFilterName = targetFilterQueryManagement.get(rowId).get().getName();
.get().getName();
targetFilterQueryManagement.delete(rowId); targetFilterQueryManagement.delete(rowId);
/* /*
@@ -229,10 +239,12 @@ public class TargetFilterTable extends Table {
Button updateIcon; Button updateIcon;
if (distSet == null) { if (distSet == null) {
updateIcon = SPUIComponentProvider.getButton(buttonId, i18n.getMessage("button.no.auto.assignment"), updateIcon = SPUIComponentProvider.getButton(buttonId, i18n.getMessage("button.no.auto.assignment"),
i18n.getMessage("button.auto.assignment.desc"), null, false, null, SPUIButtonStyleSmallNoBorder.class); i18n.getMessage("button.auto.assignment.desc"), null, false, null,
SPUIButtonStyleSmallNoBorder.class);
} else { } else {
updateIcon = SPUIComponentProvider.getButton(buttonId, distSet.getNameVersion(), updateIcon = SPUIComponentProvider.getButton(buttonId, distSet.getNameVersion(),
i18n.getMessage("button.auto.assignment.desc"), null, false, null, SPUIButtonStyleSmallNoBorder.class); i18n.getMessage("button.auto.assignment.desc"), null, false, null,
SPUIButtonStyleSmallNoBorder.class);
} }
updateIcon.addClickListener(this::onClickOfDistributionSetButton); updateIcon.addClickListener(this::onClickOfDistributionSetButton);
@@ -246,7 +258,12 @@ public class TargetFilterTable extends Table {
final Item item = (Item) ((Button) event.getComponent()).getData(); final Item item = (Item) ((Button) event.getComponent()).getData();
final Long tfqId = (Long) item.getItemProperty(SPUILabelDefinitions.VAR_ID).getValue(); final Long tfqId = (Long) item.getItemProperty(SPUILabelDefinitions.VAR_ID).getValue();
dsSelectWindow.showForTargetFilter(tfqId); if (permChecker.hasReadRepositoryPermission()) {
dsSelectWindow.showForTargetFilter(tfqId);
} else {
notification.displayValidationError(
i18n.getMessage("message.permission.insufficient", SpPermission.READ_REPOSITORY));
}
} }

View File

@@ -136,38 +136,56 @@ public class DeploymentView extends AbstractNotificationView implements BrowserW
this.i18n = i18n; this.i18n = i18n;
this.uiNotification = uiNotification; this.uiNotification = uiNotification;
this.managementUIState = managementUIState; this.managementUIState = managementUIState;
this.actionHistoryLayout = new ActionHistoryLayout(i18n, deploymentManagement, eventBus, uiNotification,
managementUIState);
this.actionStatusLayout = new ActionStatusLayout(i18n, eventBus, managementUIState);
this.actionStatusMsgLayout = new ActionStatusMsgLayout(i18n, eventBus, managementUIState);
final CreateUpdateTargetTagLayoutWindow createUpdateTargetTagLayout = new CreateUpdateTargetTagLayoutWindow(
i18n, targetTagManagement, entityFactory, eventBus, permChecker, uiNotification);
this.targetTagFilterLayout = new TargetTagFilterLayout(i18n, createUpdateTargetTagLayout, managementUIState,
managementViewClientCriterion, permChecker, eventBus, uiNotification, entityFactory,
targetFilterQueryManagement);
final TargetTable targetTable = new TargetTable(eventBus, i18n, uiNotification, targetManagement,
managementUIState, permChecker, managementViewClientCriterion, distributionSetManagement,
targetTagManagement);
this.targetTableLayout = new TargetTableLayout(eventbus, targetTable, targetManagement, entityFactory, i18n,
eventBus, uiNotification, managementUIState, managementViewClientCriterion, deploymentManagement,
uiproperties, permChecker, uiNotification, targetTagManagement, distributionSetManagement, uiExecutor);
this.distributionTagLayout = new DistributionTagLayout(eventbus, managementUIState, i18n, permChecker, eventBus,
distributionSetTagManagement, entityFactory, uiNotification, distFilterParameters,
distributionSetManagement, managementViewClientCriterion);
this.distributionTableLayout = new DistributionTableLayout(i18n, eventBus, permChecker, managementUIState,
distributionSetManagement, distributionSetTypeManagement, managementViewClientCriterion, entityFactory,
uiNotification, distributionSetTagManagement, targetTagManagement, systemManagement, targetManagement,
deploymentManagement);
this.deleteAndActionsLayout = new DeleteActionsLayout(i18n, permChecker, eventBus, uiNotification,
targetTagManagement, distributionSetTagManagement, managementViewClientCriterion, managementUIState,
targetManagement, targetTable, deploymentManagement, distributionSetManagement);
this.deploymentViewMenuItem = deploymentViewMenuItem; this.deploymentViewMenuItem = deploymentViewMenuItem;
actionHistoryLayout.registerDetails(((ActionStatusGrid) actionStatusLayout.getGrid()).getDetailsSupport()); if (permChecker.hasTargetReadPermission()) {
actionStatusLayout.registerDetails(((ActionStatusMsgGrid) actionStatusMsgLayout.getGrid()).getDetailsSupport()); this.actionHistoryLayout = new ActionHistoryLayout(i18n, deploymentManagement, eventBus, uiNotification,
managementUIState);
this.actionStatusLayout = new ActionStatusLayout(i18n, eventBus, managementUIState);
this.actionStatusMsgLayout = new ActionStatusMsgLayout(i18n, eventBus, managementUIState);
final CreateUpdateTargetTagLayoutWindow createUpdateTargetTagLayout = new CreateUpdateTargetTagLayoutWindow(
i18n, targetTagManagement, entityFactory, eventBus, permChecker, uiNotification);
this.targetTagFilterLayout = new TargetTagFilterLayout(i18n, createUpdateTargetTagLayout, managementUIState,
managementViewClientCriterion, permChecker, eventBus, uiNotification, entityFactory,
targetFilterQueryManagement);
final TargetTable targetTable = new TargetTable(eventBus, i18n, uiNotification, targetManagement,
managementUIState, permChecker, managementViewClientCriterion, distributionSetManagement,
targetTagManagement);
this.targetTableLayout = new TargetTableLayout(eventbus, targetTable, targetManagement, entityFactory, i18n,
eventBus, uiNotification, managementUIState, managementViewClientCriterion, deploymentManagement,
uiproperties, permChecker, uiNotification, targetTagManagement, distributionSetManagement,
uiExecutor);
this.deleteAndActionsLayout = new DeleteActionsLayout(i18n, permChecker, eventBus, uiNotification,
targetTagManagement, distributionSetTagManagement, managementViewClientCriterion, managementUIState,
targetManagement, targetTable, deploymentManagement, distributionSetManagement);
actionHistoryLayout.registerDetails(((ActionStatusGrid) actionStatusLayout.getGrid()).getDetailsSupport());
actionStatusLayout
.registerDetails(((ActionStatusMsgGrid) actionStatusMsgLayout.getGrid()).getDetailsSupport());
} else {
this.actionHistoryLayout = null;
this.actionStatusLayout = null;
this.actionStatusMsgLayout = null;
this.targetTagFilterLayout = null;
this.targetTableLayout = null;
this.deleteAndActionsLayout = null;
}
if (permChecker.hasReadRepositoryPermission()) {
this.distributionTagLayout = new DistributionTagLayout(eventbus, managementUIState, i18n, permChecker,
eventBus, distributionSetTagManagement, entityFactory, uiNotification, distFilterParameters,
distributionSetManagement, managementViewClientCriterion);
this.distributionTableLayout = new DistributionTableLayout(i18n, eventBus, permChecker, managementUIState,
distributionSetManagement, distributionSetTypeManagement, managementViewClientCriterion,
entityFactory, uiNotification, distributionSetTagManagement, targetTagManagement, systemManagement,
targetManagement, deploymentManagement);
} else {
this.distributionTagLayout = null;
this.distributionTableLayout = null;
}
} }
@PostConstruct @PostConstruct
@@ -182,7 +200,9 @@ public class DeploymentView extends AbstractNotificationView implements BrowserW
@Override @Override
public void enter(final ViewChangeEvent event) { public void enter(final ViewChangeEvent event) {
distributionTableLayout.getDistributionTable().selectEntity(managementUIState.getLastSelectedDsIdName()); if (permChecker.hasReadRepositoryPermission()) {
distributionTableLayout.getDistributionTable().selectEntity(managementUIState.getLastSelectedDsIdName());
}
} }
@Override @Override
@@ -382,17 +402,22 @@ public class DeploymentView extends AbstractNotificationView implements BrowserW
private void showOrHideFilterButtons(final int browserWidth) { private void showOrHideFilterButtons(final int browserWidth) {
if (browserWidth < SPUIDefinitions.REQ_MIN_BROWSER_WIDTH) { if (browserWidth < SPUIDefinitions.REQ_MIN_BROWSER_WIDTH) {
targetTagFilterLayout.setVisible(false); if (permChecker.hasTargetReadPermission()) {
targetTableLayout.setShowFilterButtonVisible(true); targetTagFilterLayout.setVisible(false);
distributionTagLayout.setVisible(false); targetTableLayout.setShowFilterButtonVisible(true);
distributionTableLayout.setShowFilterButtonVisible(true); }
if (permChecker.hasReadRepositoryPermission()) {
distributionTagLayout.setVisible(false);
distributionTableLayout.setShowFilterButtonVisible(true);
}
} else { } else {
if (!managementUIState.isTargetTagFilterClosed()) { if (permChecker.hasTargetReadPermission() && !managementUIState.isTargetTagFilterClosed()) {
targetTagFilterLayout.setVisible(true); targetTagFilterLayout.setVisible(true);
targetTableLayout.setShowFilterButtonVisible(false); targetTableLayout.setShowFilterButtonVisible(false);
} }
if (!managementUIState.isDistTagFilterClosed()) { if (permChecker.hasReadRepositoryPermission() && !managementUIState.isDistTagFilterClosed()) {
distributionTagLayout.setVisible(true); distributionTagLayout.setVisible(true);
distributionTableLayout.setShowFilterButtonVisible(false); distributionTableLayout.setShowFilterButtonVisible(false);
} }

View File

@@ -57,8 +57,7 @@ public class DeploymentViewMenuItem extends AbstractDashboardMenuItemNotificatio
@Override @Override
public List<String> getPermissions() { public List<String> getPermissions() {
return Arrays.asList(SpPermission.CREATE_REPOSITORY, SpPermission.READ_REPOSITORY, SpPermission.CREATE_TARGET, return Arrays.asList(SpPermission.READ_REPOSITORY, SpPermission.READ_TARGET);
SpPermission.READ_TARGET, SpPermission.UPDATE_TARGET, SpPermission.UPDATE_REPOSITORY);
} }
} }

View File

@@ -9,7 +9,9 @@
package org.eclipse.hawkbit.ui.management.dstable; package org.eclipse.hawkbit.ui.management.dstable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -18,6 +20,7 @@ import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.eclipse.hawkbit.im.authentication.SpPermission;
import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DeploymentManagement;
import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.TargetManagement;
@@ -124,6 +127,7 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
addNewContainerDS(); addNewContainerDS();
setColumnProperties(); setColumnProperties();
setDataAvailable(getContainerDataSource().size() != 0); setDataAvailable(getContainerDataSource().size() != 0);
} }
@EventBusListenerMethod(scope = EventScope.UI) @EventBusListenerMethod(scope = EventScope.UI)
@@ -447,8 +451,9 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
} }
@Override @Override
protected boolean hasDropPermission() { protected List<String> hasMissingPermissionsForDrop() {
return permissionChecker.hasUpdateTargetPermission(); return permissionChecker.hasUpdateTargetPermission() ? Collections.emptyList()
: Arrays.asList(SpPermission.UPDATE_TARGET);
} }
@Override @Override

View File

@@ -61,7 +61,9 @@ public class DistributionTagButtons extends AbstractFilterButtons implements Ref
this.managementUIState = managementUIState; this.managementUIState = managementUIState;
this.entityFactory = entityFactory; this.entityFactory = entityFactory;
addNewTag(entityFactory.tag().create().name(NO_TAG).build()); if (permChecker.hasReadRepositoryPermission()) {
addNewTag(entityFactory.tag().create().name(NO_TAG).build());
}
} }
@Override @Override

View File

@@ -11,6 +11,7 @@ package org.eclipse.hawkbit.ui.management.event;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import org.eclipse.hawkbit.im.authentication.SpPermission;
import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult;
import org.eclipse.hawkbit.ui.SpPermissionChecker; import org.eclipse.hawkbit.ui.SpPermissionChecker;
@@ -111,7 +112,8 @@ public class DistributionTagDropEvent implements DropHandler {
private boolean checkForDSUpdatePermission() { private boolean checkForDSUpdatePermission() {
if (!permChecker.hasUpdateRepositoryPermission()) { if (!permChecker.hasUpdateRepositoryPermission()) {
notification.displayValidationError(i18n.getMessage("message.permission.insufficient")); notification.displayValidationError(
i18n.getMessage("message.permission.insufficient", SpPermission.UPDATE_REPOSITORY));
return false; return false;
} }

View File

@@ -15,6 +15,7 @@ import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.eclipse.hawkbit.im.authentication.SpPermission;
import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DeploymentManagement;
import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.DistributionSetTagManagement; import org.eclipse.hawkbit.repository.DistributionSetTagManagement;
@@ -379,7 +380,8 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout {
private Boolean canTargetBeDeleted() { private Boolean canTargetBeDeleted() {
if (!permChecker.hasDeleteTargetPermission()) { if (!permChecker.hasDeleteTargetPermission()) {
notification.displayValidationError(i18n.getMessage("message.permission.insufficient")); notification.displayValidationError(
i18n.getMessage("message.permission.insufficient", SpPermission.DELETE_TARGET));
return false; return false;
} }
return true; return true;
@@ -387,7 +389,8 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout {
private Boolean canDSBeDeleted() { private Boolean canDSBeDeleted() {
if (!permChecker.hasDeleteRepositoryPermission()) { if (!permChecker.hasDeleteRepositoryPermission()) {
notification.displayValidationError(i18n.getMessage("message.permission.insufficient")); notification.displayValidationError(
i18n.getMessage("message.permission.insufficient", SpPermission.DELETE_REPOSITORY));
return false; return false;
} }
return true; return true;

View File

@@ -9,7 +9,9 @@
package org.eclipse.hawkbit.ui.management.targettable; package org.eclipse.hawkbit.ui.management.targettable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -19,6 +21,7 @@ import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.eclipse.hawkbit.im.authentication.SpPermission;
import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.FilterParams; import org.eclipse.hawkbit.repository.FilterParams;
import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.TargetManagement;
@@ -479,8 +482,8 @@ public class TargetTable extends AbstractTable<Target> {
final String tagName = ((DragAndDropWrapper) (event.getTransferable().getSourceComponent())).getData() final String tagName = ((DragAndDropWrapper) (event.getTransferable().getSourceComponent())).getData()
.toString(); .toString();
if (tagName.equals(SPUIDefinitions.TARGET_TAG_BUTTON)) { if (tagName.equals(SPUIDefinitions.TARGET_TAG_BUTTON)) {
notification.displayValidationError(i18n.getMessage("message.tag.cannot.be.assigned", notification.displayValidationError(
new Object[] { i18n.getMessage("label.no.tag.assigned") })); i18n.getMessage("message.tag.cannot.be.assigned", i18n.getMessage("label.no.tag.assigned")));
return false; return false;
} }
return true; return true;
@@ -528,7 +531,7 @@ public class TargetTable extends AbstractTable<Target> {
final Optional<TargetTag> tag = tagManagement.getByName(targTagName); final Optional<TargetTag> tag = tagManagement.getByName(targTagName);
if (!tag.isPresent()) { if (!tag.isPresent()) {
notification.displayWarning(i18n.getMessage("targettag.not.exists", new Object[] { targTagName })); notification.displayWarning(i18n.getMessage("targettag.not.exists", targTagName));
return new TargetTagAssignmentResult(0, 0, 0, Lists.newArrayListWithCapacity(0), return new TargetTagAssignmentResult(0, 0, 0, Lists.newArrayListWithCapacity(0),
Lists.newArrayListWithCapacity(0), null); Lists.newArrayListWithCapacity(0), null);
} }
@@ -563,8 +566,9 @@ public class TargetTable extends AbstractTable<Target> {
} }
@Override @Override
protected boolean hasDropPermission() { protected List<String> hasMissingPermissionsForDrop() {
return permChecker.hasUpdateTargetPermission(); return permChecker.hasUpdateTargetPermission() ? Collections.emptyList()
: Arrays.asList(SpPermission.UPDATE_TARGET);
} }
private void dsToTargetAssignment(final DragAndDropEvent event) { private void dsToTargetAssignment(final DragAndDropEvent event) {
@@ -575,13 +579,13 @@ public class TargetTable extends AbstractTable<Target> {
final Object targetItemId = dropData.getItemIdOver(); final Object targetItemId = dropData.getItemIdOver();
LOG.debug("Adding a log to check if targetItemId is null : {} ", targetItemId); LOG.debug("Adding a log to check if targetItemId is null : {} ", targetItemId);
if (targetItemId == null) { if (targetItemId == null) {
getNotification().displayWarning(i18n.getMessage("target.not.exists", new Object[] { "" })); getNotification().displayWarning(i18n.getMessage("target.not.exists", ""));
return; return;
} }
final Long targetId = (Long) targetItemId; final Long targetId = (Long) targetItemId;
final Optional<Target> target = targetManagement.get(targetId); final Optional<Target> target = targetManagement.get(targetId);
if (!target.isPresent()) { if (!target.isPresent()) {
getNotification().displayWarning(i18n.getMessage("target.not.exists", new Object[] { "" })); getNotification().displayWarning(i18n.getMessage("target.not.exists", ""));
return; return;
} }
final TargetIdName createTargetIdName = new TargetIdName(target.get()); final TargetIdName createTargetIdName = new TargetIdName(target.get());
@@ -635,7 +639,7 @@ public class TargetTable extends AbstractTable<Target> {
private String getPendingActionMessage(final String message, final String distName, final String controllerId) { private String getPendingActionMessage(final String message, final String distName, final String controllerId) {
if (message == null) { if (message == null) {
return i18n.getMessage("message.dist.pending.action", new Object[] { controllerId, distName }); return i18n.getMessage("message.dist.pending.action", controllerId, distName);
} }
return i18n.getMessage("message.target.assigned.pending"); return i18n.getMessage("message.target.assigned.pending");
} }

View File

@@ -11,6 +11,7 @@ package org.eclipse.hawkbit.ui.management.targettag;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import org.eclipse.hawkbit.im.authentication.SpPermission;
import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.model.Tag; import org.eclipse.hawkbit.repository.model.Tag;
import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult; import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult;
@@ -163,7 +164,7 @@ public class TargetTagFilterButtons extends AbstractFilterButtons implements Ref
final AbstractTable<?> source = (AbstractTable<?>) tabletransferable.getSourceComponent(); final AbstractTable<?> source = (AbstractTable<?>) tabletransferable.getSourceComponent();
if (!validateIfSourceisTargetTable(source) && !checkForTargetUpdatePermission()) { if (!validateIfSourceisTargetTable(source) && !hasTargetUpdatePermission()) {
return false; return false;
} }
@@ -182,10 +183,10 @@ public class TargetTagFilterButtons extends AbstractFilterButtons implements Ref
* *
* @return boolean * @return boolean
*/ */
private boolean checkForTargetUpdatePermission() { private boolean hasTargetUpdatePermission() {
if (!permChecker.hasUpdateTargetPermission()) { if (!permChecker.hasUpdateTargetPermission()) {
notification.displayValidationError(
notification.displayValidationError(i18n.getMessage("message.permission.insufficient")); i18n.getMessage("message.permission.insufficient", SpPermission.UPDATE_TARGET));
return false; return false;
} }
@@ -201,6 +202,10 @@ public class TargetTagFilterButtons extends AbstractFilterButtons implements Ref
final String targTagName = HawkbitCommonUtil.removePrefix(targetDetails.getTarget().getId(), final String targTagName = HawkbitCommonUtil.removePrefix(targetDetails.getTarget().getId(),
SPUIDefinitions.TARGET_TAG_ID_PREFIXS); SPUIDefinitions.TARGET_TAG_ID_PREFIXS);
if (!hasTargetUpdatePermission()) {
return;
}
final TargetTagAssignmentResult result = targetTable.toggleTagAssignment(targetList, targTagName); final TargetTagAssignmentResult result = targetTable.toggleTagAssignment(targetList, targTagName);
publishAssignTargetTagEvent(result); publishAssignTargetTagEvent(result);

View File

@@ -312,7 +312,7 @@ message.no.actionupdateds.available = No other updates available for this action
message.mandatory.check = Mandatory details are missing message.mandatory.check = Mandatory details are missing
message.target.duplicate.check = Target [ {0} ] must be unique, entered value already exists. message.target.duplicate.check = Target [ {0} ] must be unique, entered value already exists.
message.target.whitespace.check = Please enter a valid controller ID with no whitespaces message.target.whitespace.check = Please enter a valid controller ID with no whitespaces
message.permission.insufficient = Insufficient permissions to perform this action. message.permission.insufficient = Missing permissions to perform this action: {0}
message.error.temp = The operation cannot be fulfilled due to {0}. Please contact administrator message.error.temp = The operation cannot be fulfilled due to {0}. Please contact administrator
message.dist.alreadyassigned = {0} : {1} is already assigned/installed, cannot be updated message.dist.alreadyassigned = {0} : {1} is already assigned/installed, cannot be updated
message.dist.tag.alreadyassigned = {0} : {1} is already assigned/installed, cannot assign/un-assign to tag message.dist.tag.alreadyassigned = {0} : {1} is already assigned/installed, cannot assign/un-assign to tag