Spring Security 正在保护两个独立的 Spring Boot 后端服务,这些服务在两个独立的端口上运行,来自两个独立的 jar 文件。其中一项服务(称为resource
,在此链接中包含完整代码)响应来自前端 Node.js 服务器的 GET 请求,但另一项服务(称为authserver
,将在此链接中包含完整代码。)没有。 如何更改 spring 安全设置,以便authserver
应用程序可以响应来自 node.js 服务器的请求?
这是来自 node.js 服务器的 express.js 代码,它向两个后端服务发出请求:
var url = require('url');
var request = require('request');
// expose the routes to our app with module.exports
module.exports = function(app) {
// application --------------------------------
app.get('/resource/**', function(req, res) {
request.get('http://localhost:9000/resource', function (error, response, body) {
if(error){console.log('ERROR with resource request.')}
if (!error){// && response.statusCode == 200) {
console.log(response.statusCode);
console.log(body);
};
});
console.log("You Hit The Resource Route ");
});
app.get('/user/**', function(req, res) {
request.get('http://localhost:9999/uaa/user', function (error, response, body) {
if(error){console.log('ERROR with user request.')}
if (!error){// && response.statusCode == 200) {
console.log(response.statusCode);
console.log(body);
};
});
console.log("You Hit The User Route ");
});
};
以下是nodemon
显示的日志:
1.) 对authserver
应用程序/uaa/user
端点的调用给出了304
响应(Spring Bootauthserver
应用程序的日志没有显示任何接收请求的证据),以及
2.)resource
应用程序的/resource
端点返回了401
响应( Spring Bootresource
应用程序日志确实显示它收到了请求):
[nodemon] starting `node server.js`
App listening on port 8080
GET /user 304 4.257 ms - -
You Hit The Resource Route
401
{"error":"unauthorized","error_description":"Full authentication is required to access this resource"}
我确认http://localhost:9999/uaa/user
在 Web 浏览器中输入确实会触发 Spring Bootauthserver
应用程序创建记录请求的日志,并在浏览器中提供以下 xml:
<oauth>
<error_description>
Full authentication is required to access this resource
</error_description>
<error>unauthorized</error>
</oauth>