Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
philwebb committed Apr 16, 2016
1 parent 43256ee commit 5881c9c
Show file tree
Hide file tree
Showing 27 changed files with 100 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@
* <p>
* If a Spring Security {@link AuthenticationManager} is detected, this configuration will
* create a {@link CRaSHPlugin} to forward shell authentication requests to Spring
* Security. This authentication method will get enabled if {@code management.shell.auth.type}
* is set to {@code spring} or if no explicit {@code management.shell.auth} is provided
* and a {@link AuthenticationManager} is available. In the latter case shell access will
* be restricted to users having roles that match those configured in
* {@link ManagementServerProperties}. Required roles can be overridden by
* {@code management.shell.auth.spring.roles}.
* Security. This authentication method will get enabled if
* {@code management.shell.auth.type} is set to {@code spring} or if no explicit
* {@code management.shell.auth} is provided and a {@link AuthenticationManager} is
* available. In the latter case shell access will be restricted to users having roles
* that match those configured in {@link ManagementServerProperties}. Required roles can
* be overridden by {@code management.shell.auth.spring.roles}.
* <p>
* To add customizations to the shell simply define beans of type {@link CRaSHPlugin} in
* the application context. Those beans will get auto detected during startup and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@
@Documented
@Value("${local.management.port}")
public @interface LocalManagementPort {

}
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@ public Integer getPort() {
/**
* Auth specific properties for JAAS authentication.
*/
@ConfigurationProperties(prefix = SHELL_PREFIX + ".auth.jaas", ignoreUnknownFields = false)
@ConfigurationProperties(prefix = SHELL_PREFIX
+ ".auth.jaas", ignoreUnknownFields = false)
public static class JaasAuthenticationProperties
extends CrshShellAuthenticationProperties {

Expand Down Expand Up @@ -404,7 +405,8 @@ public String getDomain() {
/**
* Auth specific properties for key authentication.
*/
@ConfigurationProperties(prefix = SHELL_PREFIX + ".auth.key", ignoreUnknownFields = false)
@ConfigurationProperties(prefix = SHELL_PREFIX
+ ".auth.key", ignoreUnknownFields = false)
public static class KeyAuthenticationProperties
extends CrshShellAuthenticationProperties {

Expand Down Expand Up @@ -435,7 +437,8 @@ public String getPath() {
/**
* Auth specific properties for simple authentication.
*/
@ConfigurationProperties(prefix = SHELL_PREFIX + ".auth.simple", ignoreUnknownFields = false)
@ConfigurationProperties(prefix = SHELL_PREFIX
+ ".auth.simple", ignoreUnknownFields = false)
public static class SimpleAuthenticationProperties
extends CrshShellAuthenticationProperties {

Expand Down Expand Up @@ -511,7 +514,8 @@ public void setPassword(String password) {
/**
* Auth specific properties for Spring authentication.
*/
@ConfigurationProperties(prefix = SHELL_PREFIX + ".auth.spring", ignoreUnknownFields = false)
@ConfigurationProperties(prefix = SHELL_PREFIX
+ ".auth.spring", ignoreUnknownFields = false)
public static class SpringAuthenticationProperties
extends CrshShellAuthenticationProperties {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public void close() {

@Test
public void testDisabledPlugins() throws Exception {
load("management.shell.disabled_plugins=" +
"termIOHandler, org.crsh.auth.AuthenticationPlugin, javaLanguage");
load("management.shell.disabled_plugins="
+ "termIOHandler, org.crsh.auth.AuthenticationPlugin, javaLanguage");
PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class);
assertThat(lifeCycle).isNotNull();
assertThat(lifeCycle.getContext().getPlugins(TermIOHandler.class))
Expand All @@ -109,8 +109,7 @@ public void testAttributes() throws Exception {

@Test
public void testSshConfiguration() {
load("management.shell.ssh.enabled=true",
"management.shell.ssh.port=3333");
load("management.shell.ssh.enabled=true", "management.shell.ssh.port=3333");
PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class);
assertThat(lifeCycle.getConfig().getProperty("crash.ssh.port")).isEqualTo("3333");
assertThat(lifeCycle.getConfig().getProperty("crash.ssh.auth_timeout"))
Expand Down Expand Up @@ -140,7 +139,6 @@ public void testSshConfigurationCustomTimeouts() {
.isEqualTo("400000");
}


@Test
public void testCommandResolution() {
load();
Expand Down Expand Up @@ -329,7 +327,6 @@ private void load(String... environment) {
this.context.refresh();
}


@Configuration
public static class SecurityConfiguration {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public void close() {

@Test
public void testBindingAuth() {
ShellProperties props = load(ShellProperties.class, "management.shell.auth.type=spring");
ShellProperties props = load(ShellProperties.class,
"management.shell.auth.type=spring");
assertThat(props.getAuth().getType()).isEqualTo("spring");
}

Expand All @@ -78,7 +79,8 @@ public void testBindingAuthIfEmpty() {

@Test
public void testBindingCommandRefreshInterval() {
ShellProperties props = load(ShellProperties.class, "management.shell.command-refresh-interval=1");
ShellProperties props = load(ShellProperties.class,
"management.shell.command-refresh-interval=1");
assertThat(props.getCommandRefreshInterval()).isEqualTo(1);
}

Expand All @@ -87,7 +89,7 @@ public void testBindingCommandPathPatterns() {
ShellProperties props = load(ShellProperties.class,
"management.shell.command-path-patterns=pattern1, pattern2");
assertThat(props.getCommandPathPatterns().length).isEqualTo(2);
Assert.assertArrayEquals(new String[] {"pattern1", "pattern2"},
Assert.assertArrayEquals(new String[] { "pattern1", "pattern2" },
props.getCommandPathPatterns());
}

Expand All @@ -96,7 +98,7 @@ public void testBindingConfigPathPatterns() {
ShellProperties props = load(ShellProperties.class,
"management.shell.config-path-patterns=pattern1, pattern2");
assertThat(props.getConfigPathPatterns().length).isEqualTo(2);
Assert.assertArrayEquals(new String[] {"pattern1", "pattern2"},
Assert.assertArrayEquals(new String[] { "pattern1", "pattern2" },
props.getConfigPathPatterns());
}

Expand All @@ -118,8 +120,7 @@ public void testBindingDisabledCommands() {
@Test
public void testBindingSsh() {
ShellProperties props = load(ShellProperties.class,
"management.shell.ssh.enabled=true",
"management.shell.ssh.port=2222",
"management.shell.ssh.enabled=true", "management.shell.ssh.port=2222",
"management.shell.ssh.key-path=~/.ssh/test.pem");
Properties p = props.asCrshShellConfig();
assertThat(p.get("crash.ssh.port")).isEqualTo("2222");
Expand All @@ -129,8 +130,7 @@ public void testBindingSsh() {
@Test
public void testBindingSshIgnored() {
ShellProperties props = load(ShellProperties.class,
"management.shell.ssh.enabled=false",
"management.shell.ssh.port=2222",
"management.shell.ssh.enabled=false", "management.shell.ssh.port=2222",
"management.shell.ssh.key-path=~/.ssh/test.pem");
Properties p = props.asCrshShellConfig();
assertThat(p.get("crash.ssh.port")).isNull();
Expand Down Expand Up @@ -194,14 +194,16 @@ public void testBindingSimple() {

@Test
public void testDefaultPasswordAutoGeneratedIfUnresolvedPlaceholder() {
SimpleAuthenticationProperties security = load(SimpleAuthenticationProperties.class,
SimpleAuthenticationProperties security = load(
SimpleAuthenticationProperties.class,
"management.shell.auth.simple.user.password=${ADMIN_PASSWORD}");
assertThat(security.getUser().isDefaultPassword()).isTrue();
}

@Test
public void testDefaultPasswordAutoGeneratedIfEmpty() {
SimpleAuthenticationProperties security = load(SimpleAuthenticationProperties.class,
SimpleAuthenticationProperties security = load(
SimpleAuthenticationProperties.class,
"management.shell.auth.simple.user.password=");
assertThat(security.getUser().isDefaultPassword()).isTrue();
}
Expand Down Expand Up @@ -242,9 +244,9 @@ private <T> T load(Class<T> type, String... environment) {
}

@Configuration
@EnableConfigurationProperties({ShellProperties.class,
@EnableConfigurationProperties({ ShellProperties.class,
JaasAuthenticationProperties.class, KeyAuthenticationProperties.class,
SimpleAuthenticationProperties.class, SpringAuthenticationProperties.class})
SimpleAuthenticationProperties.class, SpringAuthenticationProperties.class })
static class TestConfiguration {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.boot.autoconfigure.ws;
package org.springframework.boot.autoconfigure.webservices;

import java.util.Map;

Expand Down Expand Up @@ -44,13 +44,13 @@
@ConditionalOnWebApplication
@ConditionalOnClass(MessageDispatcherServlet.class)
@ConditionalOnMissingBean(WsConfigurationSupport.class)
@EnableConfigurationProperties(WsProperties.class)
@EnableConfigurationProperties(WebServicesProperties.class)
@AutoConfigureAfter(EmbeddedServletContainerAutoConfiguration.class)
public class WsAutoConfiguration {
public class WebServicesAutoConfiguration {

private final WsProperties properties;
private final WebServicesProperties properties;

public WsAutoConfiguration(WsProperties properties) {
public WebServicesAutoConfiguration(WebServicesProperties properties) {
this.properties = properties;
}

Expand All @@ -61,9 +61,9 @@ public ServletRegistrationBean messageDispatcherServlet(
servlet.setApplicationContext(applicationContext);
String path = this.properties.getPath();
String urlMapping = (path.endsWith("/") ? path + "*" : path + "/*");
ServletRegistrationBean registration = new ServletRegistrationBean(
servlet, urlMapping);
WsProperties.Servlet servletProperties = this.properties.getServlet();
ServletRegistrationBean registration = new ServletRegistrationBean(servlet,
urlMapping);
WebServicesProperties.Servlet servletProperties = this.properties.getServlet();
registration.setLoadOnStartup(servletProperties.getLoadOnStartup());
for (Map.Entry<String, String> entry : servletProperties.getInit().entrySet()) {
registration.addInitParameter(entry.getKey(), entry.getValue());
Expand All @@ -74,6 +74,7 @@ public ServletRegistrationBean messageDispatcherServlet(
@Configuration
@EnableWs
protected static class WsConfiguration {

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.boot.autoconfigure.ws;
package org.springframework.boot.autoconfigure.webservices;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -31,8 +31,8 @@
* @author Stephane Nicoll
* @since 1.4.0
*/
@ConfigurationProperties("spring.ws")
public class WsProperties {
@ConfigurationProperties("spring.webservices")
public class WebServicesProperties {

/**
* Path that serves as the base URI for the services.
Expand All @@ -55,7 +55,6 @@ public Servlet getServlet() {
return this.servlet;
}


public static class Servlet {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
/**
* Auto-configuration for Spring Web Services.
*/
package org.springframework.boot.autoconfigure.ws;
package org.springframework.boot.autoconfigure.webservices;
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration,\
org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration,\
org.springframework.boot.autoconfigure.websocket.WebSocketAutoConfiguration,\
org.springframework.boot.autoconfigure.websocket.WebSocketMessagingAutoConfiguration,\
org.springframework.boot.autoconfigure.ws.WsAutoConfiguration
org.springframework.boot.autoconfigure.webservices.WebServicesAutoConfiguration

# Template availability providers
org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider=\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.boot.autoconfigure.ws;
package org.springframework.boot.autoconfigure.webservices;

import org.junit.After;
import org.junit.Rule;
Expand All @@ -31,12 +31,12 @@
import static org.assertj.core.api.Assertions.assertThat;

/**
* Tests for {@link WsAutoConfiguration}.
* Tests for {@link WebServicesAutoConfiguration}.
*
* @author Vedran Pavic
* @author Stephane Nicoll
*/
public class WsAutoConfigurationTests {
public class WebServicesAutoConfigurationTests {

@Rule
public ExpectedException thrown = ExpectedException.none();
Expand All @@ -52,36 +52,36 @@ public void close() {

@Test
public void defaultConfiguration() {
load(WsAutoConfiguration.class);

load(WebServicesAutoConfiguration.class);
assertThat(this.context.getBeansOfType(ServletRegistrationBean.class)).hasSize(1);
}

@Test
public void customPathMustBeginWithASlash() {
this.thrown.expect(BeanCreationException.class);
this.thrown.expectMessage("Path must start with /");
load(WsAutoConfiguration.class, "spring.ws.path=invalid");
load(WebServicesAutoConfiguration.class, "spring.webservices.path=invalid");
}

@Test
public void customPathWithTrailingSlash() {
load(WsAutoConfiguration.class, "spring.ws.path=/valid/");
load(WebServicesAutoConfiguration.class, "spring.webservices.path=/valid/");
assertThat(this.context.getBean(ServletRegistrationBean.class).getUrlMappings())
.contains("/valid/*");
}

@Test
public void customPath() {
load(WsAutoConfiguration.class, "spring.ws.path=/valid");
load(WebServicesAutoConfiguration.class, "spring.webservices.path=/valid");
assertThat(this.context.getBeansOfType(ServletRegistrationBean.class)).hasSize(1);
assertThat(this.context.getBean(ServletRegistrationBean.class).getUrlMappings())
.contains("/valid/*");
}

@Test
public void customLoadOnStartup() {
load(WsAutoConfiguration.class, "spring.ws.servlet.load-on-startup=1");
load(WebServicesAutoConfiguration.class,
"spring.webservices.servlet.load-on-startup=1");
ServletRegistrationBean registrationBean = this.context
.getBean(ServletRegistrationBean.class);
assertThat(ReflectionTestUtils.getField(registrationBean, "loadOnStartup"))
Expand All @@ -90,21 +90,22 @@ public void customLoadOnStartup() {

@Test
public void customInitParameters() {
load(WsAutoConfiguration.class, "spring.ws.servlet.init.key1=value1",
"spring.ws.servlet.init.key2=value2");
load(WebServicesAutoConfiguration.class,
"spring.webservices.servlet.init.key1=value1",
"spring.webservices.servlet.init.key2=value2");
ServletRegistrationBean registrationBean = this.context
.getBean(ServletRegistrationBean.class);
assertThat(registrationBean.getInitParameters()).containsEntry("key1", "value1");
assertThat(registrationBean.getInitParameters()).containsEntry("key2", "value2");
}

private void load(Class<?> config, String... environment) {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.setServletContext(new MockServletContext());
EnvironmentTestUtils.addEnvironment(ctx, environment);
ctx.register(config);
ctx.refresh();
this.context = ctx;
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.setServletContext(new MockServletContext());
EnvironmentTestUtils.addEnvironment(context, environment);
context.register(config);
context.refresh();
this.context = context;
}

}
Loading

0 comments on commit 5881c9c

Please sign in to comment.