Search in sources :

Example 11 with ViewConfigDescriptor

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

the class DeltaSpikePhaseListener method processInitView.

private void processInitView(String viewId) {
    try {
        WindowMetaData windowMetaData = BeanProvider.getContextualReference(WindowMetaData.class);
        //view already initialized in this or any prev. request
        if (viewId.equals(windowMetaData.getInitializedViewId())) {
            return;
        }
        //override the view-id if we have a new view
        windowMetaData.setInitializedViewId(viewId);
        ViewConfigDescriptor viewDefinitionEntry = this.viewConfigResolver.getViewConfigDescriptor(viewId);
        if (viewDefinitionEntry == null) {
            return;
        }
        ViewControllerUtils.executeViewControllerCallback(viewDefinitionEntry, InitView.class);
    } catch (ContextNotActiveException e) {
    //TODO discuss how we handle it
    }
}
Also used : ContextNotActiveException(javax.enterprise.context.ContextNotActiveException) ViewConfigDescriptor(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor)

Example 12 with ViewConfigDescriptor

use of org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor 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 13 with ViewConfigDescriptor

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

the class ViewControllerActionListener method processAction.

@Override
public void processAction(ActionEvent actionEvent) {
    if (this.activated) {
        ViewConfigDescriptor viewConfigDescriptor = BeanProvider.getContextualReference(ViewConfigResolver.class).getViewConfigDescriptor(FacesContext.getCurrentInstance().getViewRoot().getViewId());
        ViewControllerUtils.executeViewControllerCallback(viewConfigDescriptor, PreViewAction.class);
    }
    this.wrapped.processAction(actionEvent);
}
Also used : ViewConfigDescriptor(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor) ViewConfigResolver(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver)

Example 14 with ViewConfigDescriptor

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

the class DeltaSpikeNavigationHandler method getNavigationCase.

@Override
public NavigationCase getNavigationCase(FacesContext context, String action, String outcome) {
    if (this.wrapped instanceof ConfigurableNavigationHandler) {
        if (!this.activated) {
            return ((ConfigurableNavigationHandler) this.wrapped).getNavigationCase(context, action, outcome);
        }
        if (action == null && outcome != null && outcome.contains(".") && outcome.startsWith("class ") && !otherOutcomes.contains(outcome)) {
            String originalOutcome = outcome;
            NavigationCase navigationCase = this.viewConfigBasedNavigationCaseCache.get(originalOutcome);
            if (navigationCase != null) {
                return navigationCase;
            }
            outcome = outcome.substring(6);
            ViewConfigDescriptor entry = null;
            if (DefaultErrorView.class.getName().equals(originalOutcome)) {
                ViewConfigResolver viewConfigResolver = JsfUtils.getViewConfigResolver();
                entry = viewConfigResolver.getDefaultErrorViewConfigDescriptor();
            }
            if (entry == null) {
                Object loadedClass = ClassUtils.tryToLoadClassForName(outcome);
                if (loadedClass == null) {
                    this.otherOutcomes.add(originalOutcome);
                } else if (ViewConfig.class.isAssignableFrom((Class) loadedClass)) {
                    entry = JsfUtils.getViewConfigResolver().getViewConfigDescriptor((Class<? extends ViewConfig>) loadedClass);
                }
            }
            if (entry != null) {
                View.NavigationMode navigationMode = entry.getMetaData(View.class).iterator().next().navigation();
                navigationCase = new NavigationCase("*", null, null, null, entry.getViewId(), null, View.NavigationMode.REDIRECT.equals(navigationMode), false);
                this.viewConfigBasedNavigationCaseCache.put(originalOutcome, navigationCase);
                return navigationCase;
            }
        }
        return ((ConfigurableNavigationHandler) this.wrapped).getNavigationCase(context, action, outcome);
    }
    return null;
}
Also used : DefaultErrorView(org.apache.deltaspike.core.api.config.view.DefaultErrorView) NavigationCase(javax.faces.application.NavigationCase) ViewConfig(org.apache.deltaspike.core.api.config.view.ViewConfig) ViewConfigDescriptor(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor) View(org.apache.deltaspike.jsf.api.config.view.View) DefaultErrorView(org.apache.deltaspike.core.api.config.view.DefaultErrorView) ConfigurableNavigationHandler(javax.faces.application.ConfigurableNavigationHandler) ViewConfigResolver(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver)

Example 15 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, 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)

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