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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:03:50+00:00 2026-06-02T17:03:50+00:00

I am trying to set up a simple spring mvc / spring security webapp,

  • 0

I am trying to set up a simple spring mvc / spring security webapp, but I can’t seem to find the way to accomplish this:

  1. I’d like to use the normal @Secured annotations, and if the user isn’t logged in I’d like them to be redirected to the login page, and back to where they were (this is normal behaviour which I’ve managed to accomplish)
  2. I’d like the login form to be my own controller/template pair (also common and accomplished).
  3. I’d like the login form above to submit to my own controller which will authenticate the user credentials against my backend restful service. It then receives a security token back from the service. At this point I’d like to manually flag the session as authenticated authenticated and attach the token to it.

How do I go about implementing the last stage?

  • 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-02T17:03:50+00:00Added an answer on June 2, 2026 at 5:03 pm

    OK the answer is basically:

    SecurityContextHolder.getContext().setAuthentication(...)
    

    However to be able to use it in the scenario I described above where the Spring MVC controller controls the authentication process, a few other things need to be done:

    1. You must either use one of the available Impls of Authentication or create one. I found it best to subclass AbstractAuthenticationToken.
    2. Spring security won’t start up without an authentication manager which isn’t used in this scenario, so I created a null authentication manager:

      @Service("nullAuthenticationProvider")
      public class NullAuthenticationProvider implements AuthenticationProvider
      {
          @Override
          public Authentication authenticate(Authentication authentication) throws AuthenticationException
          {
              return authentication;
          }
      
          @Override
          public boolean supports(Class<?> authentication)
          {
              return true;
          }
      }
      
    3. And finally the spring context.xml:

      <security:global-method-security secured-annotations="enabled" />
      
      <security:http disable-url-rewriting="true">
          <security:access-denied-handler error-page="/login" />
          <security:form-login login-page="/login" />
      </security:http>
      
      <security:authentication-manager>
          <security:authentication-provider ref='nullAuthenticationProvider'/>
      </security:authentication-manager>
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Spring 3, and trying to set up a simple web-app using annotations
I'm trying to set up a Spring JPA Hibernate simple example WAR for deployment
I'm trying to set up a simple Roles model for my site. Users can
I'm new to MVC but am having trouble trying to find info on how
I'm trying to set up JSR-303 validation of forms using Spring MVC. I had
I'm trying to access a simple ASP.NET MVC route, but it's erroring with: The
Im trying to update a simple model in MVC,but its not working,it throws an
I'm trying to set up a simple spring application and I'm getting the below
I'm trying to set up a simple server side RSA encryption of a small
I'm trying to set together a simple TextBox with some watermark text in the

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.