Search in sources :

Example 11 with ViewConfigResolver

use of org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver in project deltaspike by apache.

the class ViewConfigPathTest method testNamesWizard14.

@Test(expected = IllegalStateException.class)
public void testNamesWizard14() {
    this.viewConfigExtension.addPageDefinition(Pages.Wizard14.Step1.class);
    ViewConfigResolver viewConfigResolver = this.viewConfigResolverProducer.createViewConfigResolver();
    viewConfigResolver.getViewConfigDescriptor(Pages.Wizard14.Step1.class);
}
Also used : ViewConfigResolver(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver) Test(org.junit.Test)

Example 12 with ViewConfigResolver

use of org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver in project deltaspike by apache.

the class ViewConfigTest method testSimpleViewConfigWithViewControllerCallback.

@Test
public void testSimpleViewConfigWithViewControllerCallback() {
    this.viewConfigExtension.addPageDefinition(SimplePageConfig.class);
    ViewConfigResolver viewConfigResolver = this.viewConfigResolverProducer.createViewConfigResolver();
    ViewConfigDescriptor viewConfigDescriptor = viewConfigResolver.getViewConfigDescriptor(SimplePageConfig.class);
    Assert.assertNotNull(viewConfigDescriptor);
    Assert.assertNotNull(viewConfigDescriptor.getCallbackDescriptor(ViewControllerRef.class, PreRenderView.class));
    Assert.assertEquals(PageBean001.class, viewConfigDescriptor.getCallbackDescriptor(ViewControllerRef.class, PreRenderView.class).getCallbackMethods().keySet().iterator().next());
    Assert.assertEquals("preRenderViewCallbackMethod", ((List<Method>) viewConfigDescriptor.getCallbackDescriptor(ViewControllerRef.class, PreRenderView.class).getCallbackMethods().values().iterator().next()).iterator().next().getName());
}
Also used : PreRenderView(org.apache.deltaspike.core.api.config.view.controller.PreRenderView) ViewControllerRef(org.apache.deltaspike.core.api.config.view.controller.ViewControllerRef) ViewConfigDescriptor(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor) Method(java.lang.reflect.Method) ViewConfigResolver(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver) Test(org.junit.Test)

Example 13 with ViewConfigResolver

use of org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver in project deltaspike by apache.

the class ViewConfigTest method testViewConfigWithRandomOrder.

@Test
public void testViewConfigWithRandomOrder() {
    this.viewConfigExtension.addPageDefinition(Pages.Index.class);
    // simulates random processing-order
    this.viewConfigExtension.addPageDefinition(Pages.class);
    ViewConfigResolver viewConfigResolver = this.viewConfigResolverProducer.createViewConfigResolver();
    ViewConfigDescriptor viewConfigDescriptor = viewConfigResolver.getViewConfigDescriptor(Pages.Index.class);
    Assert.assertEquals("/pages/index.xhtml", viewConfigDescriptor.getViewId());
    Assert.assertEquals(View.ViewParameterMode.EXCLUDE, viewConfigDescriptor.getMetaData(View.class).iterator().next().viewParams());
}
Also used : ViewConfigDescriptor(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor) ViewConfigResolver(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver) Test(org.junit.Test)

Example 14 with ViewConfigResolver

use of org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver in project deltaspike by apache.

the class SecurityAwareViewHandler method createView.

@Override
public UIViewRoot createView(FacesContext context, String viewId) {
    UIViewRoot result = this.wrapped.createView(context, viewId);
    if (!this.activated) {
        return result;
    }
    if (this.securityModuleActivated == null) {
        lazyInit();
    }
    if (!this.securityModuleActivated) {
        return result;
    }
    UIViewRoot originalViewRoot = context.getViewRoot();
    Map<String, Object> viewMap = null;
    if (originalViewRoot != null) {
        Map<String, Object> originalViewMap = originalViewRoot.getViewMap(false);
        if (originalViewMap != null && !originalViewMap.isEmpty()) {
            viewMap = new HashMap<String, Object>();
            viewMap.putAll(originalViewMap);
        }
    }
    // workaround for PreDestroyViewMapEvent which would be caused by the security check
    deactivatePreDestroyViewMapEvent(context);
    // we have to use it as current view if an AccessDecisionVoter uses the JSF API to check access to the view-id
    context.setViewRoot(result);
    try {
        ViewRootAccessHandler viewRootAccessHandler = BeanProvider.getContextualReference(ViewRootAccessHandler.class);
        viewRootAccessHandler.checkAccessTo(result);
    } catch (ErrorViewAwareAccessDeniedException accessDeniedException) {
        ViewConfigResolver viewConfigResolver = BeanProvider.getContextualReference(ViewConfigResolver.class);
        ViewConfigDescriptor errorViewDescriptor = viewConfigResolver.getViewConfigDescriptor(accessDeniedException.getErrorView());
        try {
            if (errorViewDescriptor != null && View.NavigationMode.REDIRECT == errorViewDescriptor.getMetaData(View.class).iterator().next().navigation() && /*always available*/
            BeanProvider.getContextualReference(JsfModuleConfig.class).isAlwaysUseNavigationHandlerOnSecurityViolation()) {
                SecurityUtils.tryToHandleSecurityViolation(accessDeniedException);
            } else {
                SecurityUtils.handleSecurityViolationWithoutNavigation(accessDeniedException);
            }
        } finally {
            broadcastAccessDeniedException(accessDeniedException);
        }
        if (errorViewDescriptor != null) {
            return this.wrapped.createView(context, errorViewDescriptor.getViewId());
        } else {
            // the previous page (including the error message)
            if (!context.isPostback() && context.getViewRoot() != null) {
                context.getViewRoot().setViewId(null);
            }
        }
        // security exception without error-view
        throw accessDeniedException;
    } finally {
        activatePreDestroyViewMapEvent(context);
        if (originalViewRoot != null) {
            context.setViewRoot(originalViewRoot);
            if (viewMap != null) {
                originalViewRoot.getViewMap().putAll(viewMap);
            }
        }
    }
    return result;
}
Also used : JsfModuleConfig(org.apache.deltaspike.jsf.api.config.JsfModuleConfig) ErrorViewAwareAccessDeniedException(org.apache.deltaspike.security.api.authorization.ErrorViewAwareAccessDeniedException) ViewConfigDescriptor(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor) UIViewRoot(javax.faces.component.UIViewRoot) View(org.apache.deltaspike.jsf.api.config.view.View) ViewConfigResolver(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver)

Example 15 with ViewConfigResolver

use of org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver in project deltaspike by apache.

the class ViewConfigTest method testSimpleViewConfigWithCustomMetaData.

@Test
public void testSimpleViewConfigWithCustomMetaData() {
    this.viewConfigExtension.addPageDefinition(SimplePageConfig.class);
    ViewConfigResolver viewConfigResolver = this.viewConfigResolverProducer.createViewConfigResolver();
    ViewConfigDescriptor viewConfigDescriptor = viewConfigResolver.getViewConfigDescriptor(SimplePageConfig.class);
    Assert.assertNotNull(viewConfigDescriptor);
    Assert.assertNotNull(viewConfigDescriptor.getMetaData());
    Assert.assertEquals(2, viewConfigDescriptor.getMetaData().size());
    Assert.assertEquals(1, viewConfigDescriptor.getMetaData(View.class).size());
    Assert.assertEquals(1, viewConfigDescriptor.getMetaData(TestEntryPoint.class).size());
}
Also used : ViewConfigDescriptor(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor) ViewConfigResolver(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver) Test(org.junit.Test)

Aggregations

ViewConfigResolver (org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver)44 Test (org.junit.Test)37 ViewConfigDescriptor (org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor)36 ArrayList (java.util.ArrayList)5 Method (java.lang.reflect.Method)3 ViewControllerRef (org.apache.deltaspike.core.api.config.view.controller.ViewControllerRef)3 View (org.apache.deltaspike.jsf.api.config.view.View)3 DefaultErrorView (org.apache.deltaspike.core.api.config.view.DefaultErrorView)2 ViewConfig (org.apache.deltaspike.core.api.config.view.ViewConfig)2 PreRenderView (org.apache.deltaspike.core.api.config.view.controller.PreRenderView)2 JsfModuleConfig (org.apache.deltaspike.jsf.api.config.JsfModuleConfig)2 ErrorViewAwareAccessDeniedException (org.apache.deltaspike.security.api.authorization.ErrorViewAwareAccessDeniedException)2 MalformedURLException (java.net.MalformedURLException)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 Produces (javax.enterprise.inject.Produces)1 ConfigurableNavigationHandler (javax.faces.application.ConfigurableNavigationHandler)1 NavigationCase (javax.faces.application.NavigationCase)1 ProjectStage (javax.faces.application.ProjectStage)1