首页 > 解决方案 > 我的 heroku 应用程序正在请求一个我没有放在那里的密码

问题描述

我不熟悉将应用程序发送到生产的过程,我正在使用 Heroku 免费计划进行测试。今天我去检查我的应用程序,我使用 Spring boot 制作的 API 无法正常工作,并且正在请求我没有做的登录。我的应用程序地址是https://erik-financial-api.herokuapp.com,当你去那里时,它会将你重定向到地址https://erik-financial-api.herokuapp.com/login,其中包含以下内容:

在此处输入图像描述

我没有创建此页面,并且没有任何密码(来自我的应用程序或来自我的 Heroku 帐户)可以使用它。这应该只是另一个前端应用程序的 REST API。有谁知道为什么会这样?

这个项目的代码可以在我的 GitHub 上找到https://github.com/esscheffer/financial-api

编辑:这似乎是一个默认的弹簧安全登录页面。我一直在寻找解决方案,但到目前为止都没有。我试过的:

添加

override fun configure(security: HttpSecurity) {
    security.httpBasic().disable()
            .formLogin().disable()
}

到我的WebSecurityConfigurerAdapter课。

添加http.httpBasic().disable().formLogin().disable()configure我的ResourceServerConfigurerAdapter班级。

添加(exclude = [SecurityAutoConfiguration::class])@SpringBootApplication我的应用程序类的卫生。

前 2 次尝试没有删除登录页面,最后一次尝试破坏了应用程序,所有页面都返回 404。请注意,这只发生在我将应用程序部署到 Heroku 时。在本地运行时,我没有此登录页面或任何其他问题。

标签: herokuspring-security

解决方案


添加一个新的配置类com.scheffer.erik.financial.api.config.SecurityConfig,在配置方法中,您可以禁用 HTTP 基本身份验证以及基于登录表单的身份验证,如下所示:

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity security) throws Exception {
        security
                .httpBasic().disable()
                .formLogin().disable();
    }
}

推荐阅读