【发布时间】:2018-08-05 02:40:06
【问题描述】:
我有一个问题。我想使用 Spring Boot 创建简单的微服务应用程序。我有两个微服务:带有端口 8001 的 auth-service,用于验证用户并返回令牌,以及带有端口 8002db-service /strong>,从数据库中检索数据。在 db-service 我有一个简单的休息控制器,在这个控制器中我有一个方法,女巫通过用户名找到用户,但默认情况下这个方法是安全的,我想从 auth-service 无需身份验证。该怎么做?
这是一个例子
DbServiceController.java
@RestController
public class DbServiceController {
/**
* This method is secured by default, so if I want to
* access to this resouce I need to have a token,
* but I want to prevent authentication for auth-service,
* because I want to retrieve token by user, which was provided by this microservice
*/
@RequestMapping(value = "user", method = RequestMethod.GET)
public User findByUsername(@RequestParam("username") String username) {
return new User("john", "doe", new String[] {"ROLE_USER"});
}
}
感谢您的所有回答。
【问题讨论】:
标签: spring-boot oauth-2.0