Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge branch 'master' into feature/SHIBUI-1031
- v2.0.6
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v2.0.0-BETA-RC5
- v2.0.0-BETA-R2
- v2.0.0-BETA-R1
- v1.18.0
- v1.17.4
- v1.17.3
- v1.17.2
- v1.17.1
- v1.17.0
- v1.16.0
- v1.15.2
- v1.15.1
- v1.15.0
- v1.14.0
- v1.13.3
- v1.13.2
- v1.13.1
- v1.13.0
- v1.12.0
- v1.11.1
- v1.11.0
- v1.10.3
- v1.10.2
- v1.10.1
- v1.10.0
- v1.9.2
- v1.9.1
- v1.9.0
- v1.8.1
- v1.8.0
- v1.7.0
- v1.7.0-RC2
- v1.7.0-RC1
- v1.6.4
- v1.6.4-SNAPSHOT
- v1.6.0
- v1.6.0-RC1
- v1.5.3
- v1.5.2
- v1.5.1
- v1.5.0
- 2.0.6
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 2.0.0-BETA-RC5
- 2.0.0-BETA-R2
- 2.0.0-BETA-R1
- 1.18.0
- 1.17.4
- 1.17.3
- 1.17.2
- 1.17.1
- 1.17.0
- 1.16.0
- 1.15.2
- 1.15.1
- 1.15.0
- 1.14.0
- 1.13.3
- 1.13.2
- 1.13.1
- 1.13.0
- 1.12.0
- 1.11.1
- 1.11.0
- 1.10.3
- 1.10.2
- 1.10.1
- 1.10.0
- 1.9.2
- 1.9.1
- 1.9.0
- 1.8.1
- 1.8.0
- 1.7.0
- 1.7.0-RC2
- 1.7.0-RC1
- 1.6.4
- 1.6.3
- 1.6.2
- 1.6.1
- 1.6.0
- 1.6.0-RC1
- 1.5.3
Showing
20 changed files
with
3,465 additions
and
9,722 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
backend/src/main/groovy/edu/internet2/tier/shibboleth/admin/ui/service/UserBootstrap.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package edu.internet2.tier.shibboleth.admin.ui.service | ||
|
||
import com.opencsv.CSVReader | ||
import edu.internet2.tier.shibboleth.admin.ui.configuration.ShibUIConfiguration | ||
import edu.internet2.tier.shibboleth.admin.ui.security.model.Role | ||
import edu.internet2.tier.shibboleth.admin.ui.security.model.User | ||
import edu.internet2.tier.shibboleth.admin.ui.security.repository.RoleRepository | ||
import edu.internet2.tier.shibboleth.admin.ui.security.repository.UserRepository | ||
import groovy.util.logging.Slf4j | ||
import org.springframework.boot.context.event.ApplicationStartedEvent | ||
import org.springframework.context.event.EventListener | ||
import org.springframework.stereotype.Component | ||
|
||
import javax.transaction.Transactional | ||
|
||
@Component | ||
@Slf4j | ||
class UserBootstrap { | ||
private final ShibUIConfiguration shibUIConfiguration | ||
private final UserRepository userRepository | ||
private final RoleRepository roleRepository | ||
|
||
UserBootstrap(ShibUIConfiguration shibUIConfiguration, UserRepository userRepository, RoleRepository roleRepository) { | ||
this.shibUIConfiguration = shibUIConfiguration | ||
this.userRepository = userRepository | ||
this.roleRepository = roleRepository | ||
} | ||
|
||
@Transactional | ||
@EventListener | ||
void bootstrapUsersAndRoles(ApplicationStartedEvent e) { | ||
if (shibUIConfiguration.userBootstrapResource) { | ||
log.info("configuring users from ${shibUIConfiguration.userBootstrapResource.URI}") | ||
new CSVReader(new InputStreamReader(shibUIConfiguration.userBootstrapResource.inputStream)).each { it -> | ||
def (username, password, firstName, lastName, roleName) = it | ||
def role = roleRepository.findByName(roleName).orElse(roleRepository.save(new Role(name: roleName))) | ||
def user = userRepository.findByUsername(username).orElse(new User(username: username)).with { | ||
it.password = password | ||
it.firstName = firstName | ||
it.lastName = lastName | ||
it.roles.add(role) | ||
it | ||
} | ||
userRepository.save(user) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
.../src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/service/UserBootstrapTests.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package edu.internet2.tier.shibboleth.admin.ui.service | ||
|
||
import edu.internet2.tier.shibboleth.admin.ui.configuration.CoreShibUiConfiguration | ||
import edu.internet2.tier.shibboleth.admin.ui.configuration.InternationalizationConfiguration | ||
import edu.internet2.tier.shibboleth.admin.ui.configuration.SearchConfiguration | ||
import edu.internet2.tier.shibboleth.admin.ui.configuration.ShibUIConfiguration | ||
import edu.internet2.tier.shibboleth.admin.ui.configuration.TestConfiguration | ||
import edu.internet2.tier.shibboleth.admin.ui.security.repository.RoleRepository | ||
import edu.internet2.tier.shibboleth.admin.ui.security.repository.UserRepository | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.autoconfigure.domain.EntityScan | ||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest | ||
import org.springframework.core.io.ClassPathResource | ||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories | ||
import org.springframework.test.annotation.DirtiesContext | ||
import org.springframework.test.context.ContextConfiguration | ||
import spock.lang.Specification | ||
|
||
@DataJpaTest | ||
@ContextConfiguration(classes=[CoreShibUiConfiguration, SearchConfiguration, TestConfiguration, InternationalizationConfiguration, ShibUIConfiguration]) | ||
@EnableJpaRepositories(basePackages = ["edu.internet2.tier.shibboleth.admin.ui"]) | ||
@EntityScan(["edu.internet2.tier.shibboleth.admin.ui", "edu.internet2.tier.shibboleth.admin.ui.security.model"]) | ||
@DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD) | ||
class UserBootstrapTests extends Specification { | ||
@Autowired | ||
ShibUIConfiguration shibUIConfiguration | ||
|
||
@Autowired | ||
UserRepository userRepository | ||
|
||
@Autowired | ||
RoleRepository roleRepository | ||
|
||
def "simple test"() { | ||
setup: | ||
shibUIConfiguration.userBootstrapResource = new ClassPathResource('/conf/1044.csv') | ||
def userBootstrap = new UserBootstrap(shibUIConfiguration, userRepository, roleRepository) | ||
|
||
when: | ||
userBootstrap.bootstrapUsersAndRoles(null) | ||
|
||
then: | ||
noExceptionThrown() | ||
assert userRepository.findAll().size() == 2 | ||
assert roleRepository.findAll().size() == 2 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
"user1","password1","firstName1","lastName1","ROLE_ADMIN" | ||
"user2","password2","firstName2","lastName2","ROLE_USER" |
Oops, something went wrong.