List of usage examples for com.vaadin.server VaadinSession getCurrent
public static VaadinSession getCurrent()
From source file:org.adho.dhconvalidator.ui.ServiceSelectionPanel.java
/** Setup UI. */ private void initComponents() { User user = (User) VaadinSession.getCurrent().getAttribute(SessionStorageKey.USER.name()); if (user.isAdmin()) { UserSwitchPanel userSwitchPanel = new UserSwitchPanel(); addCenteredComponent(userSwitchPanel, Alignment.TOP_RIGHT); }/* w w w . j av a 2s. c o m*/ Label infoLabel = new Label(Messages.getString("ServiceSelectionPanel.intro"), ContentMode.HTML); infoLabel.setWidth("600px"); addCenteredComponent(infoLabel); VerticalLayout option1Panel = new VerticalLayout(); option1Panel.setSpacing(true); option1Panel.setMargin(new MarginInfo(true, false, true, false)); addCenteredComponent(option1Panel); Label option1Label = new Label(Messages.getString("ServiceSelectionPanel.option1Info"), ContentMode.HTML); option1Panel.addComponent(option1Label); btTemplateGeneration = new Button(Messages.getString("ServiceSelectionPanel.option1")); option1Panel.addComponent(btTemplateGeneration); VerticalLayout option2Panel = new VerticalLayout(); option2Panel.setSpacing(true); addCenteredComponent(option2Panel); Label option2Label = new Label(Messages.getString("ServiceSelectionPanel.option2Info"), ContentMode.HTML); option2Panel.addComponent(option2Label); btConversion = new Button(Messages.getString("ServiceSelectionPanel.option2")); option2Panel.addComponent(btConversion); VerticalLayout option3Panel = new VerticalLayout(); option3Panel.setSpacing(true); option3Panel.setMargin(new MarginInfo(true, false, true, false)); addCenteredComponent(option3Panel); Label option3Label = new Label(Messages.getString("ServiceSelectionPanel.option3Info"), ContentMode.HTML); option3Panel.addComponent(option3Label); btConfTool = new Button(Messages.getString("ServiceSelectionPanel.option3")); option3Panel.addComponent(btConfTool); }
From source file:org.adho.dhconvalidator.ui.UserSwitchPanel.java
/** Setup behaviour. */ private void initActions() { btReload.addClickListener(new ClickListener() { @Override/* w w w . j a v a 2 s . co m*/ public void buttonClick(ClickEvent event) { // reload the user list and refill box UserList.INSTANCE.reload(); User selected = (User) userSwitchBox.getValue(); userSwitchBox.removeAllItems(); List<User> users = UserList.INSTANCE.getUsers(); setUsers(users); if (selected != null && users.contains(selected)) { userSwitchBox.setValue(selected); } } }); userSwitchBox.addValueChangeListener(new ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { // switch to selected user User oldUser = (User) VaadinSession.getCurrent().getAttribute(SessionStorageKey.USER.name()); if (oldUser.isAdmin()) { User selectedUser = (User) event.getProperty().getValue(); if ((selectedUser != null) && (!oldUser.equals(selectedUser))) { VaadinSession.getCurrent().setAttribute(SessionStorageKey.USER.name(), new User(selectedUser.getUserId(), selectedUser.getFirstName(), selectedUser.getLastName(), selectedUser.getEmail(), true)); Notification.show(Messages.getString("UserSwitchPanel.notificationTitle"), Messages.getString("UserSwitchPanel.notificationContent", selectedUser.getLastName(), selectedUser.getFirstName(), selectedUser.getEmail()), Type.HUMANIZED_MESSAGE); } } else { throw new IllegalStateException(Messages.getString("UserSwitchPanel.illegalState")); } } }); }
From source file:org.adho.dhconvalidator.ui.UserSwitchPanel.java
/** Setup UI. */ private void initComponents() { List<User> users = UserList.INSTANCE.getUsers(); userSwitchBox = new ComboBox(Messages.getString("UserSwitchPanel.boxCaption")); setUsers(users);// w w w . j a v a2s .co m User current = (User) VaadinSession.getCurrent().getAttribute(SessionStorageKey.USER.name()); userSwitchBox.setValue(current); userSwitchBox.setDescription(Messages.getString("UserSwitchPanel.boxDescription")); userSwitchBox.setNewItemsAllowed(false); userSwitchBox.setNullSelectionAllowed(false); addComponent(userSwitchBox); btReload = new Button(Messages.getString("UserSwitchPanel.reloadCaption")); btReload.setStyleName(BaseTheme.BUTTON_LINK); btReload.addStyleName("plain-link"); addComponent(btReload); }
From source file:org.adho.dhconvalidator.ui.VaadinSessionLocaleProvider.java
@Override public Locale getLocale() { VaadinSession session = VaadinSession.getCurrent(); if (session != null) { return session.getLocale(); }//w ww .j ava 2s . c o m return null; }
From source file:org.apache.tamaya.ui.CurrentUser.java
License:Apache License
/** * Set the current users.// w w w. j ava 2s .com * @param user the current user, not null. */ public static void set(User user) { VaadinSession.getCurrent().setAttribute(KEY, user); }
From source file:org.apache.tamaya.ui.CurrentUser.java
License:Apache License
/** * Get the current user. * @return the current user, or null. */ public static User get() { return (User) VaadinSession.getCurrent().getAttribute(KEY); }
From source file:org.apache.tamaya.ui.TamayaUI.java
License:Apache License
@Subscribe public void logout(LogoutEvent logoutEvent) { // Don't invalidate the underlying HTTP session if you are using it for something else VaadinSession.getCurrent().getSession().invalidate(); VaadinSession.getCurrent().close();// w ww .java 2 s. c om Page.getCurrent().reload(); }
From source file:org.bubblecloud.ilves.site.DefaultSiteUI.java
License:Apache License
/** * Adds handler for credential posts.// w ww . ja v a 2 s .com */ private void addCredentialPostRequestHandler() { // Add handler for credentials post. VaadinSession.getCurrent().addRequestHandler(new RequestHandler() { @Override public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException { if (!StringUtils.isEmpty(request.getParameter("username")) && !StringUtils.isEmpty(request.getParameter("password")) && getSession() != null && getSession().getSession().getAttribute("user") == null) { final String emailAddress = request.getParameter("username"); final String password = request.getParameter("password"); final EntityManager entityManager = getSite().getSiteContext().getEntityManager(); final Locale locale = getLocale(); final Company company = resolveCompany(entityManager, (VaadinServletRequest) request); final User user = UserDao.getUser(entityManager, company, emailAddress); final String errorKey = LoginService.login(getSite().getSiteContext(), company, user, emailAddress, password); if (errorKey == null) { // Login success final List<Group> groups = UserDao.getUserGroups(entityManager, company, user); DefaultSiteUI.getSecurityProvider().setUser(user, groups); // Check for imminent password expiration. if (user.getPasswordExpirationDate() != null && new DateTime().plusDays(14).toDate() .getTime() > user.getPasswordExpirationDate().getTime()) { final DateTime expirationDate = new DateTime(user.getPasswordExpirationDate()); final DateTime currentDate = new DateTime(); final long daysUntilExpiration = new Duration(currentDate.toDate().getTime(), expirationDate.toDate().getTime()).getStandardDays(); setNotification(DefaultSiteUI.getLocalizationProvider().localize( "message-password-expires-in-days", locale) + ": " + daysUntilExpiration, Notification.Type.WARNING_MESSAGE); } else { setNotification(DefaultSiteUI.getLocalizationProvider().localize( "message-login-success", locale), Notification.Type.TRAY_NOTIFICATION); } } else { // Login failure setNotification(DefaultSiteUI.getLocalizationProvider().localize(errorKey, locale), Notification.Type.WARNING_MESSAGE); } } return false; // No response was written } }); }
From source file:org.bubblecloud.ilves.site.SecurityProviderSessionImpl.java
License:Apache License
/** * Sets user to session./*from w w w. j a v a 2 s.c o m*/ * @param user the user */ private void setUserToSession(final User user) { VaadinSession.getCurrent().setAttribute("user", user); VaadinSession.getCurrent().getSession().setAttribute("user", user); }
From source file:org.bubblecloud.ilves.site.SecurityProviderSessionImpl.java
License:Apache License
/** * Sets groups to session./* ww w. j a va 2s. c o m*/ * @param groups the groups */ private void setGroupsToSession(final List<Group> groups) { VaadinSession.getCurrent().setAttribute("groups", groups); VaadinSession.getCurrent().getSession().setAttribute("groups", groups); }