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

  • Home
  • SEARCH
  • 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 8891135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:39:41+00:00 2026-06-14T22:39:41+00:00

I have the following problem: I have create annotation for Security: @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD, ElementType.TYPE})

  • 0

I have the following problem:

I have create annotation for Security:

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
@Inherited
@Documented
public @interface Security {
     Role[] roles();
}

I am now annotating classes and methods with this annotation. In some cases the class is annotated with this annotation and specific method within this class is also annotated with @Security with different roles.

How can create @Before advice that will catch either methods annotated with @Security ot methods within classes annotated with @Security, and also to get the more specific definition in case there are annotation on both the class and method.

I obviously need also the content of the annotation as well (the roles).

Is it possible?

Is it also possible in cases that I have inhertience between classes that all of them have the @Security annotation to get the most specific definition?

Yosi

  • 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-14T22:39:42+00:00Added an answer on June 14, 2026 at 10:39 pm

    This should work (native AspectJ code, but you can translate to @Aspect if you prefer that):

    pointcut secureMethods() : execution(@Security * *(..));
    
    pointcut secureTypes() : execution(* (@Security *).*(..));
    
    Object around(Security security) : secureMethods() && @annotation(security) {
        apply(security);
        return proceed(security);
    }
    
    Object around(Security security) : secureTypes() && !secureMethods() && @target(security) {
        apply(security);
        return proceed(security);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have the following problem: i would like to create a footer. that footer
I have the following problem: Within a stylesheet document I want to create an
i have the following problem: Create a program where a particle will execute a
I have following problem. I want to create a file system based session storage
I have following problem statement. Export a C++ class in the dll (un-managed). Create
I have the following problem: I'm using the wsimport ant task to create a
I have the following problem. I want to write a method with which i
hello i have the following problem: i would like to create a filter for
Im facing following problem I have created mentioned condition, but when I choose y
i'm having a problem with my database. I have the folowing: create table book

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.