GithubHelp home page GithubHelp logo

Comments (3)

white3km avatar white3km commented on August 16, 2024

Not sure of your exact setup but I spend some time migrating to latest Spring Boot/ Security for Elide 7 and I kept getting flaky results with authentication. The issue was the security context wasn't really being persisted per request all the way through. Basically I could see the context get populated then later if the filter chain was run again for another dispatch type it wasn't populated. I think with the upgrade to a new Spring Security they changed the default behavior.

My setup (I use a custom filter instead of vanilla jwt)

    http
          .cors(AbstractHttpConfigurer::disable)
          .csrf(AbstractHttpConfigurer::disable)
          .formLogin(AbstractHttpConfigurer::disable)
          .httpBasic(AbstractHttpConfigurer::disable)
          .anonymous(AbstractHttpConfigurer::disable)
          .logout(AbstractHttpConfigurer::disable)
          .addFilterBefore(
              new CustomAuthFilter(apiUserDetailsService),
              RequestHeaderAuthenticationFilter.class)
          .authorizeHttpRequests(
              (authorize) ->
                  authorize
                      .requestMatchers("/foo/**")
                      .hasAnyRole("ADMIN")
                      .anyRequest()
                      .authenticated())
             .sessionManagement(
              config -> config.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
          // Spring Security 6, calls for all dispatch types
          // https://docs.spring.io/spring-security/reference/servlet/authentication/persistence.html#requestattributesecuritycontextrepository
          .securityContext(
              (securityContext) ->
                  securityContext.securityContextRepository(
                      new RequestAttributeSecurityContextRepository()));

In case it's not clear, this is the important part (https://docs.spring.io/spring-security/reference/servlet/authentication/persistence.html#requestattributesecuritycontextrepository):

.securityContext(
              (securityContext) ->
                  securityContext.securityContextRepository(
                      new RequestAttributeSecurityContextRepository()))

Hope this helps!

from elide.

StetsenkoAndrew avatar StetsenkoAndrew commented on August 16, 2024

Thanks, it helped a lot! All works now!

from elide.

StetsenkoAndrew avatar StetsenkoAndrew commented on August 16, 2024

Thanks again @white3km

from elide.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.