Example usage for com.vaadin.server VaadinServletService getCurrentServletRequest

List of usage examples for com.vaadin.server VaadinServletService getCurrentServletRequest

Introduction

In this page you can find the example usage for com.vaadin.server VaadinServletService getCurrentServletRequest.

Prototype

public static HttpServletRequest getCurrentServletRequest() 

Source Link

Usage

From source file:com.haulmont.cuba.web.config.WebDeviceInfoProvider.java

License:Apache License

@Nullable
@Override//from w  w  w .j  a va 2  s .c o  m
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());

    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;
}

From source file:de.symeda.sormas.ui.login.LoginHelper.java

License:Open Source License

public static boolean login(String username, String password) throws UserRightsException {

    if (username == null || username.isEmpty())
        return false;

    BeanManager bm = CDI.current().getBeanManager();
    @SuppressWarnings("unchecked")
    Bean<SecurityContext> securityContextBean = (Bean<SecurityContext>) bm.getBeans(SecurityContext.class)
            .iterator().next();/*w  w w . j a  va  2s . c o m*/
    CreationalContext<SecurityContext> ctx = bm.createCreationalContext(securityContextBean);
    SecurityContext securityContext = (SecurityContext) bm.getReference(securityContextBean,
            SecurityContext.class, ctx);

    AuthenticationParameters authentication = new AuthenticationParameters();
    authentication.credential(new UsernamePasswordCredential(username, password));
    authentication.newAuthentication(true);
    authentication.setRememberMe(true);
    AuthenticationStatus status = securityContext.authenticate(VaadinServletService.getCurrentServletRequest(),
            VaadinServletService.getCurrentResponse().getHttpServletResponse(), authentication);

    if (status == AuthenticationStatus.SUCCESS)
        return true;
    return false;
}

From source file:de.symeda.sormas.ui.login.LoginHelper.java

License:Open Source License

public static boolean logout() {
    try {//from  ww w. j a v a  2 s  .  c  o  m
        VaadinServletService.getCurrentServletRequest().logout();
    } catch (ServletException e) {
        return false;
    }

    VaadinSession.getCurrent().getSession().invalidate();
    Page.getCurrent().reload();

    return true;
}

From source file:de.symeda.sormas.ui.login.LoginUI.java

License:Open Source License

@Override
public void init(VaadinRequest vaadinRequest) {

    setErrorHandler(SormasErrorHandler.get());
    setLocale(vaadinRequest.getLocale());

    Responsive.makeResponsive(this);

    VaadinSession.getCurrent().setConverterFactory(new SormasDefaultConverterFactory());

    getPage().setTitle("SORMAS");

    setContent(new LoginScreen(new LoginListener() {
        @Override/*from w  w  w  .  j a  v  a2 s  .  co  m*/
        public void loginSuccessful() {
            UI.getCurrent().getPage()
                    .setLocation(VaadinServletService.getCurrentServletRequest().getContextPath() + "#"
                            + DataHelper.toStringNullable(UI.getCurrent().getPage().getUriFragment()));
        }
    }));

}

From source file:net.sf.gazpachoquest.questionnaires.views.QuestionnaireView.java

License:Open Source License

@Override
public void enter(ViewChangeEvent event) {
    logger.debug("Entering {} view ", QuestionnaireView.NAME);
    addStyleName(Reindeer.LAYOUT_BLUE);/*w  w w .ja  v  a 2  s  .  co  m*/
    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();
}

From source file:org.apache.openaz.xacml.admin.XacmlAdminUI.java

License:Apache License

@Override
protected void init(VaadinRequest request) {
    ////from   w w w.  ja  va 2 s. com
    // Set our title
    //
    this.getPage().setTitle("Apache OpenAZ Admin Console");
    //
    // Create our authorization object
    //
    this.authorizer = new XacmlAdminAuthorization();
    //
    // Is the user authorized to use the application?
    //
    if (this.authorizer.isAuthorized(this.getUserid(), XacmlAdminAuthorization.AdminAction.ACTION_ACCESS,
            XacmlAdminAuthorization.AdminResource.RESOURCE_APPLICATION) == false) {
        logger.error("user " + this.getUserid() + " is not authorized.");
        //
        // Create a navigator to manage all our views
        //
        this.navigator = new Navigator(this, this);
        //
        // Redirect to an error page
        //
        this.navigator.addView(XacmlErrorHandler.VIEWNAME, new XacmlErrorHandler(
                "User " + this.getUserid() + " is not authorized to access application", null));
        this.navigator.navigateTo(XacmlErrorHandler.VIEWNAME);
        return;
    }
    try {
        //
        // Initialize user's Git repository
        //
        this.workspacePath = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_ADMIN_WORKSPACE),
                this.getUserid());
        this.gitPath = XacmlAdminUI.initializeUserRepository(this.workspacePath, this.getUserid(),
                this.getUserEmail());
    } catch (Exception e) {
        logger.error("Git Setup failure", e);
        //
        // Create a navigator to manage all our views
        //
        this.navigator = new Navigator(this, this);
        //
        // Redirect to an error page
        //
        this.navigator.addView(XacmlErrorHandler.VIEWNAME, new XacmlErrorHandler(e.getMessage(), null));
        this.navigator.navigateTo(XacmlErrorHandler.VIEWNAME);
        return;
    }
    //
    // Create a navigator to manage all our views
    //
    this.navigator = new Navigator(this, this);
    //
    // Set our converter factory
    //
    this.getSession().setConverterFactory(new XacmlConverterFactory());
    //
    // Initialize our data objects
    //
    try {
        //
        // Initialize JPA and SQL. Create our custom entity manager.
        //
        logger.info("Creating Persistence Entity Manager");
        //
        // Now create the entity manager. This is used throughout the application to create JPA
        // containers of the entities located in the database.
        //
        this.em = XacmlAdminUI.emf.createEntityManager();
        //
        // Our Read-Only containers
        //
        logger.info("Creating JPA read-only containers");
        this.constraintTypes = new JPAContainer<ConstraintType>(ConstraintType.class);
        this.constraintTypes.setEntityProvider(
                new CachingLocalEntityProvider<ConstraintType>(ConstraintType.class, this.em));

        this.categories = new JPAContainer<Category>(Category.class);
        this.categories.setEntityProvider(new CachingLocalEntityProvider<Category>(Category.class, this.em));

        this.datatypes = new JPAContainer<Datatype>(Datatype.class);
        this.datatypes.setEntityProvider(new CachingLocalEntityProvider<Datatype>(Datatype.class, this.em));

        this.policyAlgorithms = new JPAContainer<PolicyAlgorithms>(PolicyAlgorithms.class);
        this.policyAlgorithms.setEntityProvider(
                new CachingLocalEntityProvider<PolicyAlgorithms>(PolicyAlgorithms.class, this.em));

        this.ruleAlgorithms = new JPAContainer<RuleAlgorithms>(RuleAlgorithms.class);
        this.ruleAlgorithms.setEntityProvider(
                new CachingLocalEntityProvider<RuleAlgorithms>(RuleAlgorithms.class, this.em));

        this.pipTypes = new JPAContainer<PIPType>(PIPType.class);
        this.pipTypes.setEntityProvider(new CachingLocalEntityProvider<PIPType>(PIPType.class, this.em));

        this.functionDefinitions = new JPAContainer<FunctionDefinition>(FunctionDefinition.class);
        this.functionDefinitions.setEntityProvider(
                new CachingLocalEntityProvider<FunctionDefinition>(FunctionDefinition.class, this.em));

        this.functionArguments = new JPAContainer<FunctionArgument>(FunctionArgument.class);
        this.functionArguments.setEntityProvider(
                new CachingLocalEntityProvider<FunctionArgument>(FunctionArgument.class, this.em));
        //
        // Our writable containers. NOTE: The dictionaries have their own JPA instance since they can
        // apply filters to their table views. If you update these, then refresh the dictionary containers
        // by calling the appropriate refresh method defined in XacmlAdminUI.
        //
        logger.info("Creating JPA writable containers");
        this.attributes = new JPAContainer<Attribute>(Attribute.class);
        this.attributes
                .setEntityProvider(new CachingMutableLocalEntityProvider<Attribute>(Attribute.class, this.em));

        this.obadvice = new JPAContainer<Obadvice>(Obadvice.class);
        this.obadvice
                .setEntityProvider(new CachingMutableLocalEntityProvider<Obadvice>(Obadvice.class, this.em));

        this.obadviceExpressions = new JPAContainer<ObadviceExpression>(ObadviceExpression.class);
        this.obadviceExpressions.setEntityProvider(
                new CachingMutableLocalEntityProvider<ObadviceExpression>(ObadviceExpression.class, this.em));

        this.pipConfigurations = new JPAContainer<PIPConfiguration>(PIPConfiguration.class);
        this.pipConfigurations.setEntityProvider(
                new CachingMutableLocalEntityProvider<PIPConfiguration>(PIPConfiguration.class, this.em));

        this.pipResolvers = new JPAContainer<PIPResolver>(PIPResolver.class);
        this.pipResolvers.setEntityProvider(
                new CachingMutableLocalEntityProvider<PIPResolver>(PIPResolver.class, this.em));
        //
        // Sort our persistence data
        //
        logger.info("Sorting containers");
        this.categories.sort(new String[] { "xacmlId" }, new boolean[] { true });
        this.datatypes.sort(new String[] { "xacmlId" }, new boolean[] { true });
        this.policyAlgorithms.sort(new String[] { "xacmlId" }, new boolean[] { true });
        this.ruleAlgorithms.sort(new String[] { "xacmlId" }, new boolean[] { true });
        this.functionDefinitions.sort(new String[] { "xacmlid" }, new boolean[] { true });
        //this.functionArguments.sort(new String[]{"datatypeBean"}, new boolean[]{true});
        //
        // Create our special query for MatchType functions. We need a custom
        // QueryDelegate because these functions are accessible via a View (vs a Table).
        // The basic FreeformQuery does not work with filters on a View (via Vaadin).
        //
        // TODO: Consider putting this into a couple of Map's. Doing so would speed up
        // access. However, if we want to support custom functions, then there needs to
        // be a way for those custom functions to get into the Map. This is why a database
        // is being used to store ALL the functions, both standard and custom.
        //
        logger.info("Creating SQL Queries");
        MatchFunctionQueryDelegate delegate = new MatchFunctionQueryDelegate();
        FreeformQuery query = new FreeformQuery("SELECT * FROM match_functions", XacmlAdminUI.pool,
                new String[] {});
        query.setDelegate(delegate);
        this.matchFunctionContainer = new SQLContainer(query);
        //
        // Same for this one
        //
        delegate = new MatchFunctionQueryDelegate();
        query = new FreeformQuery("SELECT * FROM higherorder_bag_functions", XacmlAdminUI.pool,
                new String[] {});
        query.setDelegate(delegate);
        this.higherorderBagContainer = new SQLContainer(query);
        //
        // Load our PAP engine
        //
        logger.info("Creating PAP engine");
        String myRequestURL = VaadinServletService.getCurrentServletRequest().getRequestURL().toString();
        try {
            //
            // Set the URL for the RESTful PAP Engine
            //
            papEngine = new RESTfulPAPEngine(myRequestURL);
        } catch (PAPException e) {
            logger.error("Failed to create PAP engine", e);
        } catch (Exception e) {
            logger.error("Failed to create PAP engine", e);
        }
        logger.info("done creating connections");
    } catch (Exception e) {
        //
        // Redirect to an error page
        //
        logger.error(e);
        e.printStackTrace();
        this.navigator.addView("", new XacmlErrorHandler(e.getMessage(), null));
        this.navigator.navigateTo("");
        return;
    }
    logger.info("Creating main layout");
    //
    // Create our main component layout
    //
    this.console = new XacmlAdminConsole();
    this.navigator.addView("", console);
    this.navigator.setErrorView(new XacmlErrorHandler(null, null));
    //
    // Navigate to our view
    //
    this.navigator.navigateTo("");
    //
    // Register to receive PAP change notifications broadcasts
    //
    PAPNotificationBroadcaster.register(this);
}

From source file:org.ow2.sirocco.cloudmanager.MyUI.java

License:Open Source License

private void logout() {
    this.getUI().getSession().close();
    // UI.getCurrent().close();

    // Invalidate underlying session instead if login info is stored there
    VaadinService.getCurrentRequest().getWrappedSession().invalidate();

    // Redirect to avoid keeping the removed UI open in the browser
    this.getUI().getPage()
            .setLocation(VaadinServletService.getCurrentServletRequest().getContextPath() + "/logout.jsp");
}

From source file:org.ripla.web.internal.services.RiplaEventDispatcher.java

License:Open Source License

private String getAppLocation() {
    return VaadinServlet.getCurrent().getServletContext().getContextPath()
            + VaadinServletService.getCurrentServletRequest().getServletPath();
}

From source file:org.ripla.web.util.RiplaRequestHandler.java

License:Open Source License

/**
 * RequestHandler constructor./*from  www .  j a  v a  2s  .  c o m*/
 */
public RiplaRequestHandler() {
    requestURL = VaadinServlet.getCurrent().getServletContext().getContextPath()
            + VaadinServletService.getCurrentServletRequest().getServletPath();
}

From source file:org.vaadin.addons.lazycontainer.LazyContainer.java

License:Apache License

protected boolean needRefreshCachedSize() {
    // in older version, thread's id was used.
    // but in some environment, thread's id was not unique each request.
    // so use servletrequest's object identity insted.
    final HttpServletRequest currentServletRequest = VaadinServletService.getCurrentServletRequest();
    if (weakRef == null || weakRef.get() == null)
        return true;
    if (weakRef.get() == currentServletRequest)
        return false;
    return true;/*from w w w.j  a v  a 2s.c  o  m*/
}