Results 1 to 9 of 9

Thread: How to dynamically decide <intercept-url> access attribute value in Spring Security?

Hybrid View

  1. #1

    Default How to dynamically decide <intercept-url> access attribute value in Spring Security?

    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?

  2. #2
    Luke Taylor is offline Senior Member Acegi Security System TeamSpring Team
    Join Date
    Aug 2004
    Location
    Glasgow, Scotland
    Posts
    3,449

    Default

    Do you mean at startup or every time someone accesses a URL?

    If at startup, you could write a custom PropertyPlaceholderConfigurer and replace the access attributes with placeholders.
    Spring - by Pivotal
    twitter @tekul

  3. #3

    Default

    I store the URL patterns and the roles which can access the patterns in a database table. Something like:

    URL Pattern Roles
    ------------------------------------------------------------------------
    /student ROLE_STUDENT
    /admin ROLE_ADMIN
    /login ROLE_ADMIN, ROLE_STUDENT, ROLE_FACULTY

    When I load the application I read the values from the database and want to set the access as per these values. Essentially I want to perform the function of <intercept-url> tag using the values from the database.

    In short, I do not want to hard code the URL patterns and the roles in applicationConfig-security.xml. Instead I want to load them from a database table.

  4. #4
    Join Date
    May 2006
    Location
    Madrid
    Posts
    382

    Default

    I put an answer to your question at stackoverflow: http://stackoverflow.com/questions/6...-spring-securi

  5. #5
    Luke Taylor is offline Senior Member Acegi Security System TeamSpring Team
    Join Date
    Aug 2004
    Location
    Glasgow, Scotland
    Posts
    3,449

    Default

    You'll find a FAQ entry on this.
    Spring - by Pivotal
    twitter @tekul

  6. #6

    Default

    I followed the FAQ and the SO answer and some other tutorials. I have created my own filter chain as below:

    <beans:bean id="springSecurityFilterChain"
    class="org.springframework.security.web.FilterChai nProxy">
    <filter-chain-map path-type="ant">
    <filter-chain pattern="/css/**" filters="none" />
    <filter-chain pattern="/images/**" filters="none" />
    <filter-chain pattern="/Login.xhtml" filters="none" />
    <filter-chain pattern="/j_spring_security_check" filters="none" />
    <filter-chain pattern="/securepage.xhtml" filters="
    securityContextPersistenceFilter,
    logoutFilter,
    authenticationProcessingFilter,
    exceptionTranslationFilter,
    filterSecurityInterceptor" />
    </filter-chain-map>
    </beans:bean>

    I can access all pages directly except securepage.xhtml for which I get the login page. This is as expected. But when I try to login I get an error saying /j_spring_security_check is not available.

    If I simply use the namespace configuration http tag I can access /j_spring_security_check. But since I am using my own filter chain I have removed the http tag.

    I guess I am missing something which is setup by the http tag. Sorry, but I am really new to Spring Security. May be I am missing the most obvious thing

  7. #7

    Default

    I have attached the contents of my applicationContext-security.xml if those would be helpful.

    Shortly, the problem is there is no https://localhost/myapp/j_spring_security_check resource for this configuration.

    If I insert
    <http><form-login login-page="/Login.xhtml" /></http> to the above file then /j_spring_security_check is accessible but then my springSecurityFilterChain has no effect.

    So I think I am missing something which <http><form-login /></http> does.
    Attached Files Attached Files

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •