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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:37:53+00:00 2026-05-27T22:37:53+00:00

I have implemented spring security in controller method. Below is my spring security.xml –>

  • 0

I have implemented spring security in controller method.

Below is my spring security.xml

–>

<!-- URL pattern based security -->
<security:http auto-config="false" entry-point-ref="authenticationEntryPoint"
    use-expressions="true">
    <custom-filter ref="authenticationFilter" position="FORM_LOGIN_FILTER" />
    <security:intercept-url access="hasAnyRole('ROLE_ADMIN','ROLE_USER')" pattern="/common/admin/**" />
    <security:intercept-url pattern="/common/accounting/**" access="hasRole('ROLE_USER')" />
    <security:logout logout-url="/j_spring_security_logout" invalidate-session="true" logout-success-url="/login"/>

</security:http>

Below is my controller

@Secured({"ROLE_ADMIN"})
@RequestMapping(value = "/common/admin/addAdmin", method = RequestMethod.GET)
public String add(ModelMap map) {
    map.addAttribute(new Administrator());
    return "/common/admin/addAdmin";
}

@Secured({"ROLE_ADMIN"})
@RequestMapping(value = "/common/admin/addAdmin", method = RequestMethod.POST)
public String processadd(
        @ModelAttribute("administrator") Administrator administrator) {
    this.administratorManager.addAdmin(administrator);
    return "/common/admin/success";
}

I allow the url /common/admin/** for both admin and user role. But i do some restriction in the admin controller. when user is go in to /common/admin/* as a user role, he can but he can also go in to method that is only for admin role only.

How can I solve it?

Thanks!

  • 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-27T22:37:54+00:00Added an answer on May 27, 2026 at 10:37 pm

    You already have added the @Secured annotation.

    But you need to enable it:

    <!-- secured-annotations = (@Secured("ROLE_ADMIN")) -->
    <!-- jsr250-annotations = (@RunAs @RolesAllowed @PermitAll @DenyAll @DeclareRoles) -->
    <!-- pre-post-annotations = @PreAuthorized("hasAuthority('ROLE_ADMIN')") -->
    <global-method-security
        secured-annotations="enabled" 
        jsr250-annotations="disabled"
        pre-post-annotations="disabled">        
    </global-method-security>
    

    @Secured can take a single or several roles.

    • @Secured("ROLE_USER")
    • @Secured({"ROLE_USER", "ROLE_ADMIN"}) //grand access if the user has one of this roles

    BWT: From Spring Security 3 Book (http://www.springsecuritybook.com/):

    The @Secured annotation is functionallz and syntactiallz the same as @RollesAllowed … As @Secured functions the same as the JSR standard @RollesAllowed there’s not reallz a compelling reason to use it (@Secured) in in new code…

    (do not forgett to enable it jsr250-annotations="enabled")

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

Sidebar

Related Questions

I have implemented spring-security in my application, my spring-security.xml has following form-login tag. <form-login
I'm working on Spring based application with Spring Security. I have users with different
I have implemented spring security's remember me feature in our app, the way i
I have the following situation: my application's authorization mechanism is implemented using Spring security.
I have implemented Spring Security in my application. I have used default implementation, i.e.,
I have strange issue with logging in and out. I've implemented container-based security. I
I have this Spring config: <bean id=boo class=com.x.TheClass/> The class TheClass implements TheInterface .
I have implemented a python webserver. Each http request spawns a new thread. I
I have a custom-authentication-provider defined in my Spring Security configuration. This class implements AuthenticationProvider,
We're developing an app (using Grails Spring Security (formerly Acegi)) in which we'll have

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.