Search in sources :

Example 1 with ViewConfig

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

the class SecurityUtils method invokeVoters.

public static void invokeVoters(EditableAccessDecisionVoterContext accessDecisionVoterContext, ConfigDescriptor<?> viewConfigDescriptor) {
    if (viewConfigDescriptor == null) {
        return;
    }
    List<Secured> securedMetaData = viewConfigDescriptor.getMetaData(Secured.class);
    if (securedMetaData.isEmpty()) {
        return;
    }
    accessDecisionVoterContext.addMetaData(ViewConfig.class.getName(), viewConfigDescriptor.getConfigClass());
    for (Annotation viewMetaData : viewConfigDescriptor.getMetaData()) {
        if (!viewMetaData.annotationType().equals(Secured.class)) {
            accessDecisionVoterContext.addMetaData(viewMetaData.annotationType().getName(), viewMetaData);
        }
    }
    Secured.Descriptor securedDescriptor = viewConfigDescriptor.getExecutableCallbackDescriptor(Secured.class, Secured.Descriptor.class);
    AccessDecisionState voterState = AccessDecisionState.VOTE_IN_PROGRESS;
    try {
        accessDecisionVoterContext.setState(voterState);
        List<Set<SecurityViolation>> violations = securedDescriptor.execute(accessDecisionVoterContext);
        Set<SecurityViolation> allViolations = createViolationResult(violations);
        if (!allViolations.isEmpty()) {
            voterState = AccessDecisionState.VIOLATION_FOUND;
            for (SecurityViolation violation : allViolations) {
                accessDecisionVoterContext.addViolation(violation);
            }
            Class<? extends ViewConfig> errorView = securedMetaData.iterator().next().errorView();
            throw new ErrorViewAwareAccessDeniedException(allViolations, errorView);
        }
    } finally {
        if (AccessDecisionState.VOTE_IN_PROGRESS.equals(voterState)) {
            voterState = AccessDecisionState.NO_VIOLATION_FOUND;
        }
        accessDecisionVoterContext.setState(voterState);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Secured(org.apache.deltaspike.security.api.authorization.Secured) ErrorViewAwareAccessDeniedException(org.apache.deltaspike.security.api.authorization.ErrorViewAwareAccessDeniedException) ViewConfig(org.apache.deltaspike.core.api.config.view.ViewConfig) AccessDecisionState(org.apache.deltaspike.security.api.authorization.AccessDecisionState) SecurityViolation(org.apache.deltaspike.security.api.authorization.SecurityViolation) Annotation(java.lang.annotation.Annotation)

Example 2 with ViewConfig

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

the class ViewConfigTest method testMetaDataTree.

@Test
public void testMetaDataTree() {
    List<Class<? extends ViewConfig>> menuViewConfigClasses = new ArrayList<>();
    menuViewConfigClasses.add(Pages.Section1.Content1.class);
    menuViewConfigClasses.add(Pages.Section1.Content2.class);
    menuViewConfigClasses.add(Pages.Section2.Content1.class);
    menuViewConfigClasses.add(Pages.Section2.Content2.class);
    this.viewConfigExtension.addPageDefinition(Pages.Index.class);
    for (Class<? extends ViewConfig> menuViewConfigClass : menuViewConfigClasses) {
        this.viewConfigExtension.addPageDefinition(menuViewConfigClass);
    }
    ViewConfigNode node = this.viewConfigExtension.findNode(Pages.Index.class);
    Assert.assertNotNull(node.getMetaData());
    Assert.assertEquals(0, node.getMetaData().size());
    for (Class<? extends ViewConfig> menuViewConfigClass : menuViewConfigClasses) {
        node = this.viewConfigExtension.findNode(menuViewConfigClass);
        Assert.assertNotNull(node.getMetaData());
        Assert.assertEquals(1, node.getMetaData().size());
        Assert.assertEquals(TestMenuEntry.class, node.getMetaData().iterator().next().annotationType());
    }
}
Also used : ArrayList(java.util.ArrayList) ViewConfig(org.apache.deltaspike.core.api.config.view.ViewConfig) ViewConfigNode(org.apache.deltaspike.core.spi.config.view.ViewConfigNode) Test(org.junit.Test)

Example 3 with ViewConfig

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

the class ViewConfigExtension method addNode.

private ViewConfigNode addNode(ViewConfigNode parentNode, Class idOfNewNode, Set<Annotation> viewConfigAnnotations) {
    if (parentNode == null) {
        parentNode = this.rootViewConfigNode;
    }
    ViewConfigNode viewConfigNode;
    if (ViewConfigUtils.isFolderConfig(idOfNewNode)) {
        viewConfigNode = new FolderConfigNode(idOfNewNode, parentNode, viewConfigAnnotations);
    } else {
        viewConfigNode = new PageViewConfigNode((Class<? extends ViewConfig>) idOfNewNode, parentNode, viewConfigAnnotations);
    }
    parentNode.getChildren().add(viewConfigNode);
    return viewConfigNode;
}
Also used : ViewConfig(org.apache.deltaspike.core.api.config.view.ViewConfig) ViewConfigNode(org.apache.deltaspike.core.spi.config.view.ViewConfigNode)

Example 4 with ViewConfig

use of org.apache.deltaspike.core.api.config.view.ViewConfig 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 5 with ViewConfig

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

the class ViewConfigTest method testViewConfig.

@Test
public void testViewConfig() {
    List<Class<? extends ViewConfig>> menuViewConfigClasses = new ArrayList<>();
    menuViewConfigClasses.add(Pages.Section1.Content1.class);
    menuViewConfigClasses.add(Pages.Section1.Content2.class);
    menuViewConfigClasses.add(Pages.Section2.Content1.class);
    menuViewConfigClasses.add(Pages.Section2.Content2.class);
    this.viewConfigExtension.addPageDefinition(Pages.Index.class);
    for (Class<? extends ViewConfig> menuViewConfigClass : menuViewConfigClasses) {
        this.viewConfigExtension.addPageDefinition(menuViewConfigClass);
    }
    ViewConfigResolver viewConfigResolver = this.viewConfigResolverProducer.createViewConfigResolver();
    ViewConfigDescriptor viewConfigDescriptor = viewConfigResolver.getViewConfigDescriptor(Pages.Index.class);
    Assert.assertTrue(viewConfigDescriptor.getMetaData(TestMenuEntry.class).isEmpty());
    for (Class<? extends ViewConfig> menuViewConfigClass : menuViewConfigClasses) {
        viewConfigDescriptor = viewConfigResolver.getViewConfigDescriptor(menuViewConfigClass);
        Assert.assertEquals(1, viewConfigDescriptor.getMetaData(TestMenuEntry.class).size());
        Assert.assertTrue(viewConfigDescriptor.getMetaData(TestMenuEntry.class).iterator().next().pos() > 0);
    }
}
Also used : ArrayList(java.util.ArrayList) ViewConfig(org.apache.deltaspike.core.api.config.view.ViewConfig) 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

ViewConfig (org.apache.deltaspike.core.api.config.view.ViewConfig)7 ViewConfigDescriptor (org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor)3 View (org.apache.deltaspike.jsf.api.config.view.View)3 Annotation (java.lang.annotation.Annotation)2 ArrayList (java.util.ArrayList)2 DefaultErrorView (org.apache.deltaspike.core.api.config.view.DefaultErrorView)2 ViewConfigResolver (org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver)2 ViewConfigNode (org.apache.deltaspike.core.spi.config.view.ViewConfigNode)2 Test (org.junit.Test)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ConfigurableNavigationHandler (javax.faces.application.ConfigurableNavigationHandler)1 NavigationCase (javax.faces.application.NavigationCase)1 PreViewConfigNavigateEvent (org.apache.deltaspike.core.api.config.view.navigation.event.PreViewConfigNavigateEvent)1 Folder (org.apache.deltaspike.jsf.api.config.view.Folder)1 AccessDecisionState (org.apache.deltaspike.security.api.authorization.AccessDecisionState)1 ErrorViewAwareAccessDeniedException (org.apache.deltaspike.security.api.authorization.ErrorViewAwareAccessDeniedException)1 Secured (org.apache.deltaspike.security.api.authorization.Secured)1 SecurityViolation (org.apache.deltaspike.security.api.authorization.SecurityViolation)1