Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SEAMFACES-33 Added a system event listener to enforce @ViewConfig vie…
…w restrictions
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
impl/src/main/java/org/jboss/seam/faces/security/ViewMetaRestrictEnforcer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* To change this template, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
|
||
package org.jboss.seam.faces.security; | ||
|
||
import javax.enterprise.event.Observes; | ||
import javax.faces.event.AbortProcessingException; | ||
import javax.faces.event.PostConstructViewMapEvent; | ||
import javax.inject.Inject; | ||
import org.jboss.logging.Logger; | ||
import org.jboss.seam.faces.transaction.TransactionPhaseListener; | ||
import org.jboss.seam.faces.viewmeta.ViewMetaStore; | ||
import org.jboss.seam.solder.el.Expressions; | ||
|
||
/** | ||
* | ||
* @author bleathem | ||
*/ | ||
public class ViewMetaRestrictEnforcer | ||
{ | ||
private static final Logger log = Logger.getLogger(TransactionPhaseListener.class); | ||
|
||
@Inject | ||
private ViewMetaStore metaStore; | ||
@Inject | ||
private Expressions expressions; | ||
|
||
public void enforce (@Observes PostConstructViewMapEvent event) | ||
{ | ||
log.info("PostConstructViewMapEvent"); | ||
Restrict annotation = metaStore.getDataForCurrentViewId(Restrict.class); | ||
if (annotation == null) | ||
{ | ||
log.info("Annotation is null"); | ||
return; | ||
} | ||
log.info("Evaluating Annotation"); | ||
String el = annotation.value(); | ||
Boolean allowed = expressions.evaluateMethodExpression(el, Boolean.class); | ||
if (allowed) | ||
{ | ||
log.info("Access allowed"); | ||
return; | ||
} | ||
else | ||
{ | ||
log.info("Access denied"); | ||
throw new AbortProcessingException("Access denied"); | ||
} | ||
} | ||
} |