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 6873057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:00:34+00:00 2026-05-27T04:00:34+00:00

I want to see if it is possible to use annotations to evaulate if

  • 0

I want to see if it is possible to use annotations to evaulate if a user is logged in or not.

Example

@AuthRequired
public String myProtectedArea() {
  return View("view/protectedArea"); // If user is NOT authenticated, return "view/login"
}
  • 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-05-27T04:00:35+00:00Added an answer on May 27, 2026 at 4:00 am

    As per your edit:
    Check this SO Post:

    Scanning Java annotations at runtime

    I’d still recommend using Spring Security for this, it’s tested and secure:

    @PreAuthorize("hasRole('ROLE_USER')")
    public String myProtectedArea() {
      return View("view/protectedArea"); 
    }
    

    The annotation will check if the user is logged in and has the required credentials.

    Another way with Spring Security is to intercept the URL pattern by setting this inside a spring.security-settings.xml:

        <intercept-url pattern="/view/protectedArea/*" access="hasRole('ROLE_USER')" />
    

    I’d recommend using both to maximize security.

    In the security settings file you can then tell spring security where to redirect the user to login. If the user is already logged in, you can redirect him to yet another page:

    <form-login login-page="/view/login.xhtml" default-target-url="/view/protectedArea/home.xhtml"
                authentication-failure-url="/view/login.xhtml" />
    

    It’s a tested framework and thus secure and versatile. However it requires a bit of setting up if you want more than the standard behaviour.

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

Sidebar

Related Questions

I'm not sure if this is possible but I want to see objects created
Possible Duplicate: Standard Android menu icons, for example refresh I want to use some
Possible Duplicate: Use grep to report back only line numbers I only want to
Coming from mercurial, I use branches to organize features. Naturally, I want to see
I want to see the real time use of Volatile keyword in c#. but
I want to know if it is possible to use the same index file
For example, I am using Google Maps API and I want to see all
I want see the source code of System.Web.Routing.RouteValueDictionary class. But Reflector can't disassemble it
I want to see if a time I read from a db overlaps with
I want to see a list of all changes the next push would do.

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.