com.vaadin.server.VaadinService Java Examples

The following examples show how to use com.vaadin.server.VaadinService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LinkHandler.java    From cuba with Apache License 2.0 6 votes vote down vote up
/**
 * Called to handle the link.
 */
public void handle() {
    try {
        ExternalLinkContext linkContext = new ExternalLinkContext(requestParams, action, app);
        for (LinkHandlerProcessor processor : processors) {
            if (processor.canHandle(linkContext)) {
                processor.handle(linkContext);
                break;
            }
        }
    } finally {
        VaadinRequest request = VaadinService.getCurrentRequest();
        WrappedSession wrappedSession = request.getWrappedSession();
        wrappedSession.removeAttribute(AppUI.LAST_REQUEST_PARAMS_ATTR);
        wrappedSession.removeAttribute(AppUI.LAST_REQUEST_ACTION_ATTR);
    }
}
 
Example #2
Source File: UserDetailsFormatter.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
public static UserDetails getCurrentUser() {
    final SecurityContext context = (SecurityContext) VaadinService.getCurrentRequest().getWrappedSession()
            .getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY);
    Authentication authentication = context.getAuthentication();
    if (authentication instanceof OAuth2AuthenticationToken) {
        OidcUser oidcUser = (OidcUser) authentication.getPrincipal();
        Object details = authentication.getDetails();
        String tenant = "DEFAULT";
        if (details instanceof TenantAwareAuthenticationDetails) {
            tenant = ((TenantAwareAuthenticationDetails) details).getTenant();
        }
        return new UserPrincipal(oidcUser.getPreferredUsername(), "***", oidcUser.getGivenName(),
                oidcUser.getFamilyName(), oidcUser.getPreferredUsername(), oidcUser.getEmail(), tenant,
                oidcUser.getAuthorities());
    } else {
        return (UserDetails) authentication.getPrincipal();
    }
}
 
Example #3
Source File: LogoutClickListener.java    From cia with Apache License 2.0 6 votes vote down vote up
@Override
public final void buttonClick(final ClickEvent event) {
	final ServiceResponse response = getApplicationManager().service(logoutRequest);


	if (ServiceResult.SUCCESS == response.getResult()) {
		UI.getCurrent().getNavigator().navigateTo(CommonsViews.MAIN_VIEW_NAME);
		UI.getCurrent().getSession().close();
		VaadinService.getCurrentRequest().getWrappedSession().invalidate();
	} else {
		showNotification(LOGOUT_FAILED,
                  ERROR_MESSAGE,
                  Notification.Type.WARNING_MESSAGE);
		LOGGER.info(LOG_MSG_LOGOUT_FAILURE,logoutRequest.getSessionId());
	}
}
 
Example #4
Source File: VaadinAccessDeniedHandler.java    From jdal with Apache License 2.0 6 votes vote down vote up
/**
 * Test if current request is an UIDL request
 * @return true if in UIDL request, false otherwise
 */
private boolean isUidlRequest() {
	VaadinRequest request = VaadinService.getCurrentRequest();
	
	if (request == null)
		return false;
	
	 String pathInfo = request.getPathInfo();

	 if (pathInfo == null) {
            return false;
	 }
	 
	 if (pathInfo.startsWith("/" + ApplicationConstants.UIDL_PATH)) {
            return true;
        }

        return false;
}
 
Example #5
Source File: ConnectionImpl.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected WebBrowser getWebBrowserDetails() {
    // timezone info is passed only on VaadinSession creation
    WebBrowser webBrowser = VaadinSession.getCurrent().getBrowser();
    VaadinRequest currentRequest = VaadinService.getCurrentRequest();
    // update web browser instance if current request is not null
    // it can be null in case of background/async processing of login request
    if (currentRequest != null) {
        webBrowser.updateRequestDetails(currentRequest);
    }
    return webBrowser;
}
 
Example #6
Source File: WebHttpSessionUrlsHolder.java    From cuba with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
@Nullable
public List<String> getUrls(String selectorId) {
    VaadinRequest vaadinRequest = VaadinService.getCurrentRequest();
    if (vaadinRequest != null)
        return (List) vaadinRequest.getWrappedSession().getAttribute(getAttributeName(selectorId));
    else {
        HttpSession httpSession = getHttpSession();
        return httpSession != null ? (List<String>) httpSession.getAttribute(getAttributeName(selectorId)) : null;
    }
}
 
Example #7
Source File: WebHttpSessionUrlsHolder.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void setUrls(String selectorId, List<String> urls) {
    VaadinRequest vaadinRequest = VaadinService.getCurrentRequest();
    if (vaadinRequest != null)
        vaadinRequest.getWrappedSession().setAttribute(getAttributeName(selectorId), urls);
    else {
        HttpSession httpSession = getHttpSession();
        if (httpSession != null) {
            httpSession.setAttribute(getAttributeName(selectorId), urls);
        }
    }
}
 
Example #8
Source File: MainView.java    From usergrid with Apache License 2.0 5 votes vote down vote up
private void redirectToMainView() {
    // Close the VaadinServiceSession
    getUI().getSession().close();

    // Invalidate underlying session instead if login info is stored there
    VaadinService.getCurrentRequest().getWrappedSession().invalidate();
    getUI().getPage().setLocation( "/VAADIN" );
}
 
Example #9
Source File: VaadinUtils.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * Exit application
 */
public static void exit() {
	VaadinSession.getCurrent().getSession().removeAttribute(
			HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY);
	UI.getCurrent().close();
	VaadinSession.getCurrent().close();
	Page page = Page.getCurrent();
	page.setLocation(VaadinService.getCurrentRequest().getContextPath() + "/logout"); 
}
 
Example #10
Source File: SockJSPushHandler.java    From vertx-vaadin with MIT License 4 votes vote down vote up
private static void sendRefreshAndDisconnect(PushSocket socket) {
    sendNotificationAndDisconnect(socket, VaadinService
        .createCriticalNotificationJSON(null, null, null, null));
}
 
Example #11
Source File: ExposeVaadinCommunicationPkg.java    From vertx-vaadin with MIT License 4 votes vote down vote up
static String getUINotFoundErrorJSON(VaadinService service, VaadinRequest vaadinRequest) {
    return UidlRequestHandler.getUINotFoundErrorJSON(service, vaadinRequest);
}
 
Example #12
Source File: ConnectionImpl.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Nullable
protected String getUserRemoteAddress() {
    VaadinRequest currentRequest = VaadinService.getCurrentRequest();
    return currentRequest != null ? currentRequest.getRemoteAddr() : null;
}
 
Example #13
Source File: TestVaadinRequest.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
public VaadinService getService() {
    return null;
}
 
Example #14
Source File: Icon.java    From chipster with MIT License 4 votes vote down vote up
private static String removePathEnd() {
	return VaadinService.getCurrent().getBaseDirectory().getAbsolutePath().replace(getPathEnd(), "");
}
 
Example #15
Source File: LoginUI.java    From jdal with Apache License 2.0 4 votes vote down vote up
/**
 * @return
 */
private String getApplicationUrl() {
	return VaadinService.getCurrentRequest().getContextPath() + successUrl;
}
 
Example #16
Source File: RDFUnitDemoSession.java    From RDFUnit with Apache License 2.0 2 votes vote down vote up
/**
 * Instantiates a new RDF unit demo session.
 *
 * @param service the service
 */
public RDFUnitDemoSession(VaadinService service) {
    super(service);
}