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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:03:46+00:00 2026-05-15T08:03:46+00:00

I would like to have both form and basic authentication. If the request comes

  • 0

I would like to have both form and basic authentication.

If the request comes like https://username:password@mysite.com/ basic authentication is used.
If the request comes like https://mysite.com form authentication is used.

Is that possible?

  • 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-15T08:03:47+00:00Added an answer on May 15, 2026 at 8:03 am

    Yes, this is possible.

    Assuming you are using namespace configuration, this is really pretty easy. By default, they are both enabled if you use auto config on the http element. See section 2.2 of the springsecurity3 reference docs. You can set a custom realm for the basic auth by using the realm attribute on the http element. Both form and basic auth will use whatever authentication-provider is configured.

    If you aren’t using auto config on the http element, you just need to add an <http-basic /> tag as a child to the http element to enable basic auth. Odds are good you aren’t interested in the default config for the form authentication, so that tag can be a little more complicated.

    Mine looks like this:

        <form-login login-page="/login.html"
            default-target-url="/home.html" always-use-default-target="true"
            authentication-success-handler-ref="authenticationSuccessHandler"
            authentication-failure-handler-ref="authenticationFailureHandler"
            login-processing-url="/j_spring_security_check" />
    

    Obviously, it is necessary to allow anonymous access to the /login.html path. That page needs to render a form which submits to /j_spring_security_check, which the filter will intercept, find the username and password, and authenticate against the authentication provider which is configured. If you dig into the rest of the namespace, you’ll find it is possible to override the names of the fields, etc.

    I’m not sure if spring always defaults to using form auth unless an Authorization header is supplied in the request and it is lacking a valid username/password pair, or if it defaults to the first filter or the last, or what. But experimentation should allow you to figure that out easily enough. Looking at the last section of chapter 8 and the first of chapter 9, it looks as though it will send all unauthenticated users to the form entry point unless there is an Authorization header in the request, in which case, a failure to authenticate will result in a basic auth required response to the client. Chapters 8 and 9 are also where you’ll look if you want to manually configure everything instead of using the namespace.

    The authentication-success-handler and authentication-failure-handler must implement the AuthenticationSuccessHandler and AuthenticationFailureHandler and allow you to customize how the filter will respond to successful and failed authentication attempts. They are not required.

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

Sidebar

Ask A Question

Stats

  • Questions 449k
  • Answers 449k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I think it will be very useful to you to… May 15, 2026 at 8:20 pm
  • Editorial Team
    Editorial Team added an answer You can take a look at the DMOSample in the… May 15, 2026 at 8:20 pm
  • Editorial Team
    Editorial Team added an answer All browsers have SSL support (period). No one is going… May 15, 2026 at 8:20 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.