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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:29:36+00:00 2026-05-31T16:29:36+00:00

I’m using Spring Security 3.0.7 How can I get with java code the access

  • 0

I’m using Spring Security 3.0.7

How can I get with java code the “access” attributes of the “patterns” that I have defined in the <intercept-url> elements of my security configuration file?

I need to get them in my custom session management filter, so that if the requested URL has an ANONYMOUS access required, I skip the filter and don’t check the session timeout.

Now I’m doing it “manually”, by comparing the requested URL with those patterns I know they have an ANONYMOUS access required. It works, but it’s not a good solution because if I change the xml config file, I have to change the java code.

Thank you in advance.

  • 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-31T16:29:37+00:00Added an answer on May 31, 2026 at 4:29 pm

    I’ve found the solution. If someone’s interested I explain it here.

    I added the following Java code to the doFilter method in my session management filter, for checking if the user (anonymous user in this case) is allowed to access the requested page:

    ...
    private WebInvocationPrivilegeEvaluator webPrivilegeEvaluator;
    ...
    // Before this I have checked that the session is invalid and that the invalidSessionUrl parameter isn't null
    String uri = request.getRequestURI();
    String cPath = request.getContextPath();
    int longCPath = cPath.length();
    String pagSolicitada = uri.substring(longCPath);
    Authentication autenticacion = SecurityContextHolder.getContext().getAuthentication();
    if ( !webPrivilegeEvaluator.isAllowed(pagSolicitada, autenticacion) ) {
         // Redirect to the invalidSessionUrl
         redirectStrategy.sendRedirect(request, response, invalidSessionUrl);
         return;
    }
    // Do nothing, just skip this filter
    chain.doFilter(request, response);
    return;
    ...
    

    The webPrivilegeEvaluator is a property of the session management filter that I inject in the xml config file:

    <beans:bean id="filtroGestionSesion" class="springSecurity.FiltroGestionSesion">
        <beans:constructor-arg name="securityContextRepository" ref="securityContextRepository" />
        <beans:property name="sessionAuthenticationStrategy" ref="sas" />   
        <beans:property name="invalidSessionUrl" value="/faces/paginas/autenticacion/login.xhtml?error=timeout" />
        <beans:property name="webPrivilegeEvaluator" ref="webPrivilegeEvaluator" /> 
    </beans:bean>
    

    And the bean that this property references is:

    <beans:bean id="webPrivilegeEvaluator" class="org.springframework.security.web.access.DefaultWebInvocationPrivilegeEvaluator">
        <beans:constructor-arg ref="filterSecurityInterceptor" />
    </beans:bean>
    

    Finally, the filterSecurityInterceptor has the intercept-url elements with the patterns and access required for them (you don’t put these intercept-url in the http element of the NameSpace, just put them here):

    <beans:bean id="filterSecurityInterceptor" class="org.springframework.security.web.access.intercept.FilterSecurityInterceptor">
        <beans:property name="securityMetadataSource">
            <filter-security-metadata-source use-expressions="true">
            <!-- IMPORTANTE: Poner las URLs más específicas primero -->
            <intercept-url pattern="/" access="permitAll"/> <!-- Página inicio al arrancar la aplic (contextPath) -->
            <intercept-url pattern="/faces/inicio.xhtml" access="permitAll"/>
            <intercept-url pattern="/faces/paginas/autenticacion/login.xhtml*" access="permitAll"/>
            <intercept-url pattern="/faces/paginas/autenticacion/**" access="isAuthenticated()"/>
            <intercept-url pattern="/faces/paginas/administracion/**" access="isAuthenticated()"/>
            <intercept-url pattern="/faces/paginas/barco/**" access="isAuthenticated()"/>
            <intercept-url pattern="/faces/paginas/catalogo/**" access="permitAll"/>
            <intercept-url pattern="/faces/paginas/error/**" access="permitAll"/>
            <intercept-url pattern="/faces/paginas/plantillas/**" access="permitAll"/>
            <intercept-url pattern="/**" access="denyAll" />
            </filter-security-metadata-source>
        </beans:property>
        <beans:property name="authenticationManager" ref="authenticationManager" />
        <beans:property name="accessDecisionManager" ref="httpRequestAccessDecisionManager" />
        <beans:property name="observeOncePerRequest" value="false" />
    </beans:bean>
    

    This filter has to be declared as the last one of the filter chain, this way:

    <custom-filter position="LAST" ref="filterSecurityInterceptor" />
    

    NOTE: I’ve intentionally omitted the declarations of other beans in order to not make this answer too large.

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

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.