简体   繁体   English

带有Angular登录端点的Spring Security?

[英]Spring Security with Angular Login Endpoint?

I've been working through the Spring tutorial for Spring Security , and I'm a bit confused. 我一直在研究Spring SecuritySpring教程,但有些困惑。 So far, it got me to spin up a java app and an angular app. 到目前为止,我不得不启动一个Java应用程序和一个angular应用程序。 I created the java app using the initializer and I created the angular app using the angular CLI. 我使用初始化程序创建了Java应用程序,并使用angular CLI创建了angular应用程序。 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. 当我运行Java和angular并进入localhost时,它直接将我带到我的app.component页面。 I went on with the tutorial as normal and created an endpoint on my Java side to get a resource. 我像往常一样继续本教程,并在Java端创建了一个端点来获取资源。 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). 当我从角度代码发出get请求时,在“网络”选项卡中,我看到了get请求,该请求的返回状态为302,没有响应数据,然后对本地主机进行了第二次网络调用:[端口] /登录(我没有明确地打这个电话)。 This call has a status of 200, but it fails when it tries to parse it. 此调用的状态为200,但是在尝试解析它时失败。 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? 我需要做一些事情来关联角度,以了解我正在使用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) 我只是用ng服务来运行角度,而我只是在我的IDE(intelliJ)中运行Java的主程序

I can include my package.json or pom.xml or anything else if that helps? 我可以包含package.json或pom.xml或其他任何内容(如果有帮助的话)?

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. 事实证明,他们的教程分解一个有角度的项目的方式与他们的maven Java构建结合在一起,因此在构建Java时会执行npm和ng的工作。 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. 我独立地运行角度,所以当我运行角度时,我指定了与Java不同的端口,因此没有获得运行Java的端口上的Spring登录名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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