CCM NG: Vaadin Prototype for UI
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4683 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
b769298ef8
commit
944d09f7c0
|
|
@ -60,8 +60,6 @@ public class ExternalVideoAssetForm extends BookmarkForm {
|
|||
assetSearchWidget = new AssetSearchWidget("legal-metadata",
|
||||
LegalMetadata.class);
|
||||
add(assetSearchWidget);
|
||||
|
||||
//ToDo
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -22,9 +22,12 @@ import com.vaadin.cdi.CDIUI;
|
|||
import com.vaadin.cdi.CDIViewProvider;
|
||||
import com.vaadin.cdi.URLMapping;
|
||||
import com.vaadin.navigator.Navigator;
|
||||
import com.vaadin.navigator.ViewChangeListener;
|
||||
import com.vaadin.server.VaadinRequest;
|
||||
import com.vaadin.ui.Notification;
|
||||
import com.vaadin.ui.UI;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.libreccm.security.PermissionChecker;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
|
@ -39,29 +42,31 @@ public class AdminUIVaadin extends UI {
|
|||
private static final long serialVersionUID = -1352590567964037112L;
|
||||
|
||||
// private TabSheet tabSheet;
|
||||
|
||||
// @Inject
|
||||
// private UserRepository userRepo;
|
||||
|
||||
@Inject
|
||||
private CDIViewProvider viewProvider;
|
||||
|
||||
@Inject
|
||||
private Subject subject;
|
||||
|
||||
@Inject
|
||||
private PermissionChecker permissionChecker;
|
||||
|
||||
@Override
|
||||
protected void init(VaadinRequest request) {
|
||||
|
||||
final Navigator navigator = new Navigator(this, this);
|
||||
navigator.addProvider(viewProvider);
|
||||
|
||||
navigator.addViewChangeListener(new AuthNavListener());
|
||||
|
||||
if (subject.isAuthenticated()) {
|
||||
navigator.navigateTo(AdminView.VIEWNAME);
|
||||
} else {
|
||||
navigator.navigateTo(LoginView.VIEWNAME);
|
||||
}
|
||||
|
||||
|
||||
// tabSheet = new TabSheet();
|
||||
//
|
||||
// final TabSheet userGroupsRoles = new TabSheet();
|
||||
|
|
@ -80,4 +85,32 @@ public class AdminUIVaadin extends UI {
|
|||
// setContent(tabSheet);
|
||||
}
|
||||
|
||||
private class AuthNavListener implements ViewChangeListener {
|
||||
|
||||
private static final long serialVersionUID = -693722234602948170L;
|
||||
|
||||
@Override
|
||||
public boolean beforeViewChange(final ViewChangeEvent event) {
|
||||
|
||||
if (event.getNewView() instanceof AdminView) {
|
||||
|
||||
if (subject.isAuthenticated()) {
|
||||
|
||||
if (!permissionChecker.isPermitted("admin")) {
|
||||
Notification.show(
|
||||
"Access denied",
|
||||
"Your are not allowed to access the LibreCCM admin application.",
|
||||
Notification.Type.ERROR_MESSAGE);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
event.getNavigator().navigateTo(LoginView.VIEWNAME);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,15 +18,26 @@
|
|||
*/
|
||||
package org.libreccm.admin.ui;
|
||||
|
||||
import com.arsdigita.ui.admin.AdminUiConstants;
|
||||
|
||||
import com.vaadin.cdi.CDIView;
|
||||
import com.vaadin.navigator.View;
|
||||
import com.vaadin.navigator.ViewChangeListener;
|
||||
import com.vaadin.ui.Component;
|
||||
import com.vaadin.ui.CssLayout;
|
||||
import com.vaadin.ui.CustomComponent;
|
||||
import com.vaadin.ui.Grid;
|
||||
import com.vaadin.ui.TabSheet;
|
||||
import com.vaadin.ui.VerticalLayout;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.libreccm.l10n.GlobalizationHelper;
|
||||
import org.libreccm.security.PermissionChecker;
|
||||
import org.libreccm.security.User;
|
||||
import org.libreccm.security.UserRepository;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
|
|
@ -41,6 +52,23 @@ public class AdminView extends CustomComponent implements View {
|
|||
|
||||
public static final String VIEWNAME = "admin";
|
||||
|
||||
private static final String COL_USER_NAME = "username";
|
||||
private static final String COL_GIVEN_NAME = "given_name";
|
||||
private static final String COL_FAMILY_NAME = "family_name";
|
||||
private static final String COL_EMAIL = "email";
|
||||
private static final String COL_BANNED = "banned";
|
||||
|
||||
@Inject
|
||||
private Subject subject;
|
||||
|
||||
@Inject
|
||||
private PermissionChecker permissionChecker;
|
||||
|
||||
@Inject
|
||||
private GlobalizationHelper globalizationHelper;
|
||||
|
||||
private ResourceBundle bundle;
|
||||
|
||||
@Inject
|
||||
private UserRepository userRepo;
|
||||
|
||||
|
|
@ -48,27 +76,79 @@ public class AdminView extends CustomComponent implements View {
|
|||
private final Grid<User> usersTable;
|
||||
|
||||
public AdminView() {
|
||||
|
||||
tabSheet = new TabSheet();
|
||||
|
||||
final TabSheet userGroupsRoles = new TabSheet();
|
||||
usersTable = new Grid<>();
|
||||
usersTable.setWidth("100%");
|
||||
// usersTable.setItems(userRepo.findAll());
|
||||
usersTable.addColumn(User::getName).setCaption("User name");
|
||||
usersTable.addColumn(User::getGivenName).setCaption("Given name");
|
||||
usersTable.addColumn(User::getFamilyName).setCaption("Family name");
|
||||
usersTable.addColumn(User::getName)
|
||||
.setId(COL_USER_NAME)
|
||||
.setCaption("User name");
|
||||
usersTable
|
||||
.addColumn(User::getGivenName)
|
||||
.setId(COL_GIVEN_NAME)
|
||||
.setCaption("Given name");
|
||||
usersTable
|
||||
.addColumn(User::getFamilyName)
|
||||
.setId(COL_FAMILY_NAME)
|
||||
.setCaption("Family name");
|
||||
usersTable
|
||||
.addColumn(user -> user.getPrimaryEmailAddress().getAddress())
|
||||
.setId(COL_EMAIL)
|
||||
.setCaption("E-Mail");
|
||||
usersTable.addColumn(User::isBanned).setCaption("Banned?");
|
||||
usersTable
|
||||
.addColumn(user -> {
|
||||
if (user.isBanned()) {
|
||||
return bundle.getString("ui.admin.user.banned_yes");
|
||||
} else {
|
||||
return bundle.getString("ui.admin.user.banned_no");
|
||||
}
|
||||
})
|
||||
.setId(COL_BANNED)
|
||||
.setCaption("Banned?");
|
||||
userGroupsRoles.addTab(usersTable, "Users");
|
||||
|
||||
tabSheet.addTab(userGroupsRoles, "Users/Groups/Roles");
|
||||
setCompositionRoot(tabSheet);
|
||||
|
||||
final CssLayout header = new CssLayout() {
|
||||
|
||||
private static final long serialVersionUID = -4372147161604688854L;
|
||||
|
||||
@Override
|
||||
protected String getCss(final Component component) {
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
// header.setWidth("100%");
|
||||
header.setHeight("5em");
|
||||
|
||||
final CssLayout footer = new CssLayout();
|
||||
// footer.setWidth("100%");
|
||||
footer.setHeight("5em");
|
||||
|
||||
final VerticalLayout viewLayout = new VerticalLayout();
|
||||
|
||||
viewLayout.addComponent(tabSheet);
|
||||
|
||||
setCompositionRoot(viewLayout);
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void postConstruct() {
|
||||
bundle = ResourceBundle
|
||||
.getBundle(AdminUiConstants.ADMIN_BUNDLE,
|
||||
globalizationHelper.getNegotiatedLocale());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enter(final ViewChangeListener.ViewChangeEvent event) {
|
||||
|
||||
// if (!subject.isAuthenticated()) {
|
||||
// getUI().getNavigator().navigateTo(LoginView.VIEWNAME);
|
||||
// }
|
||||
usersTable.setItems(userRepo.findAll());
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,17 +19,19 @@
|
|||
package org.libreccm.admin.ui;
|
||||
|
||||
import com.arsdigita.kernel.KernelConfig;
|
||||
import com.arsdigita.ui.admin.AdminUiConstants;
|
||||
|
||||
import com.vaadin.cdi.CDIView;
|
||||
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.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;
|
||||
|
|
@ -63,28 +65,34 @@ public class LoginView extends CustomComponent implements View {
|
|||
|
||||
private ResourceBundle bundle;
|
||||
|
||||
private final FormLayout layout;
|
||||
private final Panel loginPanel;
|
||||
private final FormLayout formLayout;
|
||||
private final TextField userName;
|
||||
private final TextField password;
|
||||
private final Button submitButton;
|
||||
|
||||
public LoginView() {
|
||||
|
||||
layout = new FormLayout();
|
||||
layout.setSizeFull();
|
||||
formLayout = new FormLayout();
|
||||
formLayout.setSizeFull();
|
||||
|
||||
userName = new TextField();
|
||||
userName.setCaption("User name");
|
||||
layout.addComponent(userName);
|
||||
formLayout.addComponent(userName);
|
||||
|
||||
password = new PasswordField("Password");
|
||||
layout.addComponent(password);
|
||||
formLayout.addComponent(password);
|
||||
|
||||
submitButton = new Button("Login");
|
||||
submitButton.addClickListener(event -> login(event));
|
||||
layout.addComponent(submitButton);
|
||||
formLayout.addComponent(submitButton);
|
||||
|
||||
setCompositionRoot(layout);
|
||||
loginPanel = new Panel("Login", formLayout);
|
||||
loginPanel.setWidth("24em");
|
||||
|
||||
final VerticalLayout viewLayout = new VerticalLayout(loginPanel);
|
||||
viewLayout.setComponentAlignment(loginPanel, Alignment.MIDDLE_CENTER);
|
||||
setCompositionRoot(viewLayout);
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
|
|
@ -92,7 +100,6 @@ public class LoginView extends CustomComponent implements View {
|
|||
bundle = ResourceBundle.getBundle(
|
||||
"com.arsdigita.ui.login.LoginResources",
|
||||
globalizationHelper.getNegotiatedLocale());
|
||||
|
||||
}
|
||||
|
||||
private void login(final Button.ClickEvent event) {
|
||||
|
|
@ -104,7 +111,7 @@ public class LoginView extends CustomComponent implements View {
|
|||
try {
|
||||
subject.login(token);
|
||||
} catch (AuthenticationException ex) {
|
||||
layout.setComponentError(
|
||||
formLayout.setComponentError(
|
||||
new UserError(bundle.getString("login.error.loginFail")));
|
||||
return;
|
||||
}
|
||||
|
|
@ -117,6 +124,8 @@ public class LoginView extends CustomComponent implements View {
|
|||
|
||||
final KernelConfig kernelConfig = confManager
|
||||
.findConfiguration(KernelConfig.class);
|
||||
loginPanel
|
||||
.setCaption(bundle.getString("login.userRegistrationForm.title"));
|
||||
if (kernelConfig.emailIsPrimaryIdentifier()) {
|
||||
userName.setCaption(bundle
|
||||
.getString("login.userRegistrationForm.email"));
|
||||
|
|
|
|||
|
|
@ -555,3 +555,5 @@ ui.admin.tab.users_groups_roles.role_details.cancel=Cancel
|
|||
ui.admin.jpqlconsole.query.label=Query
|
||||
ui.admin.jpqlconsole.query.execute=Execute
|
||||
ui.admin.jpqlconsole.query.clear=Clear
|
||||
ui.admin.user.banned_yes=Yes
|
||||
ui.admin.user.banned_no=No
|
||||
|
|
|
|||
|
|
@ -559,3 +559,5 @@ ui.admin.tab.users_groups_roles.role_details.cancel=Abbrechen
|
|||
ui.admin.jpqlconsole.query.label=Abfrage
|
||||
ui.admin.jpqlconsole.query.execute=Ausf\u00fchren
|
||||
ui.admin.jpqlconsole.query.clear=Zur\u00fccksetzen
|
||||
ui.admin.user.banned_yes=Ja
|
||||
ui.admin.user.banned_no=Nein
|
||||
|
|
|
|||
|
|
@ -552,3 +552,5 @@ ui.admin.tab.users_groups_roles.role_details.cancel=Cancel
|
|||
ui.admin.jpqlconsole.query.label=Query
|
||||
ui.admin.jpqlconsole.query.execute=Excute
|
||||
ui.admin.jpqlconsole.query.clear=Clear
|
||||
ui.admin.user.banned_yes=Yes
|
||||
ui.admin.user.banned_no=No
|
||||
|
|
|
|||
|
|
@ -543,3 +543,5 @@ ui.admin.tab.users_groups_roles.role_details.cancel=Cancel
|
|||
ui.admin.jpqlconsole.query.label=Query
|
||||
ui.admin.jpqlconsole.query.execute=Execute
|
||||
ui.admin.jpqlconsole.query.clear=Clear
|
||||
ui.admin.user.banned_yes=Yes
|
||||
ui.admin.user.banned_no=No
|
||||
|
|
|
|||
Loading…
Reference in New Issue