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
f7c16764
Commit
f7c16764
authored
Apr 21, 2014
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add setter for security.user.role
Fixes gh-700
parent
0aa93036
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
40 deletions
+52
-40
SecurityProperties.java
...ework/boot/autoconfigure/security/SecurityProperties.java
+4
-0
SecurityPropertiesTests.java
.../boot/autoconfigure/security/SecurityPropertiesTests.java
+48
-40
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityProperties.java
View file @
f7c16764
...
@@ -223,6 +223,10 @@ public class SecurityProperties implements SecurityPrequisite {
...
@@ -223,6 +223,10 @@ public class SecurityProperties implements SecurityPrequisite {
return
this
.
role
;
return
this
.
role
;
}
}
public
void
setRole
(
List
<
String
>
role
)
{
this
.
role
=
new
ArrayList
<
String
>(
role
);
}
public
boolean
isDefaultPassword
()
{
public
boolean
isDefaultPassword
()
{
return
this
.
defaultPassword
;
return
this
.
defaultPassword
;
}
}
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityPropertiesTests.java
View file @
f7c16764
...
@@ -20,6 +20,7 @@ import java.util.Collections;
...
@@ -20,6 +20,7 @@ import java.util.Collections;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.springframework.beans.MutablePropertyValues
;
import
org.springframework.beans.MutablePropertyValues
;
import
org.springframework.boot.bind.RelaxedDataBinder
;
import
org.springframework.boot.bind.RelaxedDataBinder
;
...
@@ -36,81 +37,88 @@ import static org.junit.Assert.assertTrue;
...
@@ -36,81 +37,88 @@ import static org.junit.Assert.assertTrue;
*/
*/
public
class
SecurityPropertiesTests
{
public
class
SecurityPropertiesTests
{
private
SecurityProperties
security
=
new
SecurityProperties
();
private
RelaxedDataBinder
binder
=
new
RelaxedDataBinder
(
this
.
security
,
"security"
);
@Before
public
void
init
()
{
this
.
binder
.
setIgnoreUnknownFields
(
false
);
this
.
binder
.
setConversionService
(
new
DefaultConversionService
());
}
@Test
@Test
public
void
testBindingIgnoredSingleValued
()
{
public
void
testBindingIgnoredSingleValued
()
{
SecurityProperties
security
=
new
SecurityProperties
();
this
.
binder
.
bind
(
new
MutablePropertyValues
(
Collections
.
singletonMap
(
RelaxedDataBinder
binder
=
new
RelaxedDataBinder
(
security
,
"security"
);
binder
.
bind
(
new
MutablePropertyValues
(
Collections
.
singletonMap
(
"security.ignored"
,
"/css/**"
)));
"security.ignored"
,
"/css/**"
)));
assertFalse
(
binder
.
getBindingResult
().
hasErrors
());
assertFalse
(
this
.
binder
.
getBindingResult
().
hasErrors
());
assertEquals
(
1
,
security
.
getIgnored
().
size
());
assertEquals
(
1
,
this
.
security
.
getIgnored
().
size
());
}
}
@Test
@Test
public
void
testBindingIgnoredEmpty
()
{
public
void
testBindingIgnoredEmpty
()
{
SecurityProperties
security
=
new
SecurityProperties
();
this
.
binder
.
bind
(
new
MutablePropertyValues
(
Collections
.
singletonMap
(
RelaxedDataBinder
binder
=
new
RelaxedDataBinder
(
security
,
"security"
);
binder
.
setConversionService
(
new
DefaultConversionService
());
binder
.
bind
(
new
MutablePropertyValues
(
Collections
.
singletonMap
(
"security.ignored"
,
""
)));
"security.ignored"
,
""
)));
assertFalse
(
binder
.
getBindingResult
().
hasErrors
());
assertFalse
(
this
.
binder
.
getBindingResult
().
hasErrors
());
assertEquals
(
0
,
security
.
getIgnored
().
size
());
assertEquals
(
0
,
this
.
security
.
getIgnored
().
size
());
}
}
@Test
@Test
public
void
testBindingIgnoredDisable
()
{
public
void
testBindingIgnoredDisable
()
{
SecurityProperties
security
=
new
SecurityProperties
();
this
.
binder
.
bind
(
new
MutablePropertyValues
(
Collections
.
singletonMap
(
RelaxedDataBinder
binder
=
new
RelaxedDataBinder
(
security
,
"security"
);
binder
.
setConversionService
(
new
DefaultConversionService
());
binder
.
bind
(
new
MutablePropertyValues
(
Collections
.
singletonMap
(
"security.ignored"
,
"none"
)));
"security.ignored"
,
"none"
)));
assertFalse
(
binder
.
getBindingResult
().
hasErrors
());
assertFalse
(
this
.
binder
.
getBindingResult
().
hasErrors
());
assertEquals
(
1
,
security
.
getIgnored
().
size
());
assertEquals
(
1
,
this
.
security
.
getIgnored
().
size
());
}
}
@Test
@Test
public
void
testBindingIgnoredMultiValued
()
{
public
void
testBindingIgnoredMultiValued
()
{
SecurityProperties
security
=
new
SecurityProperties
();
this
.
binder
.
bind
(
new
MutablePropertyValues
(
Collections
.
singletonMap
(
RelaxedDataBinder
binder
=
new
RelaxedDataBinder
(
security
,
"security"
);
binder
.
setConversionService
(
new
DefaultConversionService
());
binder
.
bind
(
new
MutablePropertyValues
(
Collections
.
singletonMap
(
"security.ignored"
,
"/css/**,/images/**"
)));
"security.ignored"
,
"/css/**,/images/**"
)));
assertFalse
(
binder
.
getBindingResult
().
hasErrors
());
assertFalse
(
this
.
binder
.
getBindingResult
().
hasErrors
());
assertEquals
(
2
,
security
.
getIgnored
().
size
());
assertEquals
(
2
,
this
.
security
.
getIgnored
().
size
());
}
}
@Test
@Test
public
void
testBindingIgnoredMultiValuedList
()
{
public
void
testBindingIgnoredMultiValuedList
()
{
SecurityProperties
security
=
new
SecurityProperties
();
RelaxedDataBinder
binder
=
new
RelaxedDataBinder
(
security
,
"security"
);
binder
.
setConversionService
(
new
DefaultConversionService
());
Map
<
String
,
String
>
map
=
new
HashMap
<
String
,
String
>();
Map
<
String
,
String
>
map
=
new
HashMap
<
String
,
String
>();
map
.
put
(
"security.ignored[0]"
,
"/css/**"
);
map
.
put
(
"security.ignored[0]"
,
"/css/**"
);
map
.
put
(
"security.ignored[1]"
,
"/foo/**"
);
map
.
put
(
"security.ignored[1]"
,
"/foo/**"
);
binder
.
bind
(
new
MutablePropertyValues
(
map
));
this
.
binder
.
bind
(
new
MutablePropertyValues
(
map
));
assertFalse
(
binder
.
getBindingResult
().
hasErrors
());
assertFalse
(
this
.
binder
.
getBindingResult
().
hasErrors
());
assertEquals
(
2
,
security
.
getIgnored
().
size
());
assertEquals
(
2
,
this
.
security
.
getIgnored
().
size
());
assertTrue
(
security
.
getIgnored
().
contains
(
"/foo/**"
));
assertTrue
(
this
.
security
.
getIgnored
().
contains
(
"/foo/**"
));
}
}
@Test
@Test
public
void
testDefaultPasswordAutogeneratedIfUnresolovedPlaceholder
()
{
public
void
testDefaultPasswordAutogeneratedIfUnresolovedPlaceholder
()
{
SecurityProperties
security
=
new
SecurityProperties
();
this
.
binder
.
bind
(
new
MutablePropertyValues
(
Collections
.
singletonMap
(
RelaxedDataBinder
binder
=
new
RelaxedDataBinder
(
security
,
"security"
);
binder
.
bind
(
new
MutablePropertyValues
(
Collections
.
singletonMap
(
"security.user.password"
,
"${ADMIN_PASSWORD}"
)));
"security.user.password"
,
"${ADMIN_PASSWORD}"
)));
assertFalse
(
binder
.
getBindingResult
().
hasErrors
());
assertFalse
(
this
.
binder
.
getBindingResult
().
hasErrors
());
assertTrue
(
security
.
getUser
().
isDefaultPassword
());
assertTrue
(
this
.
security
.
getUser
().
isDefaultPassword
());
}
}
@Test
@Test
public
void
testDefaultPasswordAutogeneratedIfEmpty
()
{
public
void
testDefaultPasswordAutogeneratedIfEmpty
()
{
SecurityProperties
security
=
new
SecurityProperties
();
this
.
binder
.
bind
(
new
MutablePropertyValues
(
Collections
.
singletonMap
(
RelaxedDataBinder
binder
=
new
RelaxedDataBinder
(
security
,
"security"
);
binder
.
bind
(
new
MutablePropertyValues
(
Collections
.
singletonMap
(
"security.user.password"
,
""
)));
"security.user.password"
,
""
)));
assertFalse
(
binder
.
getBindingResult
().
hasErrors
());
assertFalse
(
this
.
binder
.
getBindingResult
().
hasErrors
());
assertTrue
(
security
.
getUser
().
isDefaultPassword
());
assertTrue
(
this
.
security
.
getUser
().
isDefaultPassword
());
}
@Test
public
void
testRoles
()
{
this
.
binder
.
bind
(
new
MutablePropertyValues
(
Collections
.
singletonMap
(
"security.user.role"
,
"USER,ADMIN"
)));
assertFalse
(
this
.
binder
.
getBindingResult
().
hasErrors
());
assertEquals
(
"[USER, ADMIN]"
,
this
.
security
.
getUser
().
getRole
().
toString
());
}
@Test
public
void
testRole
()
{
this
.
binder
.
bind
(
new
MutablePropertyValues
(
Collections
.
singletonMap
(
"security.user.role"
,
"ADMIN"
)));
assertFalse
(
this
.
binder
.
getBindingResult
().
hasErrors
());
assertEquals
(
"[ADMIN]"
,
this
.
security
.
getUser
().
getRole
().
toString
());
}
}
}
}
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