Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
d784cb6a
Commit
d784cb6a
authored
Nov 04, 2013
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Apply eclipse-formatter conventions
parent
0def4477
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
240 additions
and
236 deletions
+240
-236
CrshAutoConfiguration.java
...ork/boot/actuate/autoconfigure/CrshAutoConfiguration.java
+97
-101
CrshProperties.java
...ringframework/boot/actuate/properties/CrshProperties.java
+39
-48
CrshAutoConfigurationTests.java
...oot/actuate/autoconfigure/CrshAutoConfigurationTests.java
+51
-38
CrshPropertiesTests.java
...ramework/boot/actuate/properties/CrshPropertiesTests.java
+48
-43
DataSourceAutoConfigurationTests.java
.../autoconfigure/jdbc/DataSourceAutoConfigurationTests.java
+4
-5
Repackage.java
...roovy/org/springframework/boot/gradle/task/Repackage.java
+1
-1
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfiguration.java
View file @
d784cb6a
This diff is collapsed.
Click to expand it.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/properties/CrshProperties.java
View file @
d784cb6a
...
@@ -36,7 +36,7 @@ import org.springframework.util.StringUtils;
...
@@ -36,7 +36,7 @@ import org.springframework.util.StringUtils;
*/
*/
@ConfigurationProperties
(
name
=
"shell"
,
ignoreUnknownFields
=
true
)
@ConfigurationProperties
(
name
=
"shell"
,
ignoreUnknownFields
=
true
)
public
class
CrshProperties
{
public
class
CrshProperties
{
protected
static
final
String
CRASH_AUTH
=
"crash.auth"
;
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_JAAS_DOMAIN
=
"crash.auth.jaas.domain"
;
protected
static
final
String
CRASH_AUTH_KEY_PATH
=
"crash.auth.key.path"
;
protected
static
final
String
CRASH_AUTH_KEY_PATH
=
"crash.auth.key.path"
;
...
@@ -49,13 +49,13 @@ public class CrshProperties {
...
@@ -49,13 +49,13 @@ public class CrshProperties {
protected
static
final
String
CRASH_VFS_REFRESH_PERIOD
=
"crash.vfs.refresh_period"
;
protected
static
final
String
CRASH_VFS_REFRESH_PERIOD
=
"crash.vfs.refresh_period"
;
private
String
auth
=
"simple"
;
private
String
auth
=
"simple"
;
@Autowired
(
required
=
false
)
@Autowired
(
required
=
false
)
private
AuthenticationProperties
authenticationProperties
;
private
AuthenticationProperties
authenticationProperties
;
private
int
commandRefreshInterval
=
-
1
;
private
int
commandRefreshInterval
=
-
1
;
private
String
[]
commandPathPatterns
=
new
String
[]
{
"classpath*:/commands/**"
,
private
String
[]
commandPathPatterns
=
new
String
[]
{
"classpath*:/commands/**"
,
"classpath*:/crash/commands/**"
};
"classpath*:/crash/commands/**"
};
private
String
[]
configPathPatterns
=
new
String
[]
{
"classpath*:/crash/*"
};
private
String
[]
configPathPatterns
=
new
String
[]
{
"classpath*:/crash/*"
};
...
@@ -66,7 +66,6 @@ public class CrshProperties {
...
@@ -66,7 +66,6 @@ public class CrshProperties {
private
Telnet
telnet
=
new
Telnet
();
private
Telnet
telnet
=
new
Telnet
();
public
String
getAuth
()
{
public
String
getAuth
()
{
return
this
.
auth
;
return
this
.
auth
;
}
}
...
@@ -74,11 +73,11 @@ public class CrshProperties {
...
@@ -74,11 +73,11 @@ public class CrshProperties {
public
AuthenticationProperties
getAuthenticationProperties
()
{
public
AuthenticationProperties
getAuthenticationProperties
()
{
return
this
.
authenticationProperties
;
return
this
.
authenticationProperties
;
}
}
public
int
getCommandRefreshInterval
()
{
public
int
getCommandRefreshInterval
()
{
return
this
.
commandRefreshInterval
;
return
this
.
commandRefreshInterval
;
}
}
public
String
[]
getCommandPathPatterns
()
{
public
String
[]
getCommandPathPatterns
()
{
return
this
.
commandPathPatterns
;
return
this
.
commandPathPatterns
;
}
}
...
@@ -100,28 +99,29 @@ public class CrshProperties {
...
@@ -100,28 +99,29 @@ public class CrshProperties {
}
}
public
Properties
mergeProperties
(
Properties
properties
)
{
public
Properties
mergeProperties
(
Properties
properties
)
{
properties
=
ssh
.
mergeProperties
(
properties
);
properties
=
this
.
ssh
.
mergeProperties
(
properties
);
properties
=
telnet
.
mergeProperties
(
properties
);
properties
=
t
his
.
t
elnet
.
mergeProperties
(
properties
);
properties
.
put
(
CRASH_AUTH
,
auth
);
properties
.
put
(
CRASH_AUTH
,
this
.
auth
);
if
(
authenticationProperties
!=
null
)
{
if
(
this
.
authenticationProperties
!=
null
)
{
properties
=
authenticationProperties
.
mergeProperties
(
properties
);
properties
=
this
.
authenticationProperties
.
mergeProperties
(
properties
);
}
}
if
(
this
.
commandRefreshInterval
>
0
)
{
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
// special handling for disabling Ssh and Telnet support
List
<
String
>
dp
=
new
ArrayList
<
String
>(
Arrays
.
asList
(
this
.
disabledPlugins
));
List
<
String
>
dp
=
new
ArrayList
<
String
>(
Arrays
.
asList
(
this
.
disabledPlugins
));
if
(!
ssh
.
isEnabled
())
{
if
(!
this
.
ssh
.
isEnabled
())
{
dp
.
add
(
"org.crsh.ssh.SSHPlugin"
);
dp
.
add
(
"org.crsh.ssh.SSHPlugin"
);
}
}
if
(!
telnet
.
isEnabled
())
{
if
(!
t
his
.
t
elnet
.
isEnabled
())
{
dp
.
add
(
"org.crsh.telnet.TelnetPlugin"
);
dp
.
add
(
"org.crsh.telnet.TelnetPlugin"
);
}
}
this
.
disabledPlugins
=
dp
.
toArray
(
new
String
[
dp
.
size
()]);
this
.
disabledPlugins
=
dp
.
toArray
(
new
String
[
dp
.
size
()]);
return
properties
;
return
properties
;
}
}
...
@@ -130,11 +130,12 @@ public class CrshProperties {
...
@@ -130,11 +130,12 @@ public class CrshProperties {
this
.
auth
=
auth
;
this
.
auth
=
auth
;
}
}
public
void
setAuthenticationProperties
(
AuthenticationProperties
authenticationProperties
)
{
public
void
setAuthenticationProperties
(
AuthenticationProperties
authenticationProperties
)
{
Assert
.
notNull
(
authenticationProperties
);
Assert
.
notNull
(
authenticationProperties
);
this
.
authenticationProperties
=
authenticationProperties
;
this
.
authenticationProperties
=
authenticationProperties
;
}
}
public
void
setCommandRefreshInterval
(
int
commandRefreshInterval
)
{
public
void
setCommandRefreshInterval
(
int
commandRefreshInterval
)
{
this
.
commandRefreshInterval
=
commandRefreshInterval
;
this
.
commandRefreshInterval
=
commandRefreshInterval
;
}
}
...
@@ -163,18 +164,15 @@ public class CrshProperties {
...
@@ -163,18 +164,15 @@ public class CrshProperties {
Assert
.
notNull
(
telnet
);
Assert
.
notNull
(
telnet
);
this
.
telnet
=
telnet
;
this
.
telnet
=
telnet
;
}
}
public
interface
AuthenticationProperties
extends
PropertiesProvider
{
public
interface
AuthenticationProperties
extends
PropertiesProvider
{
}
}
@ConfigurationProperties
(
name
=
"shell.auth.jaas"
,
ignoreUnknownFields
=
false
)
@ConfigurationProperties
(
name
=
"shell.auth.jaas"
,
ignoreUnknownFields
=
false
)
public
static
class
JaasAuthenticationProperties
implements
AuthenticationProperties
{
public
static
class
JaasAuthenticationProperties
implements
AuthenticationProperties
{
private
String
domain
=
"my-domain"
;
private
String
domain
=
"my-domain"
;
@Override
@Override
public
Properties
mergeProperties
(
Properties
properties
)
{
public
Properties
mergeProperties
(
Properties
properties
)
{
properties
.
put
(
CRASH_AUTH_JAAS_DOMAIN
,
this
.
domain
);
properties
.
put
(
CRASH_AUTH_JAAS_DOMAIN
,
this
.
domain
);
...
@@ -187,14 +185,12 @@ public class CrshProperties {
...
@@ -187,14 +185,12 @@ public class CrshProperties {
}
}
}
}
@ConfigurationProperties
(
name
=
"shell.auth.key"
,
ignoreUnknownFields
=
false
)
@ConfigurationProperties
(
name
=
"shell.auth.key"
,
ignoreUnknownFields
=
false
)
public
static
class
KeyAuthenticationProperties
implements
AuthenticationProperties
{
public
static
class
KeyAuthenticationProperties
implements
AuthenticationProperties
{
private
String
path
;
private
String
path
;
@Override
@Override
public
Properties
mergeProperties
(
Properties
properties
)
{
public
Properties
mergeProperties
(
Properties
properties
)
{
if
(
this
.
path
!=
null
)
{
if
(
this
.
path
!=
null
)
{
...
@@ -210,41 +206,40 @@ public class CrshProperties {
...
@@ -210,41 +206,40 @@ public class CrshProperties {
}
}
public
interface
PropertiesProvider
{
public
interface
PropertiesProvider
{
Properties
mergeProperties
(
Properties
properties
);
Properties
mergeProperties
(
Properties
properties
);
}
}
@ConfigurationProperties
(
name
=
"shell.auth.simple"
,
ignoreUnknownFields
=
false
)
@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
username
=
"user"
;
private
String
password
=
UUID
.
randomUUID
().
toString
();
private
String
password
=
UUID
.
randomUUID
().
toString
();
private
boolean
defaultPassword
=
true
;
private
boolean
defaultPassword
=
true
;
public
boolean
isDefaultPassword
()
{
public
boolean
isDefaultPassword
()
{
return
this
.
defaultPassword
;
return
this
.
defaultPassword
;
}
}
@Override
@Override
public
Properties
mergeProperties
(
Properties
properties
)
{
public
Properties
mergeProperties
(
Properties
properties
)
{
properties
.
put
(
CRASH_AUTH_SIMPLE_USERNAME
,
this
.
username
);
properties
.
put
(
CRASH_AUTH_SIMPLE_USERNAME
,
this
.
username
);
properties
.
put
(
CRASH_AUTH_SIMPLE_PASSWORD
,
this
.
password
);
properties
.
put
(
CRASH_AUTH_SIMPLE_PASSWORD
,
this
.
password
);
if
(
this
.
defaultPassword
)
{
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
;
return
properties
;
}
}
public
void
setPassword
(
String
password
)
{
public
void
setPassword
(
String
password
)
{
if
(
password
.
startsWith
(
"${"
)
&&
password
.
endsWith
(
"}"
)
||
!
StringUtils
.
hasLength
(
password
))
{
if
(
password
.
startsWith
(
"${"
)
&&
password
.
endsWith
(
"}"
)
||
!
StringUtils
.
hasLength
(
password
))
{
return
;
return
;
}
}
this
.
password
=
password
;
this
.
password
=
password
;
...
@@ -255,20 +250,20 @@ public class CrshProperties {
...
@@ -255,20 +250,20 @@ public class CrshProperties {
Assert
.
hasLength
(
username
);
Assert
.
hasLength
(
username
);
this
.
username
=
username
;
this
.
username
=
username
;
}
}
}
}
@ConfigurationProperties
(
name
=
"shell.auth.spring"
,
ignoreUnknownFields
=
false
)
@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"
};
private
String
[]
roles
=
new
String
[]
{
"ROLE_ADMIN"
};
@Override
@Override
public
Properties
mergeProperties
(
Properties
properties
)
{
public
Properties
mergeProperties
(
Properties
properties
)
{
if
(
this
.
roles
!=
null
)
{
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
;
return
properties
;
}
}
...
@@ -280,7 +275,6 @@ public class CrshProperties {
...
@@ -280,7 +275,6 @@ public class CrshProperties {
}
}
public
static
class
Ssh
implements
PropertiesProvider
{
public
static
class
Ssh
implements
PropertiesProvider
{
private
boolean
enabled
=
true
;
private
boolean
enabled
=
true
;
...
@@ -289,11 +283,10 @@ public class CrshProperties {
...
@@ -289,11 +283,10 @@ public class CrshProperties {
private
String
port
=
"2000"
;
private
String
port
=
"2000"
;
public
boolean
isEnabled
()
{
public
boolean
isEnabled
()
{
return
this
.
enabled
;
return
this
.
enabled
;
}
}
@Override
@Override
public
Properties
mergeProperties
(
Properties
properties
)
{
public
Properties
mergeProperties
(
Properties
properties
)
{
if
(
this
.
enabled
)
{
if
(
this
.
enabled
)
{
...
@@ -321,18 +314,16 @@ public class CrshProperties {
...
@@ -321,18 +314,16 @@ public class CrshProperties {
}
}
public
static
class
Telnet
implements
PropertiesProvider
{
public
static
class
Telnet
implements
PropertiesProvider
{
private
boolean
enabled
=
false
;
private
boolean
enabled
=
false
;
private
String
port
=
"5000"
;
private
String
port
=
"5000"
;
public
boolean
isEnabled
()
{
public
boolean
isEnabled
()
{
return
this
.
enabled
;
return
this
.
enabled
;
}
}
@Override
@Override
public
Properties
mergeProperties
(
Properties
properties
)
{
public
Properties
mergeProperties
(
Properties
properties
)
{
if
(
this
.
enabled
)
{
if
(
this
.
enabled
)
{
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfigurationTests.java
View file @
d784cb6a
...
@@ -16,13 +16,6 @@
...
@@ -16,13 +16,6 @@
package
org
.
springframework
.
boot
.
actuate
.
autoconfigure
;
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.ArrayList
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.Iterator
;
import
java.util.Iterator
;
...
@@ -56,6 +49,13 @@ import org.springframework.security.core.AuthenticationException;
...
@@ -56,6 +49,13 @@ import org.springframework.security.core.AuthenticationException;
import
org.springframework.security.core.authority.SimpleGrantedAuthority
;
import
org.springframework.security.core.authority.SimpleGrantedAuthority
;
import
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
;
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}.
* Tests for {@link CrshAutoConfiguration}.
*
*
...
@@ -65,7 +65,7 @@ import org.springframework.web.context.support.AnnotationConfigWebApplicationCon
...
@@ -65,7 +65,7 @@ import org.springframework.web.context.support.AnnotationConfigWebApplicationCon
public
class
CrshAutoConfigurationTests
{
public
class
CrshAutoConfigurationTests
{
private
AnnotationConfigWebApplicationContext
context
;
private
AnnotationConfigWebApplicationContext
context
;
@After
@After
public
void
tearDown
()
{
public
void
tearDown
()
{
if
(
this
.
context
!=
null
)
{
if
(
this
.
context
!=
null
)
{
...
@@ -77,7 +77,8 @@ public class CrshAutoConfigurationTests {
...
@@ -77,7 +77,8 @@ public class CrshAutoConfigurationTests {
@Test
@Test
public
void
testDisabledPlugins
()
throws
Exception
{
public
void
testDisabledPlugins
()
throws
Exception
{
MockEnvironment
env
=
new
MockEnvironment
();
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
=
new
AnnotationConfigWebApplicationContext
();
this
.
context
.
setEnvironment
(
env
);
this
.
context
.
setEnvironment
(
env
);
this
.
context
.
register
(
CrshAutoConfiguration
.
class
);
this
.
context
.
register
(
CrshAutoConfiguration
.
class
);
...
@@ -96,15 +97,15 @@ public class CrshAutoConfigurationTests {
...
@@ -96,15 +97,15 @@ public class CrshAutoConfigurationTests {
this
.
context
=
new
AnnotationConfigWebApplicationContext
();
this
.
context
=
new
AnnotationConfigWebApplicationContext
();
this
.
context
.
register
(
CrshAutoConfiguration
.
class
);
this
.
context
.
register
(
CrshAutoConfiguration
.
class
);
this
.
context
.
refresh
();
this
.
context
.
refresh
();
PluginLifeCycle
lifeCycle
=
this
.
context
.
getBean
(
PluginLifeCycle
.
class
);
PluginLifeCycle
lifeCycle
=
this
.
context
.
getBean
(
PluginLifeCycle
.
class
);
Map
<
String
,
Object
>
attributes
=
lifeCycle
.
getContext
().
getAttributes
();
Map
<
String
,
Object
>
attributes
=
lifeCycle
.
getContext
().
getAttributes
();
assertTrue
(
attributes
.
containsKey
(
"spring.version"
));
assertTrue
(
attributes
.
containsKey
(
"spring.version"
));
assertTrue
(
attributes
.
containsKey
(
"spring.beanfactory"
));
assertTrue
(
attributes
.
containsKey
(
"spring.beanfactory"
));
assertEquals
(
this
.
context
.
getBeanFactory
(),
attributes
.
get
(
"spring.beanfactory"
));
assertEquals
(
this
.
context
.
getBeanFactory
(),
attributes
.
get
(
"spring.beanfactory"
));
}
}
@Test
@Test
public
void
testSshConfiguration
()
{
public
void
testSshConfiguration
()
{
MockEnvironment
env
=
new
MockEnvironment
();
MockEnvironment
env
=
new
MockEnvironment
();
...
@@ -129,10 +130,11 @@ public class CrshAutoConfigurationTests {
...
@@ -129,10 +130,11 @@ public class CrshAutoConfigurationTests {
this
.
context
.
setEnvironment
(
env
);
this
.
context
.
setEnvironment
(
env
);
this
.
context
.
register
(
CrshAutoConfiguration
.
class
);
this
.
context
.
register
(
CrshAutoConfiguration
.
class
);
this
.
context
.
refresh
();
this
.
context
.
refresh
();
PluginLifeCycle
lifeCycle
=
this
.
context
.
getBean
(
PluginLifeCycle
.
class
);
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
@Test
...
@@ -144,7 +146,8 @@ public class CrshAutoConfigurationTests {
...
@@ -144,7 +146,8 @@ public class CrshAutoConfigurationTests {
PluginLifeCycle
lifeCycle
=
this
.
context
.
getBean
(
PluginLifeCycle
.
class
);
PluginLifeCycle
lifeCycle
=
this
.
context
.
getBean
(
PluginLifeCycle
.
class
);
int
count
=
0
;
int
count
=
0
;
Iterator
<
Resource
>
resources
=
lifeCycle
.
getContext
().
loadResources
(
"login"
,
ResourceKind
.
LIFECYCLE
).
iterator
();
Iterator
<
Resource
>
resources
=
lifeCycle
.
getContext
()
.
loadResources
(
"login"
,
ResourceKind
.
LIFECYCLE
).
iterator
();
while
(
resources
.
hasNext
())
{
while
(
resources
.
hasNext
())
{
count
++;
count
++;
resources
.
next
();
resources
.
next
();
...
@@ -152,7 +155,8 @@ public class CrshAutoConfigurationTests {
...
@@ -152,7 +155,8 @@ public class CrshAutoConfigurationTests {
assertEquals
(
1
,
count
);
assertEquals
(
1
,
count
);
count
=
0
;
count
=
0
;
resources
=
lifeCycle
.
getContext
().
loadResources
(
"help.java"
,
ResourceKind
.
COMMAND
).
iterator
();
resources
=
lifeCycle
.
getContext
()
.
loadResources
(
"help.java"
,
ResourceKind
.
COMMAND
).
iterator
();
while
(
resources
.
hasNext
())
{
while
(
resources
.
hasNext
())
{
count
++;
count
++;
resources
.
next
();
resources
.
next
();
...
@@ -172,14 +176,15 @@ public class CrshAutoConfigurationTests {
...
@@ -172,14 +176,15 @@ public class CrshAutoConfigurationTests {
PluginContext
pluginContext
=
lifeCycle
.
getContext
();
PluginContext
pluginContext
=
lifeCycle
.
getContext
();
int
count
=
0
;
int
count
=
0
;
Iterator
<
AuthenticationPlugin
>
plugins
=
pluginContext
.
getPlugins
(
AuthenticationPlugin
.
class
).
iterator
();
Iterator
<
AuthenticationPlugin
>
plugins
=
pluginContext
.
getPlugins
(
AuthenticationPlugin
.
class
).
iterator
();
while
(
plugins
.
hasNext
())
{
while
(
plugins
.
hasNext
())
{
count
++;
count
++;
plugins
.
next
();
plugins
.
next
();
}
}
assertEquals
(
3
,
count
);
assertEquals
(
3
,
count
);
}
}
@Test
@Test
public
void
testJaasAuthenticationProvider
()
{
public
void
testJaasAuthenticationProvider
()
{
MockEnvironment
env
=
new
MockEnvironment
();
MockEnvironment
env
=
new
MockEnvironment
();
...
@@ -191,10 +196,11 @@ public class CrshAutoConfigurationTests {
...
@@ -191,10 +196,11 @@ public class CrshAutoConfigurationTests {
this
.
context
.
register
(
SecurityConfiguration
.
class
);
this
.
context
.
register
(
SecurityConfiguration
.
class
);
this
.
context
.
register
(
CrshAutoConfiguration
.
class
);
this
.
context
.
register
(
CrshAutoConfiguration
.
class
);
this
.
context
.
refresh
();
this
.
context
.
refresh
();
PluginLifeCycle
lifeCycle
=
this
.
context
.
getBean
(
PluginLifeCycle
.
class
);
PluginLifeCycle
lifeCycle
=
this
.
context
.
getBean
(
PluginLifeCycle
.
class
);
assertEquals
(
lifeCycle
.
getConfig
().
get
(
"crash.auth"
),
"jaas"
);
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
@Test
...
@@ -208,7 +214,7 @@ public class CrshAutoConfigurationTests {
...
@@ -208,7 +214,7 @@ public class CrshAutoConfigurationTests {
this
.
context
.
register
(
SecurityConfiguration
.
class
);
this
.
context
.
register
(
SecurityConfiguration
.
class
);
this
.
context
.
register
(
CrshAutoConfiguration
.
class
);
this
.
context
.
register
(
CrshAutoConfiguration
.
class
);
this
.
context
.
refresh
();
this
.
context
.
refresh
();
PluginLifeCycle
lifeCycle
=
this
.
context
.
getBean
(
PluginLifeCycle
.
class
);
PluginLifeCycle
lifeCycle
=
this
.
context
.
getBean
(
PluginLifeCycle
.
class
);
assertEquals
(
lifeCycle
.
getConfig
().
get
(
"crash.auth"
),
"key"
);
assertEquals
(
lifeCycle
.
getConfig
().
get
(
"crash.auth"
),
"key"
);
assertEquals
(
lifeCycle
.
getConfig
().
get
(
"crash.auth.key.path"
),
"~/test.pem"
);
assertEquals
(
lifeCycle
.
getConfig
().
get
(
"crash.auth.key.path"
),
"~/test.pem"
);
...
@@ -226,14 +232,15 @@ public class CrshAutoConfigurationTests {
...
@@ -226,14 +232,15 @@ public class CrshAutoConfigurationTests {
this
.
context
.
register
(
SecurityConfiguration
.
class
);
this
.
context
.
register
(
SecurityConfiguration
.
class
);
this
.
context
.
register
(
CrshAutoConfiguration
.
class
);
this
.
context
.
register
(
CrshAutoConfiguration
.
class
);
this
.
context
.
refresh
();
this
.
context
.
refresh
();
PluginLifeCycle
lifeCycle
=
this
.
context
.
getBean
(
PluginLifeCycle
.
class
);
PluginLifeCycle
lifeCycle
=
this
.
context
.
getBean
(
PluginLifeCycle
.
class
);
assertEquals
(
lifeCycle
.
getConfig
().
get
(
"crash.auth"
),
"simple"
);
assertEquals
(
lifeCycle
.
getConfig
().
get
(
"crash.auth"
),
"simple"
);
AuthenticationPlugin
<
String
>
authenticationPlugin
=
null
;
AuthenticationPlugin
<
String
>
authenticationPlugin
=
null
;
String
authentication
=
lifeCycle
.
getConfig
().
getProperty
(
"crash.auth"
);
String
authentication
=
lifeCycle
.
getConfig
().
getProperty
(
"crash.auth"
);
assertNotNull
(
authentication
);
assertNotNull
(
authentication
);
for
(
AuthenticationPlugin
plugin
:
lifeCycle
.
getContext
().
getPlugins
(
AuthenticationPlugin
.
class
))
{
for
(
AuthenticationPlugin
plugin
:
lifeCycle
.
getContext
().
getPlugins
(
AuthenticationPlugin
.
class
))
{
if
(
authentication
.
equals
(
plugin
.
getName
()))
{
if
(
authentication
.
equals
(
plugin
.
getName
()))
{
authenticationPlugin
=
plugin
;
authenticationPlugin
=
plugin
;
break
;
break
;
...
@@ -246,7 +253,7 @@ public class CrshAutoConfigurationTests {
...
@@ -246,7 +253,7 @@ public class CrshAutoConfigurationTests {
catch
(
Exception
e
)
{
catch
(
Exception
e
)
{
fail
();
fail
();
}
}
try
{
try
{
assertFalse
(
authenticationPlugin
.
authenticate
(
UUID
.
randomUUID
().
toString
(),
assertFalse
(
authenticationPlugin
.
authenticate
(
UUID
.
randomUUID
().
toString
(),
"password"
));
"password"
));
...
@@ -272,7 +279,8 @@ public class CrshAutoConfigurationTests {
...
@@ -272,7 +279,8 @@ public class CrshAutoConfigurationTests {
AuthenticationPlugin
<
String
>
authenticationPlugin
=
null
;
AuthenticationPlugin
<
String
>
authenticationPlugin
=
null
;
String
authentication
=
lifeCycle
.
getConfig
().
getProperty
(
"crash.auth"
);
String
authentication
=
lifeCycle
.
getConfig
().
getProperty
(
"crash.auth"
);
assertNotNull
(
authentication
);
assertNotNull
(
authentication
);
for
(
AuthenticationPlugin
plugin
:
lifeCycle
.
getContext
().
getPlugins
(
AuthenticationPlugin
.
class
))
{
for
(
AuthenticationPlugin
plugin
:
lifeCycle
.
getContext
().
getPlugins
(
AuthenticationPlugin
.
class
))
{
if
(
authentication
.
equals
(
plugin
.
getName
()))
{
if
(
authentication
.
equals
(
plugin
.
getName
()))
{
authenticationPlugin
=
plugin
;
authenticationPlugin
=
plugin
;
break
;
break
;
...
@@ -286,7 +294,7 @@ public class CrshAutoConfigurationTests {
...
@@ -286,7 +294,7 @@ public class CrshAutoConfigurationTests {
catch
(
Exception
e
)
{
catch
(
Exception
e
)
{
fail
();
fail
();
}
}
try
{
try
{
assertFalse
(
authenticationPlugin
.
authenticate
(
UUID
.
randomUUID
().
toString
(),
assertFalse
(
authenticationPlugin
.
authenticate
(
UUID
.
randomUUID
().
toString
(),
SecurityConfiguration
.
PASSWORD
));
SecurityConfiguration
.
PASSWORD
));
...
@@ -308,10 +316,15 @@ public class CrshAutoConfigurationTests {
...
@@ -308,10 +316,15 @@ public class CrshAutoConfigurationTests {
return
new
AuthenticationManager
()
{
return
new
AuthenticationManager
()
{
@Override
@Override
public
Authentication
authenticate
(
Authentication
authentication
)
throws
AuthenticationException
{
public
Authentication
authenticate
(
Authentication
authentication
)
if
(
authentication
.
getName
().
equals
(
USERNAME
)
&&
authentication
.
getCredentials
().
equals
(
PASSWORD
))
{
throws
AuthenticationException
{
authentication
=
new
UsernamePasswordAuthenticationToken
(
authentication
.
getPrincipal
(),
if
(
authentication
.
getName
().
equals
(
USERNAME
)
authentication
.
getCredentials
(),
Collections
.
singleton
(
new
SimpleGrantedAuthority
(
"ROLE_ADMIN"
)));
&&
authentication
.
getCredentials
().
equals
(
PASSWORD
))
{
authentication
=
new
UsernamePasswordAuthenticationToken
(
authentication
.
getPrincipal
(),
authentication
.
getCredentials
(),
Collections
.
singleton
(
new
SimpleGrantedAuthority
(
"ROLE_ADMIN"
)));
}
}
else
{
else
{
throw
new
BadCredentialsException
(
"Invalid username and password"
);
throw
new
BadCredentialsException
(
"Invalid username and password"
);
...
@@ -320,13 +333,13 @@ public class CrshAutoConfigurationTests {
...
@@ -320,13 +333,13 @@ public class CrshAutoConfigurationTests {
}
}
};
};
}
}
@Bean
@Bean
public
AccessDecisionManager
accessDecisionManager
()
{
public
AccessDecisionManager
accessDecisionManager
()
{
List
<
AccessDecisionVoter
>
voters
=
new
ArrayList
<
AccessDecisionVoter
>();
List
<
AccessDecisionVoter
>
voters
=
new
ArrayList
<
AccessDecisionVoter
>();
voters
.
add
(
new
RoleVoter
());
voters
.
add
(
new
RoleVoter
());
AccessDecisionManager
result
=
new
UnanimousBased
(
voters
);
AccessDecisionManager
result
=
new
UnanimousBased
(
voters
);
return
result
;
return
result
;
}
}
}
}
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/properties/CrshPropertiesTests.java
View file @
d784cb6a
...
@@ -16,12 +16,6 @@
...
@@ -16,12 +16,6 @@
package
org
.
springframework
.
boot
.
actuate
.
properties
;
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.Collections
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -37,6 +31,12 @@ import org.springframework.boot.actuate.properties.CrshProperties.SpringAuthenti
...
@@ -37,6 +31,12 @@ import org.springframework.boot.actuate.properties.CrshProperties.SpringAuthenti
import
org.springframework.boot.bind.RelaxedDataBinder
;
import
org.springframework.boot.bind.RelaxedDataBinder
;
import
org.springframework.core.convert.support.DefaultConversionService
;
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}.
* Tests for {@link CrshProperties}.
*
*
...
@@ -48,7 +48,8 @@ public class CrshPropertiesTests {
...
@@ -48,7 +48,8 @@ public class CrshPropertiesTests {
public
void
testBindingAuth
()
{
public
void
testBindingAuth
()
{
CrshProperties
props
=
new
CrshProperties
();
CrshProperties
props
=
new
CrshProperties
();
RelaxedDataBinder
binder
=
new
RelaxedDataBinder
(
props
,
"shell"
);
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
());
assertFalse
(
binder
.
getBindingResult
().
hasErrors
());
assertEquals
(
"spring"
,
props
.
getAuth
());
assertEquals
(
"spring"
,
props
.
getAuth
());
}
}
...
@@ -67,7 +68,8 @@ public class CrshPropertiesTests {
...
@@ -67,7 +68,8 @@ public class CrshPropertiesTests {
CrshProperties
props
=
new
CrshProperties
();
CrshProperties
props
=
new
CrshProperties
();
RelaxedDataBinder
binder
=
new
RelaxedDataBinder
(
props
,
"shell"
);
RelaxedDataBinder
binder
=
new
RelaxedDataBinder
(
props
,
"shell"
);
binder
.
setConversionService
(
new
DefaultConversionService
());
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
());
assertFalse
(
binder
.
getBindingResult
().
hasErrors
());
assertEquals
(
1
,
props
.
getCommandRefreshInterval
());
assertEquals
(
1
,
props
.
getCommandRefreshInterval
());
}
}
...
@@ -77,11 +79,12 @@ public class CrshPropertiesTests {
...
@@ -77,11 +79,12 @@ public class CrshPropertiesTests {
CrshProperties
props
=
new
CrshProperties
();
CrshProperties
props
=
new
CrshProperties
();
RelaxedDataBinder
binder
=
new
RelaxedDataBinder
(
props
,
"shell"
);
RelaxedDataBinder
binder
=
new
RelaxedDataBinder
(
props
,
"shell"
);
binder
.
setConversionService
(
new
DefaultConversionService
());
binder
.
setConversionService
(
new
DefaultConversionService
());
binder
.
bind
(
new
MutablePropertyValues
(
Collections
.
singletonMap
(
"shell.command_path_patterns"
,
binder
.
bind
(
new
MutablePropertyValues
(
Collections
.
singletonMap
(
"pattern1, pattern2"
)));
"
shell.command_path_patterns"
,
"
pattern1, pattern2"
)));
assertFalse
(
binder
.
getBindingResult
().
hasErrors
());
assertFalse
(
binder
.
getBindingResult
().
hasErrors
());
assertEquals
(
2
,
props
.
getCommandPathPatterns
().
length
);
assertEquals
(
2
,
props
.
getCommandPathPatterns
().
length
);
Assert
.
assertArrayEquals
(
new
String
[]
{
"pattern1"
,
"pattern2"
},
props
.
getCommandPathPatterns
());
Assert
.
assertArrayEquals
(
new
String
[]
{
"pattern1"
,
"pattern2"
},
props
.
getCommandPathPatterns
());
}
}
@Test
@Test
...
@@ -89,11 +92,12 @@ public class CrshPropertiesTests {
...
@@ -89,11 +92,12 @@ public class CrshPropertiesTests {
CrshProperties
props
=
new
CrshProperties
();
CrshProperties
props
=
new
CrshProperties
();
RelaxedDataBinder
binder
=
new
RelaxedDataBinder
(
props
,
"shell"
);
RelaxedDataBinder
binder
=
new
RelaxedDataBinder
(
props
,
"shell"
);
binder
.
setConversionService
(
new
DefaultConversionService
());
binder
.
setConversionService
(
new
DefaultConversionService
());
binder
.
bind
(
new
MutablePropertyValues
(
Collections
.
singletonMap
(
"shell.config_path_patterns"
,
binder
.
bind
(
new
MutablePropertyValues
(
Collections
.
singletonMap
(
"pattern1, pattern2"
)));
"
shell.config_path_patterns"
,
"
pattern1, pattern2"
)));
assertFalse
(
binder
.
getBindingResult
().
hasErrors
());
assertFalse
(
binder
.
getBindingResult
().
hasErrors
());
assertEquals
(
2
,
props
.
getConfigPathPatterns
().
length
);
assertEquals
(
2
,
props
.
getConfigPathPatterns
().
length
);
Assert
.
assertArrayEquals
(
new
String
[]
{
"pattern1"
,
"pattern2"
},
props
.
getConfigPathPatterns
());
Assert
.
assertArrayEquals
(
new
String
[]
{
"pattern1"
,
"pattern2"
},
props
.
getConfigPathPatterns
());
}
}
@Test
@Test
...
@@ -101,11 +105,12 @@ public class CrshPropertiesTests {
...
@@ -101,11 +105,12 @@ public class CrshPropertiesTests {
CrshProperties
props
=
new
CrshProperties
();
CrshProperties
props
=
new
CrshProperties
();
RelaxedDataBinder
binder
=
new
RelaxedDataBinder
(
props
,
"shell"
);
RelaxedDataBinder
binder
=
new
RelaxedDataBinder
(
props
,
"shell"
);
binder
.
setConversionService
(
new
DefaultConversionService
());
binder
.
setConversionService
(
new
DefaultConversionService
());
binder
.
bind
(
new
MutablePropertyValues
(
Collections
.
singletonMap
(
"shell.disabled_plugins"
,
binder
.
bind
(
new
MutablePropertyValues
(
Collections
.
singletonMap
(
"pattern1, pattern2"
)));
"
shell.disabled_plugins"
,
"
pattern1, pattern2"
)));
assertFalse
(
binder
.
getBindingResult
().
hasErrors
());
assertFalse
(
binder
.
getBindingResult
().
hasErrors
());
assertEquals
(
2
,
props
.
getDisabledPlugins
().
length
);
assertEquals
(
2
,
props
.
getDisabledPlugins
().
length
);
assertArrayEquals
(
new
String
[]
{
"pattern1"
,
"pattern2"
},
props
.
getDisabledPlugins
());
assertArrayEquals
(
new
String
[]
{
"pattern1"
,
"pattern2"
},
props
.
getDisabledPlugins
());
}
}
@Test
@Test
...
@@ -119,10 +124,10 @@ public class CrshPropertiesTests {
...
@@ -119,10 +124,10 @@ public class CrshPropertiesTests {
map
.
put
(
"shell.ssh.key_path"
,
"~/.ssh/test.pem"
);
map
.
put
(
"shell.ssh.key_path"
,
"~/.ssh/test.pem"
);
binder
.
bind
(
new
MutablePropertyValues
(
map
));
binder
.
bind
(
new
MutablePropertyValues
(
map
));
assertFalse
(
binder
.
getBindingResult
().
hasErrors
());
assertFalse
(
binder
.
getBindingResult
().
hasErrors
());
Properties
p
=
new
Properties
();
Properties
p
=
new
Properties
();
p
=
props
.
mergeProperties
(
p
);
p
=
props
.
mergeProperties
(
p
);
assertEquals
(
"2222"
,
p
.
get
(
CrshProperties
.
CRASH_SSH_PORT
));
assertEquals
(
"2222"
,
p
.
get
(
CrshProperties
.
CRASH_SSH_PORT
));
assertEquals
(
"~/.ssh/test.pem"
,
p
.
get
(
CrshProperties
.
CRASH_SSH_KEYPATH
));
assertEquals
(
"~/.ssh/test.pem"
,
p
.
get
(
CrshProperties
.
CRASH_SSH_KEYPATH
));
}
}
...
@@ -138,14 +143,14 @@ public class CrshPropertiesTests {
...
@@ -138,14 +143,14 @@ public class CrshPropertiesTests {
map
.
put
(
"shell.ssh.key_path"
,
"~/.ssh/test.pem"
);
map
.
put
(
"shell.ssh.key_path"
,
"~/.ssh/test.pem"
);
binder
.
bind
(
new
MutablePropertyValues
(
map
));
binder
.
bind
(
new
MutablePropertyValues
(
map
));
assertFalse
(
binder
.
getBindingResult
().
hasErrors
());
assertFalse
(
binder
.
getBindingResult
().
hasErrors
());
Properties
p
=
new
Properties
();
Properties
p
=
new
Properties
();
p
=
props
.
mergeProperties
(
p
);
p
=
props
.
mergeProperties
(
p
);
assertNull
(
p
.
get
(
CrshProperties
.
CRASH_SSH_PORT
));
assertNull
(
p
.
get
(
CrshProperties
.
CRASH_SSH_PORT
));
assertNull
(
p
.
get
(
CrshProperties
.
CRASH_SSH_KEYPATH
));
assertNull
(
p
.
get
(
CrshProperties
.
CRASH_SSH_KEYPATH
));
}
}
@Test
@Test
public
void
testBindingTelnet
()
{
public
void
testBindingTelnet
()
{
CrshProperties
props
=
new
CrshProperties
();
CrshProperties
props
=
new
CrshProperties
();
...
@@ -156,13 +161,13 @@ public class CrshPropertiesTests {
...
@@ -156,13 +161,13 @@ public class CrshPropertiesTests {
map
.
put
(
"shell.telnet.port"
,
"2222"
);
map
.
put
(
"shell.telnet.port"
,
"2222"
);
binder
.
bind
(
new
MutablePropertyValues
(
map
));
binder
.
bind
(
new
MutablePropertyValues
(
map
));
assertFalse
(
binder
.
getBindingResult
().
hasErrors
());
assertFalse
(
binder
.
getBindingResult
().
hasErrors
());
Properties
p
=
new
Properties
();
Properties
p
=
new
Properties
();
p
=
props
.
mergeProperties
(
p
);
p
=
props
.
mergeProperties
(
p
);
assertEquals
(
"2222"
,
p
.
get
(
CrshProperties
.
CRASH_TELNET_PORT
));
assertEquals
(
"2222"
,
p
.
get
(
CrshProperties
.
CRASH_TELNET_PORT
));
}
}
@Test
@Test
public
void
testBindingTelnetIgnored
()
{
public
void
testBindingTelnetIgnored
()
{
CrshProperties
props
=
new
CrshProperties
();
CrshProperties
props
=
new
CrshProperties
();
...
@@ -173,13 +178,13 @@ public class CrshPropertiesTests {
...
@@ -173,13 +178,13 @@ public class CrshPropertiesTests {
map
.
put
(
"shell.telnet.port"
,
"2222"
);
map
.
put
(
"shell.telnet.port"
,
"2222"
);
binder
.
bind
(
new
MutablePropertyValues
(
map
));
binder
.
bind
(
new
MutablePropertyValues
(
map
));
assertFalse
(
binder
.
getBindingResult
().
hasErrors
());
assertFalse
(
binder
.
getBindingResult
().
hasErrors
());
Properties
p
=
new
Properties
();
Properties
p
=
new
Properties
();
p
=
props
.
mergeProperties
(
p
);
p
=
props
.
mergeProperties
(
p
);
assertNull
(
p
.
get
(
CrshProperties
.
CRASH_TELNET_PORT
));
assertNull
(
p
.
get
(
CrshProperties
.
CRASH_TELNET_PORT
));
}
}
@Test
@Test
public
void
testBindingJaas
()
{
public
void
testBindingJaas
()
{
JaasAuthenticationProperties
props
=
new
JaasAuthenticationProperties
();
JaasAuthenticationProperties
props
=
new
JaasAuthenticationProperties
();
...
@@ -189,13 +194,13 @@ public class CrshPropertiesTests {
...
@@ -189,13 +194,13 @@ public class CrshPropertiesTests {
map
.
put
(
"shell.auth.jaas.domain"
,
"my-test-domain"
);
map
.
put
(
"shell.auth.jaas.domain"
,
"my-test-domain"
);
binder
.
bind
(
new
MutablePropertyValues
(
map
));
binder
.
bind
(
new
MutablePropertyValues
(
map
));
assertFalse
(
binder
.
getBindingResult
().
hasErrors
());
assertFalse
(
binder
.
getBindingResult
().
hasErrors
());
Properties
p
=
new
Properties
();
Properties
p
=
new
Properties
();
p
=
props
.
mergeProperties
(
p
);
p
=
props
.
mergeProperties
(
p
);
assertEquals
(
"my-test-domain"
,
p
.
get
(
CrshProperties
.
CRASH_AUTH_JAAS_DOMAIN
));
assertEquals
(
"my-test-domain"
,
p
.
get
(
CrshProperties
.
CRASH_AUTH_JAAS_DOMAIN
));
}
}
@Test
@Test
public
void
testBindingKey
()
{
public
void
testBindingKey
()
{
KeyAuthenticationProperties
props
=
new
KeyAuthenticationProperties
();
KeyAuthenticationProperties
props
=
new
KeyAuthenticationProperties
();
...
@@ -205,13 +210,13 @@ public class CrshPropertiesTests {
...
@@ -205,13 +210,13 @@ public class CrshPropertiesTests {
map
.
put
(
"shell.auth.key.path"
,
"~/.ssh/test.pem"
);
map
.
put
(
"shell.auth.key.path"
,
"~/.ssh/test.pem"
);
binder
.
bind
(
new
MutablePropertyValues
(
map
));
binder
.
bind
(
new
MutablePropertyValues
(
map
));
assertFalse
(
binder
.
getBindingResult
().
hasErrors
());
assertFalse
(
binder
.
getBindingResult
().
hasErrors
());
Properties
p
=
new
Properties
();
Properties
p
=
new
Properties
();
p
=
props
.
mergeProperties
(
p
);
p
=
props
.
mergeProperties
(
p
);
assertEquals
(
"~/.ssh/test.pem"
,
p
.
get
(
CrshProperties
.
CRASH_AUTH_KEY_PATH
));
assertEquals
(
"~/.ssh/test.pem"
,
p
.
get
(
CrshProperties
.
CRASH_AUTH_KEY_PATH
));
}
}
@Test
@Test
public
void
testBindingKeyIgnored
()
{
public
void
testBindingKeyIgnored
()
{
KeyAuthenticationProperties
props
=
new
KeyAuthenticationProperties
();
KeyAuthenticationProperties
props
=
new
KeyAuthenticationProperties
();
...
@@ -220,10 +225,10 @@ public class CrshPropertiesTests {
...
@@ -220,10 +225,10 @@ public class CrshPropertiesTests {
Map
<
String
,
String
>
map
=
new
HashMap
<
String
,
String
>();
Map
<
String
,
String
>
map
=
new
HashMap
<
String
,
String
>();
binder
.
bind
(
new
MutablePropertyValues
(
map
));
binder
.
bind
(
new
MutablePropertyValues
(
map
));
assertFalse
(
binder
.
getBindingResult
().
hasErrors
());
assertFalse
(
binder
.
getBindingResult
().
hasErrors
());
Properties
p
=
new
Properties
();
Properties
p
=
new
Properties
();
p
=
props
.
mergeProperties
(
p
);
p
=
props
.
mergeProperties
(
p
);
assertNull
(
p
.
get
(
CrshProperties
.
CRASH_AUTH_KEY_PATH
));
assertNull
(
p
.
get
(
CrshProperties
.
CRASH_AUTH_KEY_PATH
));
}
}
...
@@ -237,14 +242,14 @@ public class CrshPropertiesTests {
...
@@ -237,14 +242,14 @@ public class CrshPropertiesTests {
map
.
put
(
"shell.auth.simple.password"
,
"password123"
);
map
.
put
(
"shell.auth.simple.password"
,
"password123"
);
binder
.
bind
(
new
MutablePropertyValues
(
map
));
binder
.
bind
(
new
MutablePropertyValues
(
map
));
assertFalse
(
binder
.
getBindingResult
().
hasErrors
());
assertFalse
(
binder
.
getBindingResult
().
hasErrors
());
Properties
p
=
new
Properties
();
Properties
p
=
new
Properties
();
p
=
props
.
mergeProperties
(
p
);
p
=
props
.
mergeProperties
(
p
);
assertEquals
(
"username123"
,
p
.
get
(
CrshProperties
.
CRASH_AUTH_SIMPLE_USERNAME
));
assertEquals
(
"username123"
,
p
.
get
(
CrshProperties
.
CRASH_AUTH_SIMPLE_USERNAME
));
assertEquals
(
"password123"
,
p
.
get
(
CrshProperties
.
CRASH_AUTH_SIMPLE_PASSWORD
));
assertEquals
(
"password123"
,
p
.
get
(
CrshProperties
.
CRASH_AUTH_SIMPLE_PASSWORD
));
}
}
@Test
@Test
public
void
testDefaultPasswordAutogeneratedIfUnresolovedPlaceholder
()
{
public
void
testDefaultPasswordAutogeneratedIfUnresolovedPlaceholder
()
{
SimpleAuthenticationProperties
security
=
new
SimpleAuthenticationProperties
();
SimpleAuthenticationProperties
security
=
new
SimpleAuthenticationProperties
();
...
@@ -264,19 +269,19 @@ public class CrshPropertiesTests {
...
@@ -264,19 +269,19 @@ public class CrshPropertiesTests {
assertFalse
(
binder
.
getBindingResult
().
hasErrors
());
assertFalse
(
binder
.
getBindingResult
().
hasErrors
());
assertTrue
(
security
.
isDefaultPassword
());
assertTrue
(
security
.
isDefaultPassword
());
}
}
@Test
@Test
public
void
testBindingSpring
()
{
public
void
testBindingSpring
()
{
SpringAuthenticationProperties
props
=
new
SpringAuthenticationProperties
();
SpringAuthenticationProperties
props
=
new
SpringAuthenticationProperties
();
RelaxedDataBinder
binder
=
new
RelaxedDataBinder
(
props
,
"shell.auth.spring"
);
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
());
assertFalse
(
binder
.
getBindingResult
().
hasErrors
());
Properties
p
=
new
Properties
();
Properties
p
=
new
Properties
();
p
=
props
.
mergeProperties
(
p
);
p
=
props
.
mergeProperties
(
p
);
assertEquals
(
"role1, role2"
,
p
.
get
(
CrshProperties
.
CRASH_AUTH_SPRING_ROLES
));
assertEquals
(
"role1, role2"
,
p
.
get
(
CrshProperties
.
CRASH_AUTH_SPRING_ROLES
));
}
}
}
}
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java
View file @
d784cb6a
...
@@ -16,11 +16,6 @@
...
@@ -16,11 +16,6 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
jdbc
;
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.Connection
;
import
java.sql.Driver
;
import
java.sql.Driver
;
import
java.sql.DriverPropertyInfo
;
import
java.sql.DriverPropertyInfo
;
...
@@ -47,6 +42,10 @@ import org.springframework.jdbc.core.JdbcTemplate;
...
@@ -47,6 +42,10 @@ import org.springframework.jdbc.core.JdbcTemplate;
import
org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations
;
import
org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations
;
import
org.springframework.util.ClassUtils
;
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}.
* Tests for {@link DataSourceAutoConfiguration}.
...
...
spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/task/Repackage.java
View file @
d784cb6a
...
@@ -29,7 +29,7 @@ import org.springframework.boot.loader.tools.Repackager;
...
@@ -29,7 +29,7 @@ import org.springframework.boot.loader.tools.Repackager;
/**
/**
* Repackage task.
* Repackage task.
*
*
* @author Phillip Webb
* @author Phillip Webb
*/
*/
public
class
Repackage
extends
DefaultTask
{
public
class
Repackage
extends
DefaultTask
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment