Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
philwebb committed Sep 8, 2015
1 parent 6740240 commit 6e29ee4
Show file tree
Hide file tree
Showing 125 changed files with 636 additions and 504 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ public class ManagementServerProperties implements SecurityPrerequisite {

private final Security security = maybeCreateSecurity();

private Security maybeCreateSecurity() {
if (ClassUtils.isPresent(SECURITY_CHECK_CLASS, null)) {
return new Security();
}
return null;
}

/**
* Returns the management port or {@code null} if the
* {@link ServerProperties#getPort() server port} should be used.
Expand Down Expand Up @@ -183,11 +190,4 @@ public void setEnabled(boolean enabled) {

}

private static Security maybeCreateSecurity() {
if (ClassUtils.isPresent(SECURITY_CHECK_CLASS, null)) {
return new Security();
}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ public void init(WebSecurity builder) throws Exception {
List<String> ignored = SpringBootWebSecurityConfiguration
.getIgnored(this.security);
if (!this.management.getSecurity().isEnabled()) {
ignored.addAll(Arrays
.asList(getEndpointPaths(this.endpointHandlerMapping)));
ignored.addAll(Arrays.asList(EndpointPaths
.get(this.endpointHandlerMapping)));
}
if (ignored.contains("none")) {
ignored.remove("none");
Expand Down Expand Up @@ -333,44 +333,48 @@ private RequestMatcher createDelegate() {
private String[] getPaths() {
EndpointHandlerMapping endpointHandlerMapping = ManagementWebSecurityConfigurerAdapter.this.endpointHandlerMapping;
if (this.sensitive) {
return getEndpointPaths(endpointHandlerMapping);
return EndpointPaths.get(endpointHandlerMapping);
}
return getEndpointPaths(endpointHandlerMapping, false);
return EndpointPaths.get(endpointHandlerMapping, false);
}

}

}

private static String[] getEndpointPaths(EndpointHandlerMapping endpointHandlerMapping) {
return StringUtils.mergeStringArrays(
getEndpointPaths(endpointHandlerMapping, false),
getEndpointPaths(endpointHandlerMapping, true));
}
private static class EndpointPaths {

private static String[] getEndpointPaths(
EndpointHandlerMapping endpointHandlerMapping, boolean secure) {
if (endpointHandlerMapping == null) {
return NO_PATHS;
public static String[] get(EndpointHandlerMapping endpointHandlerMapping) {
String[] insecure = get(endpointHandlerMapping, false);
String[] secure = get(endpointHandlerMapping, true);
return StringUtils.mergeStringArrays(insecure, secure);
}
Set<? extends MvcEndpoint> endpoints = endpointHandlerMapping.getEndpoints();
Set<String> paths = new LinkedHashSet<String>(endpoints.size());
for (MvcEndpoint endpoint : endpoints) {
if (endpoint.isSensitive() == secure) {
String path = endpointHandlerMapping.getPath(endpoint.getPath());
paths.add(path);
if (!path.equals("")) {
// Ensure that nested paths are secured
paths.add(path + "/**");
// Add Spring MVC-generated additional paths
paths.add(path + ".*");
}
else {
paths.add("/");

public static String[] get(EndpointHandlerMapping endpointHandlerMapping,
boolean secure) {
if (endpointHandlerMapping == null) {
return NO_PATHS;
}
Set<? extends MvcEndpoint> endpoints = endpointHandlerMapping.getEndpoints();
Set<String> paths = new LinkedHashSet<String>(endpoints.size());
for (MvcEndpoint endpoint : endpoints) {
if (endpoint.isSensitive() == secure) {
String path = endpointHandlerMapping.getPath(endpoint.getPath());
paths.add(path);
if (!path.equals("")) {
// Ensure that nested paths are secured
paths.add(path + "/**");
// Add Spring MVC-generated additional paths
paths.add(path + ".*");
}
else {
paths.add("/");
}
}
}
return paths.toArray(new String[paths.size()]);
}
return paths.toArray(new String[paths.size()]);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public DefaultGaugeService gaugeService() {
}

@Configuration
@ConditionalOnJava(value = JavaVersion.EIGHT)
@ConditionalOnJava(JavaVersion.EIGHT)
@ConditionalOnMissingBean(GaugeService.class)
static class FastMetricServicesConfiguration {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public static HalBrowserLocation getHalBrowserLocation(ResourceLoader resourceLo
}
}
catch (Exception ex) {
// Ignore
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public ActuatorHalJsonEndpoint(ManagementServletContext managementServletContext

private String getDefaultPath(ManagementServletContext managementServletContext) {
if (StringUtils.hasText(managementServletContext.getContextPath())) {
return this.path = "";
return "";
}
return "/actuator";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public void reset(String name) {
/**
* Simple {@link Gauge} implementation to {@literal double} value.
*/
private static class SimpleGauge implements Gauge<Double> {
private final static class SimpleGauge implements Gauge<Double> {

private final double value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
*
* @author Luke Taylor
*/
class RedisUtils {
final class RedisUtils {

private RedisUtils() {
}

static <K, V> RedisTemplate<K, V> createRedisTemplate(
RedisConnectionFactory connectionFactory, Class<V> valueClass) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void reset(String metricName) {
/**
* Simple {@link Gauge} implementation to {@literal double} value.
*/
private static class SimpleGauge implements Gauge<Double> {
private final static class SimpleGauge implements Gauge<Double> {

private final double value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
*
* @author Phillip Webb
*/
class SystemProperties {
final class SystemProperties {

private SystemProperties() {
}

public static String get(String... properties) {
for (String property : properties) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,18 +269,18 @@ static class MultipleDataSourcesConfig {

@Bean
public DataSource tomcatDataSource() {
return initializeBuilder().type(org.apache.tomcat.jdbc.pool.DataSource.class)
.build();
return InitalizedBuilder.create()
.type(org.apache.tomcat.jdbc.pool.DataSource.class).build();
}

@Bean
public DataSource hikariDS() {
return initializeBuilder().type(HikariDataSource.class).build();
return InitalizedBuilder.create().type(HikariDataSource.class).build();
}

@Bean
public DataSource commonsDbcpDataSource() {
return initializeBuilder().type(BasicDataSource.class).build();
return InitalizedBuilder.create().type(BasicDataSource.class).build();
}
}

Expand All @@ -290,13 +290,13 @@ static class MultipleDataSourcesWithPrimaryConfig {
@Bean
@Primary
public DataSource myDataSource() {
return initializeBuilder().type(org.apache.tomcat.jdbc.pool.DataSource.class)
.build();
return InitalizedBuilder.create()
.type(org.apache.tomcat.jdbc.pool.DataSource.class).build();
}

@Bean
public DataSource commonsDbcpDataSource() {
return initializeBuilder().type(BasicDataSource.class).build();
return InitalizedBuilder.create().type(BasicDataSource.class).build();
}
}

Expand All @@ -306,13 +306,13 @@ static class MultipleDataSourcesWithCustomPrimaryConfig {
@Bean
@Primary
public DataSource myDataSource() {
return initializeBuilder().type(org.apache.tomcat.jdbc.pool.DataSource.class)
.build();
return InitalizedBuilder.create()
.type(org.apache.tomcat.jdbc.pool.DataSource.class).build();
}

@Bean
public DataSource dataSource() {
return initializeBuilder().type(BasicDataSource.class).build();
return InitalizedBuilder.create().type(BasicDataSource.class).build();
}
}

Expand All @@ -331,11 +331,6 @@ protected String createPrefix(String dataSourceName,
}
}

private static DataSourceBuilder initializeBuilder() {
return DataSourceBuilder.create().driverClassName("org.hsqldb.jdbc.JDBCDriver")
.url("jdbc:hsqldb:mem:test").username("sa");
}

@Configuration
static class RichGaugeReaderConfig {

Expand Down Expand Up @@ -385,4 +380,13 @@ public CacheManager second() {

}

private static class InitalizedBuilder {

public static DataSourceBuilder create() {
return DataSourceBuilder.create()
.driverClassName("org.hsqldb.jdbc.JDBCDriver")
.url("jdbc:hsqldb:mem:test").username("sa");
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -294,18 +294,6 @@ public static class Foo {

private String name = "654321";

public static class Bar {
private String name = "123456";

public String getName() {
return this.name;
}

public void setName(String name) {
this.name = name;
}
}

private Bar bar = new Bar();

public Bar getBar() {
Expand All @@ -329,6 +317,18 @@ public String getSummary() {
return "Name: " + this.name;
}

public static class Bar {
private String name = "123456";

public String getName() {
return this.name;
}

public void setName(String name) {
this.name = name;
}
}

}

public static class Cycle extends Foo {
Expand All @@ -346,6 +346,7 @@ public Foo getSelf() {
public void setSelf(Foo self) {
this.self = self;
}

}

public static class MapHolder extends Foo {
Expand All @@ -359,6 +360,7 @@ public Map<String, Object> getMap() {
public void setMap(Map<String, Object> map) {
this.map = map;
}

}

public static class ListHolder extends Foo {
Expand All @@ -372,6 +374,7 @@ public List<String> getList() {
public void setList(List<String> list) {
this.list = list;
}

}

public static class Addressed extends Foo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public class MetricsEndpointTests extends AbstractEndpointTests<MetricsEndpoint>

private Metric<Number> metric1 = new Metric<Number>("a", 1);

private Metric<Number> metric2 = new Metric<Number>("b", 2);;
private Metric<Number> metric2 = new Metric<Number>("b", 2);

private Metric<Number> metric3 = new Metric<Number>("c", 3);;
private Metric<Number> metric3 = new Metric<Number>("c", 3);

public MetricsEndpointTests() {
super(Config.class, MetricsEndpoint.class, "metrics", true, "endpoints.metrics");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private <T> void assertDetail(Map<String, Object> details, String detail, T valu
assertThat((T) details.get(detail), is(equalTo(value)));
}

private static class StubClusterHealthResponse extends ClusterHealthResponse {
private final static class StubClusterHealthResponse extends ClusterHealthResponse {

private final ClusterHealthStatus status;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.doThrow;
import static org.mockito.BDDMockito.willThrow;
import static org.mockito.Mockito.mock;

/**
Expand Down Expand Up @@ -72,7 +72,7 @@ public void smtpIsUp() {

@Test
public void smtpIsDown() throws MessagingException {
doThrow(new MessagingException("A test exception")).when(this.mailSender)
willThrow(new MessagingException("A test exception")).given(this.mailSender)
.testConnection();
Health health = this.indicator.health();
assertEquals(Status.DOWN, health.getStatus());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public void run() {
.getData(), Charset.forName("UTF-8")).trim());
}
catch (Exception e) {
// Ignore
}
}
}).start();
Expand All @@ -135,6 +136,7 @@ public void waitForMessage() {
Thread.sleep(50L);
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
Expand Down
Loading

0 comments on commit 6e29ee4

Please sign in to comment.