CCM NG/ccm-cms: Some more experimenets with Vaadin
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4988 8810af33-2d31-482b-a856-94f89814c4df
parent
67531353c3
commit
1fa9f31d91
|
|
@ -90,6 +90,20 @@
|
||||||
<artifactId>shiro-web</artifactId>
|
<artifactId>shiro-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Vaadin dependencies for Vaadin prototype -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.vaadin</groupId>
|
||||||
|
<artifactId>vaadin-themes</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.vaadin</groupId>
|
||||||
|
<artifactId>vaadin-client-compiled</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.vaadin</groupId>
|
||||||
|
<artifactId>vaadin-cdi</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
|
|
@ -255,6 +269,24 @@
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<groupId>com.vaadin</groupId>
|
||||||
|
<artifactId>vaadin-maven-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>clean</goal>
|
||||||
|
<goal>resources</goal>
|
||||||
|
<goal>update-theme</goal>
|
||||||
|
<goal>update-widgetset</goal>
|
||||||
|
<goal>compile-theme</goal>
|
||||||
|
<goal>compile</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
</plugins>
|
</plugins>
|
||||||
|
|
||||||
</build>
|
</build>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,70 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2017 LibreCCM Foundation.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.librecms.ui;
|
||||||
|
|
||||||
|
import com.vaadin.cdi.CDIUI;
|
||||||
|
import com.vaadin.cdi.CDIViewProvider;
|
||||||
|
import com.vaadin.cdi.URLMapping;
|
||||||
|
import com.vaadin.navigator.Navigator;
|
||||||
|
import com.vaadin.server.VaadinRequest;
|
||||||
|
import com.vaadin.ui.UI;
|
||||||
|
import org.apache.shiro.subject.Subject;
|
||||||
|
import org.libreccm.l10n.GlobalizationHelper;
|
||||||
|
import org.libreccm.security.PermissionChecker;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@URLMapping("vaadin")
|
||||||
|
@CDIUI("cms")
|
||||||
|
public class CmsUI extends UI {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1867619939266841203L;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private CDIViewProvider viewProvider;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private Subject subject;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private PermissionChecker permissionChecker;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private GlobalizationHelper globalizationHelper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void init(final VaadinRequest request) {
|
||||||
|
|
||||||
|
final Navigator navigator = new Navigator(this, this);
|
||||||
|
navigator.addProvider(viewProvider);
|
||||||
|
|
||||||
|
// navigator.addViewChangeListener(new AuthNavListener());
|
||||||
|
|
||||||
|
if (subject.isAuthenticated()) {
|
||||||
|
navigator.navigateTo(CmsView.VIEWNAME);
|
||||||
|
} else {
|
||||||
|
navigator.navigateTo(LoginView.VIEWNAME);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,59 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2017 LibreCCM Foundation.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.librecms.ui;
|
||||||
|
|
||||||
|
import com.vaadin.cdi.CDIView;
|
||||||
|
import com.vaadin.navigator.View;
|
||||||
|
import com.vaadin.ui.CustomComponent;
|
||||||
|
import com.vaadin.ui.Label;
|
||||||
|
import com.vaadin.ui.TabSheet;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@CDIView(value = CmsView.VIEWNAME,
|
||||||
|
uis = {CmsUI.class})
|
||||||
|
class CmsView extends CustomComponent implements View {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 8989848156887929448L;
|
||||||
|
|
||||||
|
public static final String VIEWNAME = "cms";
|
||||||
|
|
||||||
|
private final TabSheet tabSheet;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
CmsView(final CmsViewController controller) {
|
||||||
|
|
||||||
|
super();
|
||||||
|
|
||||||
|
tabSheet = new TabSheet();
|
||||||
|
|
||||||
|
final ContentSectionsGrid sectionsGrid = new ContentSectionsGrid(controller);
|
||||||
|
sectionsGrid.setWidth("100%");
|
||||||
|
tabSheet.addTab(sectionsGrid, "Content Section");
|
||||||
|
tabSheet.addTab(new Label("Placeholder"), "Search");
|
||||||
|
tabSheet.addTab(new Label("Placeholder"), "My tasks");
|
||||||
|
|
||||||
|
super.setCompositionRoot(tabSheet);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,63 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2017 LibreCCM Foundation.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.librecms.ui;
|
||||||
|
|
||||||
|
import com.vaadin.cdi.ViewScoped;
|
||||||
|
import org.libreccm.l10n.GlobalizationHelper;
|
||||||
|
import org.libreccm.security.PermissionChecker;
|
||||||
|
import org.libreccm.security.PermissionManager;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@ViewScoped
|
||||||
|
class CmsViewController {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private GlobalizationHelper globalizationHelper;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private PermissionManager permissionManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private PermissionChecker permissionChecker;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ContentSectionsGridDataProvider sectionsDataProvider;
|
||||||
|
|
||||||
|
protected GlobalizationHelper getGlobalizationHelper() {
|
||||||
|
return globalizationHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected PermissionManager getPermissionManager() {
|
||||||
|
return permissionManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected PermissionChecker getPermissionChecker() {
|
||||||
|
return permissionChecker;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ContentSectionsGridDataProvider getSectionsDataProvider() {
|
||||||
|
return sectionsDataProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,99 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2017 LibreCCM Foundation.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.librecms.ui;
|
||||||
|
|
||||||
|
import com.vaadin.cdi.CDIView;
|
||||||
|
import com.vaadin.navigator.View;
|
||||||
|
import com.vaadin.navigator.ViewChangeListener;
|
||||||
|
import com.vaadin.ui.Label;
|
||||||
|
import com.vaadin.ui.Panel;
|
||||||
|
import com.vaadin.ui.TabSheet;
|
||||||
|
import com.vaadin.ui.themes.ValoTheme;
|
||||||
|
import org.librecms.contentsection.ContentSection;
|
||||||
|
import org.librecms.contentsection.ContentSectionRepository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@CDIView(value = ContentSectionView.VIEWNAME,
|
||||||
|
uis = {CmsUI.class})
|
||||||
|
class ContentSectionView implements View {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 602851260519364741L;
|
||||||
|
|
||||||
|
public static final String VIEWNAME = "ContentSection";
|
||||||
|
|
||||||
|
private final ContentSectionViewController controller;
|
||||||
|
|
||||||
|
private ContentSection selectedSection;
|
||||||
|
|
||||||
|
private final TabSheet tabSheet;
|
||||||
|
private final Panel noSectionPanel;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ContentSectionView(final ContentSectionViewController controller) {
|
||||||
|
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.controller = controller;
|
||||||
|
|
||||||
|
tabSheet = new TabSheet();
|
||||||
|
|
||||||
|
noSectionPanel = new Panel();
|
||||||
|
noSectionPanel.setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enter(ViewChangeListener.ViewChangeEvent event) {
|
||||||
|
|
||||||
|
final String parameters = event.getParameters();
|
||||||
|
|
||||||
|
if (parameters == null || parameters.trim().isEmpty()) {
|
||||||
|
tabSheet.setVisible(false);
|
||||||
|
noSectionPanel.setCaption("No content section selected");
|
||||||
|
noSectionPanel.setContent(new Label("No content section selected"));
|
||||||
|
noSectionPanel.setVisible(true);
|
||||||
|
} else {
|
||||||
|
final ContentSectionRepository sectionRepo = controller
|
||||||
|
.getSectionRepo();
|
||||||
|
|
||||||
|
final Optional<ContentSection> contentSection = sectionRepo
|
||||||
|
.findByLabel(parameters);
|
||||||
|
|
||||||
|
if (contentSection.isPresent()) {
|
||||||
|
selectedSection = contentSection.get();
|
||||||
|
} else {
|
||||||
|
tabSheet.setVisible(false);
|
||||||
|
noSectionPanel.setCaption(String
|
||||||
|
.format("No content section \"%s\"", parameters));
|
||||||
|
noSectionPanel.setContent(new Label(String
|
||||||
|
.format("No content section with label \"%s\" found.",
|
||||||
|
parameters)));
|
||||||
|
noSectionPanel.setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,56 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2017 LibreCCM Foundation.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.librecms.ui;
|
||||||
|
|
||||||
|
import com.vaadin.cdi.ViewScoped;
|
||||||
|
import org.libreccm.l10n.GlobalizationHelper;
|
||||||
|
import org.libreccm.security.PermissionChecker;
|
||||||
|
import org.librecms.contentsection.ContentSectionRepository;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@ViewScoped
|
||||||
|
class ContentSectionViewController {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private GlobalizationHelper globalizationHelper;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private PermissionChecker permissionChecker;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ContentSectionRepository sectionRepo;
|
||||||
|
|
||||||
|
public GlobalizationHelper getGlobalizationHelper() {
|
||||||
|
return globalizationHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PermissionChecker getPermissionChecker() {
|
||||||
|
return permissionChecker;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContentSectionRepository getSectionRepo() {
|
||||||
|
return sectionRepo;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,165 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2017 LibreCCM Foundation.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.librecms.ui;
|
||||||
|
|
||||||
|
import com.vaadin.icons.VaadinIcons;
|
||||||
|
import com.vaadin.navigator.Navigator;
|
||||||
|
import com.vaadin.ui.Button;
|
||||||
|
import com.vaadin.ui.Component;
|
||||||
|
import com.vaadin.ui.Grid;
|
||||||
|
import com.vaadin.ui.HorizontalLayout;
|
||||||
|
import com.vaadin.ui.Label;
|
||||||
|
import com.vaadin.ui.components.grid.HeaderCell;
|
||||||
|
import com.vaadin.ui.components.grid.HeaderRow;
|
||||||
|
import com.vaadin.ui.themes.ValoTheme;
|
||||||
|
import org.libreccm.security.PermissionChecker;
|
||||||
|
import org.librecms.contentsection.ContentSection;
|
||||||
|
import org.librecms.contentsection.privileges.AdminPrivileges;
|
||||||
|
import org.librecms.contentsection.privileges.ItemPrivileges;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
class ContentSectionsGrid extends Grid<ContentSection> {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -2840544148539285341L;
|
||||||
|
|
||||||
|
private static final String COL_LABEL = "label";
|
||||||
|
private static final String COL_EDIT = "edit";
|
||||||
|
private static final String COL_DELETE = "delete";
|
||||||
|
|
||||||
|
private final CmsViewController controller;
|
||||||
|
|
||||||
|
public ContentSectionsGrid(final CmsViewController controller) {
|
||||||
|
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.controller = controller;
|
||||||
|
|
||||||
|
final PermissionChecker permissionChecker = controller
|
||||||
|
.getPermissionChecker();
|
||||||
|
|
||||||
|
addComponentColumn(this::buildSectionLink)
|
||||||
|
.setId(COL_LABEL)
|
||||||
|
.setCaption("Content Section");
|
||||||
|
addComponentColumn(this::buildEditButton)
|
||||||
|
.setId(COL_EDIT)
|
||||||
|
.setCaption("Edit");
|
||||||
|
addComponentColumn(this::buildDeleteButton)
|
||||||
|
.setId(COL_DELETE)
|
||||||
|
.setCaption("Delete");
|
||||||
|
|
||||||
|
setDataProvider(controller.getSectionsDataProvider());
|
||||||
|
|
||||||
|
if (controller.getPermissionChecker().isPermitted("admin")) {
|
||||||
|
final HeaderRow actionsRow = prependHeaderRow();
|
||||||
|
final HeaderCell actionsCell = actionsRow.join(COL_LABEL,
|
||||||
|
COL_EDIT,
|
||||||
|
COL_DELETE);
|
||||||
|
|
||||||
|
final Button createButton = new Button("Create new content section",
|
||||||
|
VaadinIcons.PLUS_CIRCLE_O);
|
||||||
|
createButton.addStyleName(ValoTheme.BUTTON_TINY);
|
||||||
|
createButton.addClickListener(event -> {
|
||||||
|
});
|
||||||
|
|
||||||
|
final HorizontalLayout actionsLayout = new HorizontalLayout(
|
||||||
|
createButton);
|
||||||
|
actionsCell.setComponent(actionsLayout);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private Component buildSectionLink(final ContentSection section) {
|
||||||
|
|
||||||
|
final PermissionChecker permissionChecker = controller
|
||||||
|
.getPermissionChecker();
|
||||||
|
|
||||||
|
if (canAccessSection(section)) {
|
||||||
|
final Button button = new Button();
|
||||||
|
button.setCaption(section.getLabel());
|
||||||
|
button.setStyleName(ValoTheme.BUTTON_LINK);
|
||||||
|
button.addClickListener(event -> {
|
||||||
|
getUI()
|
||||||
|
.getNavigator()
|
||||||
|
.navigateTo(String.format("%s/%s",
|
||||||
|
ContentSectionView.VIEWNAME,
|
||||||
|
section.getLabel()));
|
||||||
|
});
|
||||||
|
return button;
|
||||||
|
} else {
|
||||||
|
return new Label(section.getLabel());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean canAccessSection(final ContentSection section) {
|
||||||
|
final List<String> adminPrivileges = controller
|
||||||
|
.getPermissionManager()
|
||||||
|
.listDefiniedPrivileges(AdminPrivileges.class);
|
||||||
|
final List<String> itemPrivileges = controller
|
||||||
|
.getPermissionManager()
|
||||||
|
.listDefiniedPrivileges(ItemPrivileges.class);
|
||||||
|
|
||||||
|
for (final String privilege : adminPrivileges) {
|
||||||
|
if (controller.getPermissionChecker().isPermitted(privilege)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (final String privilege : itemPrivileges) {
|
||||||
|
if (controller.getPermissionChecker().isPermitted(privilege)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return controller.getPermissionChecker().isPermitted("admin");
|
||||||
|
}
|
||||||
|
|
||||||
|
private Component buildEditButton(final ContentSection section) {
|
||||||
|
|
||||||
|
if (controller.getPermissionChecker().isPermitted("admin")) {
|
||||||
|
final Button button = new Button("Edit", VaadinIcons.EDIT);
|
||||||
|
button.addStyleName(ValoTheme.BUTTON_TINY);
|
||||||
|
button.addClickListener(event -> {
|
||||||
|
});
|
||||||
|
return button;
|
||||||
|
} else {
|
||||||
|
return new Label("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Component buildDeleteButton(final ContentSection section) {
|
||||||
|
|
||||||
|
if (controller.getPermissionChecker().isPermitted("admin")) {
|
||||||
|
final Button button = new Button("Delete", VaadinIcons.DEL);
|
||||||
|
button.addStyleName(ValoTheme.BUTTON_TINY);
|
||||||
|
button.addStyleName(ValoTheme.BUTTON_DANGER);
|
||||||
|
button.addClickListener(event -> {
|
||||||
|
});
|
||||||
|
return button;
|
||||||
|
} else {
|
||||||
|
return new Label("");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,86 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2017 LibreCCM Foundation.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.librecms.ui;
|
||||||
|
|
||||||
|
import com.vaadin.cdi.ViewScoped;
|
||||||
|
import com.vaadin.data.provider.AbstractBackEndDataProvider;
|
||||||
|
import com.vaadin.data.provider.Query;
|
||||||
|
import org.librecms.contentsection.ContentSection;
|
||||||
|
import org.librecms.contentsection.ContentSectionRepository;
|
||||||
|
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@ViewScoped
|
||||||
|
class ContentSectionsGridDataProvider
|
||||||
|
extends AbstractBackEndDataProvider<ContentSection, String> {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 2173898409635046482L;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private EntityManager entityManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ContentSectionRepository sectionRepo;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Stream<ContentSection> fetchFromBackEnd(
|
||||||
|
final Query<ContentSection, String> query) {
|
||||||
|
|
||||||
|
final CriteriaBuilder builder = entityManager.getCriteriaBuilder();
|
||||||
|
final CriteriaQuery<ContentSection> criteriaQuery = builder
|
||||||
|
.createQuery(ContentSection.class);
|
||||||
|
final Root<ContentSection> from = criteriaQuery
|
||||||
|
.from(ContentSection.class);
|
||||||
|
|
||||||
|
return entityManager
|
||||||
|
.createQuery(criteriaQuery)
|
||||||
|
.setMaxResults(query.getLimit())
|
||||||
|
.setFirstResult(query.getOffset())
|
||||||
|
.getResultList()
|
||||||
|
.stream();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int sizeInBackEnd(final Query<ContentSection, String> query) {
|
||||||
|
|
||||||
|
final CriteriaBuilder builder = entityManager.getCriteriaBuilder();
|
||||||
|
final CriteriaQuery<Long> criteriaQuery = builder
|
||||||
|
.createQuery(Long.class);
|
||||||
|
final Root<ContentSection> from = criteriaQuery
|
||||||
|
.from(ContentSection.class);
|
||||||
|
|
||||||
|
criteriaQuery.select(builder.count(from));
|
||||||
|
|
||||||
|
return entityManager
|
||||||
|
.createQuery(criteriaQuery)
|
||||||
|
.getSingleResult()
|
||||||
|
.intValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2017 LibreCCM Foundation.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.librecms.ui;
|
||||||
|
|
||||||
|
import com.vaadin.cdi.CDIView;
|
||||||
|
import org.libreccm.ui.AbstractLoginView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@CDIView(value = LoginView.VIEWNAME,
|
||||||
|
uis = {CmsUI.class})
|
||||||
|
public class LoginView extends AbstractLoginView {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -8076055152219333275L;
|
||||||
|
|
||||||
|
public static final String VIEWNAME = "cmslogin";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getTargetView() {
|
||||||
|
return CmsView.VIEWNAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
|
||||||
|
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
|
||||||
|
bean-discovery-mode="all">
|
||||||
|
|
||||||
|
|
||||||
|
</beans>
|
||||||
|
|
||||||
|
|
@ -18,180 +18,165 @@
|
||||||
*/
|
*/
|
||||||
package org.libreccm.admin.ui;
|
package org.libreccm.admin.ui;
|
||||||
|
|
||||||
import com.arsdigita.kernel.KernelConfig;
|
|
||||||
|
|
||||||
import com.vaadin.cdi.CDIView;
|
import com.vaadin.cdi.CDIView;
|
||||||
import com.vaadin.event.ShortcutAction;
|
import org.libreccm.ui.AbstractLoginView;
|
||||||
import com.vaadin.navigator.View;
|
|
||||||
import com.vaadin.navigator.ViewChangeListener;
|
|
||||||
import com.vaadin.server.UserError;
|
|
||||||
import com.vaadin.ui.Alignment;
|
|
||||||
import com.vaadin.ui.Button;
|
|
||||||
import com.vaadin.ui.CustomComponent;
|
|
||||||
import com.vaadin.ui.FormLayout;
|
|
||||||
import com.vaadin.ui.Notification;
|
|
||||||
import com.vaadin.ui.Panel;
|
|
||||||
import com.vaadin.ui.PasswordField;
|
|
||||||
import com.vaadin.ui.TextField;
|
|
||||||
import com.vaadin.ui.VerticalLayout;
|
|
||||||
import org.apache.shiro.authc.AuthenticationException;
|
|
||||||
import org.apache.shiro.authc.UsernamePasswordToken;
|
|
||||||
import org.apache.shiro.subject.Subject;
|
|
||||||
import org.libreccm.configuration.ConfigurationManager;
|
|
||||||
import org.libreccm.l10n.GlobalizationHelper;
|
|
||||||
|
|
||||||
import java.util.ResourceBundle;
|
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
@CDIView(LoginView.VIEWNAME)
|
@CDIView(value = LoginView.VIEWNAME,
|
||||||
public class LoginView extends CustomComponent implements View {
|
uis = {AdminUIVaadin.class})
|
||||||
|
//public class LoginView extends CustomComponent implements View {
|
||||||
|
|
||||||
|
public class LoginView extends AbstractLoginView {
|
||||||
|
|
||||||
private static final long serialVersionUID = 997966222985596011L;
|
private static final long serialVersionUID = 997966222985596011L;
|
||||||
|
|
||||||
public static final String VIEWNAME = "login";
|
public static final String VIEWNAME = "adminlogin";
|
||||||
|
|
||||||
@Inject
|
@Override
|
||||||
private ConfigurationManager confManager;
|
protected String getTargetView() {
|
||||||
|
return AdminView.VIEWNAME;
|
||||||
|
}
|
||||||
|
|
||||||
@Inject
|
// @Inject
|
||||||
private GlobalizationHelper globalizationHelper;
|
// private ConfigurationManager confManager;
|
||||||
|
//
|
||||||
@Inject
|
// @Inject
|
||||||
private Subject subject;
|
// private GlobalizationHelper globalizationHelper;
|
||||||
|
//
|
||||||
private ResourceBundle bundle;
|
// @Inject
|
||||||
|
// private Subject subject;
|
||||||
private final Panel loginPanel;
|
//
|
||||||
private final FormLayout formLayout;
|
// private ResourceBundle bundle;
|
||||||
private final TextField userName;
|
//
|
||||||
private final TextField password;
|
// private final Panel loginPanel;
|
||||||
private final Button submitButton;
|
// private final FormLayout formLayout;
|
||||||
|
// private final TextField userName;
|
||||||
public LoginView() {
|
// private final TextField password;
|
||||||
|
// private final Button submitButton;
|
||||||
formLayout = new FormLayout();
|
//
|
||||||
formLayout.setSizeFull();
|
// public LoginView() {
|
||||||
formLayout.setMargin(true);
|
//
|
||||||
|
// formLayout = new FormLayout();
|
||||||
userName = new TextField();
|
// formLayout.setSizeFull();
|
||||||
userName.setCaption("User name");
|
// formLayout.setMargin(true);
|
||||||
formLayout.addComponent(userName);
|
//
|
||||||
|
// userName = new TextField();
|
||||||
password = new PasswordField("Password");
|
// userName.setCaption("User name");
|
||||||
formLayout.addComponent(password);
|
// formLayout.addComponent(userName);
|
||||||
|
//
|
||||||
submitButton = new Button("Login");
|
// password = new PasswordField("Password");
|
||||||
submitButton.addClickListener(event -> login(event));
|
// formLayout.addComponent(password);
|
||||||
submitButton.setEnabled(false);
|
//
|
||||||
formLayout.addComponent(submitButton);
|
// submitButton = new Button("Login");
|
||||||
|
// submitButton.addClickListener(event -> login(event));
|
||||||
userName.addValueChangeListener(event -> {
|
// submitButton.setEnabled(false);
|
||||||
if (userName.getValue() != null
|
// formLayout.addComponent(submitButton);
|
||||||
&& !userName.getValue().trim().isEmpty()
|
//
|
||||||
&& password.getValue() != null
|
// userName.addValueChangeListener(event -> {
|
||||||
&& !password.getValue().trim().isEmpty()) {
|
|
||||||
submitButton.setEnabled(true);
|
|
||||||
submitButton.setClickShortcut(ShortcutAction.KeyCode.ENTER);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
password.addValueChangeListener(event -> {
|
|
||||||
if (userName.getValue() != null
|
|
||||||
&& !userName.getValue().trim().isEmpty()
|
|
||||||
&& password.getValue() != null
|
|
||||||
&& !password.getValue().trim().isEmpty()) {
|
|
||||||
submitButton.setEnabled(true);
|
|
||||||
submitButton.setClickShortcut(ShortcutAction.KeyCode.ENTER);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// userName.addFocusListener(event -> {
|
|
||||||
// if (userName.getValue() != null
|
// if (userName.getValue() != null
|
||||||
// && !userName.getValue().trim().isEmpty()
|
// && !userName.getValue().trim().isEmpty()
|
||||||
// && password.getValue() != null
|
// && password.getValue() != null
|
||||||
// && !password.getValue().trim().isEmpty()) {
|
// && !password.getValue().trim().isEmpty()) {
|
||||||
|
// submitButton.setEnabled(true);
|
||||||
// submitButton.setClickShortcut(ShortcutAction.KeyCode.ENTER);
|
// submitButton.setClickShortcut(ShortcutAction.KeyCode.ENTER);
|
||||||
// }
|
// }
|
||||||
// });
|
// });
|
||||||
// userName.addBlurListener(event -> {
|
//
|
||||||
|
// password.addValueChangeListener(event -> {
|
||||||
// if (userName.getValue() != null
|
// if (userName.getValue() != null
|
||||||
// && !userName.getValue().trim().isEmpty()
|
// && !userName.getValue().trim().isEmpty()
|
||||||
// && password.getValue() != null
|
// && password.getValue() != null
|
||||||
// && !password.getValue().trim().isEmpty()) {
|
// && !password.getValue().trim().isEmpty()) {
|
||||||
// submitButton.removeClickShortcut();
|
// submitButton.setEnabled(true);
|
||||||
|
// submitButton.setClickShortcut(ShortcutAction.KeyCode.ENTER);
|
||||||
// }
|
// }
|
||||||
// });
|
// });
|
||||||
password.addFocusListener(event -> {
|
//
|
||||||
submitButton.setClickShortcut(ShortcutAction.KeyCode.ENTER);
|
//// userName.addFocusListener(event -> {
|
||||||
});
|
//// if (userName.getValue() != null
|
||||||
password.addBlurListener(event -> {
|
//// && !userName.getValue().trim().isEmpty()
|
||||||
submitButton.removeClickShortcut();
|
//// && password.getValue() != null
|
||||||
});
|
//// && !password.getValue().trim().isEmpty()) {
|
||||||
|
//// submitButton.setClickShortcut(ShortcutAction.KeyCode.ENTER);
|
||||||
loginPanel = new Panel("Login", formLayout);
|
//// }
|
||||||
loginPanel.setWidth("27em");
|
//// });
|
||||||
|
//// userName.addBlurListener(event -> {
|
||||||
final VerticalLayout viewLayout = new VerticalLayout(new Header(),
|
//// if (userName.getValue() != null
|
||||||
loginPanel);
|
//// && !userName.getValue().trim().isEmpty()
|
||||||
|
//// && password.getValue() != null
|
||||||
viewLayout.setComponentAlignment(loginPanel, Alignment.MIDDLE_CENTER);
|
//// && !password.getValue().trim().isEmpty()) {
|
||||||
|
//// submitButton.removeClickShortcut();
|
||||||
super.setCompositionRoot(viewLayout);
|
//// }
|
||||||
}
|
//// });
|
||||||
|
// password.addFocusListener(event -> {
|
||||||
@PostConstruct
|
// submitButton.setClickShortcut(ShortcutAction.KeyCode.ENTER);
|
||||||
private void postConstruct() {
|
// });
|
||||||
bundle = ResourceBundle.getBundle(
|
// password.addBlurListener(event -> {
|
||||||
"com.arsdigita.ui.login.LoginResources",
|
// submitButton.removeClickShortcut();
|
||||||
globalizationHelper.getNegotiatedLocale());
|
// });
|
||||||
}
|
//
|
||||||
|
// loginPanel = new Panel("Login", formLayout);
|
||||||
private void login(final Button.ClickEvent event) {
|
// loginPanel.setWidth("27em");
|
||||||
final UsernamePasswordToken token = new UsernamePasswordToken(
|
//
|
||||||
userName.getValue(),
|
// final VerticalLayout viewLayout = new VerticalLayout(new Header(),
|
||||||
password.getValue());
|
// loginPanel);
|
||||||
token.setRememberMe(true);
|
//
|
||||||
|
// viewLayout.setComponentAlignment(loginPanel, Alignment.MIDDLE_CENTER);
|
||||||
try {
|
//
|
||||||
subject.login(token);
|
// super.setCompositionRoot(viewLayout);
|
||||||
} catch (AuthenticationException ex) {
|
// }
|
||||||
submitButton.setComponentError(
|
//
|
||||||
new UserError(bundle.getString("login.error.loginFail")));
|
// @PostConstruct
|
||||||
Notification.show(bundle.getString("login.error.loginFail"),
|
// private void postConstruct() {
|
||||||
Notification.Type.ERROR_MESSAGE);
|
// bundle = ResourceBundle.getBundle(
|
||||||
password.setValue("");
|
// "com.arsdigita.ui.login.LoginResources",
|
||||||
return;
|
// globalizationHelper.getNegotiatedLocale());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
getUI().getNavigator().navigateTo(AdminView.VIEWNAME);
|
// private void login(final Button.ClickEvent event) {
|
||||||
}
|
// final UsernamePasswordToken token = new UsernamePasswordToken(
|
||||||
|
// userName.getValue(),
|
||||||
@Override
|
// password.getValue());
|
||||||
public void enter(final ViewChangeListener.ViewChangeEvent event) {
|
// token.setRememberMe(true);
|
||||||
|
//
|
||||||
final KernelConfig kernelConfig = confManager
|
// try {
|
||||||
.findConfiguration(KernelConfig.class
|
// subject.login(token);
|
||||||
);
|
// } catch (AuthenticationException ex) {
|
||||||
loginPanel
|
// submitButton.setComponentError(
|
||||||
.setCaption(bundle.getString("login.userRegistrationForm.title"));
|
// new UserError(bundle.getString("login.error.loginFail")));
|
||||||
if (kernelConfig.emailIsPrimaryIdentifier()) {
|
// Notification.show(bundle.getString("login.error.loginFail"),
|
||||||
userName.setCaption(bundle
|
// Notification.Type.ERROR_MESSAGE);
|
||||||
.getString("login.userRegistrationForm.email"));
|
// password.setValue("");
|
||||||
} else {
|
// return;
|
||||||
userName.setCaption(bundle
|
// }
|
||||||
.getString("login.userRegistrationForm.screenName"));
|
//
|
||||||
}
|
// getUI().getNavigator().navigateTo(AdminView.VIEWNAME);
|
||||||
password.setCaption(
|
// }
|
||||||
bundle.getString("login.userRegistrationForm.password"));
|
//
|
||||||
|
// @Override
|
||||||
submitButton.setCaption(bundle
|
// public void enter(final ViewChangeListener.ViewChangeEvent event) {
|
||||||
.getString("login.userRegistrationForm.title"));
|
//
|
||||||
}
|
// final KernelConfig kernelConfig = confManager
|
||||||
|
// .findConfiguration(KernelConfig.class
|
||||||
|
// );
|
||||||
|
// loginPanel
|
||||||
|
// .setCaption(bundle.getString("login.userRegistrationForm.title"));
|
||||||
|
// if (kernelConfig.emailIsPrimaryIdentifier()) {
|
||||||
|
// userName.setCaption(bundle
|
||||||
|
// .getString("login.userRegistrationForm.email"));
|
||||||
|
// } else {
|
||||||
|
// userName.setCaption(bundle
|
||||||
|
// .getString("login.userRegistrationForm.screenName"));
|
||||||
|
// }
|
||||||
|
// password.setCaption(
|
||||||
|
// bundle.getString("login.userRegistrationForm.password"));
|
||||||
|
//
|
||||||
|
// submitButton.setCaption(bundle
|
||||||
|
// .getString("login.userRegistrationForm.title"));
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,200 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2017 LibreCCM Foundation.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.libreccm.ui;
|
||||||
|
|
||||||
|
import com.arsdigita.kernel.KernelConfig;
|
||||||
|
|
||||||
|
import com.vaadin.event.ShortcutAction;
|
||||||
|
import com.vaadin.navigator.View;
|
||||||
|
import com.vaadin.navigator.ViewChangeListener;
|
||||||
|
import com.vaadin.server.UserError;
|
||||||
|
import com.vaadin.ui.Alignment;
|
||||||
|
import com.vaadin.ui.Button;
|
||||||
|
import com.vaadin.ui.CustomComponent;
|
||||||
|
import com.vaadin.ui.FormLayout;
|
||||||
|
import com.vaadin.ui.Notification;
|
||||||
|
import com.vaadin.ui.Panel;
|
||||||
|
import com.vaadin.ui.PasswordField;
|
||||||
|
import com.vaadin.ui.TextField;
|
||||||
|
import com.vaadin.ui.VerticalLayout;
|
||||||
|
import org.apache.shiro.authc.AuthenticationException;
|
||||||
|
import org.apache.shiro.authc.UsernamePasswordToken;
|
||||||
|
import org.apache.shiro.subject.Subject;
|
||||||
|
import org.libreccm.admin.ui.AdminView;
|
||||||
|
import org.libreccm.admin.ui.Header;
|
||||||
|
import org.libreccm.configuration.ConfigurationManager;
|
||||||
|
import org.libreccm.l10n.GlobalizationHelper;
|
||||||
|
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
public abstract class AbstractLoginView extends CustomComponent implements View{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1481112180843568446L;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ConfigurationManager confManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private GlobalizationHelper globalizationHelper;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private Subject subject;
|
||||||
|
|
||||||
|
private ResourceBundle bundle;
|
||||||
|
|
||||||
|
private final Panel loginPanel;
|
||||||
|
private final FormLayout formLayout;
|
||||||
|
private final TextField userName;
|
||||||
|
private final TextField password;
|
||||||
|
private final Button submitButton;
|
||||||
|
|
||||||
|
public AbstractLoginView() {
|
||||||
|
|
||||||
|
formLayout = new FormLayout();
|
||||||
|
formLayout.setSizeFull();
|
||||||
|
formLayout.setMargin(true);
|
||||||
|
|
||||||
|
userName = new TextField();
|
||||||
|
userName.setCaption("User name");
|
||||||
|
formLayout.addComponent(userName);
|
||||||
|
|
||||||
|
password = new PasswordField("Password");
|
||||||
|
formLayout.addComponent(password);
|
||||||
|
|
||||||
|
submitButton = new Button("Login");
|
||||||
|
submitButton.addClickListener(event -> login(event));
|
||||||
|
submitButton.setEnabled(false);
|
||||||
|
formLayout.addComponent(submitButton);
|
||||||
|
|
||||||
|
userName.addValueChangeListener(event -> {
|
||||||
|
if (userName.getValue() != null
|
||||||
|
&& !userName.getValue().trim().isEmpty()
|
||||||
|
&& password.getValue() != null
|
||||||
|
&& !password.getValue().trim().isEmpty()) {
|
||||||
|
submitButton.setEnabled(true);
|
||||||
|
submitButton.setClickShortcut(ShortcutAction.KeyCode.ENTER);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
password.addValueChangeListener(event -> {
|
||||||
|
if (userName.getValue() != null
|
||||||
|
&& !userName.getValue().trim().isEmpty()
|
||||||
|
&& password.getValue() != null
|
||||||
|
&& !password.getValue().trim().isEmpty()) {
|
||||||
|
submitButton.setEnabled(true);
|
||||||
|
submitButton.setClickShortcut(ShortcutAction.KeyCode.ENTER);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// userName.addFocusListener(event -> {
|
||||||
|
// if (userName.getValue() != null
|
||||||
|
// && !userName.getValue().trim().isEmpty()
|
||||||
|
// && password.getValue() != null
|
||||||
|
// && !password.getValue().trim().isEmpty()) {
|
||||||
|
// submitButton.setClickShortcut(ShortcutAction.KeyCode.ENTER);
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// userName.addBlurListener(event -> {
|
||||||
|
// if (userName.getValue() != null
|
||||||
|
// && !userName.getValue().trim().isEmpty()
|
||||||
|
// && password.getValue() != null
|
||||||
|
// && !password.getValue().trim().isEmpty()) {
|
||||||
|
// submitButton.removeClickShortcut();
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
password.addFocusListener(event -> {
|
||||||
|
submitButton.setClickShortcut(ShortcutAction.KeyCode.ENTER);
|
||||||
|
});
|
||||||
|
password.addBlurListener(event -> {
|
||||||
|
submitButton.removeClickShortcut();
|
||||||
|
});
|
||||||
|
|
||||||
|
loginPanel = new Panel("Login", formLayout);
|
||||||
|
loginPanel.setWidth("27em");
|
||||||
|
|
||||||
|
final VerticalLayout viewLayout = new VerticalLayout(new Header(),
|
||||||
|
loginPanel);
|
||||||
|
|
||||||
|
viewLayout.setComponentAlignment(loginPanel, Alignment.MIDDLE_CENTER);
|
||||||
|
|
||||||
|
super.setCompositionRoot(viewLayout);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
private void postConstruct() {
|
||||||
|
bundle = ResourceBundle.getBundle(
|
||||||
|
"com.arsdigita.ui.login.LoginResources",
|
||||||
|
globalizationHelper.getNegotiatedLocale());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract String getTargetView();
|
||||||
|
|
||||||
|
private void login(final Button.ClickEvent event) {
|
||||||
|
final UsernamePasswordToken token = new UsernamePasswordToken(
|
||||||
|
userName.getValue(),
|
||||||
|
password.getValue());
|
||||||
|
token.setRememberMe(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
subject.login(token);
|
||||||
|
} catch (AuthenticationException ex) {
|
||||||
|
submitButton.setComponentError(
|
||||||
|
new UserError(bundle.getString("login.error.loginFail")));
|
||||||
|
Notification.show(bundle.getString("login.error.loginFail"),
|
||||||
|
Notification.Type.ERROR_MESSAGE);
|
||||||
|
password.setValue("");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
getUI().getNavigator().navigateTo(getTargetView());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enter(final ViewChangeListener.ViewChangeEvent event) {
|
||||||
|
|
||||||
|
final KernelConfig kernelConfig = confManager
|
||||||
|
.findConfiguration(KernelConfig.class
|
||||||
|
);
|
||||||
|
loginPanel
|
||||||
|
.setCaption(bundle.getString("login.userRegistrationForm.title"));
|
||||||
|
if (kernelConfig.emailIsPrimaryIdentifier()) {
|
||||||
|
userName.setCaption(bundle
|
||||||
|
.getString("login.userRegistrationForm.email"));
|
||||||
|
} else {
|
||||||
|
userName.setCaption(bundle
|
||||||
|
.getString("login.userRegistrationForm.screenName"));
|
||||||
|
}
|
||||||
|
password.setCaption(
|
||||||
|
bundle.getString("login.userRegistrationForm.password"));
|
||||||
|
|
||||||
|
submitButton.setCaption(bundle
|
||||||
|
.getString("login.userRegistrationForm.title"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue