{
+public abstract class AbstractLogHandlerConfiguration {
- public final static String PREFIX = CasLoggingConfigurationProperties.PREFIX + ".history";
+ protected final static PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull();
- protected final P handlerProperties;
+ public static class AbstractBasicLogHandlerConfiguration
+ extends AbstractLogHandlerConfiguration {
- protected final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull();
+ public final static String PREFIX = CasLoggingConfigurationProperties.PREFIX + ".basic";
+
+ public final static String LOG_HANDLER_BEAN_NAME = "basicLoggingLogHandler";
+
+ protected final P handlerProperties;
+
+ public AbstractBasicLogHandlerConfiguration(final P handlerProperties) {
+ this.handlerProperties = handlerProperties;
+ }
+
+ }
+
+ public static class AbstractHistoryLogHandlerConfiguration
+ extends AbstractLogHandlerConfiguration {
+
+ public final static String PREFIX = CasLoggingConfigurationProperties.PREFIX + ".history";
+
+ public final static String LOG_HANDLER_BEAN_NAME = "historyLoggingLogHandler";
+
+ protected final P handlerProperties;
+
+ public AbstractHistoryLogHandlerConfiguration(final P handlerProperties) {
+ this.handlerProperties = handlerProperties;
+ }
- public AbstractLogHandlerConfiguration(final P handlerProperties) {
- this.handlerProperties = handlerProperties;
}
}
\ No newline at end of file
diff --git a/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/BaseLoginLoggingConfiguration.java b/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/BaseLoginLoggingConfiguration.java
new file mode 100644
index 0000000..133e56c
--- /dev/null
+++ b/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/BaseLoginLoggingConfiguration.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package org.apereo.cas.logging.autoconfigure;
+
+import com.buession.core.validator.Validate;
+import com.buession.geoip.Resolver;
+import com.buession.logging.core.handler.LogHandler;
+import com.buession.logging.core.handler.PrincipalHandler;
+import com.buession.logging.core.request.RequestContext;
+import com.buession.logging.spring.LogManagerFactoryBean;
+import org.apereo.cas.core.CasCoreConfigurationProperties;
+import org.springframework.beans.factory.ObjectProvider;
+
+/**
+ * @author Yong.Teng
+ * @since 2.3.3
+ */
+public abstract class BaseLoginLoggingConfiguration {
+
+ protected final CasCoreConfigurationProperties casCoreConfigurationProperties;
+
+ public BaseLoginLoggingConfiguration(CasCoreConfigurationProperties casCoreConfigurationProperties) {
+ this.casCoreConfigurationProperties = casCoreConfigurationProperties;
+ }
+
+ protected LogManagerFactoryBean createLogManagerFactoryBean(
+ final ObjectProvider> principalHandler,
+ final ObjectProvider requestContext,
+ final ObjectProvider logHandler,
+ final ObjectProvider geoResolver) {
+ final LogManagerFactoryBean logManagerFactoryBean = new LogManagerFactoryBean();
+
+ requestContext.ifAvailable(logManagerFactoryBean::setRequestContext);
+ geoResolver.ifAvailable(logManagerFactoryBean::setGeoResolver);
+ principalHandler.ifAvailable(logManagerFactoryBean::setPrincipalHandler);
+ logHandler.ifAvailable(logManagerFactoryBean::setLogHandler);
+
+ if(Validate.isNotBlank(casCoreConfigurationProperties.getClientRealIpHeaderName())){
+ logManagerFactoryBean.setClientIpHeaderName(casCoreConfigurationProperties.getClientRealIpHeaderName());
+ }
+
+ return logManagerFactoryBean;
+ }
+
+}
diff --git a/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/BasicLoginLoggingConfiguration.java b/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/BasicLoginLoggingConfiguration.java
index 20721d1..bab6179 100644
--- a/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/BasicLoginLoggingConfiguration.java
+++ b/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/BasicLoginLoggingConfiguration.java
@@ -19,117 +19,57 @@
* +-------------------------------------------------------------------------------------------------------+
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
* | Author: Yong.Teng |
- * | Copyright @ 2013-2023 Buession.com Inc. |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package org.apereo.cas.logging.autoconfigure;
-import org.apereo.cas.configuration.model.support.jpa.AbstractJpaProperties;
-import org.apereo.cas.configuration.support.JpaBeans;
+import com.buession.geoip.Resolver;
+import com.buession.logging.core.handler.LogHandler;
+import com.buession.logging.core.handler.PrincipalHandler;
+import com.buession.logging.core.mgt.LogManager;
+import com.buession.logging.core.request.RequestContext;
+import com.buession.logging.spring.LogManagerFactoryBean;
+import org.apereo.cas.core.CasCoreConfigurationProperties;
import org.apereo.cas.logging.Constants;
import org.apereo.cas.logging.config.CasLoggingConfigurationProperties;
import org.apereo.cas.logging.manager.BasicLoginLoggingManager;
-import org.apereo.cas.logging.manager.ConsoleBasicLoginLoggingManager;
-import org.apereo.cas.logging.manager.JdbcBasicLoginLoggingManager;
+import org.apereo.cas.logging.manager.DefaultBasicLoginLoggingManager;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import org.springframework.jdbc.datasource.DataSourceTransactionManager;
-import org.springframework.transaction.PlatformTransactionManager;
-import org.springframework.transaction.support.TransactionTemplate;
-
-import javax.sql.DataSource;
/**
* @author Yong.Teng
* @since 2.3.0
*/
@Configuration(proxyBeanMethods = false)
-@EnableConfigurationProperties({CasLoggingConfigurationProperties.class})
+@EnableConfigurationProperties({CasCoreConfigurationProperties.class, CasLoggingConfigurationProperties.class})
@ConditionalOnProperty(prefix = CasLoggingConfigurationProperties.PREFIX, name = "enabled", havingValue = "true")
-public class BasicLoginLoggingConfiguration {
-
- private final static String PREFIX = CasLoggingConfigurationProperties.PREFIX + ".basic";
-
- @Configuration(proxyBeanMethods = false)
- @EnableConfigurationProperties({CasLoggingConfigurationProperties.class})
- @ConditionalOnProperty(prefix = PREFIX, name = "jdbc.enabled", havingValue = "true")
- @ConditionalOnMissingBean(name = Constants.BASIC_LOGIN_LOGGING_MANAGER_BEAN_NAME)
- static class BasicJdbcLoginLoggingManagerConfiguration {
-
- protected final CasLoggingConfigurationProperties loggingConfigurationProperties;
-
- protected final AbstractJpaProperties jpaProperties;
-
- public BasicJdbcLoginLoggingManagerConfiguration(
- CasLoggingConfigurationProperties loggingConfigurationProperties) {
- this.loggingConfigurationProperties = loggingConfigurationProperties;
- this.jpaProperties = loggingConfigurationProperties.getBasic().getJdbc();
- }
-
- @Bean(name = Constants.BASIC_LOGIN_LOGGING_DATASOURCE_BEAN_NAME)
- @ConditionalOnMissingBean(name = Constants.BASIC_LOGIN_LOGGING_DATASOURCE_BEAN_NAME)
- public DataSource basicLoginLoggingDataSource() {
- return JpaBeans.newDataSource(jpaProperties);
- }
-
- @Bean(name = Constants.BASIC_LOGIN_LOGGING_JDBC_TRANSACTION_MANAGER_BEAN_NAME)
- @ConditionalOnMissingBean(name = Constants.BASIC_LOGIN_LOGGING_JDBC_TRANSACTION_MANAGER_BEAN_NAME)
- public PlatformTransactionManager basicLoginLoggingTransactionManager(
- @Qualifier(Constants.BASIC_LOGIN_LOGGING_DATASOURCE_BEAN_NAME) DataSource loginLogDataSource) {
- return new DataSourceTransactionManager(loginLogDataSource);
- }
-
- @Bean(name = Constants.BASIC_LOGIN_LOGGING_JDBC_TRANSACTION_TEMPLATE_BEAN_NAME)
- @ConditionalOnMissingBean(name = Constants.BASIC_LOGIN_LOGGING_JDBC_TRANSACTION_TEMPLATE_BEAN_NAME)
- public TransactionTemplate basicLoginLoggingTransactionTemplate(
- @Qualifier(Constants.BASIC_LOGIN_LOGGING_JDBC_TRANSACTION_MANAGER_BEAN_NAME) PlatformTransactionManager loginLogTransactionManager) {
- return createTransactionTemplate(loginLogTransactionManager);
- }
-
- @Bean(name = Constants.BASIC_LOGIN_LOGGING_MANAGER_BEAN_NAME)
- @ConditionalOnBean(name = Constants.BASIC_LOGIN_LOGGING_JDBC_TRANSACTION_TEMPLATE_BEAN_NAME)
- public BasicLoginLoggingManager basicLoginLoggingManager(
- @Qualifier(Constants.BASIC_LOGIN_LOGGING_DATASOURCE_BEAN_NAME) ObjectProvider dataSource,
- @Qualifier(Constants.BASIC_LOGIN_LOGGING_JDBC_TRANSACTION_TEMPLATE_BEAN_NAME) ObjectProvider transactionTemplate) {
- return new JdbcBasicLoginLoggingManager(dataSource.getIfAvailable(),
- transactionTemplate.getIfAvailable(), loggingConfigurationProperties.getBasic().getJdbc());
- }
-
- protected TransactionTemplate createTransactionTemplate(final PlatformTransactionManager transactionManager) {
- final TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager);
-
- transactionTemplate.setIsolationLevelName(jpaProperties.getIsolationLevelName());
- transactionTemplate.setPropagationBehaviorName(jpaProperties.getPropagationBehaviorName());
-
- return transactionTemplate;
- }
+public class BasicLoginLoggingConfiguration extends BaseLoginLoggingConfiguration {
+ public BasicLoginLoggingConfiguration(CasCoreConfigurationProperties casCoreConfigurationProperties) {
+ super(casCoreConfigurationProperties);
}
- @Configuration(proxyBeanMethods = false)
- @EnableConfigurationProperties({CasLoggingConfigurationProperties.class})
- @ConditionalOnMissingBean(name = Constants.BASIC_LOGIN_LOGGING_MANAGER_BEAN_NAME)
- static class BasicConsoleLoginLoggingManagerConfiguration {
-
- protected final CasLoggingConfigurationProperties loggingConfigurationProperties;
-
- public BasicConsoleLoginLoggingManagerConfiguration(
- CasLoggingConfigurationProperties loggingConfigurationProperties) {
- this.loggingConfigurationProperties = loggingConfigurationProperties;
- }
-
- @Bean(name = Constants.BASIC_LOGIN_LOGGING_MANAGER_BEAN_NAME)
- public BasicLoginLoggingManager basicLoginLoggingManager() {
- return new ConsoleBasicLoginLoggingManager(
- loggingConfigurationProperties.getBasic().getConsole().getMessage());
- }
+ @Bean(name = Constants.BASIC_LOGIN_LOGGING_MANAGER_FACTORY_BEAN_NAME)
+ @ConditionalOnMissingBean(name = {Constants.BASIC_LOGIN_LOGGING_MANAGER_FACTORY_BEAN_NAME})
+ public LogManagerFactoryBean logManagerFactoryBean(ObjectProvider> principalHandler,
+ ObjectProvider requestContext,
+ @Qualifier(AbstractLogHandlerConfiguration.AbstractBasicLogHandlerConfiguration.LOG_HANDLER_BEAN_NAME) ObjectProvider logHandler,
+ ObjectProvider geoResolver) {
+ return createLogManagerFactoryBean(principalHandler, requestContext, logHandler, geoResolver);
+ }
+ @Bean(name = Constants.BASIC_LOGIN_LOGGING_MANAGER_BEAN_NAME)
+ @ConditionalOnMissingBean(name = {Constants.BASIC_LOGIN_LOGGING_MANAGER_BEAN_NAME})
+ public BasicLoginLoggingManager historyLoginLoggingManager(
+ @Qualifier(Constants.BASIC_LOGIN_LOGGING_MANAGER_FACTORY_BEAN_NAME) ObjectProvider logManager) {
+ return new DefaultBasicLoginLoggingManager(logManager.getIfAvailable());
}
}
diff --git a/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/HistoryLoginLoggingConfiguration.java b/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/HistoryLoginLoggingConfiguration.java
index 8314bce..8f0a052 100644
--- a/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/HistoryLoginLoggingConfiguration.java
+++ b/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/HistoryLoginLoggingConfiguration.java
@@ -19,19 +19,16 @@
* +-------------------------------------------------------------------------------------------------------+
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
* | Author: Yong.Teng |
- * | Copyright @ 2013-2023 Buession.com Inc. |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package org.apereo.cas.logging.autoconfigure;
-import com.buession.core.validator.Validate;
import com.buession.geoip.Resolver;
-import com.buession.logging.core.handler.DefaultLogHandler;
-import com.buession.logging.core.handler.DefaultPrincipalHandler;
import com.buession.logging.core.handler.LogHandler;
import com.buession.logging.core.handler.PrincipalHandler;
import com.buession.logging.core.mgt.LogManager;
-import com.buession.logging.core.request.ServletRequestContext;
+import com.buession.logging.core.request.RequestContext;
import com.buession.logging.spring.LogManagerFactoryBean;
import org.apereo.cas.core.CasCoreConfigurationProperties;
import org.apereo.cas.logging.Constants;
@@ -39,6 +36,8 @@
import org.apereo.cas.logging.manager.DefaultHistoryLoginLoggingManager;
import org.apereo.cas.logging.manager.HistoryLoginLoggingManager;
import org.springframework.beans.factory.ObjectProvider;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
@@ -51,49 +50,25 @@
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties({CasCoreConfigurationProperties.class, CasLoggingConfigurationProperties.class})
@ConditionalOnProperty(prefix = CasLoggingConfigurationProperties.PREFIX, name = "enabled", havingValue = "true")
-public class HistoryLoginLoggingConfiguration {
+public class HistoryLoginLoggingConfiguration extends BaseLoginLoggingConfiguration {
- private CasCoreConfigurationProperties casCoreConfigurationProperties;
-
- public HistoryLoginLoggingConfiguration(
- CasCoreConfigurationProperties casCoreConfigurationProperties) {
- this.casCoreConfigurationProperties = casCoreConfigurationProperties;
+ public HistoryLoginLoggingConfiguration(CasCoreConfigurationProperties casCoreConfigurationProperties) {
+ super(casCoreConfigurationProperties);
}
- @Bean
+ @Bean(name = Constants.HISTORY_LOGIN_LOGGING_MANAGER_FACTORY_BEAN_NAME)
+ @ConditionalOnMissingBean(name = {Constants.HISTORY_LOGIN_LOGGING_MANAGER_FACTORY_BEAN_NAME})
public LogManagerFactoryBean logManagerFactoryBean(ObjectProvider> principalHandler,
- ObjectProvider logHandler,
+ ObjectProvider requestContext,
+ @Qualifier(AbstractLogHandlerConfiguration.AbstractHistoryLogHandlerConfiguration.LOG_HANDLER_BEAN_NAME) ObjectProvider logHandler,
ObjectProvider geoResolver) {
- final LogManagerFactoryBean logManagerFactoryBean = new LogManagerFactoryBean();
-
- logManagerFactoryBean.setRequestContext(new ServletRequestContext());
-
- geoResolver.ifUnique(logManagerFactoryBean::setGeoResolver);
- principalHandler.ifUnique(logManagerFactoryBean::setPrincipalHandler);
-
- PrincipalHandler> principalHandlerInstance = principalHandler.getIfAvailable();
- if(principalHandlerInstance == null){
- logManagerFactoryBean.setPrincipalHandler(new DefaultPrincipalHandler());
- }else{
- logManagerFactoryBean.setPrincipalHandler(principalHandlerInstance);
- }
-
- LogHandler logHandlerInstance = logHandler.getIfAvailable();
- if(logHandlerInstance == null){
- logManagerFactoryBean.setLogHandler(new DefaultLogHandler());
- }else{
- logManagerFactoryBean.setLogHandler(logHandlerInstance);
- }
-
- if(Validate.isNotBlank(casCoreConfigurationProperties.getClientRealIpHeaderName())){
- logManagerFactoryBean.setClientIpHeaderName(casCoreConfigurationProperties.getClientRealIpHeaderName());
- }
-
- return logManagerFactoryBean;
+ return createLogManagerFactoryBean(principalHandler, requestContext, logHandler, geoResolver);
}
@Bean(name = Constants.HISTORY_LOGIN_LOGGING_MANAGER_BEAN_NAME)
- public HistoryLoginLoggingManager historyLoginLoggingManager(ObjectProvider logManager) {
+ @ConditionalOnMissingBean(name = {Constants.HISTORY_LOGIN_LOGGING_MANAGER_BEAN_NAME})
+ public HistoryLoginLoggingManager historyLoginLoggingManager(
+ @Qualifier(Constants.HISTORY_LOGIN_LOGGING_MANAGER_FACTORY_BEAN_NAME) ObjectProvider logManager) {
return new DefaultHistoryLoginLoggingManager(logManager.getIfAvailable());
}
diff --git a/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/LoginLoggingConfiguration.java b/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/LoginLoggingConfiguration.java
new file mode 100644
index 0000000..1249bee
--- /dev/null
+++ b/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/LoginLoggingConfiguration.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package org.apereo.cas.logging.autoconfigure;
+
+import com.buession.logging.core.handler.DefaultPrincipalHandler;
+import com.buession.logging.core.handler.PrincipalHandler;
+import com.buession.logging.core.request.RequestContext;
+import com.buession.logging.core.request.ServletRequestContext;
+import org.apereo.cas.core.CasCoreConfigurationProperties;
+import org.apereo.cas.logging.config.CasLoggingConfigurationProperties;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import java.security.Principal;
+
+/**
+ * @author Yong.Teng
+ * @since 2.3.3
+ */
+@Configuration(proxyBeanMethods = false)
+@EnableConfigurationProperties({CasCoreConfigurationProperties.class, CasLoggingConfigurationProperties.class})
+@ConditionalOnProperty(prefix = CasLoggingConfigurationProperties.PREFIX, name = "enabled", havingValue = "true")
+public class LoginLoggingConfiguration {
+
+ @Bean
+ public RequestContext requestContext() {
+ return new ServletRequestContext();
+ }
+
+ @Bean
+ public PrincipalHandler extends Principal> principalHandler() {
+ return new DefaultPrincipalHandler();
+ }
+
+}
diff --git a/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/console/ConsoleLogHandlerConfiguration.java b/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/console/ConsoleLogHandlerConfiguration.java
new file mode 100644
index 0000000..85d8990
--- /dev/null
+++ b/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/console/ConsoleLogHandlerConfiguration.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package org.apereo.cas.logging.autoconfigure.console;
+
+import com.buession.logging.console.formatter.ConsoleLogDataFormatter;
+import com.buession.logging.console.formatter.DefaultConsoleLogDataFormatter;
+import com.buession.logging.console.spring.ConsoleLogHandlerFactoryBean;
+import org.apereo.cas.logging.autoconfigure.AbstractLogHandlerConfiguration;
+import org.apereo.cas.logging.config.CasLoggingConfigurationProperties;
+import org.apereo.cas.logging.config.basic.BasicConsoleLogProperties;
+import org.springframework.beans.factory.ObjectProvider;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * 控制台日志处理器自动配置类
+ *
+ * @author Yong.Teng
+ * @since 2.3.3
+ */
+@Configuration(proxyBeanMethods = false)
+@EnableConfigurationProperties(CasLoggingConfigurationProperties.class)
+@ConditionalOnClass(name = {"com.buession.logging.console.spring.ConsoleLogHandlerFactoryBean"})
+public class ConsoleLogHandlerConfiguration extends AbstractLogHandlerConfiguration {
+
+ @Configuration(proxyBeanMethods = false)
+ @EnableConfigurationProperties(CasLoggingConfigurationProperties.class)
+ @ConditionalOnProperty(prefix = Basic.PREFIX, name = "console.enabled", havingValue = "true")
+ @ConditionalOnMissingBean(name = Basic.LOG_HANDLER_BEAN_NAME)
+ static class Basic extends AbstractBasicLogHandlerConfiguration {
+
+ public Basic(CasLoggingConfigurationProperties logProperties) {
+ super(logProperties.getBasic().getConsole());
+ }
+
+ @Bean(name = "basicLoggingConsoleLogDataFormatter")
+ @ConditionalOnMissingBean(name = "basicLoggingConsoleLogDataFormatter")
+ public ConsoleLogDataFormatter consoleLogDataFormatter() {
+ return new DefaultConsoleLogDataFormatter();
+ }
+
+ @Bean(name = Basic.LOG_HANDLER_BEAN_NAME)
+ public ConsoleLogHandlerFactoryBean logHandlerFactoryBean(
+ @Qualifier("basicLoggingConsoleLogDataFormatter") ObjectProvider> consoleLogDataFormatter) {
+ final ConsoleLogHandlerFactoryBean logHandlerFactoryBean = new ConsoleLogHandlerFactoryBean();
+
+ consoleLogDataFormatter.ifAvailable(logHandlerFactoryBean::setFormatter);
+ propertyMapper.from(handlerProperties.getTemplate()).to(logHandlerFactoryBean::setTemplate);
+
+ return logHandlerFactoryBean;
+ }
+
+ }
+
+}
diff --git a/buession-cas-logging/src/main/java/org/apereo/cas/logging/utils/package-info.java b/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/console/package-info.java
similarity index 91%
rename from buession-cas-logging/src/main/java/org/apereo/cas/logging/utils/package-info.java
rename to buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/console/package-info.java
index 3f24867..d5a8755 100644
--- a/buession-cas-logging/src/main/java/org/apereo/cas/logging/utils/package-info.java
+++ b/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/console/package-info.java
@@ -19,11 +19,11 @@
* +-------------------------------------------------------------------------------------------------------+
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
* | Author: Yong.Teng |
- * | Copyright @ 2013-2023 Buession.com Inc. |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
/**
* @author Yong.Teng
- * @since 2.3.0
+ * @since 2.3.3
*/
-package org.apereo.cas.logging.utils;
\ No newline at end of file
+package org.apereo.cas.logging.autoconfigure.console;
\ No newline at end of file
diff --git a/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/elasticsearch/ElasticsearchLogHandlerConfiguration.java b/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/elasticsearch/ElasticsearchLogHandlerConfiguration.java
index afee944..2335042 100644
--- a/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/elasticsearch/ElasticsearchLogHandlerConfiguration.java
+++ b/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/elasticsearch/ElasticsearchLogHandlerConfiguration.java
@@ -19,12 +19,11 @@
* +-------------------------------------------------------------------------------------------------------+
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
* | Author: Yong.Teng |
- * | Copyright @ 2013-2023 Buession.com Inc. |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package org.apereo.cas.logging.autoconfigure.elasticsearch;
-import com.buession.logging.core.handler.LogHandler;
import com.buession.logging.elasticsearch.spring.ElasticsearchLogHandlerFactoryBean;
import com.buession.logging.elasticsearch.spring.ElasticsearchRestTemplateFactoryBean;
import com.buession.logging.elasticsearch.spring.RestHighLevelClientFactoryBean;
@@ -50,52 +49,57 @@
*/
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(CasLoggingConfigurationProperties.class)
-@ConditionalOnMissingBean(LogHandler.class)
-@ConditionalOnClass({ElasticsearchLogHandlerFactoryBean.class})
-@ConditionalOnProperty(prefix = ElasticsearchLogHandlerConfiguration.PREFIX, name = "elasticsearch.enabled", havingValue = "true")
-public class ElasticsearchLogHandlerConfiguration
- extends AbstractLogHandlerConfiguration {
+@ConditionalOnClass(name = {"com.buession.logging.elasticsearch.spring.ElasticsearchLogHandlerFactoryBean"})
+public class ElasticsearchLogHandlerConfiguration extends AbstractLogHandlerConfiguration {
- public ElasticsearchLogHandlerConfiguration(CasLoggingConfigurationProperties logProperties) {
- super(logProperties.getHistory().getElasticsearch());
- }
+ @Configuration(proxyBeanMethods = false)
+ @EnableConfigurationProperties(CasLoggingConfigurationProperties.class)
+ @ConditionalOnProperty(prefix = History.PREFIX, name = "elasticsearch.enabled", havingValue = "true")
+ @ConditionalOnMissingBean(name = History.LOG_HANDLER_BEAN_NAME)
+ static class History extends AbstractHistoryLogHandlerConfiguration {
- @Bean(name = "loggingElasticsearchRestHighLevelClient")
- public RestHighLevelClientFactoryBean restHighLevelClientFactoryBean() {
- final RestHighLevelClientFactoryBean restHighLevelClientFactoryBean = new RestHighLevelClientFactoryBean();
+ public History(CasLoggingConfigurationProperties logProperties) {
+ super(logProperties.getHistory().getElasticsearch());
+ }
- propertyMapper.from(handlerProperties::getUrls).to(restHighLevelClientFactoryBean::setUrls);
- propertyMapper.from(handlerProperties::getHost).to(restHighLevelClientFactoryBean::setHost);
- propertyMapper.from(handlerProperties::getPort).to(restHighLevelClientFactoryBean::setPort);
- propertyMapper.from(handlerProperties::getUsername).to(restHighLevelClientFactoryBean::setUsername);
- propertyMapper.from(handlerProperties::getPassword).to(restHighLevelClientFactoryBean::setPassword);
- propertyMapper.from(handlerProperties::getConnectionTimeout)
- .to(restHighLevelClientFactoryBean::setConnectionTimeout);
- propertyMapper.from(handlerProperties::getReadTimeout).to(restHighLevelClientFactoryBean::setReadTimeout);
+ @Bean(name = "historyLoggingElasticsearchRestHighLevelClient")
+ public RestHighLevelClientFactoryBean restHighLevelClientFactoryBean() {
+ final RestHighLevelClientFactoryBean restHighLevelClientFactoryBean = new RestHighLevelClientFactoryBean();
- return restHighLevelClientFactoryBean;
- }
+ propertyMapper.from(handlerProperties::getUrls).to(restHighLevelClientFactoryBean::setUrls);
+ propertyMapper.from(handlerProperties::getHost).to(restHighLevelClientFactoryBean::setHost);
+ propertyMapper.from(handlerProperties::getPort).to(restHighLevelClientFactoryBean::setPort);
+ propertyMapper.from(handlerProperties::getUsername).to(restHighLevelClientFactoryBean::setUsername);
+ propertyMapper.from(handlerProperties::getPassword).to(restHighLevelClientFactoryBean::setPassword);
+ propertyMapper.from(handlerProperties::getConnectionTimeout)
+ .to(restHighLevelClientFactoryBean::setConnectionTimeout);
+ propertyMapper.from(handlerProperties::getReadTimeout).to(restHighLevelClientFactoryBean::setReadTimeout);
- @Bean(name = "loggingElasticsearchElasticsearchRestTemplate")
- public ElasticsearchRestTemplateFactoryBean elasticsearchRestTemplateFactoryBean(
- @Qualifier("loggingElasticsearchRestHighLevelClient") ObjectProvider restHighLevelClient) {
- final ElasticsearchRestTemplateFactoryBean elasticsearchRestTemplateFactoryBean =
- new ElasticsearchRestTemplateFactoryBean();
+ return restHighLevelClientFactoryBean;
+ }
- restHighLevelClient.ifUnique(elasticsearchRestTemplateFactoryBean::setClient);
+ @Bean(name = "historyLoggingElasticsearchRestTemplate")
+ public ElasticsearchRestTemplateFactoryBean elasticsearchRestTemplateFactoryBean(
+ @Qualifier("historyLoggingElasticsearchRestHighLevelClient") ObjectProvider restHighLevelClient) {
+ final ElasticsearchRestTemplateFactoryBean elasticsearchRestTemplateFactoryBean =
+ new ElasticsearchRestTemplateFactoryBean();
- return elasticsearchRestTemplateFactoryBean;
- }
+ restHighLevelClient.ifAvailable(elasticsearchRestTemplateFactoryBean::setClient);
+
+ return elasticsearchRestTemplateFactoryBean;
+ }
+
+ @Bean(name = History.LOG_HANDLER_BEAN_NAME)
+ public ElasticsearchLogHandlerFactoryBean logHandlerFactoryBean(
+ @Qualifier("historyLoggingElasticsearchRestTemplate") ObjectProvider restTemplateFactory) {
+ final ElasticsearchLogHandlerFactoryBean logHandlerFactoryBean = new ElasticsearchLogHandlerFactoryBean();
- @Bean
- public ElasticsearchLogHandlerFactoryBean logHandlerFactoryBean(
- @Qualifier("loggingElasticsearchElasticsearchRestTemplate") ObjectProvider restTemplateFactory) {
- final ElasticsearchLogHandlerFactoryBean logHandlerFactoryBean = new ElasticsearchLogHandlerFactoryBean();
+ restTemplateFactory.ifAvailable(logHandlerFactoryBean::setRestTemplate);
+ propertyMapper.from(handlerProperties::getIndexName).to(logHandlerFactoryBean::setIndexName);
- restTemplateFactory.ifUnique(logHandlerFactoryBean::setRestTemplate);
- propertyMapper.from(handlerProperties::getIndexName).to(logHandlerFactoryBean::setIndexName);
+ return logHandlerFactoryBean;
+ }
- return logHandlerFactoryBean;
}
}
diff --git a/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/jdbc/JdbcLogHandlerConfiguration.java b/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/jdbc/JdbcLogHandlerConfiguration.java
index edc973a..ac930e9 100644
--- a/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/jdbc/JdbcLogHandlerConfiguration.java
+++ b/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/jdbc/JdbcLogHandlerConfiguration.java
@@ -19,16 +19,22 @@
* +-------------------------------------------------------------------------------------------------------+
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
* | Author: Yong.Teng |
- * | Copyright @ 2013-2023 Buession.com Inc. |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package org.apereo.cas.logging.autoconfigure.jdbc;
-import com.buession.logging.core.handler.LogHandler;
+import com.buession.jdbc.datasource.config.HikariPoolConfiguration;
+import com.buession.logging.jdbc.converter.DefaultLogDataConverter;
+import com.buession.logging.jdbc.converter.LogDataConverter;
import com.buession.logging.jdbc.spring.JdbcLogHandlerFactoryBean;
import com.buession.logging.jdbc.spring.JdbcTemplateFactoryBean;
+import org.apereo.cas.configuration.model.support.ConnectionPoolingProperties;
+import org.apereo.cas.configuration.support.Beans;
import org.apereo.cas.logging.autoconfigure.AbstractLogHandlerConfiguration;
+import org.apereo.cas.logging.config.BaseJdbcLogProperties;
import org.apereo.cas.logging.config.CasLoggingConfigurationProperties;
+import org.apereo.cas.logging.config.basic.BasicJdbcLogProperties;
import org.apereo.cas.logging.config.history.HistoryJdbcLogProperties;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.ObjectProvider;
@@ -41,6 +47,8 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
+import java.time.Duration;
+
/**
* JDBC 日志处理器自动配置类
*
@@ -49,45 +57,115 @@
*/
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(CasLoggingConfigurationProperties.class)
-@ConditionalOnMissingBean(LogHandler.class)
-@ConditionalOnClass({JdbcLogHandlerFactoryBean.class})
-@ConditionalOnProperty(prefix = JdbcLogHandlerConfiguration.PREFIX, name = "jdbc.enabled", havingValue = "true")
-public class JdbcLogHandlerConfiguration extends AbstractLogHandlerConfiguration {
-
- public JdbcLogHandlerConfiguration(CasLoggingConfigurationProperties logProperties) {
- super(logProperties.getHistory().getJdbc());
- }
+@ConditionalOnClass(name = {"com.buession.logging.jdbc.spring.JdbcLogHandlerFactoryBean"})
+public class JdbcLogHandlerConfiguration extends AbstractLogHandlerConfiguration {
- @Bean(name = "loggingJdbcJdbcTemplate")
- public JdbcTemplateFactoryBean jdbcTemplateFactoryBean() {
+ protected static JdbcTemplateFactoryBean jdbcTemplateFactoryBean(final BaseJdbcLogProperties jdbcLogProperties) {
final JdbcTemplateFactoryBean jdbcTemplateFactoryBean = new JdbcTemplateFactoryBean();
- propertyMapper.from(handlerProperties::getDriverClassName).to(jdbcTemplateFactoryBean::setDriverClassName);
- propertyMapper.from(handlerProperties::getUrl).to(jdbcTemplateFactoryBean::setUrl);
- propertyMapper.from(handlerProperties::getUser).to(jdbcTemplateFactoryBean::setUsername);
- propertyMapper.from(handlerProperties::getPassword).to(jdbcTemplateFactoryBean::setPassword);
- propertyMapper.from(handlerProperties::getPoolConfiguration).to(jdbcTemplateFactoryBean::setPoolConfiguration);
+ propertyMapper.from(jdbcLogProperties::getDriverClass).to(jdbcTemplateFactoryBean::setDriverClassName);
+ propertyMapper.from(jdbcLogProperties::getUrl).to(jdbcTemplateFactoryBean::setUrl);
+ propertyMapper.from(jdbcLogProperties::getUser).to(jdbcTemplateFactoryBean::setUsername);
+ propertyMapper.from(jdbcLogProperties::getPassword).to(jdbcTemplateFactoryBean::setPassword);
+
+ final ConnectionPoolingProperties pool = jdbcLogProperties.getPool();
+ final HikariPoolConfiguration poolConfiguration = new HikariPoolConfiguration();
+
+ poolConfiguration.setIdleTimeout(Beans.newDuration(jdbcLogProperties.getIdleTimeout()));
+ poolConfiguration.setMinIdle(pool.getMinSize());
+ poolConfiguration.setMaxPoolSize(pool.getMaxSize());
+ poolConfiguration.setInitializationFailTimeout(Duration.ofMillis(jdbcLogProperties.getFailFastTimeout()));
+ poolConfiguration.setConnectionTestQuery(jdbcLogProperties.getHealthQuery());
+ poolConfiguration.setValidationTimeout(Duration.ofMillis(pool.getTimeoutMillis()));
+ poolConfiguration.setAutoCommit(jdbcLogProperties.isAutocommit());
+ poolConfiguration.setAllowPoolSuspension(jdbcLogProperties.getPool().isSuspension());
+ poolConfiguration.setIsolateInternalQueries(jdbcLogProperties.isIsolateInternalQueries());
+ poolConfiguration.setLeakDetectionThreshold((long) jdbcLogProperties.getLeakThreshold());
+
+ jdbcTemplateFactoryBean.setPoolConfiguration(poolConfiguration);
return jdbcTemplateFactoryBean;
}
- @Bean
- public JdbcLogHandlerFactoryBean logHandlerFactoryBean(
- @Qualifier("loggingJdbcJdbcTemplate") ObjectProvider jdbcTemplate) {
+ protected static JdbcLogHandlerFactoryBean logHandlerFactoryBean(final BaseJdbcLogProperties jdbcLogProperties,
+ final LogDataConverter logDataConverter,
+ final JdbcTemplate jdbcTemplate) {
final JdbcLogHandlerFactoryBean logHandlerFactoryBean = new JdbcLogHandlerFactoryBean();
- jdbcTemplate.ifUnique(logHandlerFactoryBean::setJdbcTemplate);
-
- propertyMapper.from(handlerProperties::getSql).to(logHandlerFactoryBean::setSql);
- propertyMapper.from(handlerProperties::getIdGenerator).as(BeanUtils::instantiateClass)
+ propertyMapper.from(jdbcTemplate).to(logHandlerFactoryBean::setJdbcTemplate);
+ propertyMapper.from(jdbcLogProperties::getSql).to(logHandlerFactoryBean::setSql);
+ propertyMapper.from(jdbcLogProperties::getIdGenerator).as(BeanUtils::instantiateClass)
.to(logHandlerFactoryBean::setIdGenerator);
- propertyMapper.from(handlerProperties::getDateTimeFormat).to(logHandlerFactoryBean::setDateTimeFormat);
- propertyMapper.from(handlerProperties::getRequestParametersFormatter).as(BeanUtils::instantiateClass)
+ propertyMapper.from(jdbcLogProperties::getDateTimeFormat).to(logHandlerFactoryBean::setDateTimeFormat);
+ propertyMapper.from(jdbcLogProperties::getRequestParametersFormatter).as(BeanUtils::instantiateClass)
.to(logHandlerFactoryBean::setRequestParametersFormatter);
- propertyMapper.from(handlerProperties::getExtraFormatter).as(BeanUtils::instantiateClass)
+ propertyMapper.from(jdbcLogProperties::getExtraFormatter).as(BeanUtils::instantiateClass)
.to(logHandlerFactoryBean::setExtraFormatter);
+ propertyMapper.from(logDataConverter).to(logHandlerFactoryBean::setLogDataConverter);
return logHandlerFactoryBean;
}
+ @Configuration(proxyBeanMethods = false)
+ @EnableConfigurationProperties(CasLoggingConfigurationProperties.class)
+ @ConditionalOnProperty(prefix = Basic.PREFIX, name = "jdbc.enabled", havingValue = "true")
+ @ConditionalOnMissingBean(name = Basic.LOG_HANDLER_BEAN_NAME)
+ static class Basic extends AbstractBasicLogHandlerConfiguration {
+
+ public Basic(CasLoggingConfigurationProperties logProperties) {
+ super(logProperties.getBasic().getJdbc());
+ }
+
+ @Bean(name = "basicLoggingJdbcJdbcTemplate")
+ public JdbcTemplateFactoryBean jdbcTemplateFactoryBean() {
+ return JdbcLogHandlerConfiguration.jdbcTemplateFactoryBean(handlerProperties);
+ }
+
+ @Bean(name = "basicLoggingJdbcDataConverter")
+ @ConditionalOnMissingBean(name = "basicLoggingJdbcDataConverter")
+ public LogDataConverter logDataConverter() {
+ return new DefaultLogDataConverter();
+ }
+
+ @Bean(name = Basic.LOG_HANDLER_BEAN_NAME)
+ public JdbcLogHandlerFactoryBean logHandlerFactoryBean(
+ @Qualifier("basicLoggingJdbcJdbcTemplate") ObjectProvider jdbcTemplate,
+ @Qualifier("basicLoggingJdbcDataConverter") ObjectProvider logDataConverter) {
+ return JdbcLogHandlerConfiguration.logHandlerFactoryBean(handlerProperties,
+ logDataConverter.getIfAvailable(), jdbcTemplate.getIfAvailable());
+ }
+
+ }
+
+ @Configuration(proxyBeanMethods = false)
+ @EnableConfigurationProperties(CasLoggingConfigurationProperties.class)
+ @ConditionalOnProperty(prefix = History.PREFIX, name = "jdbc.enabled", havingValue = "true")
+ @ConditionalOnMissingBean(name = History.LOG_HANDLER_BEAN_NAME)
+ static class History extends AbstractHistoryLogHandlerConfiguration {
+
+ public History(CasLoggingConfigurationProperties logProperties) {
+ super(logProperties.getHistory().getJdbc());
+ }
+
+ @Bean(name = "historyLoggingJdbcJdbcTemplate")
+ public JdbcTemplateFactoryBean jdbcTemplateFactoryBean() {
+ return JdbcLogHandlerConfiguration.jdbcTemplateFactoryBean(handlerProperties);
+ }
+
+ @Bean(name = "historyLoggingJdbcDataConverter")
+ @ConditionalOnMissingBean(name = "historyLoggingJdbcDataConverter")
+ public LogDataConverter logDataConverter() {
+ return new DefaultLogDataConverter();
+ }
+
+ @Bean(name = History.LOG_HANDLER_BEAN_NAME)
+ public JdbcLogHandlerFactoryBean logHandlerFactoryBean(
+ @Qualifier("historyLoggingJdbcJdbcTemplate") ObjectProvider jdbcTemplate,
+ @Qualifier("historyLoggingJdbcDataConverter") ObjectProvider logDataConverter) {
+ return JdbcLogHandlerConfiguration.logHandlerFactoryBean(handlerProperties,
+ logDataConverter.getIfAvailable(), jdbcTemplate.getIfAvailable());
+ }
+
+ }
+
}
diff --git a/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/jdbc/package-info.java b/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/jdbc/package-info.java
index 4f07bca..c3d6b53 100644
--- a/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/jdbc/package-info.java
+++ b/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/jdbc/package-info.java
@@ -19,7 +19,7 @@
* +-------------------------------------------------------------------------------------------------------+
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
* | Author: Yong.Teng |
- * | Copyright @ 2013-2023 Buession.com Inc. |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
/**
diff --git a/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/kafka/KafkaLogHandlerConfiguration.java b/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/kafka/KafkaLogHandlerConfiguration.java
index 52ab625..ef045c1 100644
--- a/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/kafka/KafkaLogHandlerConfiguration.java
+++ b/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/kafka/KafkaLogHandlerConfiguration.java
@@ -19,12 +19,11 @@
* +-------------------------------------------------------------------------------------------------------+
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
* | Author: Yong.Teng |
- * | Copyright @ 2013-2023 Buession.com Inc. |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package org.apereo.cas.logging.autoconfigure.kafka;
-import com.buession.logging.core.handler.LogHandler;
import com.buession.logging.kafka.spring.KafkaLogHandlerFactoryBean;
import com.buession.logging.kafka.spring.KafkaTemplateFactoryBean;
import com.buession.logging.kafka.spring.ProducerFactoryBean;
@@ -40,6 +39,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.core.KafkaTemplate;
+import org.springframework.kafka.core.ProducerFactory;
/**
* Kafka 日志处理器自动配置类
@@ -49,57 +49,64 @@
*/
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(CasLoggingConfigurationProperties.class)
-@ConditionalOnMissingBean(LogHandler.class)
-@ConditionalOnClass({KafkaLogHandlerFactoryBean.class})
-@ConditionalOnProperty(prefix = KafkaLogHandlerConfiguration.PREFIX, name = "kafka.enabled", havingValue = "true")
-public class KafkaLogHandlerConfiguration extends AbstractLogHandlerConfiguration {
+@ConditionalOnClass(name = {"com.buession.logging.kafka.spring.KafkaLogHandlerFactoryBean"})
+public class KafkaLogHandlerConfiguration extends AbstractLogHandlerConfiguration {
- public KafkaLogHandlerConfiguration(CasLoggingConfigurationProperties logProperties) {
- super(logProperties.getHistory().getKafka());
- }
+ @Configuration(proxyBeanMethods = false)
+ @EnableConfigurationProperties(CasLoggingConfigurationProperties.class)
+ @ConditionalOnProperty(prefix = History.PREFIX, name = "kafka.enabled", havingValue = "true")
+ @ConditionalOnMissingBean(name = History.LOG_HANDLER_BEAN_NAME)
+ static class History extends AbstractHistoryLogHandlerConfiguration {
- @Bean(name = "loggingKafkaProducerFactory")
- public ProducerFactoryBean producerFactoryBean() {
- final ProducerFactoryBean producerFactoryBean = new ProducerFactoryBean();
-
- propertyMapper.from(handlerProperties::getBootstrapServers).to(producerFactoryBean::setBootstrapServers);
- propertyMapper.from(handlerProperties::getClientId).to(producerFactoryBean::setClientId);
- propertyMapper.from(handlerProperties::getTransactionIdPrefix)
- .to(producerFactoryBean::setTransactionIdPrefix);
- propertyMapper.from(handlerProperties::getAcks).to(producerFactoryBean::setAcks);
- propertyMapper.from(handlerProperties::getBatchSize).to(producerFactoryBean::setBatchSize);
- propertyMapper.from(handlerProperties::getBufferMemory).to(producerFactoryBean::setBufferMemory);
- propertyMapper.from(handlerProperties::getCompressionType).to(producerFactoryBean::setCompressionType);
- propertyMapper.from(handlerProperties::getRetries).to(producerFactoryBean::setRetries);
- propertyMapper.from(handlerProperties::getSslConfiguration).to(producerFactoryBean::setSslConfiguration);
- propertyMapper.from(handlerProperties::getSecurityConfiguration)
- .to(producerFactoryBean::setSecurityConfiguration);
- propertyMapper.from(handlerProperties::getTransactionIdPrefix).to(producerFactoryBean::setTransactionIdPrefix);
- propertyMapper.from(handlerProperties::getProperties).to(producerFactoryBean::setProperties);
-
- return producerFactoryBean;
- }
+ public History(CasLoggingConfigurationProperties logProperties) {
+ super(logProperties.getHistory().getKafka());
+ }
- @Bean(name = "loggingKafkaKafkaTemplate")
- public KafkaTemplateFactoryBean kafkaTemplateFactoryBean(@Qualifier("loggingKafkaProducerFactory")
- ObjectProvider> producerFactory) {
- final KafkaTemplateFactoryBean kafkaTemplateFactoryBean = new KafkaTemplateFactoryBean<>();
+ @Bean(name = "historyLoggingKafkaProducerFactory")
+ public ProducerFactoryBean producerFactoryBean() {
+ final ProducerFactoryBean producerFactoryBean = new ProducerFactoryBean();
- producerFactory.ifUnique(kafkaTemplateFactoryBean::setProducerFactory);
+ propertyMapper.from(handlerProperties::getBootstrapServers).to(producerFactoryBean::setBootstrapServers);
+ propertyMapper.from(handlerProperties::getClientId).to(producerFactoryBean::setClientId);
+ propertyMapper.from(handlerProperties::getTransactionIdPrefix)
+ .to(producerFactoryBean::setTransactionIdPrefix);
+ propertyMapper.from(handlerProperties::getAcks).to(producerFactoryBean::setAcks);
+ propertyMapper.from(handlerProperties::getBatchSize).to(producerFactoryBean::setBatchSize);
+ propertyMapper.from(handlerProperties::getBufferMemory).to(producerFactoryBean::setBufferMemory);
+ propertyMapper.from(handlerProperties::getCompressionType).to(producerFactoryBean::setCompressionType);
+ propertyMapper.from(handlerProperties::getRetries).to(producerFactoryBean::setRetries);
+ propertyMapper.from(handlerProperties::getSslConfiguration).to(producerFactoryBean::setSslConfiguration);
+ propertyMapper.from(handlerProperties::getSecurityConfiguration)
+ .to(producerFactoryBean::setSecurityConfiguration);
+ propertyMapper.from(handlerProperties::getTransactionIdPrefix)
+ .to(producerFactoryBean::setTransactionIdPrefix);
+ propertyMapper.from(handlerProperties::getProperties).to(producerFactoryBean::setProperties);
- return kafkaTemplateFactoryBean;
- }
+ return producerFactoryBean;
+ }
+
+ @Bean(name = "historyLoggingKafkaKafkaTemplate")
+ public KafkaTemplateFactoryBean kafkaTemplateFactoryBean(
+ @Qualifier("historyLoggingKafkaProducerFactory") ObjectProvider> producerFactory) {
+ final KafkaTemplateFactoryBean kafkaTemplateFactoryBean = new KafkaTemplateFactoryBean<>();
+
+ producerFactory.ifAvailable(kafkaTemplateFactoryBean::setProducerFactory);
+
+ return kafkaTemplateFactoryBean;
+ }
+
+ @Bean(name = History.LOG_HANDLER_BEAN_NAME)
+ public KafkaLogHandlerFactoryBean logHandlerFactoryBean(
+ @Qualifier("historyLoggingKafkaKafkaTemplate") ObjectProvider> kafkaTemplate) {
+ final KafkaLogHandlerFactoryBean logHandlerFactoryBean = new KafkaLogHandlerFactoryBean();
- @Bean
- public KafkaLogHandlerFactoryBean logHandlerFactoryBean(
- @Qualifier("loggingKafkaKafkaTemplate") ObjectProvider> kafkaTemplate) {
- final KafkaLogHandlerFactoryBean logHandlerFactoryBean = new KafkaLogHandlerFactoryBean();
+ kafkaTemplate.ifAvailable(logHandlerFactoryBean::setKafkaTemplate);
- kafkaTemplate.ifUnique(logHandlerFactoryBean::setKafkaTemplate);
+ propertyMapper.from(handlerProperties::getTopic).to(logHandlerFactoryBean::setTopic);
- propertyMapper.from(handlerProperties::getTopic).to(logHandlerFactoryBean::setTopic);
+ return logHandlerFactoryBean;
+ }
- return logHandlerFactoryBean;
}
}
diff --git a/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/mongo/MongoLogHandlerConfiguration.java b/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/mongo/MongoLogHandlerConfiguration.java
index 0e94271..74ba21a 100644
--- a/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/mongo/MongoLogHandlerConfiguration.java
+++ b/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/mongo/MongoLogHandlerConfiguration.java
@@ -19,7 +19,7 @@
* +-------------------------------------------------------------------------------------------------------+
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
* | Author: Yong.Teng |
- * | Copyright @ 2013-2023 Buession.com Inc. |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package org.apereo.cas.logging.autoconfigure.mongo;
@@ -28,10 +28,9 @@
import com.buession.dao.mongodb.core.ReadConcern;
import com.buession.dao.mongodb.core.ReadPreference;
import com.buession.dao.mongodb.core.WriteConcern;
-import com.buession.logging.core.handler.LogHandler;
import com.buession.logging.mongodb.spring.MongoClientFactoryBean;
import com.buession.logging.mongodb.spring.MongoDatabaseFactoryBean;
-import com.buession.logging.mongodb.spring.MongoHandlerFactoryBean;
+import com.buession.logging.mongodb.spring.MongoLogHandlerFactoryBean;
import com.buession.logging.mongodb.spring.MongoMappingContextFactoryBean;
import com.buession.logging.mongodb.spring.MongoTemplateFactoryBean;
import com.mongodb.ConnectionString;
@@ -66,154 +65,168 @@
*/
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(CasLoggingConfigurationProperties.class)
-@ConditionalOnMissingBean(LogHandler.class)
-@ConditionalOnClass({MongoHandlerFactoryBean.class})
-@ConditionalOnProperty(prefix = MongoLogHandlerConfiguration.PREFIX, name = "mongo.enabled", havingValue = "true")
-public class MongoLogHandlerConfiguration extends AbstractLogHandlerConfiguration {
+@ConditionalOnClass(name = {"com.buession.logging.mongodb.spring.MongoLogHandlerFactoryBean"})
+public class MongoLogHandlerConfiguration extends AbstractLogHandlerConfiguration {
- public MongoLogHandlerConfiguration(CasLoggingConfigurationProperties logProperties) {
- super(logProperties.getHistory().getMongo());
- }
-
- @Bean(name = "logMongoDbMongoClient")
- public MongoClientFactoryBean mongoClientFactoryBean() {
- final MongoClientFactoryBean mongoClientFactoryBean = new MongoClientFactoryBean();
+ @Configuration(proxyBeanMethods = false)
+ @EnableConfigurationProperties(CasLoggingConfigurationProperties.class)
+ @ConditionalOnProperty(prefix = History.PREFIX, name = "mongo.enabled", havingValue = "true")
+ @ConditionalOnMissingBean(name = History.LOG_HANDLER_BEAN_NAME)
+ static class History extends AbstractHistoryLogHandlerConfiguration {
- if(Validate.hasText(handlerProperties.getUrl())){
- propertyMapper.from(handlerProperties::getUrl).as(ConnectionString::new)
- .to(mongoClientFactoryBean::setConnectionString);
- }else{
- propertyMapper.from(handlerProperties::getHost).to(mongoClientFactoryBean::setHost);
- propertyMapper.from(handlerProperties::getPort).to(mongoClientFactoryBean::setPort);
+ public History(CasLoggingConfigurationProperties logProperties) {
+ super(logProperties.getHistory().getMongo());
}
- propertyMapper.from(handlerProperties::getReplicaSetName).to(mongoClientFactoryBean::setReplicaSet);
-
- if(handlerProperties.getUsername() != null && handlerProperties.getPassword() != null){
- final String database =
- handlerProperties.getAuthenticationDatabase() ==
- null ? handlerProperties.getDatabaseName() : handlerProperties.getAuthenticationDatabase();
- final MongoCredential credential = MongoCredential.createCredential(handlerProperties.getUsername(),
- database, handlerProperties.getPassword().toCharArray());
- mongoClientFactoryBean.setCredential(new MongoCredential[]{credential});
- }
+ @Bean(name = "historyLoggingMongoDbMongoClient")
+ public MongoClientFactoryBean mongoClientFactoryBean() {
+ final MongoClientFactoryBean mongoClientFactoryBean = new MongoClientFactoryBean();
- final MongoClientSettings.Builder mongoClientSettingsBuilder = MongoClientSettings.builder();
+ if(Validate.hasText(handlerProperties.getUrl())){
+ propertyMapper.from(handlerProperties::getUrl).as(ConnectionString::new)
+ .to(mongoClientFactoryBean::setConnectionString);
+ }else{
+ propertyMapper.from(handlerProperties::getHost).to(mongoClientFactoryBean::setHost);
+ propertyMapper.from(handlerProperties::getPort).to(mongoClientFactoryBean::setPort);
+ }
+ propertyMapper.from(handlerProperties::getReplicaSetName).to(mongoClientFactoryBean::setReplicaSet);
- propertyMapper.from(handlerProperties::getReadPreference).as(ReadPreference::getValue)
- .to(mongoClientSettingsBuilder::readPreference);
- propertyMapper.from(handlerProperties::getReadConcern).as(ReadConcern::getValue)
- .to(mongoClientSettingsBuilder::readConcern);
- propertyMapper.from(handlerProperties::getWriteConcern).as(WriteConcern::getValue)
- .to(mongoClientSettingsBuilder::writeConcern);
- propertyMapper.from(handlerProperties::getUuidRepresentation)
- .to(mongoClientSettingsBuilder::uuidRepresentation);
+ if(handlerProperties.getUsername() != null && handlerProperties.getPassword() != null){
+ mongoClientFactoryBean.setCredential(createMongoCredential());
+ }
- mongoClientSettingsBuilder.applyToSocketSettings(($builder)->{
- final SocketSettings.Builder socketBuilder = SocketSettings.builder();
+ final MongoClientSettings.Builder mongoClientSettingsBuilder = MongoClientSettings.builder();
- if(handlerProperties.getConnectionTimeout() != null){
- socketBuilder.connectTimeout((int) handlerProperties.getConnectionTimeout().toMillis(),
- TimeUnit.MILLISECONDS);
- }
- if(handlerProperties.getReadTimeout() != null){
- socketBuilder.readTimeout((int) handlerProperties.getReadTimeout().toMillis(), TimeUnit.MILLISECONDS);
- }
+ propertyMapper.from(handlerProperties::getReadPreference).as(ReadPreference::getValue)
+ .to(mongoClientSettingsBuilder::readPreference);
+ propertyMapper.from(handlerProperties::getReadConcern).as(ReadConcern::getValue)
+ .to(mongoClientSettingsBuilder::readConcern);
+ propertyMapper.from(handlerProperties::getWriteConcern).as(WriteConcern::getValue)
+ .to(mongoClientSettingsBuilder::writeConcern);
+ propertyMapper.from(handlerProperties::getUuidRepresentation)
+ .to(mongoClientSettingsBuilder::uuidRepresentation);
- $builder.applySettings(socketBuilder.build());
- }).applyToConnectionPoolSettings(($builder)->{
- if(handlerProperties.getPool() != null){
- final ConnectionPoolSettings.Builder poolBuilder = ConnectionPoolSettings.builder();
+ mongoClientSettingsBuilder.applyToSocketSettings(($builder)->{
+ final SocketSettings.Builder socketBuilder = SocketSettings.builder();
- if(handlerProperties.getPool().getMinSize() > 0){
- poolBuilder.minSize(handlerProperties.getPool().getMinSize());
- }
- if(handlerProperties.getPool().getMaxSize() > 0){
- poolBuilder.minSize(handlerProperties.getPool().getMaxSize());
- }
- if(handlerProperties.getPool().getMaxWaitTime() != null){
- poolBuilder.maxWaitTime(handlerProperties.getPool().getMaxWaitTime().toMillis(),
- TimeUnit.MILLISECONDS);
- }
- if(handlerProperties.getPool().getMaxConnectionLifeTime() != null){
- poolBuilder.maxConnectionLifeTime(handlerProperties.getPool().getMaxConnectionLifeTime().toMillis(),
- TimeUnit.MILLISECONDS);
- }
- if(handlerProperties.getPool().getMaxConnectionIdleTime() != null){
- poolBuilder.maxConnectionIdleTime(handlerProperties.getPool().getMaxConnectionIdleTime().toMillis(),
- TimeUnit.MILLISECONDS);
- }
- if(handlerProperties.getPool().getMaintenanceInitialDelay() != null){
- poolBuilder.maintenanceInitialDelay(
- handlerProperties.getPool().getMaintenanceInitialDelay().toMillis(),
+ if(handlerProperties.getConnectionTimeout() != null){
+ socketBuilder.connectTimeout((int) handlerProperties.getConnectionTimeout().toMillis(),
TimeUnit.MILLISECONDS);
}
- if(handlerProperties.getPool().getMaintenanceFrequency() != null){
- poolBuilder.maintenanceFrequency(handlerProperties.getPool().getMaintenanceFrequency().toMillis(),
+ if(handlerProperties.getReadTimeout() != null){
+ socketBuilder.readTimeout((int) handlerProperties.getReadTimeout().toMillis(),
TimeUnit.MILLISECONDS);
}
- if(handlerProperties.getPool().getMaxConnecting() > 0){
- poolBuilder.maxConnecting(handlerProperties.getPool().getMaxConnecting());
+
+ $builder.applySettings(socketBuilder.build());
+ }).applyToConnectionPoolSettings(($builder)->{
+ if(handlerProperties.getPool() != null){
+ final ConnectionPoolSettings.Builder poolBuilder = ConnectionPoolSettings.builder();
+
+ if(handlerProperties.getPool().getMinSize() > 0){
+ poolBuilder.minSize(handlerProperties.getPool().getMinSize());
+ }
+ if(handlerProperties.getPool().getMaxSize() > 0){
+ poolBuilder.minSize(handlerProperties.getPool().getMaxSize());
+ }
+ if(handlerProperties.getPool().getMaxWaitTime() != null){
+ poolBuilder.maxWaitTime(handlerProperties.getPool().getMaxWaitTime().toMillis(),
+ TimeUnit.MILLISECONDS);
+ }
+ if(handlerProperties.getPool().getMaxConnectionLifeTime() != null){
+ poolBuilder.maxConnectionLifeTime(
+ handlerProperties.getPool().getMaxConnectionLifeTime().toMillis(),
+ TimeUnit.MILLISECONDS);
+ }
+ if(handlerProperties.getPool().getMaxConnectionIdleTime() != null){
+ poolBuilder.maxConnectionIdleTime(
+ handlerProperties.getPool().getMaxConnectionIdleTime().toMillis(),
+ TimeUnit.MILLISECONDS);
+ }
+ if(handlerProperties.getPool().getMaintenanceInitialDelay() != null){
+ poolBuilder.maintenanceInitialDelay(
+ handlerProperties.getPool().getMaintenanceInitialDelay().toMillis(),
+ TimeUnit.MILLISECONDS);
+ }
+ if(handlerProperties.getPool().getMaintenanceFrequency() != null){
+ poolBuilder.maintenanceFrequency(
+ handlerProperties.getPool().getMaintenanceFrequency().toMillis(),
+ TimeUnit.MILLISECONDS);
+ }
+ if(handlerProperties.getPool().getMaxConnecting() > 0){
+ poolBuilder.maxConnecting(handlerProperties.getPool().getMaxConnecting());
+ }
+
+ $builder.applySettings(poolBuilder.build());
}
+ });
- $builder.applySettings(poolBuilder.build());
- }
- });
+ return mongoClientFactoryBean;
+ }
- return mongoClientFactoryBean;
- }
+ @Bean(name = "historyLoggingMongoDbMongoDatabase")
+ public MongoDatabaseFactoryBean mongoDatabaseFactoryBean(
+ @Qualifier("historyLoggingMongoDbMongoClient") ObjectProvider mongoClient) {
+ final MongoDatabaseFactoryBean mongoDatabaseFactoryBean = new MongoDatabaseFactoryBean();
- @Bean(name = "logMongoDbMongoDatabase")
- public MongoDatabaseFactoryBean mongoDatabaseFactoryBean(
- @Qualifier("logMongoDbMongoClient") ObjectProvider mongoClient) {
- final MongoDatabaseFactoryBean mongoDatabaseFactoryBean = new MongoDatabaseFactoryBean();
+ mongoClient.ifAvailable(mongoDatabaseFactoryBean::setMongoClient);
- mongoClient.ifUnique(mongoDatabaseFactoryBean::setMongoClient);
+ if(Validate.hasText(handlerProperties.getDatabaseName())){
+ mongoDatabaseFactoryBean.setDatabaseName(handlerProperties.getDatabaseName());
+ }else{
+ String database = new ConnectionString(handlerProperties.getUrl()).getDatabase();
+ mongoDatabaseFactoryBean.setDatabaseName(database);
+ }
- if(Validate.hasText(handlerProperties.getDatabaseName())){
- mongoDatabaseFactoryBean.setDatabaseName(handlerProperties.getDatabaseName());
- }else{
- String database = new ConnectionString(handlerProperties.getUrl()).getDatabase();
- mongoDatabaseFactoryBean.setDatabaseName(database);
+ return mongoDatabaseFactoryBean;
}
- return mongoDatabaseFactoryBean;
- }
+ @Bean(name = "historyLoggingMongoDbMongoMappingContext")
+ public MongoMappingContextFactoryBean mongoMappingContextFactoryBean() {
+ final MongoMappingContextFactoryBean mongoMappingContextFactoryBean = new MongoMappingContextFactoryBean();
- @Bean(name = "logMongoDbMongoMappingContext")
- public MongoMappingContextFactoryBean mongoMappingContextFactoryBean() {
- final MongoMappingContextFactoryBean mongoMappingContextFactoryBean = new MongoMappingContextFactoryBean();
+ propertyMapper.from(handlerProperties::getAutoIndexCreation)
+ .to(mongoMappingContextFactoryBean::setAutoIndexCreation);
+ propertyMapper.from(handlerProperties::getFieldNamingStrategy).as(BeanUtils::instantiateClass)
+ .to(mongoMappingContextFactoryBean::setFieldNamingStrategy);
- propertyMapper.from(handlerProperties::getAutoIndexCreation)
- .to(mongoMappingContextFactoryBean::setAutoIndexCreation);
- propertyMapper.from(handlerProperties::getFieldNamingStrategy).as(BeanUtils::instantiateClass)
- .to(mongoMappingContextFactoryBean::setFieldNamingStrategy);
+ return mongoMappingContextFactoryBean;
+ }
- return mongoMappingContextFactoryBean;
- }
+ @Bean(name = "historyLoggingMongoDbMongoTemplate")
+ public MongoTemplateFactoryBean mongoTemplateFactoryBean(
+ @Qualifier("historyLoggingMongoDbMongoDatabase") ObjectProvider mongoDatabaseFactory,
+ @Qualifier("historyLoggingMongoDbMongoMappingContext") ObjectProvider mongoMappingContext) {
+ final MongoTemplateFactoryBean mongoTemplateFactoryBean = new MongoTemplateFactoryBean();
+
+ mongoDatabaseFactory.ifAvailable(mongoTemplateFactoryBean::setMongoDatabaseFactory);
+ mongoMappingContext.ifAvailable(mongoTemplateFactoryBean::setMongoMappingContext);
- @Bean(name = "logMongoDbMongoTemplate")
- public MongoTemplateFactoryBean mongoTemplateFactoryBean(
- @Qualifier("logMongoDbMongoDatabase") ObjectProvider mongoDatabaseFactory,
- @Qualifier("logMongoDbMongoMappingContext") ObjectProvider mongoMappingContext) {
- final MongoTemplateFactoryBean mongoTemplateFactoryBean = new MongoTemplateFactoryBean();
+ return mongoTemplateFactoryBean;
+ }
- mongoDatabaseFactory.ifUnique(mongoTemplateFactoryBean::setMongoDatabaseFactory);
- mongoMappingContext.ifUnique(mongoTemplateFactoryBean::setMongoMappingContext);
+ @Bean(name = History.LOG_HANDLER_BEAN_NAME)
+ public MongoLogHandlerFactoryBean logHandlerFactoryBean(
+ @Qualifier("historyLoggingMongoDbMongoTemplate") ObjectProvider mongoTemplate) {
+ final MongoLogHandlerFactoryBean logHandlerFactoryBean = new MongoLogHandlerFactoryBean();
- return mongoTemplateFactoryBean;
- }
+ mongoTemplate.ifAvailable(logHandlerFactoryBean::setMongoTemplate);
- @Bean
- public MongoHandlerFactoryBean logHandlerFactoryBean(
- @Qualifier("logMongoDbMongoTemplate") ObjectProvider mongoTemplate) {
- final MongoHandlerFactoryBean logHandlerFactoryBean = new MongoHandlerFactoryBean();
+ propertyMapper.from(handlerProperties::getCollectionName).to(logHandlerFactoryBean::setCollectionName);
- mongoTemplate.ifUnique(logHandlerFactoryBean::setMongoTemplate);
+ return logHandlerFactoryBean;
+ }
+
+ private MongoCredential[] createMongoCredential() {
+ final String database =
+ handlerProperties.getAuthenticationDatabase() ==
+ null ? handlerProperties.getDatabaseName() : handlerProperties.getAuthenticationDatabase();
+ final MongoCredential credential = MongoCredential.createCredential(handlerProperties.getUsername(),
+ database, handlerProperties.getPassword().toCharArray());
- propertyMapper.from(handlerProperties::getCollectionName).to(logHandlerFactoryBean::setCollectionName);
+ return new MongoCredential[]{credential};
+ }
- return logHandlerFactoryBean;
}
}
diff --git a/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/rabbit/RabbitLogHandlerConfiguration.java b/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/rabbit/RabbitLogHandlerConfiguration.java
index 3157f94..385bb15 100644
--- a/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/rabbit/RabbitLogHandlerConfiguration.java
+++ b/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/rabbit/RabbitLogHandlerConfiguration.java
@@ -19,18 +19,18 @@
* +-------------------------------------------------------------------------------------------------------+
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
* | Author: Yong.Teng |
- * | Copyright @ 2013-2023 Buession.com Inc. |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package org.apereo.cas.logging.autoconfigure.rabbit;
-import com.buession.logging.core.handler.LogHandler;
import com.buession.logging.rabbitmq.spring.ConnectionFactoryBean;
import com.buession.logging.rabbitmq.spring.RabbitLogHandlerFactoryBean;
import com.buession.logging.rabbitmq.spring.RabbitTemplateFactoryBean;
import org.apereo.cas.logging.autoconfigure.AbstractLogHandlerConfiguration;
import org.apereo.cas.logging.config.CasLoggingConfigurationProperties;
import org.apereo.cas.logging.config.history.HistoryRabbitLogProperties;
+import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Qualifier;
@@ -49,58 +49,67 @@
*/
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(CasLoggingConfigurationProperties.class)
-@ConditionalOnMissingBean(LogHandler.class)
-@ConditionalOnClass({RabbitLogHandlerFactoryBean.class})
-@ConditionalOnProperty(prefix = RabbitLogHandlerConfiguration.PREFIX, name = "rabbit.enabled", havingValue = "true")
-public class RabbitLogHandlerConfiguration extends AbstractLogHandlerConfiguration {
+@ConditionalOnClass(name = {"com.buession.logging.rabbitmq.spring.RabbitLogHandlerFactoryBean"})
+public class RabbitLogHandlerConfiguration extends AbstractLogHandlerConfiguration {
- public RabbitLogHandlerConfiguration(CasLoggingConfigurationProperties logProperties) {
- super(logProperties.getHistory().getRabbit());
- }
+ @Configuration(proxyBeanMethods = false)
+ @EnableConfigurationProperties(CasLoggingConfigurationProperties.class)
+ @ConditionalOnProperty(prefix = History.PREFIX, name = "rabbit.enabled", havingValue = "true")
+ @ConditionalOnMissingBean(name = History.LOG_HANDLER_BEAN_NAME)
+ static class History extends AbstractHistoryLogHandlerConfiguration {
- @Bean(name = "logRabbitConnectionFactory")
- public ConnectionFactoryBean connectionFactoryBean() {
- final ConnectionFactoryBean connectionFactoryBean = new ConnectionFactoryBean();
+ public History(CasLoggingConfigurationProperties logProperties) {
+ super(logProperties.getHistory().getRabbit());
+ }
- propertyMapper.from(handlerProperties::getHost).to(connectionFactoryBean::setHost);
- propertyMapper.from(handlerProperties::getPort).to(connectionFactoryBean::setPort);
- propertyMapper.from(handlerProperties::getVirtualHost).to(connectionFactoryBean::setVirtualHost);
- propertyMapper.from(handlerProperties::getUsername).to(connectionFactoryBean::setUsername);
- propertyMapper.from(handlerProperties::getPassword).to(connectionFactoryBean::setPassword);
- propertyMapper.from(handlerProperties::getRequestedHeartbeat).to(connectionFactoryBean::setRequestedHeartbeat);
- propertyMapper.from(handlerProperties::getRequestedChannelMax)
- .to(connectionFactoryBean::setRequestedChannelMax);
- propertyMapper.from(handlerProperties::getPublisherConfirmType)
- .to(connectionFactoryBean::setPublisherConfirmType);
- propertyMapper.from(handlerProperties::getConnectionTimeout).to(connectionFactoryBean::setConnectionTimeout);
- propertyMapper.from(handlerProperties::getSslConfiguration).to(connectionFactoryBean::setSslConfiguration);
- propertyMapper.from(handlerProperties::getCache).to(connectionFactoryBean::setCache);
+ @Bean(name = "historyLoggingRabbitConnectionFactory")
+ public ConnectionFactoryBean connectionFactoryBean() {
+ final ConnectionFactoryBean connectionFactoryBean = new ConnectionFactoryBean();
- return connectionFactoryBean;
- }
+ propertyMapper.from(handlerProperties::getHost).to(connectionFactoryBean::setHost);
+ propertyMapper.from(handlerProperties::getPort).to(connectionFactoryBean::setPort);
+ propertyMapper.from(handlerProperties::getVirtualHost).to(connectionFactoryBean::setVirtualHost);
+ propertyMapper.from(handlerProperties::getUsername).to(connectionFactoryBean::setUsername);
+ propertyMapper.from(handlerProperties::getPassword).to(connectionFactoryBean::setPassword);
+ propertyMapper.from(handlerProperties::getRequestedHeartbeat)
+ .to(connectionFactoryBean::setRequestedHeartbeat);
+ propertyMapper.from(handlerProperties::getRequestedChannelMax)
+ .to(connectionFactoryBean::setRequestedChannelMax);
+ propertyMapper.from(handlerProperties::getPublisherConfirmType)
+ .to(connectionFactoryBean::setPublisherConfirmType);
+ propertyMapper.from(handlerProperties::getConnectionTimeout)
+ .to(connectionFactoryBean::setConnectionTimeout);
+ propertyMapper.from(handlerProperties::getSslConfiguration).to(connectionFactoryBean::setSslConfiguration);
+ propertyMapper.from(handlerProperties::getCache).to(connectionFactoryBean::setCache);
- @Bean(name = "logRabbitRabbitTemplate")
- public RabbitTemplateFactoryBean rabbitTemplateFactoryBean(
- @Qualifier("logRabbitConnectionFactory") ObjectProvider connectionFactory) {
- final RabbitTemplateFactoryBean rabbitTemplateFactoryBean = new RabbitTemplateFactoryBean();
+ return connectionFactoryBean;
+ }
- connectionFactory.ifUnique(rabbitTemplateFactoryBean::setConnectionFactory);
- propertyMapper.from(handlerProperties::getTemplate).to(rabbitTemplateFactoryBean::setTemplate);
- propertyMapper.from(handlerProperties::isPublisherReturns).to(rabbitTemplateFactoryBean::setPublisherReturns);
+ @Bean(name = "historyLoggingRabbitRabbitTemplate")
+ public RabbitTemplateFactoryBean rabbitTemplateFactoryBean(
+ @Qualifier("historyLoggingRabbitConnectionFactory") ObjectProvider connectionFactory) {
+ final RabbitTemplateFactoryBean rabbitTemplateFactoryBean = new RabbitTemplateFactoryBean();
- return rabbitTemplateFactoryBean;
- }
+ connectionFactory.ifAvailable(rabbitTemplateFactoryBean::setConnectionFactory);
+ propertyMapper.from(handlerProperties::getTemplate).to(rabbitTemplateFactoryBean::setTemplate);
+ propertyMapper.from(handlerProperties::isPublisherReturns)
+ .to(rabbitTemplateFactoryBean::setPublisherReturns);
+
+ return rabbitTemplateFactoryBean;
+ }
+
+ @Bean(name = History.LOG_HANDLER_BEAN_NAME)
+ public RabbitLogHandlerFactoryBean logHandlerFactoryBean(@Qualifier("historyLoggingRabbitRabbitTemplate")
+ ObjectProvider rabbitTemplate) {
+ final RabbitLogHandlerFactoryBean logHandlerFactoryBean = new RabbitLogHandlerFactoryBean();
- @Bean
- public RabbitLogHandlerFactoryBean logHandlerFactoryBean(@Qualifier("logRabbitRabbitTemplate")
- ObjectProvider rabbitTemplate) {
- final RabbitLogHandlerFactoryBean logHandlerFactoryBean = new RabbitLogHandlerFactoryBean();
+ rabbitTemplate.ifAvailable(logHandlerFactoryBean::setRabbitTemplate);
+ logHandlerFactoryBean.setExchange(handlerProperties.getExchange());
+ logHandlerFactoryBean.setRoutingKey(handlerProperties.getRoutingKey());
- rabbitTemplate.ifUnique(logHandlerFactoryBean::setRabbitTemplate);
- logHandlerFactoryBean.setExchange(handlerProperties.getExchange());
- logHandlerFactoryBean.setRoutingKey(handlerProperties.getRoutingKey());
+ return logHandlerFactoryBean;
+ }
- return logHandlerFactoryBean;
}
}
diff --git a/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/rest/RestLogHandlerConfiguration.java b/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/rest/RestLogHandlerConfiguration.java
index dad7708..5d6ae45 100644
--- a/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/rest/RestLogHandlerConfiguration.java
+++ b/buession-cas-logging/src/main/java/org/apereo/cas/logging/autoconfigure/rest/RestLogHandlerConfiguration.java
@@ -19,12 +19,11 @@
* +-------------------------------------------------------------------------------------------------------+
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
* | Author: Yong.Teng |
- * | Copyright @ 2013-2023 Buession.com Inc. |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package org.apereo.cas.logging.autoconfigure.rest;
-import com.buession.logging.core.handler.LogHandler;
import com.buession.logging.rest.spring.RestLogHandlerFactoryBean;
import org.apereo.cas.logging.autoconfigure.AbstractLogHandlerConfiguration;
import org.apereo.cas.logging.config.CasLoggingConfigurationProperties;
@@ -45,25 +44,31 @@
*/
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(CasLoggingConfigurationProperties.class)
-@ConditionalOnMissingBean(LogHandler.class)
-@ConditionalOnClass({RestLogHandlerFactoryBean.class})
-@ConditionalOnProperty(prefix = RestLogHandlerConfiguration.PREFIX, name = "rest.enabled", havingValue = "true")
-public class RestLogHandlerConfiguration extends AbstractLogHandlerConfiguration {
+@ConditionalOnClass(name = {"com.buession.logging.rest.spring.RestLogHandlerFactoryBean"})
+public class RestLogHandlerConfiguration extends AbstractLogHandlerConfiguration {
- public RestLogHandlerConfiguration(CasLoggingConfigurationProperties logProperties) {
- super(logProperties.getHistory().getRest());
- }
+ @Configuration(proxyBeanMethods = false)
+ @EnableConfigurationProperties(CasLoggingConfigurationProperties.class)
+ @ConditionalOnProperty(prefix = History.PREFIX, name = "rest.enabled", havingValue = "true")
+ @ConditionalOnMissingBean(name = History.LOG_HANDLER_BEAN_NAME)
+ static class History extends AbstractHistoryLogHandlerConfiguration {
+
+ public History(CasLoggingConfigurationProperties logProperties) {
+ super(logProperties.getHistory().getRest());
+ }
+
+ @Bean(name = History.LOG_HANDLER_BEAN_NAME)
+ public RestLogHandlerFactoryBean logHandlerFactoryBean() {
+ final RestLogHandlerFactoryBean logHandlerFactoryBean = new RestLogHandlerFactoryBean();
- @Bean
- public RestLogHandlerFactoryBean logHandlerFactoryBean() {
- final RestLogHandlerFactoryBean logHandlerFactoryBean = new RestLogHandlerFactoryBean();
+ propertyMapper.from(handlerProperties::getUrl).to(logHandlerFactoryBean::setUrl);
+ propertyMapper.from(handlerProperties::getRequestMethod).to(logHandlerFactoryBean::setRequestMethod);
+ propertyMapper.from(handlerProperties::getRequestBodyBuilder).as(BeanUtils::instantiateClass)
+ .to(logHandlerFactoryBean::setRequestBodyBuilder);
- propertyMapper.from(handlerProperties::getUrl).to(logHandlerFactoryBean::setUrl);
- propertyMapper.from(handlerProperties::getRequestMethod).to(logHandlerFactoryBean::setRequestMethod);
- propertyMapper.from(handlerProperties::getRequestBodyBuilder).as(BeanUtils::instantiateClass)
- .to(logHandlerFactoryBean::setRequestBodyBuilder);
+ return logHandlerFactoryBean;
+ }
- return logHandlerFactoryBean;
}
}
diff --git a/buession-cas-logging/src/main/java/org/apereo/cas/logging/config/BaseJdbcLogProperties.java b/buession-cas-logging/src/main/java/org/apereo/cas/logging/config/BaseJdbcLogProperties.java
new file mode 100644
index 0000000..07c8dce
--- /dev/null
+++ b/buession-cas-logging/src/main/java/org/apereo/cas/logging/config/BaseJdbcLogProperties.java
@@ -0,0 +1,189 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package org.apereo.cas.logging.config;
+
+import com.buession.core.id.IdGenerator;
+import com.buession.logging.core.formatter.GeoFormatter;
+import com.buession.logging.core.formatter.MapFormatter;
+import com.buession.logging.jdbc.formatter.DefaultGeoFormatter;
+import com.buession.logging.jdbc.formatter.JsonMapFormatter;
+import com.buession.logging.support.config.HandlerProperties;
+import org.apereo.cas.configuration.model.support.jpa.AbstractJpaProperties;
+
+import java.io.Serializable;
+
+/**
+ * @author Yong.Teng
+ * @since 2.3.3
+ */
+public abstract class BaseJdbcLogProperties extends AbstractJpaProperties implements HandlerProperties, Serializable {
+
+ private final static long serialVersionUID = 6396868404292124235L;
+
+ /**
+ * SQL
+ */
+ private String sql;
+
+ /**
+ * ID 生成器
+ */
+ private Class extends IdGenerator>> idGenerator;
+
+ /**
+ * 日期时间格式
+ */
+ private String dateTimeFormat;
+
+ /**
+ * 请求参数格式化为字符串
+ */
+ private Class extends MapFormatter