use of com.vaadin.flow.server.VaadinService in project flow by vaadin.
the class VaadinRouteScopeTest method mockServletContext.
private void mockServletContext(UI ui) {
VaadinService service = ui.getSession().getService();
VaadinServletContext context = ((VaadinServletContext) service.getContext());
ServletContext servletContext = context.getContext();
WebApplicationContext appContext = Mockito.mock(WebApplicationContext.class);
Mockito.when(servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE)).thenReturn(appContext);
}
use of com.vaadin.flow.server.VaadinService in project flow by vaadin.
the class RequestUtil method isAnonymousRoute.
/**
* Checks whether the request targets a Flow route that is public, i.e.
* marked as @{@link AnonymousAllowed}.
*
* @param request
* the servlet request
* @return {@code true} if the request is targeting an anonymous route,
* {@code false} otherwise
*/
public boolean isAnonymousRoute(HttpServletRequest request) {
String vaadinMapping = configurationProperties.getUrlMapping();
String requestedPath = HandlerHelper.getRequestPathInsideContext(request);
Optional<String> maybePath = HandlerHelper.getPathIfInsideServlet(vaadinMapping, requestedPath);
if (!maybePath.isPresent()) {
return false;
}
String path = maybePath.get();
if (path.startsWith("/")) {
// Requested path includes a beginning "/" but route mapping is done
// without one
path = path.substring(1);
}
SpringServlet servlet = springServletRegistration.getServlet();
VaadinService service = servlet.getService();
Router router = service.getRouter();
RouteRegistry routeRegistry = router.getRegistry();
NavigationRouteTarget target = routeRegistry.getNavigationRouteTarget(path);
if (target == null) {
return false;
}
RouteTarget routeTarget = target.getRouteTarget();
if (routeTarget == null) {
return false;
}
Class<? extends com.vaadin.flow.component.Component> targetView = routeTarget.getTarget();
if (targetView == null) {
return false;
}
// Check if a not authenticated user can access the view
boolean result = accessAnnotationChecker.hasAccess(targetView, null, role -> false);
if (result) {
getLogger().debug(path + " refers to a public view");
}
return result;
}
use of com.vaadin.flow.server.VaadinService in project flow by vaadin.
the class SpringServletTest method readUniformNameProperty_propertyNameContainsDash_propertyNameIsConvertedToCamelCaseAndReadProperly.
@Test
public void readUniformNameProperty_propertyNameContainsDash_propertyNameIsConvertedToCamelCaseAndReadProperly() throws ServletException {
VaadinService service = SpringInstantiatorTest.getService(context, new Properties());
PushMode pushMode = service.getDeploymentConfiguration().getPushMode();
Assert.assertEquals(PushMode.MANUAL, pushMode);
}
use of com.vaadin.flow.server.VaadinService in project flow by vaadin.
the class SpringServletTest method fallbackChunk_givenInInitParameter_passedOnToDeploymentConfiguration.
// #662
@Test
public void fallbackChunk_givenInInitParameter_passedOnToDeploymentConfiguration() throws ServletException {
FallbackChunk fallbackChunk = new FallbackChunk(Collections.emptyList(), Collections.emptyList());
final Properties properties = new Properties();
properties.put(DeploymentConfigurationFactory.FALLBACK_CHUNK, fallbackChunk);
VaadinService service = SpringInstantiatorTest.getService(context, properties, true);
Assert.assertSame(fallbackChunk, service.getDeploymentConfiguration().getInitParameters().get(DeploymentConfigurationFactory.FALLBACK_CHUNK));
}
use of com.vaadin.flow.server.VaadinService in project flow by vaadin.
the class SpringVaadinServletServiceTest method getInstantiator_javaSPIClass_instantiatorPojoReturned.
@Test
public void getInstantiator_javaSPIClass_instantiatorPojoReturned() throws ServletException {
Properties properties = new Properties(BASE_PROPERTIES);
properties.setProperty(FOO, Boolean.FALSE.toString());
VaadinService service = SpringInstantiatorTest.getService(context, properties);
Instantiator instantiator = service.getInstantiator();
Assert.assertEquals(JavaSPIInstantiator.class, instantiator.getClass());
}
Aggregations