Code Monkey home page Code Monkey logo

Comments (11)

ralscha avatar ralscha commented on July 24, 2024

Hi
I think I had a similar issue with an older spring-security version. What version of spring and spring-security do you use?

from blog.

iranicus avatar iranicus commented on July 24, 2024

Thanks for the quick response, so taking a look the versions are:
Spring: 5.0.5.RELEASE
Spring Boot: 2.0.1.RELEASE
Spring Security Core: 5.0.4.RELEASE

from blog.

ralscha avatar ralscha commented on July 24, 2024

Same I use for my demo.

Have you added the cors() configuration in the security config

		http
		  .cors()    // <---------
		    .and()

https://github.com/ralscha/blog/blob/master/jwt/server/src/main/java/ch/rasc/jwt/security/SecurityConfig.java

from blog.

iranicus avatar iranicus commented on July 24, 2024

I have indeed I have the same setup for the server you have in the repo, in the security config:

    protected void configure(HttpSecurity http) throws Exception {
        http
                .csrf().disable()
                .cors().and()
                .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
                // .httpBasic().and() //optional, if the service wants to be accessed via the browser
                .authorizeRequests()
                    // endPoint configuration requiring authorization
                    .antMatchers("/signup").permitAll()
                    .antMatchers("/login").permitAll()
                    .antMatchers("/public").permitAll()
                    .anyRequest().authenticated().and()
                .apply(new JWTConfigurer(this.tokenProvider));
    }

from blog.

ralscha avatar ralscha commented on July 24, 2024

Is there also a @CrossOrigin annotation on the Controller class where the /login mapping is located?

@RestController
@CrossOrigin
public class AuthController {

 @PostMapping("/login")
  public String authorize(@Valid @RequestBody User loginUser,
      HttpServletResponse response) {
      .....
  }
}

from blog.

iranicus avatar iranicus commented on July 24, 2024

Indeed I have, I have uploaded my current server code in a repo on (https://github.com/iranicus/JWT_attempt) if you could take a ganders pls :>

from blog.

ralscha avatar ralscha commented on July 24, 2024

I will look tomorrow.

One quick thing you could try is to remove

spring.mvc.dispatch-options-request=true

in your application.properties file.

from blog.

iranicus avatar iranicus commented on July 24, 2024

Will do that was just added as part of a potential CORS fix, just removed it now but unfortunately no change.

from blog.

ralscha avatar ralscha commented on July 24, 2024

I have just tested my application and it works. I will try your project tomorrow.

2018-05-06 22_20_36-developer tools - http___localhost_8100_

2018-05-06 22_20_55-developer tools - http___localhost_8100_

from blog.

ralscha avatar ralscha commented on July 24, 2024

It works when you remove

//@ComponentScan({ "com.rdanby.jwt.security.jwt" })

on the JwtApplication class. This annotation only configures beans in the com.rdanby.jwt.security.jwt package and skips everything else

and add @component on the TokenProvider, because the application needs to inject this bean into other beans.

@Component
public class TokenProvider {

from blog.

iranicus avatar iranicus commented on July 24, 2024

Just added this now and it has fixed the issue, thanks loads. There is another issue I have ran into however with the /secret and /authenticate api calls which I'll bring up as a different issue.

from blog.

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.