gpt4 book ai didi

java - 无法使执行器端点在旧版Spring Boot项目中工作-获取身份验证页面

转载 作者:行者123 更新时间:2023-12-04 17:22:05 25 4
gpt4 key购买 nike

Spring Boot执行器已包含在POM中,并显示在启动日志中。
但是,当我尝试访问/ actuator甚至项目的基本URL时,都会得到以下内容-

{
"timestamp": 1577096144986,
"status": 401,
"error": "Unauthorized",
"message": "Full authentication is required to access this resource",
"path": "/actuator"
}

我读到可能为端点设置了基本的HTTP身份验证。
我在配置属性中查找了spring.security.user.name,密码,但找不到任何密码。

如果我按下 http://localhost:8083/actuator或什至 http://localhost:8083/或任何其他映射的API端点以外的URL,看来我在浏览器上收到此密码提示-

enter image description here

在应用程序日志中,我得到了-
2019-12-23 19:30:54,489 75773 [XNIO-3 task-3] INFO  c.c.common.web.LoggerInterceptor [LoggerInterceptor.java:42] - Visitor [okp91Dj1NzT2KPPUjaUvhqEg4oOhwPQ49I9LTR2z] [GET] [/error] [1ms] [OK]
2019-12-23 19:30:54,493 75777 [XNIO-3 task-3] ERROR org.apache.velocity [CommonsLogLogChute.java:96] - ResourceManager : unable to find resource 'error.vm' in any resource loader.

输入凭据后,它将失败,并再次出现密码提示,并重复上述相同的日志。

更新

Spring 启动版本-1.5.2.RELEASE。

/ src / main / resources中有一个web.xml。它具有以下-
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:META-INF/spring/applicationContext*.xml
classpath*:com.packagename
/WEB-INF/spring/oauth-security.xml
/WEB-INF/spring/security-config.xml
classpath*:META-INF/gateway/*.xml
</param-value>
</context-param>

我可以在此微服务组件中找到oauth-security.xml和security.xml文件。

oauth-security.xml具有基于oauth范围的API路径定义-
 <sec:http pattern="/service/v2/**"
create-session="never"
entry-point-ref="oauthAuthenticationEntryPoint"
access-decision-manager-ref="accessDecisionManager">
<sec:intercept-url pattern="/some/path/v2/profile/**" access="ROLE_USER,SCOPE_PROFILE" method="GET"/>

我看到了导入webmvc-config.xml的security-config.xml。

我在security-config.xml中看到了其中一些-
<sec:http pattern="/somepath/**">
<sec:intercept-url pattern="/somepath/**" access="ROLE_USER"/>
<sec:http-basic/>
</sec:http>

但我在任何地方都看不到/ **路径的任何配置。

更新2

我检查了在名为customscopes.properties的文件中似乎也有auth配置,这似乎是一个自定义文件,像这样添加到webmvc-config.xml中-
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="ignoreResourceNotFound" value="true" />
<property name="locations">
<list>
<value>classpath:/spring/application.properties</value>
<value>classpath:/spring/local.properties</value>
<value>classpath:/spring/customscopes.properties</value>
<value> file:${project.config.dir}/application.properties </value>
<value>file:${project.config.dir}/customscopes.properties</value>
</list>
</property>
</bean>

customscopes.properties具有此类网址-

service / v2 / path / ** = SCOPE_SOMETHING;

同时,oauth-security.xml中有相同的网址-
<sec:intercept-url pattern="/service/v2/path/**" access="SCOPE_SOMETHING"/>

我不确定为什么有两套配置。我尝试一个接一个地更改它们,同时使另一个保持身份验证。我观察到,只有更改customscopes.properties才会受到影响-
service/v2/path/**=IS_AUTHENTICATED_ANONYMOUSLY;

我也是Spring Security的新手。我检查了此 video tutorial,但在我的项目中找不到那些提到的config方法。没有提到WebSecurityConfigurerAdapter。

但是,在这两个文件上都使用IS_AUTHENTICATED_ANONYMOUSLY添加执行器/ **的路径不起作用-开头显示为401错误。

更新3

哦,另一件事-security-config.xml包含
<sec:http pattern="/favicon.ico" security="none"/>

当我访问 http://localhost:8083/actuator/http://localhost:8083/somethingelse/时,我看到日志中的差异

http://localhost:8083/actuator/

第1步-点击此网址-日志-
2019-12-24 12:31:03,051 590999 [XNIO-3 task-16] INFO  c.c.common.web.LoggerInterceptor [LoggerInterceptor.java:42] - Visitor [OICBz6CqYzI58UqobnBYNEXsZUNErjBkv6wEUUkX] [GET] [/error] [2ms] [OK]
2019-12-24 12:31:03,054 591002 [XNIO-3 task-16] ERROR org.apache.velocity [CommonsLogLogChute.java:96] - ResourceManager : unable to find resource 'error.vm' in any resource loader.

第2步-取消登录表单-获取favicon.ico而不是/ error-
2019-12-24 12:31:18,641 606589 [XNIO-3 task-20] ERROR org.apache.velocity [CommonsLogLogChute.java:96] - ResourceManager : unable to find resource 'error.vm' in any resource loader.
2019-12-24 12:31:18,912 606860 [XNIO-3 task-21] INFO c.c.common.web.LoggerInterceptor [LoggerInterceptor.java:42] - Visitor [OICBz6CqYzI58UqobnBYNEXsZUNErjBkv6wEUUkX] [GET] [/favicon.ico] [2ms] [OK]

http://localhost:8083/somethingelse

第1步-点击此网址-日志-
2019-12-24 12:31:03,051 590999 [XNIO-3 task-16] INFO  c.c.common.web.LoggerInterceptor [LoggerInterceptor.java:42] - Visitor [OICBz6CqYzI58UqobnBYNEXsZUNErjBkv6wEUUkX] [GET] [/error] [2ms] [OK]
2019-12-24 12:31:03,054 591002 [XNIO-3 task-16] ERROR org.apache.velocity [CommonsLogLogChute.java:96] - ResourceManager : unable to find resource 'error.vm' in any resource loader.

步骤2-取消登录表单-再次使用与上述相同的日志

更新4

如果我添加了一个扩展WebSecurityConfigurerAdapter的类,而只针对我所需的路径添加了allowAll()-
@Override
protected void configure(HttpSecurity http) throws Exception {
http.
authorizeRequests().antMatchers("/service/trace/**").permitAll()
.antMatchers("/service/actuator/**").permitAll()
.antMatchers("/actuator/**").permitAll()
.antMatchers("/trace").permitAll()
.antMatchers("/actuator").permitAll();
}

这次我遇到了其他错误(找不到404)-
{
"timestamp": 1577181851520,
"status": 404,
"error": "Not Found",
"message": "Not Found",
"path": "/service/trace"
}

注意-我不确定哪些是可用的执行器端点,因此我尝试确保所有这些组合。如果可以在此基础上进行确认,请参阅下面的应用程序启动日志。

我针对所有这些网址收到404错误-
http://localhost:8083/service/actuator/beans
http://localhost:8083/actuator/beans
http://localhost:8083/beans

我的其他经过身份验证的API端点开始出现此错误-
{
"timestamp": 1577181062281,
"status": 403,
"error": "Forbidden",
"message": "Could not verify the provided CSRF token because your session was not found.",
"path": "/service/v2/some/end/point"
}

另外,我发现我们在web.xml中也定义了这些过滤器。因此,似乎有Spring配置以及Spring Boot附加功能。如果我的理解是错误的,请纠正我。
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

因此,问题归结为-

我无法访问执行器端点。我在包含启动器的应用程序启动日志中看到以下内容,但我似乎也无法加载它们。我猜想Spring安全性介于两者之间,但无法防止相同情况发生。
2019-12-24 14:14:10,769 14209 [main] INFO  o.s.b.a.e.m.EndpointHandlerMapping [AbstractHandlerMethodMapping.java:543] - Mapped "{[/beans || /beans.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2019-12-24 14:14:10,770 14210 [main] INFO o.s.b.a.e.m.EndpointHandlerMapping [AbstractHandlerMethodMapping.java:543] - Mapped "{[/health || /health.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint.invoke(javax.servlet.http.HttpServletRequest,java.security.Principal)
2019-12-24 14:14:10,771 14211 [main] INFO o.s.b.a.e.m.EndpointHandlerMapping [AbstractHandlerMethodMapping.java:543] - Mapped "{[/autoconfig || /autoconfig.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2019-12-24 14:14:10,772 14212 [main] INFO o.s.b.a.e.m.EndpointHandlerMapping [AbstractHandlerMethodMapping.java:543] - Mapped "{[/metrics/{name:.*}],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.MetricsMvcEndpoint.value(java.lang.String)
2019-12-24 14:14:10,772 14212 [main] INFO o.s.b.a.e.m.EndpointHandlerMapping [AbstractHandlerMethodMapping.java:543] - Mapped "{[/metrics || /metrics.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()

注意 -
  • 我在application.properties中添加了management.endpoints.web.exposure.include = *
  • 无法看到这样的内容-

    2019-12-24 15:57:41.245 INFO 37683 --- [main] o.s.b.a.e.web.EndpointLinksResolver:在基本路径'/ actuator'下暴露18个端点

    Intellij的外部库中有
  • spring-boot-starter-actuator-1.5.2.RELEASE.jar。
  • 最佳答案

    由于未在端点上启用安全性,因此发生错误。
    对于本地部署的应用程序,将以下配置添加到application.properties文件中-

    management.security.enabled = false

    在生产应用程序上,需要进行更仔细的配置。

    关于java - 无法使执行器端点在旧版Spring Boot项目中工作-获取身份验证页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59456689/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com