Polish
This commit is contained in:
@@ -24,6 +24,7 @@ import org.springframework.boot.endpoint.EndpointPathResolver;
|
||||
* actuator endpoint paths based on the endpoint id and management.context-path.
|
||||
*
|
||||
* @author Madhura Bhave
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public class ManagementEndpointPathResolver implements EndpointPathResolver {
|
||||
|
||||
|
||||
@@ -52,10 +52,8 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur
|
||||
@ConditionalOnClass({ AuthenticationManager.class,
|
||||
GlobalAuthenticationConfigurerAdapter.class })
|
||||
@EnableConfigurationProperties(SecurityProperties.class)
|
||||
@Import({ SpringBootWebSecurityConfiguration.class,
|
||||
WebSecurityEnablerConfiguration.class,
|
||||
AuthenticationManagerConfiguration.class,
|
||||
SecurityDataConfiguration.class })
|
||||
@Import({ SpringBootWebSecurityConfiguration.class, WebSecurityEnablerConfiguration.class,
|
||||
AuthenticationManagerConfiguration.class, SecurityDataConfiguration.class })
|
||||
public class SecurityAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -108,11 +108,6 @@ public class SecurityProperties implements SecurityPrerequisite {
|
||||
*/
|
||||
private boolean enabled = true;
|
||||
|
||||
/**
|
||||
* Security authorize mode to apply.
|
||||
*/
|
||||
private SecurityAuthorizeMode authorizeMode = SecurityAuthorizeMode.ROLE;
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
@@ -33,11 +33,11 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
|
||||
/**
|
||||
* Provides request matchers that can be used to
|
||||
* configure security for static resources and the error controller path in a custom
|
||||
* {@link WebSecurityConfigurerAdapter}.
|
||||
* Provides request matchers that can be used to configure security for static resources
|
||||
* and the error controller path in a custom {@link WebSecurityConfigurerAdapter}.
|
||||
*
|
||||
* @author Madhura Bhave
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public final class SpringBootSecurity {
|
||||
|
||||
@@ -46,14 +46,15 @@ public final class SpringBootSecurity {
|
||||
*/
|
||||
public final static String ALL_ENDPOINTS = "**";
|
||||
|
||||
private static String[] STATIC_RESOURCES = new String[]{"/css/**", "/js/**",
|
||||
"/images/**", "/webjars/**", "/**/favicon.ico"};
|
||||
private static String[] STATIC_RESOURCES = new String[] { "/css/**", "/js/**",
|
||||
"/images/**", "/webjars/**", "/**/favicon.ico" };
|
||||
|
||||
private final EndpointPathResolver endpointPathResolver;
|
||||
|
||||
private final ErrorController errorController;
|
||||
|
||||
SpringBootSecurity(EndpointPathResolver endpointPathResolver, ErrorController errorController) {
|
||||
SpringBootSecurity(EndpointPathResolver endpointPathResolver,
|
||||
ErrorController errorController) {
|
||||
this.endpointPathResolver = endpointPathResolver;
|
||||
this.errorController = errorController;
|
||||
}
|
||||
@@ -67,7 +68,8 @@ public final class SpringBootSecurity {
|
||||
Assert.notEmpty(ids, "At least one endpoint id must be specified.");
|
||||
List<String> pathList = Arrays.asList(ids);
|
||||
if (pathList.contains(ALL_ENDPOINTS)) {
|
||||
return new AntPathRequestMatcher(this.endpointPathResolver.resolvePath(ALL_ENDPOINTS), null);
|
||||
return new AntPathRequestMatcher(this.endpointPathResolver.resolvePath(
|
||||
ALL_ENDPOINTS), null);
|
||||
}
|
||||
return getEndpointsRequestMatcher(pathList);
|
||||
}
|
||||
@@ -84,7 +86,8 @@ public final class SpringBootSecurity {
|
||||
if (e.isAnnotationPresent(Endpoint.class)) {
|
||||
return e.getAnnotation(Endpoint.class).id();
|
||||
}
|
||||
throw new IllegalArgumentException("Only classes annotated with @Endpoint are supported.");
|
||||
throw new IllegalArgumentException(
|
||||
"Only classes annotated with @Endpoint are supported.");
|
||||
}).collect(Collectors.toList());
|
||||
return getEndpointsRequestMatcher(paths);
|
||||
}
|
||||
@@ -104,7 +107,8 @@ public final class SpringBootSecurity {
|
||||
*/
|
||||
public RequestMatcher error() {
|
||||
if (this.errorController == null) {
|
||||
throw new IllegalStateException("Path for error controller could not be determined.");
|
||||
throw new IllegalStateException(
|
||||
"Path for error controller could not be determined.");
|
||||
}
|
||||
String path = normalizePath(this.errorController.getErrorPath());
|
||||
return new AntPathRequestMatcher(path + "/**", null);
|
||||
@@ -121,9 +125,9 @@ public final class SpringBootSecurity {
|
||||
|
||||
private static RequestMatcher getRequestMatcher(String... paths) {
|
||||
List<RequestMatcher> matchers = new ArrayList<>();
|
||||
for (String path : paths) {
|
||||
matchers.add(new AntPathRequestMatcher(path, null));
|
||||
}
|
||||
for (String path : paths) {
|
||||
matchers.add(new AntPathRequestMatcher(path, null));
|
||||
}
|
||||
return new OrRequestMatcher(matchers);
|
||||
}
|
||||
|
||||
@@ -134,5 +138,6 @@ public final class SpringBootSecurity {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -30,11 +30,12 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur
|
||||
/**
|
||||
* The default configuration for web security. It relies on Spring Security's
|
||||
* content-negotiation strategy to determine what sort of authentication to use.
|
||||
* If the user specifies their own {@link WebSecurityConfigurerAdapter}, this will back-off
|
||||
* completely and the users should specify all the bits that they want to configure as part
|
||||
* of the custom security configuration.
|
||||
* If the user specifies their own {@link WebSecurityConfigurerAdapter}, this will
|
||||
* back-off completely and the users should specify all the bits that they want to
|
||||
* configure as part of the custom security configuration.
|
||||
*
|
||||
* @author Madhura Bhave
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@ConditionalOnProperty(prefix = "security.basic", name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
@ConditionalOnClass(EnableWebSecurity.class)
|
||||
|
||||
@@ -25,12 +25,13 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
|
||||
/**
|
||||
* If there is a bean of type WebSecurityConfigurerAdapter,
|
||||
* this adds the {@code @EnableWebSecurity} annotation if it is not already specified.
|
||||
* This will make sure that the annotation is present with default security autoconfiguration
|
||||
* and also if the user adds custom security and forgets to add the annotation.
|
||||
* If there is a bean of type WebSecurityConfigurerAdapter, this adds the
|
||||
* {@code @EnableWebSecurity} annotation if it is not already specified. This will make
|
||||
* sure that the annotation is present with default security auto-configuration and also
|
||||
* if the user adds custom security and forgets to add the annotation.
|
||||
*
|
||||
* @author Madhura Bhave
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@ConditionalOnBean(WebSecurityConfigurerAdapter.class)
|
||||
@ConditionalOnClass(EnableWebSecurity.class)
|
||||
|
||||
@@ -21,6 +21,7 @@ package org.springframework.boot.endpoint;
|
||||
* resolving endpoint paths.
|
||||
*
|
||||
* @author Madhura Bhave
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public class DefaultEndpointPathResolver implements EndpointPathResolver {
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@ public interface EndpointPathResolver {
|
||||
|
||||
/**
|
||||
* Resolve endpoint path based on id.
|
||||
*
|
||||
* @param endpointId the endpoint id
|
||||
* @return the resolved path
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user