Added anonymous download section as part of authentication configuration section

Signed-off-by: Jonathan Philip Knoblauch <JonathanPhilip.Knoblauch@bosch-si.com>
This commit is contained in:
Jonathan Philip Knoblauch
2016-04-07 14:43:05 +02:00
parent cadf67ad6c
commit 9299161652
4 changed files with 105 additions and 124 deletions

View File

@@ -11,6 +11,7 @@ package org.eclipse.hawkbit.ui.tenantconfiguration;
import javax.annotation.PostConstruct;
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
import org.eclipse.hawkbit.ui.tenantconfiguration.authentication.AnonymousDownloadAuthenticationConfigurationItem;
import org.eclipse.hawkbit.ui.tenantconfiguration.authentication.AuthenticationConfigurationItem;
import org.eclipse.hawkbit.ui.tenantconfiguration.authentication.CertificateAuthenticationConfigurationItem;
import org.eclipse.hawkbit.ui.tenantconfiguration.authentication.GatewaySecurityTokenAuthenticationConfigurationItem;
@@ -52,12 +53,17 @@ public class AuthenticationConfigurationView extends BaseConfigurationView
@Autowired
private GatewaySecurityTokenAuthenticationConfigurationItem gatewaySecurityTokenAuthenticationConfigurationItem;
@Autowired
private AnonymousDownloadAuthenticationConfigurationItem anonymousDownloadAuthenticationConfigurationItem;
private CheckBox gatewaySecTokenCheckBox;
private CheckBox targetSecTokenCheckBox;
private CheckBox certificateAuthCheckbox;
private CheckBox downloadAnonymousCheckBox;
/**
* Initialize Authentication Configuration layout.
*/
@@ -77,7 +83,7 @@ public class AuthenticationConfigurationView extends BaseConfigurationView
headerDisSetType.addStyleName("config-panel-header");
vLayout.addComponent(headerDisSetType);
final GridLayout gridLayout = new GridLayout(2, 3);
final GridLayout gridLayout = new GridLayout(2, 4);
gridLayout.setSpacing(true);
gridLayout.setImmediate(true);
gridLayout.setColumnExpandRatio(1, 1.0F);
@@ -105,6 +111,13 @@ public class AuthenticationConfigurationView extends BaseConfigurationView
gridLayout.addComponent(gatewaySecTokenCheckBox, 0, 2);
gridLayout.addComponent(gatewaySecurityTokenAuthenticationConfigurationItem, 1, 2);
downloadAnonymousCheckBox = SPUIComponentProvider.getCheckBox("", DIST_CHECKBOX_STYLE, null, false, "");
downloadAnonymousCheckBox.setValue(targetSecurityTokenAuthenticationConfigurationItem.isConfigEnabled());
downloadAnonymousCheckBox.addValueChangeListener(this);
anonymousDownloadAuthenticationConfigurationItem.addChangeListener(this);
gridLayout.addComponent(downloadAnonymousCheckBox, 0, 3);
gridLayout.addComponent(anonymousDownloadAuthenticationConfigurationItem, 1, 3);
vLayout.addComponent(gridLayout);
rootPanel.setContent(vLayout);
setCompositionRoot(rootPanel);
@@ -115,6 +128,7 @@ public class AuthenticationConfigurationView extends BaseConfigurationView
certificateAuthenticationConfigurationItem.save();
targetSecurityTokenAuthenticationConfigurationItem.save();
gatewaySecurityTokenAuthenticationConfigurationItem.save();
anonymousDownloadAuthenticationConfigurationItem.save();
}
@Override
@@ -122,9 +136,11 @@ public class AuthenticationConfigurationView extends BaseConfigurationView
certificateAuthenticationConfigurationItem.undo();
targetSecurityTokenAuthenticationConfigurationItem.undo();
gatewaySecurityTokenAuthenticationConfigurationItem.undo();
anonymousDownloadAuthenticationConfigurationItem.undo();
certificateAuthCheckbox.setValue(certificateAuthenticationConfigurationItem.isConfigEnabled());
targetSecTokenCheckBox.setValue(targetSecurityTokenAuthenticationConfigurationItem.isConfigEnabled());
gatewaySecTokenCheckBox.setValue(gatewaySecurityTokenAuthenticationConfigurationItem.isConfigEnabled());
downloadAnonymousCheckBox.setValue(anonymousDownloadAuthenticationConfigurationItem.isConfigEnabled());
}
@Override
@@ -150,6 +166,8 @@ public class AuthenticationConfigurationView extends BaseConfigurationView
configurationItem = targetSecurityTokenAuthenticationConfigurationItem;
} else if (checkBox == certificateAuthCheckbox) {
configurationItem = certificateAuthenticationConfigurationItem;
} else if (checkBox == downloadAnonymousCheckBox) {
configurationItem = anonymousDownloadAuthenticationConfigurationItem;
} else {
return;
}

View File

@@ -1,119 +0,0 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.ui.tenantconfiguration;
import javax.annotation.PostConstruct;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.repository.model.TenantConfigurationValue;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
import org.eclipse.hawkbit.ui.utils.I18N;
import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider;
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
import org.springframework.beans.factory.annotation.Autowired;
import com.vaadin.spring.annotation.SpringComponent;
import com.vaadin.spring.annotation.ViewScope;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.Panel;
import com.vaadin.ui.VerticalLayout;
/**
* View to enable anonymous download.
*/
@SpringComponent
@ViewScope
public class DownloadAnonymousConfigurationView extends BaseConfigurationView
implements ConfigurationItem.ConfigurationItemChangeListener {
private static final String DIST_CHECKBOX_STYLE = "dist-checkbox-style";
private static final long serialVersionUID = 1L;
@Autowired
private I18N i18n;
@Autowired
private transient TenantConfigurationManagement tenantConfigurationManagement;
boolean anonymousDownloadEnabled;
private CheckBox downloadAnonymousCheckBox;
/**
* Initialize Default Download Anonymous layout.
*/
@PostConstruct
public void init() {
final TenantConfigurationValue<Boolean> value = tenantConfigurationManagement
.getConfigurationValue(TenantConfigurationKey.ANONYMOUS_DOWNLOAD_MODE_ENABLED, Boolean.class);
anonymousDownloadEnabled = value.getValue();
final Panel rootPanel = new Panel();
rootPanel.setSizeFull();
rootPanel.addStyleName("config-panel");
final VerticalLayout vLayout = new VerticalLayout();
vLayout.setMargin(true);
vLayout.setSizeFull();
final Label headerDisSetType = new Label(i18n.get("enonymous.download.title"));
headerDisSetType.addStyleName("config-panel-header");
vLayout.addComponent(headerDisSetType);
final GridLayout gridLayout = new GridLayout(2, 1);
gridLayout.setSpacing(true);
gridLayout.setImmediate(true);
gridLayout.setColumnExpandRatio(1, 1.0F);
gridLayout.setSizeFull();
downloadAnonymousCheckBox = SPUIComponentProvider.getCheckBox("", DIST_CHECKBOX_STYLE, null, false, "");
downloadAnonymousCheckBox.setValue(anonymousDownloadEnabled);
downloadAnonymousCheckBox.addValueChangeListener(event -> configurationHasChanged());
downloadAnonymousCheckBox.setId(SPUIComponetIdProvider.SYSTEM_CONFIGURATION_ANONYMOUS_DOWNLOAD_CHECKBOX);
gridLayout.addComponent(downloadAnonymousCheckBox);
final Label configurationLabel = SPUIComponentProvider.getLabel(i18n.get("enonymous.download.label"),
SPUILabelDefinitions.SP_LABEL_SIMPLE);
gridLayout.addComponent(configurationLabel);
gridLayout.setComponentAlignment(configurationLabel, Alignment.MIDDLE_LEFT);
vLayout.addComponent(gridLayout);
rootPanel.setContent(vLayout);
setCompositionRoot(rootPanel);
}
@Override
public void configurationHasChanged() {
anonymousDownloadEnabled = downloadAnonymousCheckBox.getValue();
notifyConfigurationChanged();
}
@Override
public void save() {
tenantConfigurationManagement.addOrUpdateConfiguration(TenantConfigurationKey.ANONYMOUS_DOWNLOAD_MODE_ENABLED,
downloadAnonymousCheckBox.getValue());
}
@Override
public void undo() {
final TenantConfigurationValue<Boolean> value = tenantConfigurationManagement
.getConfigurationValue(TenantConfigurationKey.ANONYMOUS_DOWNLOAD_MODE_ENABLED, Boolean.class);
anonymousDownloadEnabled = value.getValue();
downloadAnonymousCheckBox.setValue(anonymousDownloadEnabled);
}
}

View File

@@ -55,9 +55,6 @@ public class TenantConfigurationDashboardView extends CustomComponent implements
@Autowired
private PollingConfigurationView pollingConfigurationView;
@Autowired
private DownloadAnonymousConfigurationView downloadAnonymousConfigurationView;
@Autowired
private I18N i18n;
@@ -80,7 +77,6 @@ public class TenantConfigurationDashboardView extends CustomComponent implements
configurationViews.add(defaultDistributionSetTypeLayout);
configurationViews.add(authenticationConfigurationView);
configurationViews.add(pollingConfigurationView);
configurationViews.add(downloadAnonymousConfigurationView);
}
@Override

View File

@@ -0,0 +1,86 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.ui.tenantconfiguration.authentication;
import javax.annotation.PostConstruct;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
import org.eclipse.hawkbit.ui.utils.I18N;
import org.springframework.beans.factory.annotation.Autowired;
import com.vaadin.spring.annotation.SpringComponent;
import com.vaadin.spring.annotation.ViewScope;
/**
* This class represents the UI item for the anonymous download by in the
* authentication configuration view.
*/
@SpringComponent
@ViewScope
public class AnonymousDownloadAuthenticationConfigurationItem extends AbstractAuthenticationTenantConfigurationItem {
private static final long serialVersionUID = 1L;
private boolean configurationEnabled = false;
private boolean configurationEnabledChange = false;
@Autowired
private I18N i18n;
@Autowired
public AnonymousDownloadAuthenticationConfigurationItem(
final TenantConfigurationManagement tenantConfigurationManagement) {
super(TenantConfigurationKey.ANONYMOUS_DOWNLOAD_MODE_ENABLED, tenantConfigurationManagement);
}
@PostConstruct
public void init() {
super.init(i18n.get("enonymous.download.label"));
configurationEnabled = isConfigEnabled();
}
@Override
public void configEnable() {
if (!configurationEnabled) {
configurationEnabledChange = true;
}
configurationEnabled = true;
}
@Override
public void configDisable() {
if (configurationEnabled) {
configurationEnabledChange = true;
}
configurationEnabled = false;
}
@Override
public void save() {
if (!configurationEnabledChange) {
return;
}
getTenantConfigurationManagement().addOrUpdateConfiguration(getConfigurationKey(), configurationEnabled);
}
@Override
public void undo() {
configurationEnabledChange = false;
configurationEnabled = getTenantConfigurationManagement()
.getConfigurationValue(getConfigurationKey(), Boolean.class).getValue();
}
}