Search in sources :

Example 1 with View

use of org.apache.deltaspike.jsf.api.config.view.View 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 2 with View

use of org.apache.deltaspike.jsf.api.config.view.View in project deltaspike by apache.

the class DefaultConfigNodeConverter method convert.

@Override
public ConfigDescriptor convert(ViewConfigNode node) {
    List<Annotation> mergedMetaData = mergeMetaData(node.getMetaData(), node.getInheritedMetaData());
    //e.g. replace default placeholders needed for the merge with real default values
    mergedMetaData = preProcessMetaData(mergedMetaData, node);
    Class sourceClass = node.getSource();
    if (ViewConfigUtils.isFolderConfig(sourceClass)) {
        Folder folderAnnotation = findMetaDataByType(mergedMetaData, Folder.class);
        return new DefaultFolderConfigDescriptor(folderAnnotation.name(), node.getSource(), mergedMetaData, node.getCallbackDescriptors());
    } else if (ViewConfig.class.isAssignableFrom(sourceClass)) {
        View viewAnnotation = findMetaDataByType(mergedMetaData, View.class);
        String viewId = viewAnnotation.basePath() + viewAnnotation.name() + "." + viewAnnotation.extension();
        return new DefaultViewPathConfigDescriptor(viewId, node.getSource(), filterInheritedFolderMetaData(mergedMetaData), node.getCallbackDescriptors());
    } else {
        throw new IllegalStateException(node.getSource() + " isn't a valid view-config");
    }
}
Also used : ViewConfig(org.apache.deltaspike.core.api.config.view.ViewConfig) Folder(org.apache.deltaspike.jsf.api.config.view.Folder) View(org.apache.deltaspike.jsf.api.config.view.View) Annotation(java.lang.annotation.Annotation)

Example 3 with View

use of org.apache.deltaspike.jsf.api.config.view.View in project deltaspike by apache.

the class NavigationCaseMapWrapper method createViewConfigBasedNavigationCases.

private Map<String, Set<NavigationCase>> createViewConfigBasedNavigationCases(boolean allowParameters) {
    Map<String, Set<NavigationCase>> result;
    if (this.wrapped instanceof ConfigurableNavigationHandler) {
        result = new DelegatingMap((ConfigurableNavigationHandler) this.wrapped);
    } else {
        LOG.warning("the wrapped navigation-handler doesn't extend " + ConfigurableNavigationHandler.class.getName() + ". therefore std. navigation-rules might not work correctly with mojarra");
        result = new HashMap<String, Set<NavigationCase>>();
    }
    Collection<ViewConfigDescriptor> viewConfigDescriptors = BeanProvider.getContextualReference(ViewConfigResolver.class).getViewConfigDescriptors();
    if (!viewConfigDescriptors.isEmpty()) {
        Set<NavigationCase> navigationCase = new HashSet<NavigationCase>();
        Map<String, List<String>> parameters = null;
        if (allowParameters) {
            parameters = resolveParameters();
        }
        boolean includeParameters;
        for (ViewConfigDescriptor entry : viewConfigDescriptors) {
            View viewMetaData = entry.getMetaData(View.class).iterator().next();
            includeParameters = View.ViewParameterMode.INCLUDE.equals(viewMetaData.viewParams());
            navigationCase.add(new NavigationCase("*", null, null, null, entry.getViewId(), includeParameters ? parameters : null, View.NavigationMode.REDIRECT.equals(viewMetaData.navigation()), includeParameters));
            result.put(entry.getViewId(), navigationCase);
        }
    }
    return result;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) View(org.apache.deltaspike.jsf.api.config.view.View) ConfigurableNavigationHandler(javax.faces.application.ConfigurableNavigationHandler) NavigationCase(javax.faces.application.NavigationCase) List(java.util.List) ViewConfigDescriptor(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor) ViewConfigResolver(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver) HashSet(java.util.HashSet)

Example 4 with View

use of org.apache.deltaspike.jsf.api.config.view.View in project deltaspike by apache.

the class ViewConfigAwareNavigationHandler method convertEntryToOutcome.

private String convertEntryToOutcome(ExternalContext externalContext, ViewConfigDescriptor entry) {
    View viewMetaData = entry.getMetaData(View.class).iterator().next();
    boolean performRedirect = View.NavigationMode.REDIRECT.equals(viewMetaData.navigation());
    boolean includeViewParameters = View.ViewParameterMode.INCLUDE.equals(viewMetaData.viewParams());
    StringBuilder result = new StringBuilder(entry.getViewId());
    if (performRedirect) {
        result.append("?faces-redirect=true");
    }
    if (includeViewParameters) {
        if (performRedirect) {
            result.append("&");
        } else {
            result.append("?");
        }
        result.append("includeViewParams=true");
        return JsfUtils.addPageParameters(externalContext, result.toString(), false);
    }
    return result.toString();
}
Also used : View(org.apache.deltaspike.jsf.api.config.view.View) DefaultErrorView(org.apache.deltaspike.core.api.config.view.DefaultErrorView)

Example 5 with View

use of org.apache.deltaspike.jsf.api.config.view.View in project deltaspike by apache.

the class ViewConfigAwareNavigationHandler method handleNavigation.

//Security checks will be performed by the view-handler provided by ds
@Override
public void handleNavigation(FacesContext facesContext, String fromAction, String outcome) {
    lazyInit();
    if (outcome != null && outcome.contains(".")) {
        String originalOutcome = outcome;
        if (!this.otherOutcomes.contains(outcome)) {
            //it isn't possible to support interfaces due to cdi restrictions
            if (outcome.startsWith("class ")) {
                outcome = outcome.substring(6);
            }
            ViewConfigDescriptor entry = this.viewConfigs.get(outcome);
            if (entry == null) {
                if (DefaultErrorView.class.getName().equals(originalOutcome)) {
                    entry = this.viewConfigResolver.getDefaultErrorViewConfigDescriptor();
                }
            }
            boolean allowCaching = true;
            if (entry == null) {
                Class<?> loadedClass = ClassUtils.tryToLoadClassForName(outcome);
                if (loadedClass == null) {
                    this.otherOutcomes.add(originalOutcome);
                } else if (ViewConfig.class.isAssignableFrom(loadedClass)) {
                    //a sub-classed page-config for annotating it with different view params
                    if (loadedClass.getAnnotation(View.class) == null && loadedClass.getSuperclass().getAnnotation(View.class) != null) {
                        allowCaching = false;
                        addConfiguredViewParameters(loadedClass);
                        loadedClass = loadedClass.getSuperclass();
                    }
                    entry = this.viewConfigResolver.getViewConfigDescriptor((Class<? extends ViewConfig>) loadedClass);
                }
            }
            if (entry != null) {
                //in case of false it has been added already
                if (allowCaching) {
                    this.viewConfigs.put(outcome, entry);
                    addConfiguredViewParameters(entry.getConfigClass());
                }
                String oldViewId = null;
                if (facesContext.getViewRoot() != null) {
                    oldViewId = facesContext.getViewRoot().getViewId();
                }
                PreViewConfigNavigateEvent navigateEvent = firePreViewConfigNavigateEvent(oldViewId, entry);
                entry = tryToUpdateEntry(entry, navigateEvent);
                if (entry != null) {
                    outcome = convertEntryToOutcome(facesContext.getExternalContext(), entry);
                }
            }
        }
    }
    this.navigationHandler.handleNavigation(facesContext, fromAction, outcome);
}
Also used : PreViewConfigNavigateEvent(org.apache.deltaspike.core.api.config.view.navigation.event.PreViewConfigNavigateEvent) DefaultErrorView(org.apache.deltaspike.core.api.config.view.DefaultErrorView) 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)

Aggregations

View (org.apache.deltaspike.jsf.api.config.view.View)6 ViewConfigDescriptor (org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor)4 ViewConfigResolver (org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver)3 DefaultErrorView (org.apache.deltaspike.core.api.config.view.DefaultErrorView)2 ViewConfig (org.apache.deltaspike.core.api.config.view.ViewConfig)2 Annotation (java.lang.annotation.Annotation)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 ConfigurableNavigationHandler (javax.faces.application.ConfigurableNavigationHandler)1 NavigationCase (javax.faces.application.NavigationCase)1 UIViewRoot (javax.faces.component.UIViewRoot)1 ConfigDescriptor (org.apache.deltaspike.core.api.config.view.metadata.ConfigDescriptor)1 PreViewConfigNavigateEvent (org.apache.deltaspike.core.api.config.view.navigation.event.PreViewConfigNavigateEvent)1 JsfModuleConfig (org.apache.deltaspike.jsf.api.config.JsfModuleConfig)1 Folder (org.apache.deltaspike.jsf.api.config.view.Folder)1 ErrorViewAwareAccessDeniedException (org.apache.deltaspike.security.api.authorization.ErrorViewAwareAccessDeniedException)1 Test (org.junit.Test)1