Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7985943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:42:15+00:00 2026-06-04T11:42:15+00:00

I would like to create a custom annotation to decorate methods which would restrict

  • 0

I would like to create a custom annotation to decorate methods which would restrict access to method calls.

My annotation is defined below:

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

Then using the annotation like the following. The annotation receives two parameters, one being the required minimum roleType, the other the required minimum role level.

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

My intent is, when any call to a Managed Bean method that is decorated with this annotation, as in the method described above “deleteSomething()”, occurs, this call would be intercepted and the parameters set on the method compared to the logged in users appropriate session values. If the logged in users session role values are high enough, the Managed Bean’s method will be allowed to be invoked, otherwise the user is either redirected or an appropriate message is displayed.

My question is this, is there a way I can “hook” into what methods are bing called to then, through reflection, see if there is a @Restrict annotation on the method and then process said annotation. I’ve tried doing this in a PhaseListener class, but I’m not sure how to find out what Managed Bean is being called to perform refection on. I’ve read about a custome ElResolver, but I’m not sure if this is anything that will help me. I’ve also tried to find a way to simply create a listener that somehow knows when a method that is annotated with @Restrict has been invoked.

Environment Specifics:

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

I’m just looking for some guidance and some options available to me. Thank you to anyone who can help me with this!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T11:42:16+00:00Added an answer on June 4, 2026 at 11:42 am

    You can achieve this by implementing a custom ActionListener which is been registered as a global <action-listener> in the faces-config.xml.

    By coincidence, someone else asked and answered the same question this week: Custom Annotation JSF. Note that JAAS is not required for the particular purpose, just grab the User from the session by FacesContext the usual way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to create a custom data type which basically behaves like an
I want to create a custom annotation (using Java) which would accept other annotations
In my symfony application I would like to create custom php class. And access
I would like to create my own custom annotation. My framework is stand alone
I would like to create a custom document library where I use the standard
I would like to create a custom control in my Android App. It will
I have authored some custom classes that I would like to create using XAML:
i would like create a array of structure which have a dynamic array :
I would like to create a UIBarButtonItem on my iPhone application which has two
I would like create a custom DataRow that will have -let's say- a propery

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.