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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:29:35+00:00 2026-06-09T20:29:35+00:00

I have spring-security configured using basic and form based authentication as per auto-config=’true’ .

  • 0

I have spring-security configured using basic and form based authentication as per auto-config='true'.

I would like the endpoints under /api/** to NOT use form based security. Other endpoints outside of /api/** should use form based login. I would like a 401 response sent to any call for these endpoints who did not provide credentials under /api/**.

UPDATE: Thanks to Luke Taylor’s comment below I have come up with the following solution.

NOTE: This technique can only be applied as of spring-security 3.1.

First I single out /api/**. We never create a session though use one if available, this is handled by create-session="never" and the use of <session-management/>.

<http pattern="/api/**" create-session="never" use-expressions="true">
    <http-basic />
    <session-management />
    <intercept-url pattern="/api/**" access="hasRole('API_ACCESS')"/>
</http>

<http auto-config="true" use-expressions="true">
    <intercept-url pattern="/" access="permitAll"/>
    <intercept-url pattern="/**" access="isAuthenticated()"/>
</http>
  • 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-09T20:29:36+00:00Added an answer on June 9, 2026 at 8:29 pm

    With Spring Security 3.1, your best option is to split the restful and non-restful parts of your application into separate filter chains by using two separate <http> elements. The restful API chain can then be configured to be stateless and use basic authentication, while the default chain can use a normal form-login configuration.

    You would then have something like:

    <http pattern="/api/**" create-session="stateless">
        <intercept-url pattern="/api/**" access="ROLE_API_USER" />
        <http-basic />        
    </http>
    
    <!-- No pattern attribute, so defaults to matching any request -->
    <http>
        <intercept-url pattern="/**" access="ROLE_USER" />
        <form-login />        
    </http>
    

    The chain definitions must be ordered from most specific pattern to most general, so the default chain comes last.

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

Sidebar

Related Questions

I have configured two authentication providers in my Spring Security config: <security:authentication-manager> <security:authentication-provider ref=XProvider
I am using spring mvc and spring security. In my security-app-context.xml I have: <authentication-manager>
I have configured spring security core plugin using requestmap table inside the database.. Now
I have implemented spring security to protect sections of our website. I am using
In my project,I have integrated Spring Security with CAS server authentication. Now my project
While implementing some security aspects with Spring Security, I have noticed that both Authentication
I am trying to configure some basic HTTP authentication over HTTPS using the spring
I am using Spring Security 3.1 and I have some code which I execute
I am using latest Apache CXF to create a webservice. I have configured ws-security
I have a j2ee web application using spring web flow ang spring security. 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.