/
ViewMetaRestrictEnforcer.java
53 lines (48 loc) · 1.42 KB
/
ViewMetaRestrictEnforcer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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");
}
}
}