Hi cas-users, 

Using CAS 6.4.4.2 with MongoDB for Service-, Ticket-Registry and 
Session-Storage at the same time fails to auto-configure in my setup. 

My observations so far:

1. Adding 
------------------------------------------------------------------------------------------------
implementation 
"org.apereo.cas:cas-server-support-session-mongo:${project.'cas.version'}"
------------------------------------------------------------------------------------------------

to build.gradle only,  also requires to re-enable MongoAutoConfiguration 
and MongoDataAutoConfigration by overriding config key 
spring.autoconfigure.exclude since 
/webapp/cas-server-webapp-resources/src/main/resources/application.properties 
disables it:

------------------------------------------------------------------------------------------------
 spring.autoconfigure.exclude= \
   org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,\
   org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration,\
  
 org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration
------------------------------------------------------------------------------------------------

otherwise no MongoTemplate is found at all:

------------------------------------------------------------------------------------------------
**************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of method mongoSessionRepository in 
org.springframework.session.data.mongo.config.annotation.web.http.MongoHttpSessionConfiguration
 
required a bean of type 
'org.springframework.data.mongodb.core.MongoOperations' that could not be 
found.


Action:

Consider defining a bean of type 
'org.springframework.data.mongodb.core.MongoOperations' in your 
configuration.
------------------------------------------------------------------------------------------------


2. Additionally enabling 

------------------------------------------------------------------------------------------------
implementation 
"org.apereo.cas:cas-server-support-mongo-service-registry:${project.'cas.version'}"
implementation 
"org.apereo.cas:cas-server-support-mongo-ticket-registry:${project.'cas.version'}"
------------------------------------------------------------------------------------------------

Modules cas-server-support-mongo-service-registry and 
cas-server-support-mongo-ticket-registry both configure named MongoTemplate 
beans, which they actually do even use themselves, but lead to ambiguity 
when resolving a single candidate for the cas-server-support-session-mongo 
module.

Removing these @Bean definitions solves this problem:

------------------------------------------------------------------------------------------------
diff --git 
a/support/cas-server-support-mongo-service-registry/src/main/java/org/apereo/cas/config/MongoDbServiceRegistryConfiguration.java
 
b/support/cas-server-support-mongo-service-registry/src/main/java/org/apereo/cas/config/MongoDbServiceRegistryConfiguration.java
index 0227845922..9ed3aea44d 100644
--- 
a/support/cas-server-support-mongo-service-registry/src/main/java/org/apereo/cas/config/MongoDbServiceRegistryConfiguration.java
+++ 
b/support/cas-server-support-mongo-service-registry/src/main/java/org/apereo/cas/config/MongoDbServiceRegistryConfiguration.java
@@ -47,9 +47,7 @@ public class MongoDbServiceRegistryConfiguration {
     @Qualifier("sslContext")
     private ObjectProvider<SSLContext> sslContext;
 
-    @ConditionalOnMissingBean(name = "mongoDbServiceRegistryTemplate")
-    @Bean
-    public MongoTemplate mongoDbServiceRegistryTemplate() {
+    private MongoTemplate mongoDbServiceRegistryTemplate() {
         val mongo = casProperties.getServiceRegistry().getMongo();
         val factory = new MongoDbConnectionFactory(sslContext.getObject());
 
diff --git 
a/support/cas-server-support-mongo-ticket-registry/src/main/java/org/apereo/cas/config/MongoDbTicketRegistryConfiguration.java
 
b/support/cas-server-support-mongo-ticket-registry/src/main/java/org/apereo/cas/config/MongoDbTicketRegistryConfiguration.java
index 0a5b538a33..9195ff88a7 100644
--- 
a/support/cas-server-support-mongo-ticket-registry/src/main/java/org/apereo/cas/config/MongoDbTicketRegistryConfiguration.java
+++ 
b/support/cas-server-support-mongo-ticket-registry/src/main/java/org/apereo/cas/config/MongoDbTicketRegistryConfiguration.java
@@ -55,10 +55,7 @@ public class MongoDbTicketRegistryConfiguration {
         return registry;
     }
 
-    @ConditionalOnMissingBean(name = "mongoDbTicketRegistryTemplate")
-    @Bean
-    @RefreshScope
-    public MongoTemplate mongoDbTicketRegistryTemplate() {
+    private MongoTemplate mongoDbTicketRegistryTemplate() {
         val factory = new MongoDbConnectionFactory(sslContext.getObject());
         val mongo = casProperties.getTicket().getRegistry().getMongo();
         return factory.buildMongoTemplate(mongo);
------------------------------------------------------------------------------------------------

otherwise it fails with 

------------------------------------------------------------------------------------------------
***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of method mongoSessionRepository in 
org.springframework.session.data.mongo.config.annotation.web.http.MongoHttpSessionConfiguration
 
required a single bean, but 2 were found:
        - mongoDbServiceRegistryTemplate: defined by method 
'mongoDbServiceRegistryTemplate' in class path resource 
[org/apereo/cas/config/MongoDbServiceRegistryConfiguration.class]
        - mongoDbTicketRegistryTemplate: defined in BeanDefinition defined 
in class path resource 
[org/apereo/cas/config/MongoDbTicketRegistryConfiguration.class]


Action:

Consider marking one of the beans as @Primary, updating the consumer to 
accept multiple beans, or using @Qualifier to identify the bean that should 
be consumed
------------------------------------------------------------------------------------------------

My question now is, how can I fix this nonfunctional behavior without 
patching the original CAS 6.4.4.2 modules 
cas-server-support-mongo-service-registry and 
cas-server-support-mongo-ticket-registry? Is there better, easier or more 
elegant way to use MongoDB for Session, Service and Ticket Storage at the 
same time?

Regards

Martin





-- 
- Website: https://apereo.github.io/cas
- Gitter Chatroom: https://gitter.im/apereo/cas
- List Guidelines: https://goo.gl/1VRrw7
- Contributions: https://goo.gl/mh7qDG
--- 
You received this message because you are subscribed to the Google Groups "CAS 
Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/a/apereo.org/d/msgid/cas-user/db00850f-7c02-4912-aff3-e11a11317fa9n%40apereo.org.

Reply via email to