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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:44:38+00:00 2026-06-11T03:44:38+00:00

I have been using Spring Security 2.x for some time now, but recently I

  • 0

I have been using Spring Security 2.x for some time now, but recently I switched to 3.x. I always use my own implementation of UserDetails interface and authentication against DB.

Everything works fine (logging in, logging out, url filters, seeing username of authorized user, etc.).

The only thing left to do was to display “Please login” message when user is not authorized. I tried few approaches:

<sec:authorize access="not isAnonymous()">
or
<sec:authorize access="hasRole('ROLE_ANONYMOUS')">
etc.

None of them worked. Finally I added <sec:authentication property="principal.authorities" /> to my home page output to debug what roles user really has. This is what I see:

  • Logged user – [ROLE_USER, ROLE_ADMIN]
  • Unathorized user – “ <- empty String

It looks like I somehow lost the default ROLE_ANONYMOUS authority, which was always added by Spring, if I recall correctly. Was that recently dropped or something? Perhaps I have to take care of this anonymous access in some other manner?

Relevant part of security context:

<beans:beans
        xmlns="http://www.springframework.org/schema/security"
        xmlns:beans="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/security
           http://www.springframework.org/schema/security/spring-security-3.1.xsd">

    <!-- UNPROTECTED RESOURCES -->
    <http pattern="/" security="none"/>
    <http pattern="/favicon.ico" security="none"/>
    <http pattern="/home" security="none"/>
    <http pattern="/login*" security="none"/>
    <http pattern="/resources/**" security="none"/>

    <!-- PROTECTED RESOURCES -->
    <http auto-config='true' use-expressions="true">
        <intercept-url pattern="/**" access="hasRole('ROLE_USER')"/>
        <intercept-url pattern="/admin/**" access="hasRole('ROLE_USER,ROLE_ADMIN')"/>
        <form-login login-page="/login" default-target-url="/dashboard" authentication-failure-url="/login?login_error=true"/>
        <logout logout-url="/logout"/>
    </http>

    <beans:bean id="userAccountsAuthenticationProvider" class="pl.xxx.utils.UserAccountsAuthenticationProvider" />

    <beans:bean id="saltSource" class="org.springframework.security.authentication.dao.ReflectionSaltSource">
        <beans:property name="userPropertyToUse" value="salt" />
    </beans:bean>

    <authentication-manager>
        <authentication-provider user-service-ref="userAccountsAuthenticationProvider">
            <password-encoder ref="standardPasswordEncoder"/>
        </authentication-provider>
    </authentication-manager>
</beans:beans>
  • 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-06-11T03:44:41+00:00Added an answer on June 11, 2026 at 3:44 am

    Anonymous Authentication can be configured in few different ways – do you use <http auto-config="true">, <anonymous> tag or define beans by yourself as custom filter? It’ll be easier if you posted your security-context.xml.

    Anyway, you want to display “Please login”, so I assume you really wanted

    <sec:authorize access="isAnonymous()">Please login</sec:authorize>
    

    without “not” (by the way I can’t find if “not” is a valid part of expression in this context).

    Another way is to use isAuthenticated() instead, negate it in EL and see if it works in your case:

    <sec:authorize access="isAuthenticated()" var="isAuthenticated" />
    <c:if test="${not isAuthenticated}">
      <!-- do stuff -->
    </c:if>
    

    EDIT:

    Change security="none" to access="IS_AUTHENTICATED_ANONYMOUSLY" and move chosen patterns to intercept-url. It should enable Spring Security’s Filter Chain and apply AnonymousAuthenticationFilter on request:

    <!-- UNPROTECTED RESOURCES -->
    <http pattern="/favicon.ico" security="none"/>
    <http pattern="/resources/**" security="none"/>
    
    <!-- PROTECTED RESOURCES -->
    <http auto-config='true' use-expressions="true">
        <intercept-url pattern="/" access="IS_AUTHENTICATED_ANONYMOUSLY" />
        <intercept-url pattern="/home" access="IS_AUTHENTICATED_ANONYMOUSLY" />
        <intercept-url pattern="/login*" access="IS_AUTHENTICATED_ANONYMOUSLY" />
        <intercept-url pattern="/**" access="hasRole('ROLE_USER')"/>
        <intercept-url pattern="/admin/**" access="hasRole('ROLE_USER,ROLE_ADMIN')"/>
        <form-login login-page="/login" default-target-url="/dashboard" authentication-failure-url="/login?login_error=true"/>
        <logout logout-url="/logout"/>
    </http>
    

    assuming you want use isAnonymous() in /, /home and /login*.

    My previous solution worked, because with security="none" checking for isAuthenticated() always yielded false, so negating it was like checking for not being loggged.

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

Sidebar

Related Questions

I have been using TortoiseSVN for some time and I really like it. I
I am using Spring Security 3.1 and I have some code which I execute
I have been using spring for a while as my IOC. It has also
I have been using the new feature of Spring 3.1.1 the java based configuration.
I have been using an API to do some work. This is how I
I have been using some Javascript to create a text field once an certain
I've been struggling with Spring Security LDAP for a while now, and just when
I have a j2ee web application using spring web flow ang spring security. I
I have been trying out the spring-security-facebook plugin and so far its been smooth.
I'm using the Spring Security SAML 2.0 sample webapp on Tomcat 7 and 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.