0
我这对情侣的例子创建了我的身份确认:如何将FacesMessage添加到CDI安全拦截器?
但不幸的是,我不能看到如何添加FacesMesagges例外情况的检查失败。
我的文件:
CheckAction
@Inherited
@InterceptorBinding
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.TYPE })
public @interface CheckAction {
@Nonbinding public ESysObject object() default ESysObject.NONE;
@Nonbinding public EAction action() default EAction.NONE;
}
CheckActionInterceptor
@Interceptor
@CheckAction
public class CheckActionInterceptor implements Serializable {
private static final long serialVersionUID = 1L;
@AroundInvoke
public Object checkPermissions(InvocationContext context) throws Exception {
final CheckAction annotation = context.getMethod().getAnnotation(CheckAction.class);
if (!isActionAllowed(annotation.object(), annotation.action())) {
throw new PermissionException("Sorry you don't have needed permissions");
}
return context.proceed();
}
为myBean
@Named
@ViewScoped
@Logged
public class PageController implements Serializable {
private static final long serialVersionUID = 1L;
@CheckAction(object = ESysObject.Dictionary, action = EAction.WRITE)
public String save() {
switch (action) {
case "create":
case "edit":
service.saveOrUpdate(cursor);
break;
}
return "page?faces-redirect=true";
}
它的所有工作。
但是如何处理PermissionException对不对?如何FacesContext.getCurrentInstance().addMessage("security check", new FacesMessage("Permission Error", "you don't have needed permissions"));