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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:22:52+00:00 2026-05-24T05:22:52+00:00

In Spring Security we use the intercept-url tag to define the access for URLs

  • 0

In Spring Security we use the intercept-url tag to define the access for URLs as below:

<intercept-url pattern="/**" access="ROLE_ADMIN" />
<intercept-url pattern="/student" access="ROLE_STUDENT" />

This is hard coded in applicationContext-security.xml. I want to read the access values from a database table instead. I have defined my own UserDetailsService and I read the roles for the logged in user from the database. How do I assign these roles to the URL patterns during runtime?

  • 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-24T05:22:53+00:00Added an answer on May 24, 2026 at 5:22 am

    The FilterInvocationSecurityMetadataSourceParser class in Spring-security (try Ctrl/Cmd+Shift+T in STS with the source code) parses the intercept-url tags and creates instances of ExpressionBasedFilterInvocationSecurityMetadataSource, that extends DefaultFilterInvocationSecurityMetadataSource that implements FilterInvocationSecurityMetadataSource that extends SecurityMetadataSource.

    What I did is to create a custom class that implements FilterInvocationSecurityMetadataSource, OptionsFromDataBaseFilterInvocationSecurityMetadataSource. I used DefaultFilterInvocationSecurityMetadataSource as base to use urlMatcher, to implement the support() method and something like that.

    Then you must to implement these methods:

    • Collection getAttributes(Object object), where you can access to database, searching for the ‘object’ being secured (normally the URL to access) to obtain the allowed ConfigAttribute’s (normally the ROLE’s)

    • boolean supports(Class clazz)

    • Collection getAllConfigAttributes()

    Be careful with the later, because it’s called at startup and maybe is not well configured at this time (I mean, with the datasources or persistence context autowired, depending on what are you using). The solution in a web environment is to configure the contextConfigLocation in the web.xml to load the applicationContext.xml before the applicationContext-security.xml

    The final step is to customize the applicationContext-security.xml to load this bean.

    For doing that, I used regular beans in this file instead of the security namespace:

        <beans:bean id="springSecurityFilterChain" class="org.springframework.security.web.FilterChainProxy">
        <filter-chain-map path-type="ant">
            <filter-chain pattern="/images/*" filters="none" />
            <filter-chain pattern="/resources/**" filters="none" />
            <filter-chain pattern="/**" filters="
            securityContextPersistenceFilter,
            logoutFilter,
            basicAuthenticationFilter,
            exceptionTranslationFilter,
            filterSecurityInterceptor" 
        />
        </filter-chain-map>
    </beans:bean>
    

    You have to define all the related beans. For instance:

        <beans:bean id="filterSecurityInterceptor" class="org.springframework.security.web.access.intercept.FilterSecurityInterceptor">
        <beans:property name="authenticationManager" ref="authenticationManager"></beans:property>
        <beans:property name="accessDecisionManager" ref="affirmativeBased"></beans:property>
        <beans:property name="securityMetadataSource" ref="optionsFromDataBaseFilterInvocationSecurityMetadataSource"></beans:property>
        <beans:property name="validateConfigAttributes" value="true"/></beans:bean>
    

    I know that is not a well explained answer, but it’s not as difficult as it seems.

    Just use the spring source as base and you will obtain what you want.

    Debugging with the data in your database, will help you a lot.

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

Sidebar

Related Questions

I want to use @PreAuthorize annotation on service methods with Spring Security. One of
I use Spring MVC [version: 2.5] and Security[version: 2.0.4]. My problem looks like that:
Spring security has a nice feature, it remembers the url of request resource and
When using spring security, specifically with @notation; what is the proper way to access
I keep getting... org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: You cannot use a spring-security-2.0.xsd schema with Spring
What is the real use of the security:http element in the spring security configurations.
I am trying to use PreAuthFilter (for Siteminder) with Spring Security 3.0. <http use-expressions=true>
I am new to JSF and Spring. I am trying to use Spring Security
I need to use the Spring Security User, Role/Authority and the UserRole-join classes both
I use Spring Security 3.0.3.RELEASE. I would like to create a custom authentication processing

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.