【发布时间】:2020-05-15 19:55:06
【问题描述】:
我正在使用 Keycloak 来保护我的 rest api
我在 Keycloak 中有 2 个客户:
-我的前端:React 应用
-我的后端:Spring boot(仅承载类型)
当我运行 spring boot 应用程序时一切正常。 但我收到错误 401“没有找到指定孩子的公钥” 当我在tomcat中运行它时。 下面的一些配置:
keycloak.json
{
"realm": "pet",
"bearer-only": true,
"auth-server-url": "http://localhost:8080/auth",
"ssl-required": "none",
"resource": "secure-api",
"confidential-port": 0,
"enable-cors" : true,
"cors-max-age" : 1000,
"cors-allowed-methods" : "POST, PUT, DELETE, GET",
"cors-exposed-headers" : "WWW-Authenticate, My-custom-exposed-Header"
}
web.xml
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<module-name>myapp</module-name>
<security-constraint>
<web-resource-collection>
<web-resource-name>Authors</web-resource-name>
<url-pattern>/management/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>user</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>pet</realm-name>
</login-config>
<security-role>
<role-name>admin</role-name>
</security-role>
<security-role>
<role-name>user</role-name>
</security-role>
</web-app>
context.xml
<Context path="/myapp">
<Valve className="org.keycloak.adapters.tomcat.KeycloakAuthenticatorValve"/>
</Context>
keycloak-7.0 和 tomcat-8
你有什么想法吗?
【问题讨论】: