简体   繁体   中英

Spring Security with Angular Login Endpoint?

I've been working through the Spring tutorial for Spring Security , and I'm a bit confused. So far, it got me to spin up a java app and an angular app. I created the java app using the initializer and I created the angular app using the angular CLI. The problem is that it mentions that when I "load the home page [I] should get a browser dialog asking for username and password". My app didn't do this. When I ran my java and angular and went to localhost it just took me right to my app.component page. I went on with the tutorial as normal and created an endpoint on my Java side to get a resource. When I make the get request from my angular code, in my network tab I see my get request which comes back with a status of 302 and no response data, and then it makes a second network call to a localhost:[port]/login (I didn't explicitly make this call in the angular). This call has a status of 200, but it fails when it tries to parse it. I looked at the response from my network tab and it looks like it tried to send the login page that the tutorial references before.

在此处输入图片说明

Is there something I need to do to link up the angular to know that i'm using Spring Security? I'm just using an ng serve to run the angular, and i'm just running the main of the java in my IDE (intelliJ)

I can include my package.json or pom.xml or anything else if that helps?

Thanks

**** EDIT ****

here is what the browser console comes back with:

在此处输入图片说明

我们还使用spring安全性和angular js实现了安全性,如果您遇到相同的问题,我们也遇到了CORS(跨源请求源)错误,那么可以通过在spring应用程序中覆盖CORS配置来解决。

Turns out their tutorial's way of spinning up an angular project is coupled with their maven Java build, so it does the npm and ng stuff when you build the java. I was running the angular independently, so when I ran the angular I was specifying a different port from my java and therefore wasn't getting the Spring login which was on the port my Java was running on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM