当前位置: 首页 > 知识库问答 >
问题:

Spring Boot应用程序不会重定向到托管在不同服务器上的Keycloak

司寇嘉茂
2023-03-14

我创建了一个简单的应用程序,该应用程序由keyclope服务器进行身份验证。我已经在同一台机器上测试了应用程序和keydropage服务器,该应用程序运行良好,并将我重定向到keydropage进行相应的领域客户端身份验证。现在我已经为我的Keyclope保留了一个单独的服务器(https://192.162.10.11:8443)我的Spring Boot正在本地主机上运行。但一旦我尝试访问该服务,该应用程序就不会将我重定向到Keyclope,而是给了我一个白色的错误页面。有人能告诉我我做错了什么吗。我的完整代码详细信息如下

一个pplication.properties

server.port=8081
keycloak.realm= Myrealm
keycloak.auth-server-url= https://192.162.10.11:8443/auth
keycloak.ssl-required= external
keycloak.resource= backend-app
keycloak.public-client= true
keycloak.confidential-port= 0

**我的钥匙斗篷正在运行https://192.162.10.11:8443我可以通过浏览器访问它

来自Keyclok的MyRealings设置:

我正在访问的链接是http://localhost:8081/persons

当Keycloak与应用程序在同一台机器上时,此链接正在进行身份验证

MainClass代码

package sb.keycloak;

import java.security.Principal;
import java.util.ArrayList;
import java.util.List;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.ResponseEntity;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;


@SpringBootApplication
@RequestMapping
@CrossOrigin(allowCredentials="true")
public class SbKeycloakApplication {

  @GetMapping(path = "/persons")
  public ResponseEntity<List<Persons>> customers(final Principal principal, final Model model) {
    final var personas = new ArrayList<Persons>();
    personas.add(new Persons(1, "Person1"));
    personas.add(new Persons(2, "Person2"));
    return ResponseEntity.ok(personas);
  }

  public static void main(final String[] args) {
    SpringApplication.run(SbKeycloakApplication.class, args);
  }

}

错误屏幕截图

编辑

我还将MyRealm的IP更新为正确的IP(这是我的Spring Boot应用程序运行的IP-我的电脑的IP),但仍然存在相同的白色标签错误。

编辑2(白标错误添加为以下文本)

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Fri Apr 24 10:53:33 PKT 2020
There was an unexpected error (type=Internal Server Error, status=500).
No message available
java.lang.NullPointerException
    at org.keycloak.adapters.OAuthRequestAuthenticator.getRedirectUri(OAuthRequestAuthenticator.java:175)
    at org.keycloak.adapters.OAuthRequestAuthenticator.loginRedirect(OAuthRequestAuthenticator.java:213)
    at org.keycloak.adapters.OAuthRequestAuthenticator.authenticate(OAuthRequestAuthenticator.java:275)
    at org.keycloak.adapters.RequestAuthenticator.authenticate(RequestAuthenticator.java:138)
    at org.keycloak.adapters.springsecurity.filter.KeycloakAuthenticationProcessingFilter.attemptAuthentication(KeycloakAuthenticationProcessingFilter.java:154)
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:212)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.keycloak.adapters.springsecurity.filter.KeycloakPreAuthActionsFilter.doFilter(KeycloakPreAuthActionsFilter.java:96)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.web.filter.CorsFilter.doFilterInternal(CorsFilter.java:96)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:74)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:215)
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:178)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:357)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:270)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:200)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.keycloak.adapters.tomcat.AbstractAuthenticatedActionsValve.invoke(AbstractAuthenticatedActionsValve.java:67)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
    at org.keycloak.adapters.tomcat.AbstractKeycloakAuthenticatorValve.invoke(AbstractKeycloakAuthenticatorValve.java:181)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:836)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1747)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.base/java.lang.Thread.run(Thread.java:832)

编译器错误输出

 WARN 38292 --- [nio-8081-exec-2] o.keycloak.adapters.KeycloakDeployment   : Failed to load URLs from https://192.162.10.11:8443/auth/realms/Myrealm/.well-known/openid-configuration

共有3个答案

夏雅志
2023-03-14

当Keyclope客户端适配器无法首次调用身份验证服务器时,日志中会出现以下模式:

java.lang.NullPointerException
        at org.keycloak.adapters.OAuthRequestAuthenticator.getRedirectUri(OAuthRequestAuthenticator.java:175)

这是对一个更好的认证url的绝望的呼喊。在我的案例中,https通信是罪魁祸首:端口未打开,证书不可信任,等等。

翟俊名
2023-03-14

stacktrace中的NullPointerException指向OAuthRequestAuthenticator中的下一行。

KeycloakUriBuilder redirectUriBuilder = deployment.getAuthUrl().clone()

当我容器化Spring Boot应用程序时,未能通过环境变量传递application.properties值时,我也遇到了同样的问题。原因可能是keycloak.auth-server-url具有空值。

刘子实
2023-03-14

可能会检查它是否与证书不受信任相关,这会导致“加载URL失败…”警告,然后是OAuthRequestAuthenticator中的NullPointerException。getRedirectUri()

 类似资料:
  • 但是所有的答案和评论对链接帖子的回应也没有太大帮助

  • 我jenkins.war部署在Tomcat 9(Linux)上,并将其配置为超文本传输协议和https。 server.xml上的配置 web.xml配置 当jenkins没有被托管时,我能够使用上面的tomcat配置将http重定向到https。但在部署詹金斯之后。war将http重定向到https不起作用。 对于jenkins,将http重定向到https还需要其他配置更改吗?

  • 我需要一些上传图像的帮助。 我有两个不同的申请 在我的专用服务器上运行的Springstart应用程序 Angulal-6 Application-在我的云服务器上运行 我需要从我的spring boot应用程序上传一个图像到Angular-6资产文件夹(资产文件夹类似于spring boot应用程序的资源文件夹) 在application.properties我已经声明上传位置,如profile

  • 我正在尝试将Spring Boot应用程序作为WAR部署到tomcat服务器。我可以很好地构建war并将其部署到tomcat服务器。但是,当我启动服务器时,我的spring应用程序从未运行。服务器启动得很好。Spring要我做的我都做了, http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-creat

  • 我在本地系统上安装了laravel 5.1并开发了一个应用程序。 现在我必须在一个实时服务器上托管它。我们拥有的实时服务器是我们自己的,并且在其上运行许多其他应用程序。 我刚刚将laravel文件夹放在了一个路径中(没有其他内容),但它没有像我预期的那样工作。 我读过一些答案,上面说我必须将公用文件夹复制到服务器的公用文件夹中,其余的复制到一个文件夹中,对吗? 我必须安装作曲家,并按照larave

  • 我正在使用angular框架构建前端应用程序。有没有办法,我如何将应用程序部署到Azure Linux应用程序服务? 我已经用NodeJS堆栈创建了Web应用程序,并将其分配给Linux应用程序服务。我用命令构建了我的angular应用程序,并将其部署到这个web应用程序中。当我使用url: