Search in sources :

Example 36 with ViewConfigDescriptor

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

the class ViewConfigTest method testCallbackExecution.

@Test
public void testCallbackExecution() {
    this.viewConfigExtension.addPageDefinition(SimplePageConfig.class);
    final SimpleTestAccessDecisionVoter testInstance = new SimpleTestAccessDecisionVoter();
    ViewConfigNode node = this.viewConfigExtension.findNode(SimplePageConfig.class);
    //add it to avoid in-container test for this simple constellation - usually not needed!
    node.getCallbackDescriptors().put(TestSecured.class, new ArrayList<CallbackDescriptor>() {

        {
            add(new TestSecured.Descriptor(new Class[] { SimpleTestAccessDecisionVoter.class }, DefaultCallback.class) {

                @Override
                protected Object getTargetObject(Class targetType) {
                    return testInstance;
                }
            });
        }
    });
    ViewConfigResolver viewConfigResolver = this.viewConfigResolverProducer.createViewConfigResolver();
    ViewConfigDescriptor viewConfigDescriptor = viewConfigResolver.getViewConfigDescriptor(SimplePageConfig.class);
    Assert.assertNotNull(viewConfigDescriptor);
    Assert.assertNotNull(viewConfigDescriptor.getCallbackDescriptor(TestSecured.class));
    List<Set<String>> /*return type of one callback*/
    callbackResult = viewConfigDescriptor.getExecutableCallbackDescriptor(TestSecured.class, TestSecured.Descriptor.class).execute("param1", "param2");
    Assert.assertNotNull(callbackResult);
    Assert.assertEquals(1, callbackResult.size());
    Assert.assertEquals(2, callbackResult.iterator().next().size());
    Iterator<String> resultIterator = callbackResult.iterator().next().iterator();
    //the order in the result isn't guaranteed
    Set<String> expectedValues = new HashSet<String>();
    expectedValues.add("param1");
    expectedValues.add("param2");
    while (resultIterator.hasNext()) {
        String currentValue = resultIterator.next();
        if (!expectedValues.remove(currentValue)) {
            Assert.fail("value '" + currentValue + "' not found in the result");
        }
    }
    Assert.assertTrue(expectedValues.isEmpty());
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) CallbackDescriptor(org.apache.deltaspike.core.api.config.view.metadata.CallbackDescriptor) ViewConfigNode(org.apache.deltaspike.core.spi.config.view.ViewConfigNode) CallbackDescriptor(org.apache.deltaspike.core.api.config.view.metadata.CallbackDescriptor) ViewConfigDescriptor(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor) ViewConfigDescriptor(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor) ViewConfigResolver(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 37 with ViewConfigDescriptor

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

the class ViewConfigTest method testSimpleViewConfigWithCallbacks.

@Test
public void testSimpleViewConfigWithCallbacks() {
    this.viewConfigExtension.addPageDefinition(SimplePageConfig.class);
    ViewConfigResolver viewConfigResolver = this.viewConfigResolverProducer.createViewConfigResolver();
    ViewConfigDescriptor viewConfigDescriptor = viewConfigResolver.getViewConfigDescriptor(SimplePageConfig.class);
    Assert.assertNotNull(viewConfigDescriptor);
    Assert.assertNull(viewConfigDescriptor.getCallbackDescriptor(ViewControllerRef.class, InitView.class));
    Assert.assertNotNull(viewConfigDescriptor.getCallbackDescriptor(ViewControllerRef.class, PreRenderView.class));
    Assert.assertNotNull(viewConfigDescriptor.getCallbackDescriptor(TestSecured.class));
}
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) InitView(org.apache.deltaspike.core.api.config.view.controller.InitView) ViewConfigResolver(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver) Test(org.junit.Test)

Example 38 with ViewConfigDescriptor

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

the class SecurityUtils method tryToHandleSecurityViolation.

private static void tryToHandleSecurityViolation(RuntimeException runtimeException, boolean allowNavigation) {
    ErrorViewAwareAccessDeniedException exception = extractException(runtimeException);
    if (exception == null) {
        throw runtimeException;
    }
    Class<? extends ViewConfig> errorView = null;
    Class<? extends ViewConfig> inlineErrorView = exception.getErrorView();
    if (inlineErrorView != null && !DefaultErrorView.class.getName().equals(inlineErrorView.getName())) {
        errorView = inlineErrorView;
    }
    if (errorView == null) {
        ViewConfigResolver viewConfigResolver = BeanProvider.getContextualReference(ViewConfigResolver.class);
        ViewConfigDescriptor errorPageDescriptor = viewConfigResolver.getDefaultErrorViewConfigDescriptor();
        if (errorPageDescriptor != null) {
            errorView = errorPageDescriptor.getConfigClass();
        }
    }
    if (errorView == null && allowNavigation) {
        throw exception;
    }
    processApplicationSecurityException(exception, errorView, allowNavigation);
}
Also used : DefaultErrorView(org.apache.deltaspike.core.api.config.view.DefaultErrorView) ErrorViewAwareAccessDeniedException(org.apache.deltaspike.security.api.authorization.ErrorViewAwareAccessDeniedException) ViewConfigDescriptor(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor) ViewConfigResolver(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver)

Example 39 with ViewConfigDescriptor

use of org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor 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, PostRenderView.class));
    Assert.assertEquals(PageBean002.class, viewConfigDescriptor.getCallbackDescriptor(ViewControllerRef.class, PostRenderView.class).getCallbackMethods().keySet().iterator().next());
    Assert.assertEquals("postRenderViewCallbackMethod", ((List<Method>) viewConfigDescriptor.getCallbackDescriptor(ViewControllerRef.class, PostRenderView.class).getCallbackMethods().values().iterator().next()).iterator().next().getName());
}
Also used : PostRenderView(org.apache.deltaspike.core.api.config.view.controller.PostRenderView) 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 40 with ViewConfigDescriptor

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

the class ViewConfigPathValidator method validateViewConfigPaths.

//allows to test and re-use it in a custom listener
// (if a custom listener is needed for supporting custom extensions or
// this listener is deactivated e.g. to change the order)
protected void validateViewConfigPaths(ServletContextEvent sce, ViewConfigResolver viewConfigResolver, List<String> supportedExtensions) {
    for (ConfigDescriptor configDescriptor : viewConfigResolver.getConfigDescriptors()) {
        try {
            if (configDescriptor instanceof ViewConfigDescriptor) {
                //currently other extensions aren't supported
                String viewId = ((ViewConfigDescriptor) configDescriptor).getViewId();
                String extension = viewId.substring(viewId.lastIndexOf('.') + 1);
                if (!supportedExtensions.contains(extension)) {
                    continue;
                }
            }
            if (!isValidPath(sce, configDescriptor)) {
                if (configDescriptor instanceof DefaultFolderConfigDescriptor && !configDescriptor.getConfigClass().isAnnotationPresent(Folder.class)) {
                    LOGGER.fine(configDescriptor.getConfigClass().getName() + " looks like a marker interface" + " only used for providing meta-data, because the path " + configDescriptor.getPath() + " doesn't exist and the config-class isn't annotated with " + Folder.class.getName());
                    continue;
                }
                throw new IllegalStateException("path '" + configDescriptor.getPath() + "' is missing, but mapped by: " + configDescriptor.getConfigClass().getName());
            }
        } catch (Exception e) {
            printException(e);
            throw ExceptionUtils.throwAsRuntimeException(e);
        }
    }
}
Also used : ConfigDescriptor(org.apache.deltaspike.core.api.config.view.metadata.ConfigDescriptor) ViewConfigDescriptor(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor) ViewConfigDescriptor(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor) MalformedURLException(java.net.MalformedURLException)

Aggregations

ViewConfigDescriptor (org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor)44 ViewConfigResolver (org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver)37 Test (org.junit.Test)31 View (org.apache.deltaspike.jsf.api.config.view.View)5 Method (java.lang.reflect.Method)3 UIViewRoot (javax.faces.component.UIViewRoot)3 DefaultErrorView (org.apache.deltaspike.core.api.config.view.DefaultErrorView)3 ViewControllerRef (org.apache.deltaspike.core.api.config.view.controller.ViewControllerRef)3 ConfigDescriptor (org.apache.deltaspike.core.api.config.view.metadata.ConfigDescriptor)3 HashSet (java.util.HashSet)2 Set (java.util.Set)2 ConfigurableNavigationHandler (javax.faces.application.ConfigurableNavigationHandler)2 NavigationCase (javax.faces.application.NavigationCase)2 ViewConfig (org.apache.deltaspike.core.api.config.view.ViewConfig)2 PreRenderView (org.apache.deltaspike.core.api.config.view.controller.PreRenderView)2 PreViewConfigNavigateEvent (org.apache.deltaspike.core.api.config.view.navigation.event.PreViewConfigNavigateEvent)2 ErrorViewAwareAccessDeniedException (org.apache.deltaspike.security.api.authorization.ErrorViewAwareAccessDeniedException)2 MalformedURLException (java.net.MalformedURLException)1 HashMap (java.util.HashMap)1 List (java.util.List)1