Commit 01e66ecb authored by Stephane Nicoll's avatar Stephane Nicoll

Merge branch '1.4.x' into 1.5.x

parents 389acb09 4311cf33
...@@ -14,58 +14,52 @@ ...@@ -14,58 +14,52 @@
* limitations under the License. * limitations under the License.
*/ */
package sample.actuator.nosecurity; package org.springframework.boot.actuate.autoconfigure;
import java.util.Arrays;
import java.util.Map;
import org.junit.After;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.testutil.ClassPathExclusions;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.testutil.FilteredClassPathRunner;
import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Basic integration tests for demo application. * Tests for {@link ManagementServerPropertiesAutoConfiguration} when Spring Security is
* not present.
* *
* @author Phillip Webb * @author Stephane Nicoll
*/ */
@RunWith(SpringRunner.class) @RunWith(FilteredClassPathRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) @ClassPathExclusions("spring-security-*.jar")
@DirtiesContext public class ManagementServerPropertiesAutoConfigurationNoSecurityTests {
public class SampleActuatorNoSecurityApplicationTests {
@Autowired private AnnotationConfigApplicationContext context;
private TestRestTemplate restTemplate;
@Test @After
public void testHome() throws Exception { public void close() {
HttpHeaders headers = new HttpHeaders(); if (this.context != null) {
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); this.context.close();
ResponseEntity<String> entity = this.restTemplate.exchange("/", HttpMethod.GET, }
new HttpEntity<Void>(headers), String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("<title>Hello");
} }
@Test @Test
public void testMetrics() throws Exception { public void securitySettingsIgnoredWithoutSpringSecurity() {
@SuppressWarnings("rawtypes") ManagementServerProperties properties =
ResponseEntity<Map> entity = this.restTemplate.getForEntity("/metrics", load("management.security.enabled=false");
Map.class); assertThat(properties.getSecurity().isEnabled()).isFalse();
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); }
public ManagementServerProperties load(String... environment) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(ctx, environment);
ctx.register(ManagementServerPropertiesAutoConfiguration.class);
ctx.refresh();
this.context = ctx;
return this.context.getBean(ManagementServerProperties.class);
} }
} }
...@@ -19,10 +19,8 @@ package org.springframework.boot.actuate.autoconfigure; ...@@ -19,10 +19,8 @@ package org.springframework.boot.actuate.autoconfigure;
import org.junit.After; import org.junit.After;
import org.junit.Test; import org.junit.Test;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
...@@ -89,16 +87,10 @@ public class ManagementServerPropertiesAutoConfigurationTests { ...@@ -89,16 +87,10 @@ public class ManagementServerPropertiesAutoConfigurationTests {
public ManagementServerProperties load(String... environment) { public ManagementServerProperties load(String... environment) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(ctx, environment); EnvironmentTestUtils.addEnvironment(ctx, environment);
ctx.register(TestConfiguration.class); ctx.register(ManagementServerPropertiesAutoConfiguration.class);
ctx.refresh(); ctx.refresh();
this.context = ctx; this.context = ctx;
return this.context.getBean(ManagementServerProperties.class); return this.context.getBean(ManagementServerProperties.class);
} }
@Configuration
@EnableConfigurationProperties(ManagementServerProperties.class)
static class TestConfiguration {
}
} }
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
<module>spring-boot-sample-activemq</module> <module>spring-boot-sample-activemq</module>
<module>spring-boot-sample-actuator</module> <module>spring-boot-sample-actuator</module>
<module>spring-boot-sample-actuator-log4j2</module> <module>spring-boot-sample-actuator-log4j2</module>
<module>spring-boot-sample-actuator-no-security</module>
<module>spring-boot-sample-actuator-noweb</module> <module>spring-boot-sample-actuator-noweb</module>
<module>spring-boot-sample-actuator-ui</module> <module>spring-boot-sample-actuator-ui</module>
<module>spring-boot-sample-amqp</module> <module>spring-boot-sample-amqp</module>
......
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<!-- Your own application should inherit from spring-boot-starter-parent -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-samples</artifactId>
<version>1.5.0.BUILD-SNAPSHOT</version>
</parent>
<artifactId>spring-boot-sample-actuator-no-security</artifactId>
<name>Spring Boot Actuator UI Sample</name>
<description>Spring Boot Actuator No Security Sample</description>
<url>http://projects.spring.io/spring-boot/</url>
<organization>
<name>Pivotal Software, Inc.</name>
<url>http://www.spring.io</url>
</organization>
<properties>
<main.basedir>${basedir}/../..</main.basedir>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
/*
* Copyright 2012-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package sample.actuator.nosecurity;
import java.util.Date;
import java.util.Map;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@SpringBootApplication
@Controller
public class SampleActuatorNoSecurityApplication {
@GetMapping("/")
public String home(Map<String, Object> model) {
model.put("message", "Hello World");
model.put("title", "Hello Home");
model.put("date", new Date());
return "home";
}
@RequestMapping("/foo")
public String foo() {
throw new RuntimeException("Expected exception in controller");
}
public static void main(String[] args) throws Exception {
SpringApplication.run(SampleActuatorNoSecurityApplication.class, args);
}
}
<#import "/spring.ftl" as spring />
<!DOCTYPE html>
<html>
<head>
<title>Error</title>
<#assign home><@spring.url relativeUrl="/"/></#assign>
<#assign bootstrap><@spring.url relativeUrl="/css/bootstrap.min.css"/></#assign>
<link rel="stylesheet" href="${bootstrap}" />
</head>
<body>
<div class="container">
<div class="navbar">
<div class="navbar-inner">
<a class="brand" href="http://freemarker.org/"> FreeMarker -
Plain </a>
<ul class="nav">
<li><a href="${home}"> Home </a></li>
</ul>
</div>
</div>
<h1>Error Page</h1>
<div id="created">${timestamp?datetime}</div>
<div>
There was an unexpected error (type=${error}, status=${status}).
</div>
<div>${message}</div>
<div>
Please contact the operator with the above information.
</div>
</div>
</body>
</html>
<#import "/spring.ftl" as spring />
<!DOCTYPE html>
<html>
<head>
<title>${title}</title>
<#assign home><@spring.url relativeUrl="/"/></#assign>
<#assign bootstrap><@spring.url relativeUrl="/css/bootstrap.min.css"/></#assign>
<link rel="stylesheet" href="${bootstrap}" />
</head>
<body>
<div class="container">
<div class="navbar">
<div class="navbar-inner">
<a class="brand" href="http://freemarker.org/"> FreeMarker -
Plain </a>
<ul class="nav">
<li><a href="${home}"> Home </a></li>
</ul>
</div>
</div>
<h1>${title}</h1>
<div>${message}</div>
<div id="created">${date?datetime}</div>
</div>
</body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment