Class SpringViewProvider

java.lang.Object
com.vaadin.spring.navigator.SpringViewProvider
All Implemented Interfaces:
com.vaadin.navigator.ViewProvider, Serializable

public class SpringViewProvider extends Object implements com.vaadin.navigator.ViewProvider
A Vaadin ViewProvider that fetches the views from the Spring application context. The views must implement the View interface and be annotated with the SpringView annotation.

Use like this:

 @SpringUI
 public class MyUI extends UI {

     @Autowired
     SpringViewProvider viewProvider;

     protected void init(VaadinRequest vaadinRequest) {
         Navigator navigator = new Navigator(this, this);
         navigator.addProvider(viewProvider);
         setNavigator(navigator);
         // ...
     }
 }
 

View-based security can be provided by creating a Spring bean that implements the interface ViewAccessControl (for view bean name and annotation based security) or ViewInstanceAccessControl (if view instance specific contextual data is needed). It is also possible to set an 'Access Denied' view by using setAccessDeniedViewClass(Class).

To specify a view to show when no matching view is found, use SpringNavigator.setErrorView(Class). Unlike version 1.0, version 1.1 does not use the access denied view always when no matching view is found.

Author:
Petter Holmström (petter@vaadin.com), Henri Sara (hesara@vaadin.com)
See Also:
  • Constructor Details

    • SpringViewProvider

      @Autowired public SpringViewProvider(org.springframework.context.ApplicationContext applicationContext, org.springframework.beans.factory.support.BeanDefinitionRegistry beanDefinitionRegistry)
  • Method Details

    • getAccessDeniedViewClass

      public Class<? extends com.vaadin.navigator.View> getAccessDeniedViewClass()
      Returns the class of the access denied view. If set, a bean of this type will be fetched from the application context and showed to the user when a ViewAccessControl or a ViewInstanceAccessControl denies access to a view.
      Returns:
      the access denied view class, or null if not set.
    • setAccessDeniedViewClass

      public void setAccessDeniedViewClass(Class<? extends com.vaadin.navigator.View> accessDeniedViewClass)
      Sets the class of the access denied view. If set, a bean of this type will be fetched from the application context and showed to the user when a ViewAccessControl or a ViewInstanceAccessControl denies access to a view.
      Parameters:
      accessDeniedViewClass - the access denied view class, may be null.
    • getViewNameFromAnnotation

      protected String getViewNameFromAnnotation(Class<?> beanClass, SpringView annotation)
    • getAllViewsForCurrentUI

      protected List<SpringViewProvider.ViewInfo> getAllViewsForCurrentUI()
      Return a collection with all the registered Spring views for the current UI regardless of access restrictions.
      Returns:
      list of ViewInfo, not null
    • getAllowedViewsForCurrentUI

      protected List<SpringViewProvider.ViewInfo> getAllowedViewsForCurrentUI()
      Return a collection with all the registered Spring views for the current UI which the current user is allowed to access. Note that only view type/bean level access is checked (ViewAccessControl), and view instance specific checks (ViewInstanceAccessControl) are not applied.
      Returns:
      list of ViewInfo, not null
    • getAllowedViewsForCurrentUI

      protected List<SpringViewProvider.ViewInfo> getAllowedViewsForCurrentUI(String viewName)
      Return a collection with all the registered Spring views with the given view name for the current UI and which the current user is allowed to access. Note that only view type/bean level access is checked (ViewAccessControl), and view instance specific checks (ViewInstanceAccessControl) are not applied.
      Parameters:
      viewName - view name in the form returned by getViewName(String) (no parameters)
      Returns:
      list of ViewInfo, not null
    • getViewNamesForCurrentUI

      public Collection<String> getViewNamesForCurrentUI()
      Return a collection with all the registered Spring views for the current UI which the current user is allowed to access. Note that only view type/bean level access is checked (ViewAccessControl), and view instance specific checks (ViewInstanceAccessControl) are not applied.
      Returns:
      collection of view names, not null
    • getViewName

      public String getViewName(String viewAndParameters)
      Specified by:
      getViewName in interface com.vaadin.navigator.ViewProvider
    • getViewName

      protected String getViewName(String viewAndParameters, List<SpringViewProvider.ViewInfo> views)
    • isViewValidForCurrentUI

      protected boolean isViewValidForCurrentUI(SpringViewProvider.ViewInfo viewInfo)
    • getView

      public com.vaadin.navigator.View getView(String viewName)
      Specified by:
      getView in interface com.vaadin.navigator.ViewProvider
    • getViewFromApplicationContext

      protected com.vaadin.navigator.View getViewFromApplicationContext(SpringViewProvider.ViewInfo viewInfo)
      Fetches a view from the application context. For view scoped views created here, a view scope is set up to be active during the view creation and until navigating away from the view.
      Parameters:
      viewInfo - view metadata
      Returns:
      view instance from the application context, not null
      Throws:
      org.springframework.beans.BeansException - if no suitable bean is found or view scope initialization failed
    • getBeanDefinitionRegistry

      protected org.springframework.beans.factory.support.BeanDefinitionRegistry getBeanDefinitionRegistry()
    • getViewFromApplicationContextAndCheckAccess

      protected com.vaadin.navigator.View getViewFromApplicationContextAndCheckAccess(SpringViewProvider.ViewInfo viewInfo)
    • getAccessDeniedView

      protected com.vaadin.navigator.View getAccessDeniedView()
      Returns an instance of the access denied view from the application context based on setAccessDeniedViewClass(Class).
      Returns:
      access denied view instance from application context or null if no access denied view class is set
    • isAccessGranted

      protected boolean isAccessGranted(SpringViewProvider.ViewInfo view)
    • isAccessGrantedToViewInstance

      protected boolean isAccessGrantedToViewInstance(SpringViewProvider.ViewInfo viewInfo, com.vaadin.navigator.View view)
    • getWebApplicationContext

      protected org.springframework.context.ApplicationContext getWebApplicationContext()
    • getViewNameToBeanNamesMap

      protected Map<String,Set<String>> getViewNameToBeanNamesMap()
      Get the mapping from view names to the collections of corresponding bean names. This method is primarily for internal use, and users should typically override getAllViewsForCurrentUI() or getAllowedViewsForCurrentUI() instead of using this method.
      Returns:
      internal mapping from view names to correspoding bean names