com.vaadin.server.VaadinServletService Java Examples

The following examples show how to use com.vaadin.server.VaadinServletService. 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: VertxVaadinService.java    From vertx-vaadin with MIT License 6 votes vote down vote up
@Override
public String getStaticFileLocation(VaadinRequest request) {
    String staticFileLocation;
    // if property is defined in configurations, use that
    staticFileLocation = getDeploymentConfiguration().getResourcesPath();
    if (staticFileLocation != null) {
        return staticFileLocation;
    }

    VertxVaadinRequest vertxRequest = (VertxVaadinRequest) request;
    String requestedPath = vertxRequest.getRequest().path()
        .substring(
            Optional.ofNullable(vertxRequest.getRoutingContext().mountPoint())
                .map(String::length).orElse(0)
        );
    return VaadinServletService.getCancelingRelativePath(requestedPath);
}
 
Example #2
Source File: SpringAuthManager.java    From jdal with Apache License 2.0 6 votes vote down vote up
@Override
public boolean validate(String username, String password) {
	UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, password);
	try {
		Authentication auth = this.authenticationManager.authenticate(token);
		if (auth.isAuthenticated()) {
			// execute session authentication strategy
			if (this.sessionStrategy != null)
				this.sessionStrategy.onAuthentication(auth, VaadinServletService.getCurrentServletRequest(),
						VaadinServletService.getCurrentResponse());
			SecurityContextHolder.getContext().setAuthentication(auth);
			// save request in context session
			VaadinSession.getCurrent().getSession().setAttribute(
					HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY,
					SecurityContextHolder.getContext());
			
			return  true;
		}
		SecurityContextHolder.clearContext();
		return false;
	}
	catch(AuthenticationException ae) {
		SecurityContextHolder.clearContext();
		return false;
	}
}
 
Example #3
Source File: VertxBootstrapHandler.java    From vertx-vaadin with MIT License 5 votes vote down vote up
@Override
protected String getServiceUrl(BootstrapContext context) {
    String pathInfo = context.getRequest().getPathInfo();
    if (pathInfo == null) {
        return null;
    } else {
        /*
         * Make a relative URL to the servlet by adding one ../ for each
         * path segment in pathInfo (i.e. the part of the requested path
         * that comes after the servlet mapping)
         */
        return VaadinServletService.getCancelingRelativePath(pathInfo);
    }
}
 
Example #4
Source File: AnswerSavedListener.java    From gazpachoquest with GNU General Public License v3.0 5 votes vote down vote up
public void listen(@Observes
AnswerSavedEvent event) {
    RespondentAccount respondent = (RespondentAccount) VaadinServletService.getCurrentServletRequest()
            .getUserPrincipal();
    Integer questionnaireId = respondent.getGrantedquestionnaireIds().iterator().next();

    Answer answer = event.getAnswer();
    String questionCode = event.getQuestionCode();

    logger.debug("Trying to save answer: {}  for questionnair identified with id  = {} and questionCode = {}",
            answer, questionnaireId, questionCode);
    questionnaireResource.saveAnswer(answer, questionnaireId, questionCode);
}
 
Example #5
Source File: VertxVaadinService.java    From vertx-vaadin with MIT License 4 votes vote down vote up
public static String getCancelingRelativePath(String servletPath) {
    return VaadinServletService.getCancelingRelativePath(servletPath);
}
 
Example #6
Source File: WebDeviceInfoProvider.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public DeviceInfo getDeviceInfo() {
    // per request cache
    HttpServletRequest currentServletRequest = VaadinServletService.getCurrentServletRequest();
    if (currentServletRequest == null) {
        return null;
    }

    DeviceInfo deviceInfo = (DeviceInfo) currentServletRequest.getAttribute(DeviceInfoProvider.NAME);
    if (deviceInfo != null) {
        return deviceInfo;
    }

    Page page = Page.getCurrent();

    if (page == null) {
        return null;
    }

    WebBrowser webBrowser = page.getWebBrowser();

    DeviceInfo di = new DeviceInfo();

    di.setAddress(webBrowser.getAddress());
    di.setBrowserApplication(webBrowser.getBrowserApplication());
    di.setBrowserMajorVersion(webBrowser.getBrowserMajorVersion());
    di.setBrowserMinorVersion(webBrowser.getBrowserMinorVersion());

    di.setChrome(webBrowser.isChrome());
    di.setChromeFrame(webBrowser.isChromeFrame());
    di.setChromeFrameCapable(webBrowser.isChromeFrameCapable());
    di.setEdge(webBrowser.isEdge());
    di.setFirefox(webBrowser.isFirefox());
    di.setOpera(webBrowser.isOpera());
    di.setIE(webBrowser.isIE());
    di.setSafari(webBrowser.isSafari());

    if (webBrowser.isWindows()) {
        di.setOperatingSystem(OperatingSystem.WINDOWS);
    } else if (webBrowser.isAndroid()) {
        di.setOperatingSystem(OperatingSystem.ANDROID);
    } else if (webBrowser.isIOS()) {
        di.setOperatingSystem(OperatingSystem.IOS);
    } else if (webBrowser.isMacOSX()) {
        di.setOperatingSystem(OperatingSystem.MACOSX);
    } else if (webBrowser.isLinux()) {
        di.setOperatingSystem(OperatingSystem.LINUX);
    }

    di.setIPad(webBrowser.isIPad());
    di.setIPhone(webBrowser.isIPhone());
    di.setWindowsPhone(webBrowser.isWindowsPhone());

    di.setSecureConnection(webBrowser.isSecureConnection());
    di.setLocale(webBrowser.getLocale());

    di.setScreenHeight(webBrowser.getScreenHeight());
    di.setScreenWidth(webBrowser.getScreenWidth());

    currentServletRequest.setAttribute(DeviceInfoProvider.NAME, di);

    return di;
}
 
Example #7
Source File: TestVaadinSession.java    From cuba with Apache License 2.0 4 votes vote down vote up
public TestVaadinSession(WebBrowser webBrowser, Locale locale) {
    super(new VaadinServletService(){});
    this.webBrowser = webBrowser;

    setLocale(locale);
}
 
Example #8
Source File: QuestionnaireView.java    From gazpachoquest with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void enter(ViewChangeEvent event) {
    logger.debug("Entering {} view ", QuestionnaireView.NAME);
    addStyleName(Reindeer.LAYOUT_BLUE);
    addStyleName("questionnaires");

    WebBrowser webBrowser = Page.getCurrent().getWebBrowser();
    Integer screenWidth = webBrowser.getScreenWidth();
    Integer heightWidth = webBrowser.getScreenHeight();

    logger.debug("Browser screen settings  {} x {}", screenWidth, heightWidth);

    if (heightWidth <= 480) {
        renderingMode = RenderingMode.QUESTION_BY_QUESTION;
    }

    // centralLayout.addStyleName("questionnaires");
    // new Responsive(centralLayout);

    RespondentAccount respondent = (RespondentAccount) VaadinServletService.getCurrentServletRequest()
            .getUserPrincipal();
    if (respondent.hasPreferredLanguage()) {
        preferredLanguage =  Language.fromString(respondent.getPreferredLanguage());
    } else {
        preferredLanguage = Language.fromLocale(webBrowser.getLocale());
    }
    questionnaireId = respondent.getGrantedquestionnaireIds().iterator().next();
    logger.debug("Trying to fetch questionnair identified with id  = {} ", questionnaireId);
    QuestionnaireDefinitionDTO definition = questionnaireResource.getDefinition(questionnaireId);
    sectionInfoVisible = definition.isSectionInfoVisible();
    QuestionnairePageDTO page = questionnaireResource.getPage(questionnaireId, renderingMode, preferredLanguage,
            NavigationAction.ENTERING);

    logger.debug("Displaying page {}/{} with {} questions", page.getMetadata().getNumber(), page.getMetadata()
            .getCount(), page.getQuestions().size());
    questionsLayout = new VerticalLayout();
    update(page);

    Label questionnaireTitle = new Label(definition.getLanguageSettings().getTitle());
    questionnaireTitle.addStyleName(Reindeer.LABEL_H1);

    VerticalLayout mainLayout = new VerticalLayout();
    mainLayout.setSizeFull();
    mainLayout.setMargin(true);
    mainLayout.addComponent(questionnaireTitle);
    mainLayout.addComponent(questionsLayout);
    // Add the responsive capabilities to the components

    Panel centralLayout = new Panel();
    centralLayout.setContent(mainLayout);
    centralLayout.setSizeFull();
    centralLayout.getContent().setSizeUndefined();

    Responsive.makeResponsive(questionnaireTitle);
    setCompositionRoot(centralLayout);
    setSizeFull();
}