【发布时间】:2015-05-14 09:22:49
【问题描述】:
我通过这几个示例创建了我的安全检查:
但不幸的是,如果检查失败,我看不到如何添加 FacesMesagges 异常。
我的文件:
检查操作
@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();
}
我的豆
@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"));
【问题讨论】: