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);
}
}
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());
}
}
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;
}
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;
}
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);
}
}
Aggregations