List of usage examples for com.vaadin.server VaadinRequest getUserPrincipal
public Principal getUserPrincipal();
java.security.Principal
object containing the name of the current authenticated user. From source file:com.haulmont.cuba.web.auth.IdpAuthProvider.java
License:Apache License
@Override public void userSessionLoggedIn(UserSession session) { VaadinRequest currentRequest = VaadinService.getCurrentRequest(); if (currentRequest != null) { Principal principal = currentRequest.getUserPrincipal(); if (principal instanceof IdpSessionPrincipal) { IdpSession idpSession = ((IdpSessionPrincipal) principal).getIdpSession(); session.setAttribute(IdpService.IDP_USER_SESSION_ATTRIBUTE, idpSession.getId()); }//w w w . j a v a 2s . co m } }
From source file:com.haulmont.cuba.web.security.idp.IdpLoginLifecycleManager.java
License:Apache License
@Order(Events.HIGHEST_PLATFORM_PRECEDENCE + 10) @EventListener/*from w ww .j a v a 2 s. c om*/ protected void onAppStarted(AppStartedEvent event) throws LoginException { Connection connection = event.getApp().getConnection(); // can be already authenticated by another event listener if (webIdpConfig.getIdpEnabled() && !connection.isAuthenticated()) { VaadinRequest currentRequest = VaadinService.getCurrentRequest(); if (currentRequest != null) { Principal principal = currentRequest.getUserPrincipal(); if (principal instanceof IdpSessionPrincipal) { IdpSession idpSession = ((IdpSessionPrincipal) principal).getIdpSession(); Locale locale = event.getApp().getLocale(); ExternalUserCredentials credentials = new ExternalUserCredentials(principal.getName(), locale); credentials.setSessionAttributes( ImmutableMap.of(IdpService.IDP_USER_SESSION_ATTRIBUTE, idpSession.getId())); connection.login(credentials); } } } }
From source file:org.ow2.sirocco.cloudmanager.MyUI.java
License:Open Source License
@Override protected void init(final VaadinRequest request) { this.userName = request.getUserPrincipal().getName(); this.identityContext.setUserName(this.userName); this.getPage().setTitle("Sirocco Dashboard"); final VerticalLayout layout = new VerticalLayout(); layout.setSizeFull();//from www . j av a 2 s . c o m this.setContent(layout); // Top header ********************* HorizontalLayout header = new HorizontalLayout(); header.setMargin(true); header.setWidth("100%"); header.setHeight("70px"); header.setStyleName("topHeader"); // logo Image image = new Image(null, new ThemeResource("img/sirocco_small_logo.png")); header.addComponent(image); // spacer Label spacer = new Label(); spacer.setWidth("100%"); header.addComponent(spacer); header.setExpandRatio(spacer, 1.0f); HorizontalLayout rightButtons = new HorizontalLayout(); rightButtons.setStyleName("topHeader"); rightButtons.setSpacing(true); this.userName = request.getUserPrincipal().getName(); User user = null; try { user = this.userManager.getUserByUsername(this.userName); } catch (CloudProviderException e) { e.printStackTrace(); } Label label = new Label("Tenant:"); label.setStyleName("topHeaderLabel"); rightButtons.addComponent(label); final ComboBox tenantSelect = new ComboBox(); tenantSelect.setTextInputAllowed(false); tenantSelect.setNullSelectionAllowed(false); for (Tenant tenant : user.getTenants()) { tenantSelect.addItem(tenant.getName()); } tenantSelect.setValue(user.getTenants().iterator().next().getName()); tenantSelect.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(final ValueChangeEvent event) { Notification.show("Switching to tenant " + tenantSelect.getValue()); } }); tenantSelect.setImmediate(true); rightButtons.addComponent(tenantSelect); this.tenantId = user.getTenants().iterator().next().getUuid(); this.identityContext.setTenantId(this.tenantId); // logged user name label = new Label("Logged in as: " + this.userName); label.setStyleName("topHeaderLabel"); rightButtons.addComponent(label); // sign out button Button button = new Button("Sign Out"); // button.setStyleName(BaseTheme.BUTTON_LINK); button.addClickListener(new Button.ClickListener() { public void buttonClick(final ClickEvent event) { MyUI.this.logout(); } }); rightButtons.addComponent(button); header.addComponent(rightButtons); layout.addComponent(header); // Split view HorizontalSplitPanel splitPanel = new HorizontalSplitPanel(); splitPanel.setSizeFull(); splitPanel.setFirstComponent(this.createLeftMenu()); this.inventoryContainer = new VerticalLayout(); this.inventoryContainer.setSizeFull(); this.inventoryContainer.addComponent(this.machineView); splitPanel.setSecondComponent(this.inventoryContainer); splitPanel.setSplitPosition(15); layout.addComponent(splitPanel); layout.setExpandRatio(splitPanel, 1.0f); this.listenToNotifications(); }