English 中文(简体)
使用JSF 2.0中的自定义 Java 批注管理 Bean 方法授权
原标题:Managed Bean method authorization using custom java annotations in JSF 2.0

我想建立一个习惯性的说明, 来装饰限制使用方法电话的方法。

我的注解如下:

@Inherited
@Documented
@Retention(RetentionPolicy.RUNTIME)
public @interface Restrict {
   public enum RoleType {All, ROLE_A, ROLE_B, ROLE_C, ROLE_D}
   String roleLevel();
   RoleType roleType();
}

然后使用以下的注解。注解有两个参数,一个是要求的最低作用Type,另一个是要求的最低作用水平。

@Restrict(roleType = RoleType.ALL, roleLevel="user")
String deleteSomething() {
  // delete intended whatever
  return success;
}

我的意图是,当任何呼叫使用管理豆类方法,该方法与上面描述的“删除某物()”的方法相同,被调用时,该呼叫将被截停,并且该方法的参数将与在用户适当会话值中记录到的数值相比较。如果在用户会话作用值中记录到的数值足够高,则允许使用管理豆类方法,否则用户会被调换方向或显示适当的消息。

我的问题是,有种方法可以“锁定”到什么方法,然后通过反省, 查看该方法是否有@ restrict a注解, 然后进程表示注解。 我尝试过在“ 阶段听者” 类中这样做, 但我不知道如何找出“ 管理豆” 被调用来进行再感染。 我读过一个自定义的ElResolver, 但我不确定这是否对我有什么帮助。 我还试图找到一种方法, 简单地创建一个听众, 不知何时会引用“ 限制” 附加说明的方法 。

Environment Specifics:

Tomcat 6.0.35 (considering upgrading to Tomcat 7.0.27)
JSF version 2.1.7
RichFaces 4.1.0

我只是在寻找一些指导 和一些可供我选择的选择。谢谢任何能帮我的人!

最佳回答

您可以通过实施以下习惯实现这一点: < a href=""http://docs.oracle.com/javaee/6/api/javax/face/event/ActionListener.html" rel=“nofollow noreferr"\ code > ActionListener ,在 faces-config.xml 中注册为全球 ;action-listener>

巧合的是,本周有人问并回答了同样的问题:

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...