Skip to content

Commit

Permalink
[SHIBUI-1218]
Browse files Browse the repository at this point in the history
  • Loading branch information
jj committed Feb 12, 2019
1 parent e96494f commit f09ff34
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ class UserBootstrap {
@Transactional
@EventListener
void bootstrapUsersAndRoles(ApplicationStartedEvent e) {
if (shibUIConfiguration.roles) {
log.info("bootstrapping roles")
shibUIConfiguration.roles.each { it ->
def role = roleRepository.findByName(it).orElse(new Role(name: it))
roleRepository.saveAndFlush(role)
}
}
if (shibUIConfiguration.userBootstrapResource) {
log.info("configuring users from ${shibUIConfiguration.userBootstrapResource.URI}")
new CSVReader(new InputStreamReader(shibUIConfiguration.userBootstrapResource.inputStream)).each { it ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class ShibUIConfiguration {
* A Resource containing a CSV of users to bootstrap into the system. Currently, this must be in format
*
* <code>
* username,password,firstName,lastName,role
* username,password,firstName,lastName,role,email
* </code>
*
* Note that the password must be encrypted in the file. Ensure that you prepend the encoder to the value, e.g.
Expand All @@ -34,4 +34,9 @@ public class ShibUIConfiguration {
* </code>
*/
private Resource userBootstrapResource;

/**
* A list of roles to bootstrap into the system.
*/
private List<String> roles;
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,19 @@ class UserBootstrapTests extends Specification {
assert userRepository.findAll().size() == 2
assert roleRepository.findAll().size() == 2
}

def "bootstrap roles"() {
setup:
shibUIConfiguration.roles = ['ROLE_ADMIN', 'ROLE_USER']
def userbootstrap = new UserBootstrap(shibUIConfiguration, userRepository, roleRepository)

when:
userbootstrap.bootstrapUsersAndRoles(null)

then:
noExceptionThrown()
assert roleRepository.findAll().size() == 2
assert roleRepository.findByName('ROLE_ADMIN').get()
assert roleRepository.findByName('ROLE_USER').get()
}
}
4 changes: 3 additions & 1 deletion pac4j-module/src/test/docker/conf/application.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
spring:
profiles:
include: dev
include:
server:
port: 8443
ssl:
Expand All @@ -9,6 +9,8 @@ server:
keyStoreType: "PKCS12"
keyAlias: "tomcat"
shibui:
user-bootstrap-resource: file:/conf/users.csv
roles: ROLE_ADMIN,ROLE_NONE,ROLE_USER,ROLE_PONY
pac4j:
keystorePath: "/conf/samlKeystore.jks"
keystorePassword: "changeit"
Expand Down

0 comments on commit f09ff34

Please sign in to comment.