【问题标题】:How to remove auth request in Spring?如何在 Spring 中删除身份验证请求?
【发布时间】:2023-03-31 14:23:01
【问题描述】:

这条消息说:Required authorization. To access on the server http://localhhost:8080 you should enter login and password. Server message: Spring

我正在使用 Hibernate 4、Spring 4 和 Gradle。另外,我正在使用 Spring Boot。但即使我从tutorial 获得了飞机代码,也会出现此消息。是什么导致它以及如何摆脱它?怎么了?控制台中没有错误消息。

【问题讨论】:

  • 你只是想访问http://localhhost:8080吗?如果是 tomcat,则 tomcat 服务器要求您输入管理员凭据
  • @Chaitanya,我正在使用 Spring Boot。我正在尝试访问 localhost:8080/index,映射页面
  • 这是弹簧安全功能。编辑你的security.xml(取自web.xml)文件。

标签: java spring hibernate spring-mvc


【解决方案1】:

在你的项目中搜索security properties并设置

security.basic.enabled=false

http://docs.spring.io/spring-boot/docs/1.1.8.RELEASE/reference/htmlsingle/#howto-switch-off-spring-boot-security-configuration

在上面的链接中检查 66.1

来自文档:如果您在应用程序的任何位置使用 @EnableWebSecurity 定义 @Configuration,它将关闭 Spring Boot 中的默认 webapp 安全设置

【讨论】:

  • 你知道如何使用基于 Java 类的配置来广告这个属性吗?
  • 查看帖子中的编辑。在应用程序的任何类中使用 EnableWebSecurity 定义 @Configuration。
  • 而且 Tomcat 没有启动。我会在弄清楚如何应用它时标记答案。
【解决方案2】:

我很喜欢它,只需在文件application.properties 中添加security.basic.enabled=false,您可以在src/main/resouces 目录中找到它。 希望对你有帮助:) ps.这个文件是IDEA生成的,如果没有,自己创建吧。

【讨论】:

    【解决方案3】:

    看起来像一些基本身份验证。

    Basic-auth 典型配置在web.xml 或spring security。如果您的代码没有 spring 安全性,请检查 web.xml 是否有类似的内容:

     <security-constraint>
        <web-resource-collection>   
            <url-pattern>/</url-pattern>
            <url-pattern>/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <description>only registered user</description>
            <role-name>ROLE_USER</role-name>
        </auth-constraint>
    </security-constraint>
    

    并删除它。 (但是很可能需要验证的东西不能正常工作!

    【讨论】:

    • 我已经编辑了问题 - 我正在使用 Spring Boot。并且没有 Spring 或 web.xml 的 xml 设置。
    【解决方案4】:

    我在同一个教程中运行应用程序时遇到了同样的问题。

    我使用 IntelliJ IDEA 14.1.4 并在项目依赖项中选择了 Core_Security like that 而只需要 Web_Web 依赖项。

    然后我真的不知道如何删除它,所以我创建了没有它的新项目,问题就消失了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-08
      • 2015-04-30
      • 1970-01-01
      • 2014-01-15
      • 1970-01-01
      • 1970-01-01
      • 2021-07-03
      • 2019-12-22
      相关资源
      最近更新 更多