Camel - Spring 启动安全 - REST - 发送错误凭据时出现 404

Camel - Spring Boot Security - REST - 404 on sending wrong credentials

这真是一个奇怪的错误。我正在尝试 spring camel restlets 端点的安全性

路线

from("restlet://test?restletMethod=GET").to("some endpoint");

添加了默认安全 jar

spring-boot-starter-security

Application.properties

security.basic.enabled=true
security.user.name=user

上下文配置

    @Bean
    public ServletRegistrationBean servletRegistrationBean() {
        SpringServerServlet servlet = new SpringServerServlet();
        DispatcherServlet dispatcherServlet = new DispatcherServlet();
        ServletRegistrationBean registration = new ServletRegistrationBean( servlet , "/*");

        registration.setName("restlet");

        Map<String,String> params = new HashMap<>();
        params.put("org.restlet.component", "restletComponent");

        registration.addInitParameter( "org.restlet.component", "restletComponent" );

        return registration;
    }

当运行APP作为spring启动应用程序时,会生成一个默认密码。

Using default security password: f701928f-29c6-448f-9640-430cc5f215be

现在,如果我使用正确的凭据调用其余部分,它就可以正常工作。但是,如果我使用 wrong credentials 调用,它会返回 404 not found

怎么了?

问题是 ServletRegistrationBean am Using ,它捕获 401 错误并将重定向发送到名为 /error.

的页面

不幸的是,没有解决这个问题。但是有一个解决方法。

有一个简单的休息 api 调用路径为 '/error' 和 return 你想要的任何输出。

例子

from("restlet:/error?restletMethods=GET").transform(simple("unauthorized"));