Angular 角度-弹簧启动-键斗篷-401错误
我正试图实现一个角度应用程序,其中SpringBootRestService由KeyClope保护 在我的电脑上,一切正常。Angular应用程序是由KeyClope引导的(使用KeyClope Angular),因此我必须登录才能查看该应用程序。应用程序将REST调用与令牌一起发送到Spring Boot。 Restservice是keydepose.bearer-only接收令牌,并使用令牌中的角色进行筛选 这在本地运行得非常好,但从我将其部署到服务器的那一刻起,每当我尝试使用启用的keydape访问Restservice时,都会出现401错误。(我已在KeyClope上登录并拥有有效令牌) 这是我在Spring引导调试日志中得到的信息:Angular 角度-弹簧启动-键斗篷-401错误,angular,spring-boot,keycloak,http-status-code-401,Angular,Spring Boot,Keycloak,Http Status Code 401,我正试图实现一个角度应用程序,其中SpringBootRestService由KeyClope保护 在我的电脑上,一切正常。Angular应用程序是由KeyClope引导的(使用KeyClope Angular),因此我必须登录才能查看该应用程序。应用程序将REST调用与令牌一起发送到Spring Boot。 Restservice是keydepose.bearer-only接收令牌,并使用令牌中的角色进行筛选 这在本地运行得非常好,但从我将其部署到服务器的那一刻起,每当我尝试使用启用的keyd
2020-04-06 12:28:54.854 DEBUG 1962 --- [nio-2001-exec-2] o.s.web.servlet.DispatcherServlet : "ERROR" dispatch for GET "/error", parameters={}
2020-04-06 12:28:54.875 DEBUG 1962 --- [nio-2001-exec-2] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#error(HttpServletRequest)
2020-04-06 12:28:54.970 DEBUG 1962 --- [nio-2001-exec-2] o.s.w.s.m.m.a.HttpEntityMethodProcessor : Using 'application/json', given [application/json, text/plain, */*] and supported [application/json, application/*+json, application/json, application/*+json]
2020-04-06 12:28:54.971 DEBUG 1962 --- [nio-2001-exec-2] o.s.w.s.m.m.a.HttpEntityMethodProcessor : Writing [{timestamp=Mon Apr 06 12:28:54 CEST 2020, status=401, error=Unauthorized, message=No message availab (truncated)...]
2020-04-06 12:28:55.051 DEBUG 1962 --- [nio-2001-exec-2] o.s.web.servlet.DispatcherServlet : Exiting from "ERROR" dispatch, status 401
我的Spring Boot application.properties的KeyClope部分:
keycloak.enabled=true
keycloak.auth-server-url=http://172.16.1.20:8180/auth
keycloak.realm=Immodat
keycloak.resource=login-app
keycloak.bearer-only=true
keycloak.cors=true
keycloak.security-constraints[0].authRoles[0]=aa.intern.write
keycloak.security-constraints[0].securityCollections[0].patterns[0]=/
有一个用CrossOrigin注释的RestController。其中的所有方法都有GetMapping、PostMapping
@RestController
@CrossOrigin
public class FormController {
@PostMapping("/forms")
Form createForm(@RequestBody Form form) {
/* ... */
}
@GetMapping("/forms/{name}")
Form getForm(@PathVariable String name) {
/* ... */
}
.
.
.
}
在KeyClope客户端设置中,返回Url和Web源都设置为“*”以允许从任何地方进行访问
有什么我遗漏的吗?当地一切正常。在服务器上,如果禁用了KeyClope,但三者一起都不起作用,也会出现问题。好的,我发现了问题。也许有点愚蠢 三台服务器中有一台的时间错误,因此keydapore令牌对这台服务器无效 如果出现401错误且不知道原因,请检查服务器时间强>