diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfiguration.java
index 61c24ce0d3..8ed48c2c38 100644
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfiguration.java
+++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfiguration.java
@@ -74,25 +74,27 @@ import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
/**
- * {@link EnableAutoConfiguration Auto-configuration} for embedding an extensible shell into a Spring
- * Boot enabled application. By default a SSH daemon is started on port 2000 with a default username
- * user and password (default password is logged during application startup).
+ * {@link EnableAutoConfiguration Auto-configuration} for embedding an extensible shell
+ * into a Spring Boot enabled application. By default a SSH daemon is started on port 2000
+ * with a default username user and password (default password is logged
+ * during application startup).
*
*
- * This configuration will auto detect the existence of a Spring Security {@link AuthenticationManager}
- * and will delegate authentication requests for shell access to this detected instance.
+ * This configuration will auto detect the existence of a Spring Security
+ * {@link AuthenticationManager} and will delegate authentication requests for shell
+ * access to this detected instance.
*
*
- * 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 registered with the
- * underlying shell infrastructure.
+ * 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
+ * registered with the underlying shell infrastructure.
*
*
- * Additional shell commands can be implemented using the guide and documentation at
- * crashub.org. By default Boot will search for commands using
- * the following classpath scanning pattern classpath*:/commands/**. To add different
- * locations or override the default use shell.command_path_patterns in your application
- * configuration.
+ * Additional shell commands can be implemented using the guide and documentation at crashub.org. By default Boot will search for commands
+ * using the following classpath scanning pattern classpath*:/commands/**. To
+ * add different locations or override the default use
+ * shell.command_path_patterns in your application configuration.
*
* @author Christian Dupuis
*/
@@ -104,8 +106,7 @@ public class CrshAutoConfiguration {
@Autowired
private CrshProperties properties;
-
-
+
@Bean
@ConditionalOnExpression("#{environment['shell.auth'] == 'jaas'}")
@ConditionalOnMissingBean({ AuthenticationProperties.class })
@@ -126,7 +127,7 @@ public class CrshAutoConfiguration {
public AuthenticationProperties simpleAuthenticationProperties() {
return new SimpleAuthenticationProperties();
}
-
+
@Bean
@ConditionalOnExpression("#{environment['shell.auth'] == 'spring'}")
@ConditionalOnMissingBean({ AuthenticationProperties.class })
@@ -144,23 +145,21 @@ public class CrshAutoConfiguration {
@ConditionalOnMissingBean({ PluginLifeCycle.class })
public PluginLifeCycle shellBootstrap() {
CrshBootstrap bs = new CrshBootstrap();
- bs.setConfig(properties.mergeProperties(new Properties()));
+ bs.setConfig(this.properties.mergeProperties(new Properties()));
return bs;
}
-
public static class CrshBootstrap extends PluginLifeCycle {
-
+
@Autowired
private ListableBeanFactory beanFactory;
-
+
@Autowired
private CrshProperties properties;
@Autowired
private ResourcePatternResolver resourceLoader;
-
@PreDestroy
public void destroy() {
stop();
@@ -168,77 +167,83 @@ public class CrshAutoConfiguration {
@PostConstruct
public void init() throws Exception {
- FS commandFileSystem = createFileSystem(properties.getCommandPathPatterns());
- FS confFileSystem = createFileSystem(properties.getConfigPathPatterns());
+ FS commandFileSystem = createFileSystem(this.properties
+ .getCommandPathPatterns());
+ FS confFileSystem = createFileSystem(this.properties.getConfigPathPatterns());
- PluginDiscovery discovery = new BeanFactoryFilteringPluginDiscovery(resourceLoader.getClassLoader(),
- beanFactory, properties.getDisabledPlugins());
+ PluginDiscovery discovery = new BeanFactoryFilteringPluginDiscovery(
+ this.resourceLoader.getClassLoader(), this.beanFactory,
+ this.properties.getDisabledPlugins());
- PluginContext context = new PluginContext(discovery, createPluginContextAttributes(),
- commandFileSystem, confFileSystem, resourceLoader.getClassLoader());
+ PluginContext context = new PluginContext(discovery,
+ createPluginContextAttributes(), commandFileSystem, confFileSystem,
+ this.resourceLoader.getClassLoader());
context.refresh();
start(context);
}
-
- protected FS createFileSystem(String[] pathPatterns) throws IOException, URISyntaxException {
+ protected FS createFileSystem(String[] pathPatterns) throws IOException,
+ URISyntaxException {
Assert.notNull(pathPatterns);
FS cmdFS = new FS();
for (String pathPattern : pathPatterns) {
- cmdFS.mount(new SimpleFileSystemDriver(new DirectoryHandle(pathPattern, resourceLoader)));
+ cmdFS.mount(new SimpleFileSystemDriver(new DirectoryHandle(pathPattern,
+ this.resourceLoader)));
}
return cmdFS;
}
-
+
protected Map createPluginContextAttributes() {
Map attributes = new HashMap();
- String bootVersion = CrshAutoConfiguration.class.getPackage().getImplementationVersion();
+ String bootVersion = CrshAutoConfiguration.class.getPackage()
+ .getImplementationVersion();
if (bootVersion != null) {
attributes.put("spring.boot.version", bootVersion);
}
attributes.put("spring.version", SpringVersion.getVersion());
- if (beanFactory != null) {
- attributes.put("spring.beanfactory", beanFactory);
+ if (this.beanFactory != null) {
+ attributes.put("spring.beanfactory", this.beanFactory);
}
return attributes;
}
-
+
}
-
@SuppressWarnings("rawtypes")
- private static class AuthenticationManagerAdapter extends CRaSHPlugin implements
- AuthenticationPlugin {
-
- private static final PropertyDescriptor ROLES = PropertyDescriptor.create(
- "auth.spring.roles", "ADMIN", "Comma separated list of roles required to access the shell");
-
-
- @Autowired(required=false)
+ private static class AuthenticationManagerAdapter extends
+ CRaSHPlugin implements AuthenticationPlugin {
+
+ private static final PropertyDescriptor ROLES = PropertyDescriptor
+ .create("auth.spring.roles", "ADMIN",
+ "Comma separated list of roles required to access the shell");
+
+ @Autowired(required = false)
private AccessDecisionManager accessDecisionManager;
-
+
@Autowired
private AuthenticationManager authenticationManager;
-
+
private String[] roles = new String[] { "ROLE_ADMIN" };
-
-
+
@Override
public boolean authenticate(String username, String password) throws Exception {
// Authenticate first to make credentials are valid
- Authentication token = new UsernamePasswordAuthenticationToken(username, password);
+ Authentication token = new UsernamePasswordAuthenticationToken(username,
+ password);
try {
- token = authenticationManager.authenticate(token);
+ token = this.authenticationManager.authenticate(token);
}
catch (AuthenticationException ae) {
return false;
}
-
+
// Test access rights if a Spring Security AccessDecisionManager is installed
- if (accessDecisionManager != null && token.isAuthenticated() && roles != null) {
+ if (this.accessDecisionManager != null && token.isAuthenticated()
+ && this.roles != null) {
try {
- accessDecisionManager.decide(token, this, SecurityConfig.createList(roles));
+ this.accessDecisionManager.decide(token, this,
+ SecurityConfig.createList(this.roles));
}
catch (AccessDeniedException e) {
return false;
@@ -256,7 +261,7 @@ public class CrshAutoConfiguration {
public AuthenticationPlugin getImplementation() {
return this;
}
-
+
@Override
public String getName() {
return "spring";
@@ -266,35 +271,33 @@ public class CrshAutoConfiguration {
public void init() {
String rolesPropertyValue = getContext().getProperty(ROLES);
if (rolesPropertyValue != null) {
- this.roles = StringUtils.commaDelimitedListToStringArray(rolesPropertyValue);
+ this.roles = StringUtils
+ .commaDelimitedListToStringArray(rolesPropertyValue);
}
}
-
@Override
protected Iterable> createConfigurationCapabilities() {
- return Arrays.>asList(ROLES);
+ return Arrays.> asList(ROLES);
}
-
+
}
-
-
- private static class BeanFactoryFilteringPluginDiscovery extends ServiceLoaderDiscovery {
+
+ private static class BeanFactoryFilteringPluginDiscovery extends
+ ServiceLoaderDiscovery {
private ListableBeanFactory beanFactory;
-
+
private String[] disabledPlugins;
-
- public BeanFactoryFilteringPluginDiscovery(ClassLoader classLoader, ListableBeanFactory beanFactory,
- String[] disabledPlugins)
+ public BeanFactoryFilteringPluginDiscovery(ClassLoader classLoader,
+ ListableBeanFactory beanFactory, String[] disabledPlugins)
throws NullPointerException {
super(classLoader);
this.beanFactory = beanFactory;
this.disabledPlugins = disabledPlugins;
}
-
@Override
@SuppressWarnings("rawtypes")
public Iterable> getPlugins() {
@@ -306,29 +309,31 @@ public class CrshAutoConfiguration {
}
}
- Collection springPlugins = beanFactory.getBeansOfType(CRaSHPlugin.class).values();
+ Collection springPlugins = this.beanFactory.getBeansOfType(
+ CRaSHPlugin.class).values();
for (CRaSHPlugin> p : springPlugins) {
if (!shouldFilter(p)) {
plugins.add(p);
}
}
-
+
return plugins;
}
-
-
+
@SuppressWarnings("rawtypes")
protected boolean shouldFilter(CRaSHPlugin> plugin) {
Assert.notNull(plugin);
-
+
Set classes = ClassUtils.getAllInterfacesAsSet(plugin);
classes.add(plugin.getClass());
-
+
for (Class> clazz : classes) {
- if (disabledPlugins != null && disabledPlugins.length > 0) {
- for (String disabledPlugin : disabledPlugins) {
- if (ClassUtils.getShortName(clazz).equalsIgnoreCase(disabledPlugin)
- || ClassUtils.getQualifiedName(clazz).equalsIgnoreCase(disabledPlugin)) {
+ if (this.disabledPlugins != null && this.disabledPlugins.length > 0) {
+ for (String disabledPlugin : this.disabledPlugins) {
+ if (ClassUtils.getShortName(clazz).equalsIgnoreCase(
+ disabledPlugin)
+ || ClassUtils.getQualifiedName(clazz).equalsIgnoreCase(
+ disabledPlugin)) {
return true;
}
}
@@ -336,22 +341,20 @@ public class CrshAutoConfiguration {
}
return false;
}
-
+
}
-
private static class SimpleFileSystemDriver extends AbstractFSDriver {
private ResourceHandle root;
-
public SimpleFileSystemDriver(ResourceHandle handle) {
this.root = handle;
}
-
@Override
- public Iterable children(ResourceHandle handle) throws IOException {
+ public Iterable children(ResourceHandle handle)
+ throws IOException {
if (handle instanceof DirectoryHandle) {
return ((DirectoryHandle) handle).members();
}
@@ -379,32 +382,30 @@ public class CrshAutoConfiguration {
@Override
public Iterator open(ResourceHandle handle) throws IOException {
if (handle instanceof FileHandle) {
- return Collections.singletonList(((FileHandle) handle).openStream()).iterator();
+ return Collections.singletonList(((FileHandle) handle).openStream())
+ .iterator();
}
- return Collections.emptyList().iterator();
+ return Collections. emptyList().iterator();
}
@Override
public ResourceHandle root() throws IOException {
- return root;
+ return this.root;
}
}
-
-
+
private static class DirectoryHandle extends ResourceHandle {
private ResourcePatternResolver resourceLoader;
-
public DirectoryHandle(String name, ResourcePatternResolver resourceLoader) {
super(name);
this.resourceLoader = resourceLoader;
}
-
public List members() throws IOException {
- Resource[] resources = resourceLoader.getResources(getName());
+ Resource[] resources = this.resourceLoader.getResources(getName());
List files = new ArrayList();
for (Resource resource : resources) {
if (!resource.getURL().getPath().endsWith("/")) {
@@ -415,48 +416,43 @@ public class CrshAutoConfiguration {
}
}
-
private static class FileHandle extends ResourceHandle {
private Resource resource;
-
public FileHandle(String name, Resource resource) {
super(name);
this.resource = resource;
}
-
public InputStream openStream() throws IOException {
return this.resource.getInputStream();
}
-
+
public long getLastModified() {
try {
return this.resource.lastModified();
}
- catch (IOException e) {}
+ catch (IOException e) {
+ }
return -1;
}
-
+
}
-
private abstract static class ResourceHandle {
private String name;
-
public ResourceHandle(String name) {
this.name = name;
}
-
public String getName() {
- return name;
+ return this.name;
}
-
+
}
-
+
}
diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/properties/CrshProperties.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/properties/CrshProperties.java
index cc0c8f2e6f..57cf59eb7c 100644
--- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/properties/CrshProperties.java
+++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/properties/CrshProperties.java
@@ -36,7 +36,7 @@ import org.springframework.util.StringUtils;
*/
@ConfigurationProperties(name = "shell", ignoreUnknownFields = true)
public class CrshProperties {
-
+
protected static final String CRASH_AUTH = "crash.auth";
protected static final String CRASH_AUTH_JAAS_DOMAIN = "crash.auth.jaas.domain";
protected static final String CRASH_AUTH_KEY_PATH = "crash.auth.key.path";
@@ -49,13 +49,13 @@ public class CrshProperties {
protected static final String CRASH_VFS_REFRESH_PERIOD = "crash.vfs.refresh_period";
private String auth = "simple";
-
+
@Autowired(required = false)
private AuthenticationProperties authenticationProperties;
private int commandRefreshInterval = -1;
- private String[] commandPathPatterns = new String[] { "classpath*:/commands/**",
+ private String[] commandPathPatterns = new String[] { "classpath*:/commands/**",
"classpath*:/crash/commands/**" };
private String[] configPathPatterns = new String[] { "classpath*:/crash/*" };
@@ -66,7 +66,6 @@ public class CrshProperties {
private Telnet telnet = new Telnet();
-
public String getAuth() {
return this.auth;
}
@@ -74,11 +73,11 @@ public class CrshProperties {
public AuthenticationProperties getAuthenticationProperties() {
return this.authenticationProperties;
}
-
+
public int getCommandRefreshInterval() {
return this.commandRefreshInterval;
}
-
+
public String[] getCommandPathPatterns() {
return this.commandPathPatterns;
}
@@ -100,28 +99,29 @@ public class CrshProperties {
}
public Properties mergeProperties(Properties properties) {
- properties = ssh.mergeProperties(properties);
- properties = telnet.mergeProperties(properties);
+ properties = this.ssh.mergeProperties(properties);
+ properties = this.telnet.mergeProperties(properties);
- properties.put(CRASH_AUTH, auth);
- if (authenticationProperties != null) {
- properties = authenticationProperties.mergeProperties(properties);
+ properties.put(CRASH_AUTH, this.auth);
+ if (this.authenticationProperties != null) {
+ properties = this.authenticationProperties.mergeProperties(properties);
}
-
+
if (this.commandRefreshInterval > 0) {
- properties.put(CRASH_VFS_REFRESH_PERIOD, String.valueOf(this.commandRefreshInterval));
+ properties.put(CRASH_VFS_REFRESH_PERIOD,
+ String.valueOf(this.commandRefreshInterval));
}
-
+
// special handling for disabling Ssh and Telnet support
- List dp = new ArrayList(Arrays.asList(this.disabledPlugins));
- if (!ssh.isEnabled()) {
+ List dp = new ArrayList(Arrays.asList(this.disabledPlugins));
+ if (!this.ssh.isEnabled()) {
dp.add("org.crsh.ssh.SSHPlugin");
}
- if (!telnet.isEnabled()) {
+ if (!this.telnet.isEnabled()) {
dp.add("org.crsh.telnet.TelnetPlugin");
}
this.disabledPlugins = dp.toArray(new String[dp.size()]);
-
+
return properties;
}
@@ -130,11 +130,12 @@ public class CrshProperties {
this.auth = auth;
}
- public void setAuthenticationProperties(AuthenticationProperties authenticationProperties) {
+ public void setAuthenticationProperties(
+ AuthenticationProperties authenticationProperties) {
Assert.notNull(authenticationProperties);
this.authenticationProperties = authenticationProperties;
}
-
+
public void setCommandRefreshInterval(int commandRefreshInterval) {
this.commandRefreshInterval = commandRefreshInterval;
}
@@ -163,18 +164,15 @@ public class CrshProperties {
Assert.notNull(telnet);
this.telnet = telnet;
}
-
-
+
public interface AuthenticationProperties extends PropertiesProvider {
}
-
-
+
@ConfigurationProperties(name = "shell.auth.jaas", ignoreUnknownFields = false)
public static class JaasAuthenticationProperties implements AuthenticationProperties {
private String domain = "my-domain";
-
@Override
public Properties mergeProperties(Properties properties) {
properties.put(CRASH_AUTH_JAAS_DOMAIN, this.domain);
@@ -187,14 +185,12 @@ public class CrshProperties {
}
}
-
@ConfigurationProperties(name = "shell.auth.key", ignoreUnknownFields = false)
public static class KeyAuthenticationProperties implements AuthenticationProperties {
private String path;
-
@Override
public Properties mergeProperties(Properties properties) {
if (this.path != null) {
@@ -210,41 +206,40 @@ public class CrshProperties {
}
-
public interface PropertiesProvider {
Properties mergeProperties(Properties properties);
}
-
@ConfigurationProperties(name = "shell.auth.simple", ignoreUnknownFields = false)
- public static class SimpleAuthenticationProperties implements AuthenticationProperties {
+ public static class SimpleAuthenticationProperties implements
+ AuthenticationProperties {
- private static Log logger = LogFactory.getLog(SimpleAuthenticationProperties.class);
-
+ private static Log logger = LogFactory
+ .getLog(SimpleAuthenticationProperties.class);
private String username = "user";
private String password = UUID.randomUUID().toString();
-
- private boolean defaultPassword = true;
+ private boolean defaultPassword = true;
public boolean isDefaultPassword() {
return this.defaultPassword;
}
-
+
@Override
public Properties mergeProperties(Properties properties) {
properties.put(CRASH_AUTH_SIMPLE_USERNAME, this.username);
properties.put(CRASH_AUTH_SIMPLE_PASSWORD, this.password);
if (this.defaultPassword) {
- logger.info("Using default password for shell access: " + this.password);
+ logger.info("Using default password for shell access: " + this.password);
}
return properties;
}
public void setPassword(String password) {
- if (password.startsWith("${") && password.endsWith("}") || !StringUtils.hasLength(password)) {
+ if (password.startsWith("${") && password.endsWith("}")
+ || !StringUtils.hasLength(password)) {
return;
}
this.password = password;
@@ -255,20 +250,20 @@ public class CrshProperties {
Assert.hasLength(username);
this.username = username;
}
-
+
}
-
@ConfigurationProperties(name = "shell.auth.spring", ignoreUnknownFields = false)
- public static class SpringAuthenticationProperties implements AuthenticationProperties {
+ public static class SpringAuthenticationProperties implements
+ AuthenticationProperties {
private String[] roles = new String[] { "ROLE_ADMIN" };
-
@Override
public Properties mergeProperties(Properties properties) {
if (this.roles != null) {
- properties.put(CRASH_AUTH_SPRING_ROLES, StringUtils.arrayToCommaDelimitedString(this.roles));
+ properties.put(CRASH_AUTH_SPRING_ROLES,
+ StringUtils.arrayToCommaDelimitedString(this.roles));
}
return properties;
}
@@ -280,7 +275,6 @@ public class CrshProperties {
}
-
public static class Ssh implements PropertiesProvider {
private boolean enabled = true;
@@ -289,11 +283,10 @@ public class CrshProperties {
private String port = "2000";
-
public boolean isEnabled() {
return this.enabled;
}
-
+
@Override
public Properties mergeProperties(Properties properties) {
if (this.enabled) {
@@ -321,18 +314,16 @@ public class CrshProperties {
}
-
public static class Telnet implements PropertiesProvider {
private boolean enabled = false;
private String port = "5000";
-
public boolean isEnabled() {
return this.enabled;
}
-
+
@Override
public Properties mergeProperties(Properties properties) {
if (this.enabled) {
diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfigurationTests.java
index 1843535e2f..297f791092 100644
--- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfigurationTests.java
+++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfigurationTests.java
@@ -16,13 +16,6 @@
package org.springframework.boot.actuate.autoconfigure;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
@@ -56,6 +49,13 @@ import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
/**
* Tests for {@link CrshAutoConfiguration}.
*
@@ -65,7 +65,7 @@ import org.springframework.web.context.support.AnnotationConfigWebApplicationCon
public class CrshAutoConfigurationTests {
private AnnotationConfigWebApplicationContext context;
-
+
@After
public void tearDown() {
if (this.context != null) {
@@ -77,7 +77,8 @@ public class CrshAutoConfigurationTests {
@Test
public void testDisabledPlugins() throws Exception {
MockEnvironment env = new MockEnvironment();
- env.setProperty("shell.disabled_plugins", "GroovyREPL, termIOHandler, org.crsh.auth.AuthenticationPlugin");
+ env.setProperty("shell.disabled_plugins",
+ "GroovyREPL, termIOHandler, org.crsh.auth.AuthenticationPlugin");
this.context = new AnnotationConfigWebApplicationContext();
this.context.setEnvironment(env);
this.context.register(CrshAutoConfiguration.class);
@@ -96,15 +97,15 @@ public class CrshAutoConfigurationTests {
this.context = new AnnotationConfigWebApplicationContext();
this.context.register(CrshAutoConfiguration.class);
this.context.refresh();
-
+
PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class);
-
+
Map attributes = lifeCycle.getContext().getAttributes();
assertTrue(attributes.containsKey("spring.version"));
assertTrue(attributes.containsKey("spring.beanfactory"));
- assertEquals(this.context.getBeanFactory(), attributes.get("spring.beanfactory"));
+ assertEquals(this.context.getBeanFactory(), attributes.get("spring.beanfactory"));
}
-
+
@Test
public void testSshConfiguration() {
MockEnvironment env = new MockEnvironment();
@@ -129,10 +130,11 @@ public class CrshAutoConfigurationTests {
this.context.setEnvironment(env);
this.context.register(CrshAutoConfiguration.class);
this.context.refresh();
-
+
PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class);
-
- assertEquals(lifeCycle.getConfig().getProperty("crash.ssh.keypath"), "~/.ssh/id.pem");
+
+ assertEquals(lifeCycle.getConfig().getProperty("crash.ssh.keypath"),
+ "~/.ssh/id.pem");
}
@Test
@@ -144,7 +146,8 @@ public class CrshAutoConfigurationTests {
PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class);
int count = 0;
- Iterator resources = lifeCycle.getContext().loadResources("login", ResourceKind.LIFECYCLE).iterator();
+ Iterator resources = lifeCycle.getContext()
+ .loadResources("login", ResourceKind.LIFECYCLE).iterator();
while (resources.hasNext()) {
count++;
resources.next();
@@ -152,7 +155,8 @@ public class CrshAutoConfigurationTests {
assertEquals(1, count);
count = 0;
- resources = lifeCycle.getContext().loadResources("help.java", ResourceKind.COMMAND).iterator();
+ resources = lifeCycle.getContext()
+ .loadResources("help.java", ResourceKind.COMMAND).iterator();
while (resources.hasNext()) {
count++;
resources.next();
@@ -172,14 +176,15 @@ public class CrshAutoConfigurationTests {
PluginContext pluginContext = lifeCycle.getContext();
int count = 0;
- Iterator plugins = pluginContext.getPlugins(AuthenticationPlugin.class).iterator();
+ Iterator plugins = pluginContext.getPlugins(
+ AuthenticationPlugin.class).iterator();
while (plugins.hasNext()) {
count++;
plugins.next();
}
assertEquals(3, count);
}
-
+
@Test
public void testJaasAuthenticationProvider() {
MockEnvironment env = new MockEnvironment();
@@ -191,10 +196,11 @@ public class CrshAutoConfigurationTests {
this.context.register(SecurityConfiguration.class);
this.context.register(CrshAutoConfiguration.class);
this.context.refresh();
-
+
PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class);
assertEquals(lifeCycle.getConfig().get("crash.auth"), "jaas");
- assertEquals(lifeCycle.getConfig().get("crash.auth.jaas.domain"), "my-test-domain");
+ assertEquals(lifeCycle.getConfig().get("crash.auth.jaas.domain"),
+ "my-test-domain");
}
@Test
@@ -208,7 +214,7 @@ public class CrshAutoConfigurationTests {
this.context.register(SecurityConfiguration.class);
this.context.register(CrshAutoConfiguration.class);
this.context.refresh();
-
+
PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class);
assertEquals(lifeCycle.getConfig().get("crash.auth"), "key");
assertEquals(lifeCycle.getConfig().get("crash.auth.key.path"), "~/test.pem");
@@ -226,14 +232,15 @@ public class CrshAutoConfigurationTests {
this.context.register(SecurityConfiguration.class);
this.context.register(CrshAutoConfiguration.class);
this.context.refresh();
-
+
PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class);
assertEquals(lifeCycle.getConfig().get("crash.auth"), "simple");
-
+
AuthenticationPlugin authenticationPlugin = null;
String authentication = lifeCycle.getConfig().getProperty("crash.auth");
assertNotNull(authentication);
- for (AuthenticationPlugin plugin : lifeCycle.getContext().getPlugins(AuthenticationPlugin.class)) {
+ for (AuthenticationPlugin plugin : lifeCycle.getContext().getPlugins(
+ AuthenticationPlugin.class)) {
if (authentication.equals(plugin.getName())) {
authenticationPlugin = plugin;
break;
@@ -246,7 +253,7 @@ public class CrshAutoConfigurationTests {
catch (Exception e) {
fail();
}
-
+
try {
assertFalse(authenticationPlugin.authenticate(UUID.randomUUID().toString(),
"password"));
@@ -272,7 +279,8 @@ public class CrshAutoConfigurationTests {
AuthenticationPlugin authenticationPlugin = null;
String authentication = lifeCycle.getConfig().getProperty("crash.auth");
assertNotNull(authentication);
- for (AuthenticationPlugin plugin : lifeCycle.getContext().getPlugins(AuthenticationPlugin.class)) {
+ for (AuthenticationPlugin plugin : lifeCycle.getContext().getPlugins(
+ AuthenticationPlugin.class)) {
if (authentication.equals(plugin.getName())) {
authenticationPlugin = plugin;
break;
@@ -286,7 +294,7 @@ public class CrshAutoConfigurationTests {
catch (Exception e) {
fail();
}
-
+
try {
assertFalse(authenticationPlugin.authenticate(UUID.randomUUID().toString(),
SecurityConfiguration.PASSWORD));
@@ -308,10 +316,15 @@ public class CrshAutoConfigurationTests {
return new AuthenticationManager() {
@Override
- public Authentication authenticate(Authentication authentication) throws AuthenticationException {
- if (authentication.getName().equals(USERNAME) && authentication.getCredentials().equals(PASSWORD)) {
- authentication = new UsernamePasswordAuthenticationToken(authentication.getPrincipal(),
- authentication.getCredentials(), Collections.singleton(new SimpleGrantedAuthority("ROLE_ADMIN")));
+ public Authentication authenticate(Authentication authentication)
+ throws AuthenticationException {
+ if (authentication.getName().equals(USERNAME)
+ && authentication.getCredentials().equals(PASSWORD)) {
+ authentication = new UsernamePasswordAuthenticationToken(
+ authentication.getPrincipal(),
+ authentication.getCredentials(),
+ Collections.singleton(new SimpleGrantedAuthority(
+ "ROLE_ADMIN")));
}
else {
throw new BadCredentialsException("Invalid username and password");
@@ -320,13 +333,13 @@ public class CrshAutoConfigurationTests {
}
};
}
-
+
@Bean
public AccessDecisionManager accessDecisionManager() {
- List voters = new ArrayList();
- voters.add(new RoleVoter());
- AccessDecisionManager result = new UnanimousBased(voters);
- return result;
+ List voters = new ArrayList();
+ voters.add(new RoleVoter());
+ AccessDecisionManager result = new UnanimousBased(voters);
+ return result;
}
}
diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/properties/CrshPropertiesTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/properties/CrshPropertiesTests.java
index 0a8ee246c2..91b4288575 100644
--- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/properties/CrshPropertiesTests.java
+++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/properties/CrshPropertiesTests.java
@@ -16,12 +16,6 @@
package org.springframework.boot.actuate.properties;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -37,6 +31,12 @@ import org.springframework.boot.actuate.properties.CrshProperties.SpringAuthenti
import org.springframework.boot.bind.RelaxedDataBinder;
import org.springframework.core.convert.support.DefaultConversionService;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
/**
* Tests for {@link CrshProperties}.
*
@@ -48,7 +48,8 @@ public class CrshPropertiesTests {
public void testBindingAuth() {
CrshProperties props = new CrshProperties();
RelaxedDataBinder binder = new RelaxedDataBinder(props, "shell");
- binder.bind(new MutablePropertyValues(Collections.singletonMap("shell.auth", "spring")));
+ binder.bind(new MutablePropertyValues(Collections.singletonMap("shell.auth",
+ "spring")));
assertFalse(binder.getBindingResult().hasErrors());
assertEquals("spring", props.getAuth());
}
@@ -67,7 +68,8 @@ public class CrshPropertiesTests {
CrshProperties props = new CrshProperties();
RelaxedDataBinder binder = new RelaxedDataBinder(props, "shell");
binder.setConversionService(new DefaultConversionService());
- binder.bind(new MutablePropertyValues(Collections.singletonMap("shell.command_refresh_interval", "1")));
+ binder.bind(new MutablePropertyValues(Collections.singletonMap(
+ "shell.command_refresh_interval", "1")));
assertFalse(binder.getBindingResult().hasErrors());
assertEquals(1, props.getCommandRefreshInterval());
}
@@ -77,11 +79,12 @@ public class CrshPropertiesTests {
CrshProperties props = new CrshProperties();
RelaxedDataBinder binder = new RelaxedDataBinder(props, "shell");
binder.setConversionService(new DefaultConversionService());
- binder.bind(new MutablePropertyValues(Collections.singletonMap("shell.command_path_patterns",
- "pattern1, pattern2")));
+ binder.bind(new MutablePropertyValues(Collections.singletonMap(
+ "shell.command_path_patterns", "pattern1, pattern2")));
assertFalse(binder.getBindingResult().hasErrors());
assertEquals(2, props.getCommandPathPatterns().length);
- Assert.assertArrayEquals(new String[] { "pattern1", "pattern2" }, props.getCommandPathPatterns());
+ Assert.assertArrayEquals(new String[] { "pattern1", "pattern2" },
+ props.getCommandPathPatterns());
}
@Test
@@ -89,11 +92,12 @@ public class CrshPropertiesTests {
CrshProperties props = new CrshProperties();
RelaxedDataBinder binder = new RelaxedDataBinder(props, "shell");
binder.setConversionService(new DefaultConversionService());
- binder.bind(new MutablePropertyValues(Collections.singletonMap("shell.config_path_patterns",
- "pattern1, pattern2")));
+ binder.bind(new MutablePropertyValues(Collections.singletonMap(
+ "shell.config_path_patterns", "pattern1, pattern2")));
assertFalse(binder.getBindingResult().hasErrors());
assertEquals(2, props.getConfigPathPatterns().length);
- Assert.assertArrayEquals(new String[] { "pattern1", "pattern2" }, props.getConfigPathPatterns());
+ Assert.assertArrayEquals(new String[] { "pattern1", "pattern2" },
+ props.getConfigPathPatterns());
}
@Test
@@ -101,11 +105,12 @@ public class CrshPropertiesTests {
CrshProperties props = new CrshProperties();
RelaxedDataBinder binder = new RelaxedDataBinder(props, "shell");
binder.setConversionService(new DefaultConversionService());
- binder.bind(new MutablePropertyValues(Collections.singletonMap("shell.disabled_plugins",
- "pattern1, pattern2")));
+ binder.bind(new MutablePropertyValues(Collections.singletonMap(
+ "shell.disabled_plugins", "pattern1, pattern2")));
assertFalse(binder.getBindingResult().hasErrors());
assertEquals(2, props.getDisabledPlugins().length);
- assertArrayEquals(new String[] { "pattern1", "pattern2" }, props.getDisabledPlugins());
+ assertArrayEquals(new String[] { "pattern1", "pattern2" },
+ props.getDisabledPlugins());
}
@Test
@@ -119,10 +124,10 @@ public class CrshPropertiesTests {
map.put("shell.ssh.key_path", "~/.ssh/test.pem");
binder.bind(new MutablePropertyValues(map));
assertFalse(binder.getBindingResult().hasErrors());
-
+
Properties p = new Properties();
p = props.mergeProperties(p);
-
+
assertEquals("2222", p.get(CrshProperties.CRASH_SSH_PORT));
assertEquals("~/.ssh/test.pem", p.get(CrshProperties.CRASH_SSH_KEYPATH));
}
@@ -138,14 +143,14 @@ public class CrshPropertiesTests {
map.put("shell.ssh.key_path", "~/.ssh/test.pem");
binder.bind(new MutablePropertyValues(map));
assertFalse(binder.getBindingResult().hasErrors());
-
+
Properties p = new Properties();
p = props.mergeProperties(p);
-
+
assertNull(p.get(CrshProperties.CRASH_SSH_PORT));
assertNull(p.get(CrshProperties.CRASH_SSH_KEYPATH));
}
-
+
@Test
public void testBindingTelnet() {
CrshProperties props = new CrshProperties();
@@ -156,13 +161,13 @@ public class CrshPropertiesTests {
map.put("shell.telnet.port", "2222");
binder.bind(new MutablePropertyValues(map));
assertFalse(binder.getBindingResult().hasErrors());
-
+
Properties p = new Properties();
p = props.mergeProperties(p);
-
+
assertEquals("2222", p.get(CrshProperties.CRASH_TELNET_PORT));
}
-
+
@Test
public void testBindingTelnetIgnored() {
CrshProperties props = new CrshProperties();
@@ -173,13 +178,13 @@ public class CrshPropertiesTests {
map.put("shell.telnet.port", "2222");
binder.bind(new MutablePropertyValues(map));
assertFalse(binder.getBindingResult().hasErrors());
-
+
Properties p = new Properties();
p = props.mergeProperties(p);
-
+
assertNull(p.get(CrshProperties.CRASH_TELNET_PORT));
}
-
+
@Test
public void testBindingJaas() {
JaasAuthenticationProperties props = new JaasAuthenticationProperties();
@@ -189,13 +194,13 @@ public class CrshPropertiesTests {
map.put("shell.auth.jaas.domain", "my-test-domain");
binder.bind(new MutablePropertyValues(map));
assertFalse(binder.getBindingResult().hasErrors());
-
+
Properties p = new Properties();
p = props.mergeProperties(p);
-
+
assertEquals("my-test-domain", p.get(CrshProperties.CRASH_AUTH_JAAS_DOMAIN));
}
-
+
@Test
public void testBindingKey() {
KeyAuthenticationProperties props = new KeyAuthenticationProperties();
@@ -205,13 +210,13 @@ public class CrshPropertiesTests {
map.put("shell.auth.key.path", "~/.ssh/test.pem");
binder.bind(new MutablePropertyValues(map));
assertFalse(binder.getBindingResult().hasErrors());
-
+
Properties p = new Properties();
p = props.mergeProperties(p);
-
+
assertEquals("~/.ssh/test.pem", p.get(CrshProperties.CRASH_AUTH_KEY_PATH));
}
-
+
@Test
public void testBindingKeyIgnored() {
KeyAuthenticationProperties props = new KeyAuthenticationProperties();
@@ -220,10 +225,10 @@ public class CrshPropertiesTests {
Map map = new HashMap();
binder.bind(new MutablePropertyValues(map));
assertFalse(binder.getBindingResult().hasErrors());
-
+
Properties p = new Properties();
p = props.mergeProperties(p);
-
+
assertNull(p.get(CrshProperties.CRASH_AUTH_KEY_PATH));
}
@@ -237,14 +242,14 @@ public class CrshPropertiesTests {
map.put("shell.auth.simple.password", "password123");
binder.bind(new MutablePropertyValues(map));
assertFalse(binder.getBindingResult().hasErrors());
-
+
Properties p = new Properties();
p = props.mergeProperties(p);
-
+
assertEquals("username123", p.get(CrshProperties.CRASH_AUTH_SIMPLE_USERNAME));
assertEquals("password123", p.get(CrshProperties.CRASH_AUTH_SIMPLE_PASSWORD));
}
-
+
@Test
public void testDefaultPasswordAutogeneratedIfUnresolovedPlaceholder() {
SimpleAuthenticationProperties security = new SimpleAuthenticationProperties();
@@ -264,19 +269,19 @@ public class CrshPropertiesTests {
assertFalse(binder.getBindingResult().hasErrors());
assertTrue(security.isDefaultPassword());
}
-
+
@Test
public void testBindingSpring() {
SpringAuthenticationProperties props = new SpringAuthenticationProperties();
RelaxedDataBinder binder = new RelaxedDataBinder(props, "shell.auth.spring");
- binder.bind(new MutablePropertyValues(Collections.singletonMap("shell.auth.spring.roles", "role1, role2")));
+ binder.bind(new MutablePropertyValues(Collections.singletonMap(
+ "shell.auth.spring.roles", "role1, role2")));
assertFalse(binder.getBindingResult().hasErrors());
Properties p = new Properties();
p = props.mergeProperties(p);
-
+
assertEquals("role1, role2", p.get(CrshProperties.CRASH_AUTH_SPRING_ROLES));
}
-
}
diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java
index 1d97875ad1..72dd34a36b 100644
--- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java
+++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java
@@ -16,11 +16,6 @@
package org.springframework.boot.autoconfigure.jdbc;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverPropertyInfo;
@@ -47,6 +42,10 @@ import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
import org.springframework.util.ClassUtils;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
/**
* Tests for {@link DataSourceAutoConfiguration}.
diff --git a/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/task/Repackage.java b/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/task/Repackage.java
index d827d9c4b5..b7446f0902 100644
--- a/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/task/Repackage.java
+++ b/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/task/Repackage.java
@@ -29,7 +29,7 @@ import org.springframework.boot.loader.tools.Repackager;
/**
* Repackage task.
- *
+ *
* @author Phillip Webb
*/
public class Repackage extends DefaultTask {