Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
461202bc
Commit
461202bc
authored
Jun 06, 2018
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
EndpointRequest uses empty servlet path if not available
Fixes gh-13399
parent
7cbbd95f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
6 deletions
+35
-6
EndpointRequest.java
...tuate/autoconfigure/security/servlet/EndpointRequest.java
+22
-4
EndpointRequestTests.java
.../autoconfigure/security/servlet/EndpointRequestTests.java
+13
-2
No files found.
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/security/servlet/EndpointRequest.java
View file @
461202bc
...
...
@@ -137,9 +137,10 @@ public final class EndpointRequest {
private
RequestMatcher
createDelegate
(
WebApplicationContext
context
)
{
try
{
RequestMatcherFactory
requestMatcherFactory
=
new
RequestMatcherFactory
(
context
.
getBean
(
DispatcherServletPathProvider
.
class
)
.
getServletPath
());
String
servletPath
=
getServletPath
(
context
);
RequestMatcherFactory
requestMatcherFactory
=
(
StringUtils
.
hasText
(
servletPath
)
?
new
RequestMatcherFactory
(
servletPath
)
:
RequestMatcherFactory
.
withEmptyServletPath
());
return
createDelegate
(
context
,
requestMatcherFactory
);
}
catch
(
NoSuchBeanDefinitionException
ex
)
{
...
...
@@ -147,6 +148,16 @@ public final class EndpointRequest {
}
}
private
String
getServletPath
(
WebApplicationContext
context
)
{
try
{
return
context
.
getBean
(
DispatcherServletPathProvider
.
class
)
.
getServletPath
();
}
catch
(
NoSuchBeanDefinitionException
ex
)
{
return
""
;
}
}
protected
abstract
RequestMatcher
createDelegate
(
WebApplicationContext
context
,
RequestMatcherFactory
requestMatcherFactory
);
...
...
@@ -279,11 +290,14 @@ public final class EndpointRequest {
private
final
String
servletPath
;
private
static
final
RequestMatcherFactory
EMPTY_SERVLET_PATH
=
new
RequestMatcherFactory
(
""
);
RequestMatcherFactory
(
String
servletPath
)
{
this
.
servletPath
=
servletPath
;
}
public
RequestMatcher
antPath
(
String
...
parts
)
{
RequestMatcher
antPath
(
String
...
parts
)
{
String
pattern
=
(
this
.
servletPath
.
equals
(
"/"
)
?
""
:
this
.
servletPath
);
for
(
String
part
:
parts
)
{
pattern
+=
part
;
...
...
@@ -291,6 +305,10 @@ public final class EndpointRequest {
return
new
AntPathRequestMatcher
(
pattern
);
}
static
RequestMatcherFactory
withEmptyServletPath
()
{
return
EMPTY_SERVLET_PATH
;
}
}
}
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/servlet/EndpointRequestTests.java
View file @
461202bc
...
...
@@ -86,6 +86,15 @@ public class EndpointRequestTests {
assertMatcher
(
matcher
,
"/actuator"
,
"/spring"
).
doesNotMatch
(
""
,
"/actuator/foo"
);
}
@Test
public
void
toAnyEndpointWhenDispatcherServletPathProviderNotAvailableUsesEmptyPath
()
{
RequestMatcher
matcher
=
EndpointRequest
.
toAnyEndpoint
();
assertMatcher
(
matcher
,
"/actuator"
,
null
).
matches
(
"/actuator/foo"
);
assertMatcher
(
matcher
,
"/actuator"
,
null
).
matches
(
"/actuator/bar"
);
assertMatcher
(
matcher
,
"/actuator"
,
null
).
matches
(
"/actuator"
);
assertMatcher
(
matcher
,
"/actuator"
,
null
).
doesNotMatch
(
"/actuator/baz"
);
}
@Test
public
void
toEndpointClassShouldMatchEndpointPath
()
{
RequestMatcher
matcher
=
EndpointRequest
.
to
(
FooEndpoint
.
class
);
...
...
@@ -245,8 +254,10 @@ public class EndpointRequestTests {
properties
.
setBasePath
(
pathMappedEndpoints
.
getBasePath
());
}
}
DispatcherServletPathProvider
pathProvider
=
()
->
servletPath
;
context
.
registerBean
(
DispatcherServletPathProvider
.
class
,
()
->
pathProvider
);
if
(
servletPath
!=
null
)
{
DispatcherServletPathProvider
pathProvider
=
()
->
servletPath
;
context
.
registerBean
(
DispatcherServletPathProvider
.
class
,
()
->
pathProvider
);
}
return
assertThat
(
new
RequestMatcherAssert
(
context
,
matcher
));
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment