forked from apereo/cas
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement service registry auto-initialization (apereo#1771)
* Implement JPA service registry auto-initialization * Overlooked local dev changes pushed * updated registries to implement size; moved initializer over * fixed refreshscope issue * fixed refreshscope issue * Updated docs * fixed cloud dependency conflicts * fixed cloud dependency conflicts * added amqp settings for the cloud bus * added amqp settings for the cloud bus * changed to ctor injection * given that configuration classes are not able to pick up injections at the ctor level, switched back to Component, which then helped to set the class as package private * fixed cs errors with javadocs * fixed cs errors with javadocs * fixed cs errors with javadocs * fixed cs errors with javadocs * fixed cs errors with javadocs * fixed cs errors with javadocs * fixed cs errors with javadocs * fixed cs errors with javadocs * fixed cs errors with javadocs * fixed cs errors with javadocs * fixed cs errors with javadocs
- Loading branch information
1 parent
8d2b19a
commit a1b21f4
Showing
49 changed files
with
397 additions
and
296 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
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
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
71 changes: 71 additions & 0 deletions
71
...erver-core-services/src/main/java/org/apereo/cas/services/ServiceRegistryInitializer.java
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,71 @@ | ||
package org.apereo.cas.services; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.annotation.PostConstruct; | ||
|
||
|
||
/** | ||
* Initializes Jpa service registry database with available JSON service definitions if necessary (based on configuration flag). | ||
* | ||
* @author Dmitriy Kopylenko | ||
* @author Misagh Moayyed | ||
* @since 5.0.0 | ||
*/ | ||
@Component("serviceRegistryInitializer") | ||
class ServiceRegistryInitializer { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(ServiceRegistryInitializer.class); | ||
|
||
private final ServiceRegistryDao serviceRegistryDao; | ||
|
||
private final ServiceRegistryDao jsonServiceRegistryDao; | ||
|
||
@Value("${svcreg.database.from.json:true}") | ||
private boolean initFromJsonIfAvailable; | ||
|
||
@Autowired | ||
ServiceRegistryInitializer(@Qualifier("jsonServiceRegistryDao") | ||
final ServiceRegistryDao jsonServiceRegistryDao, | ||
@Qualifier("serviceRegistryDao") | ||
final ServiceRegistryDao serviceRegistryDao) { | ||
this.jsonServiceRegistryDao = jsonServiceRegistryDao; | ||
this.serviceRegistryDao = serviceRegistryDao; | ||
} | ||
|
||
/** | ||
* Init service registry if necessary. | ||
*/ | ||
@PostConstruct | ||
public void initServiceRegistryIfNecessary() { | ||
|
||
if (this.serviceRegistryDao.equals(this.jsonServiceRegistryDao)) { | ||
return; | ||
} | ||
|
||
final long size = this.serviceRegistryDao.size(); | ||
|
||
if (size == 0) { | ||
if (this.initFromJsonIfAvailable) { | ||
LOGGER.debug("Service registry database will be auto-initialized from default JSON services"); | ||
this.jsonServiceRegistryDao.load().forEach(r -> { | ||
LOGGER.debug("Initializing DB with the {} JSON service definition...", r); | ||
this.serviceRegistryDao.save(r); | ||
}); | ||
this.serviceRegistryDao.load(); | ||
} else { | ||
LOGGER.info("The service registry database will not be initialized from default JSON services. " | ||
+ "Since the service registry database is empty, CAS will refuse to authenticate services " | ||
+ "until service definitions are added to the database."); | ||
} | ||
} else { | ||
LOGGER.debug("Service registry database contains {} service definitions", size); | ||
} | ||
|
||
} | ||
} |
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
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
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
Oops, something went wrong.