You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by mm...@apache.org on 2020/03/23 13:10:40 UTC
[syncope] 02/03: clean up config
This is an automated email from the ASF dual-hosted git repository.
mmoayyed pushed a commit to branch SYNCOPE-163-1
in repository https://gitbox.apache.org/repos/asf/syncope.git
commit bc0eaa781b413f4598d3337e5d99cfd4dae674b8
Author: Misagh Moayyed <mm...@gmail.com>
AuthorDate: Mon Mar 23 17:36:22 2020 +0430
clean up config
---
pom.xml | 25 +++++++
wa/bootstrap/pom.xml | 6 +-
.../java/org/apache/syncope/wa}/WARestClient.java | 24 +++----
.../RestfulCloudConfigBootstrapConfiguration.java | 77 ++++++++++++++--------
wa/starter/pom.xml | 25 +++++++
.../syncope/wa/starter/SyncopeWAConfiguration.java | 32 ++++++---
.../wa/starter/rest/SyncopeServiceRegistry.java | 3 +-
7 files changed, 143 insertions(+), 49 deletions(-)
diff --git a/pom.xml b/pom.xml
index 94eb7de..0c91ba1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1487,6 +1487,16 @@ under the License.
</dependency>
<dependency>
<groupId>org.apereo.cas</groupId>
+ <artifactId>cas-server-core-services-registry</artifactId>
+ <version>${cas.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apereo.cas</groupId>
+ <artifactId>cas-server-core-services-api</artifactId>
+ <version>${cas.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apereo.cas</groupId>
<artifactId>cas-server-core-tickets</artifactId>
<version>${cas.version}</version>
</dependency>
@@ -1557,11 +1567,26 @@ under the License.
</dependency>
<dependency>
<groupId>org.apereo.cas</groupId>
+ <artifactId>cas-server-support-saml-idp</artifactId>
+ <version>${cas.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apereo.cas</groupId>
+ <artifactId>cas-server-support-saml-idp-core</artifactId>
+ <version>${cas.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apereo.cas</groupId>
<artifactId>cas-server-support-oidc</artifactId>
<version>${cas.version}</version>
</dependency>
<dependency>
<groupId>org.apereo.cas</groupId>
+ <artifactId>cas-server-support-oauth-services</artifactId>
+ <version>${cas.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apereo.cas</groupId>
<artifactId>cas-server-support-validation</artifactId>
<version>${cas.version}</version>
</dependency>
diff --git a/wa/bootstrap/pom.xml b/wa/bootstrap/pom.xml
index 72b7482..0d05ff6 100644
--- a/wa/bootstrap/pom.xml
+++ b/wa/bootstrap/pom.xml
@@ -43,7 +43,11 @@ under the License.
<artifactId>syncope-client-am-lib</artifactId>
<version>${project.version}</version>
</dependency>
-
+ <dependency>
+ <groupId>org.apache.syncope.common.keymaster</groupId>
+ <artifactId>syncope-common-keymaster-client-zookeeper</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.apereo.cas</groupId>
<artifactId>cas-server-core-configuration-api</artifactId>
diff --git a/wa/starter/src/main/java/org/apache/syncope/wa/starter/rest/WARestClient.java b/wa/bootstrap/src/main/java/org/apache/syncope/wa/WARestClient.java
similarity index 78%
rename from wa/starter/src/main/java/org/apache/syncope/wa/starter/rest/WARestClient.java
rename to wa/bootstrap/src/main/java/org/apache/syncope/wa/WARestClient.java
index 555de0c..294347e 100644
--- a/wa/starter/src/main/java/org/apache/syncope/wa/starter/rest/WARestClient.java
+++ b/wa/bootstrap/src/main/java/org/apache/syncope/wa/WARestClient.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.syncope.wa.config.rest;
+package org.apache.syncope.wa;
import org.apache.syncope.client.lib.AnonymousAuthenticationHandler;
import org.apache.syncope.client.lib.SyncopeClient;
@@ -25,27 +25,29 @@ import org.apache.syncope.common.keymaster.client.api.ServiceOps;
import org.apache.syncope.common.keymaster.client.api.model.NetworkService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
public class WARestClient {
private static final Logger LOG = LoggerFactory.getLogger(WARestClient.class);
- @Autowired
- private ServiceOps serviceOps;
+ private final ServiceOps serviceOps;
- @Value("${anonymousUser}")
- private String anonymousUser;
+ private final String anonymousUser;
- @Value("${anonymousKey}")
- private String anonymousKey;
+ private final String anonymousKey;
- @Value("${useGZIPCompression}")
- private boolean useGZIPCompression;
+ private final boolean useGZIPCompression;
private SyncopeClient client;
+ public WARestClient(final ServiceOps serviceOps, final String anonymousUser,
+ final String anonymousKey, final boolean useGZIPCompression) {
+ this.serviceOps = serviceOps;
+ this.anonymousUser = anonymousUser;
+ this.anonymousKey = anonymousKey;
+ this.useGZIPCompression = useGZIPCompression;
+ }
+
public SyncopeClient getSyncopeClient() {
synchronized (this) {
if (client == null) {
diff --git a/wa/bootstrap/src/main/java/org/apache/syncope/wa/bootstrap/RestfulCloudConfigBootstrapConfiguration.java b/wa/bootstrap/src/main/java/org/apache/syncope/wa/bootstrap/RestfulCloudConfigBootstrapConfiguration.java
index 262931f..3181a9a 100644
--- a/wa/bootstrap/src/main/java/org/apache/syncope/wa/bootstrap/RestfulCloudConfigBootstrapConfiguration.java
+++ b/wa/bootstrap/src/main/java/org/apache/syncope/wa/bootstrap/RestfulCloudConfigBootstrapConfiguration.java
@@ -18,36 +18,59 @@
*/
package org.apache.syncope.wa.bootstrap;
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import java.net.URI;
-import java.util.Map;
-import javax.ws.rs.core.MediaType;
-import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.syncope.common.keymaster.client.api.ServiceOps;
+import org.apache.syncope.common.keymaster.client.zookeper.ZookeeperKeymasterClientContext;
+import org.apache.syncope.wa.WARestClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.cloud.bootstrap.config.PropertySourceLocator;
+import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.core.env.MapPropertySource;
-import org.springframework.core.env.PropertySource;
-
-@Configuration(value = "restfulCloudConfigBootstrapConfiguration", proxyBeanMethods = false)
-public class RestfulCloudConfigBootstrapConfiguration implements PropertySourceLocator {
-
- private static final ObjectMapper MAPPER = new ObjectMapper().findAndRegisterModules();
-
- @Override
- public PropertySource<?> locate(final Environment environment) {
- try {
- String content = WebClient.create(URI.create("https://demo5926981.mockable.io/casproperties")).
- accept(MediaType.APPLICATION_JSON_TYPE).
- get().
- readEntity(String.class);
-
- Map<String, Object> payload = MAPPER.readValue(content, new TypeReference<Map<String, Object>>() {
- });
- return new MapPropertySource(getClass().getName(), payload);
- } catch (Exception e) {
- throw new IllegalArgumentException("Unable to fetch settings", e);
- }
+
+import java.util.HashMap;
+import java.util.Map;
+
+@Configuration(proxyBeanMethods = false)
+@ImportAutoConfiguration(ZookeeperKeymasterClientContext.class)
+@PropertySource("classpath:wa.properties")
+@PropertySource(value = "file:${conf.directory}/wa.properties", ignoreResourceNotFound = true)
+public class RestfulCloudConfigBootstrapConfiguration {
+ private static final Logger LOG = LoggerFactory.getLogger(RestfulCloudConfigBootstrapConfiguration.class);
+
+ @Value("${anonymousUser}")
+ private String anonymousUser;
+
+ @Value("${anonymousKey}")
+ private String anonymousKey;
+
+ @Value("${useGZIPCompression}")
+ private boolean useGZIPCompression;
+
+ @Autowired
+ @Bean
+ public WARestClient waRestClient(final ServiceOps serviceOps) {
+ return new WARestClient(serviceOps, anonymousUser, anonymousKey, useGZIPCompression);
+ }
+
+ @Bean
+ public PropertySourceLocator configPropertySourceLocator() {
+ return new PropertySourceLocator() {
+ @Override
+ public org.springframework.core.env.PropertySource<?> locate(final Environment environment) {
+ try {
+ LOG.info("Bootstrapping WA configuration");
+ Map<String, Object> payload = new HashMap<>();
+ return new MapPropertySource(getClass().getName(), payload);
+ } catch (Exception e) {
+ throw new IllegalArgumentException("Unable to fetch settings", e);
+ }
+ }
+ };
}
}
diff --git a/wa/starter/pom.xml b/wa/starter/pom.xml
index 51bd951..246a577 100644
--- a/wa/starter/pom.xml
+++ b/wa/starter/pom.xml
@@ -95,6 +95,14 @@ under the License.
</dependency>
<dependency>
<groupId>org.apereo.cas</groupId>
+ <artifactId>cas-server-core-services-registry</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apereo.cas</groupId>
+ <artifactId>cas-server-core-services-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apereo.cas</groupId>
<artifactId>cas-server-core-tickets</artifactId>
</dependency>
<dependency>
@@ -151,10 +159,22 @@ under the License.
</dependency>
<dependency>
<groupId>org.apereo.cas</groupId>
+ <artifactId>cas-server-support-saml-idp</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apereo.cas</groupId>
+ <artifactId>cas-server-support-saml-idp-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apereo.cas</groupId>
<artifactId>cas-server-support-oidc</artifactId>
</dependency>
<dependency>
<groupId>org.apereo.cas</groupId>
+ <artifactId>cas-server-support-oauth-services</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apereo.cas</groupId>
<artifactId>cas-server-support-validation</artifactId>
</dependency>
<dependency>
@@ -202,6 +222,11 @@ under the License.
</dependency>
<dependency>
+ <groupId>org.bouncycastle</groupId>
+ <artifactId>bcpkix-jdk15on</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.syncope.common.keymaster</groupId>
<artifactId>syncope-common-keymaster-client-zookeeper</artifactId>
<version>${project.version}</version>
diff --git a/wa/starter/src/main/java/org/apache/syncope/wa/starter/SyncopeWAConfiguration.java b/wa/starter/src/main/java/org/apache/syncope/wa/starter/SyncopeWAConfiguration.java
index 16375c3..82ae936 100644
--- a/wa/starter/src/main/java/org/apache/syncope/wa/starter/SyncopeWAConfiguration.java
+++ b/wa/starter/src/main/java/org/apache/syncope/wa/starter/SyncopeWAConfiguration.java
@@ -18,24 +18,38 @@
*/
package org.apache.syncope.wa.starter;
-import java.io.Serializable;
-import org.apereo.cas.services.DefaultRegisteredServiceEntityMapper;
-import org.apereo.cas.services.RegisteredService;
-import org.apereo.cas.services.RegisteredServiceEntityMapper;
+import org.apereo.cas.services.ServiceRegistryExecutionPlanConfigurer;
+import org.apereo.cas.services.ServiceRegistryListener;
+
import org.apache.syncope.common.keymaster.client.api.model.NetworkService;
import org.apache.syncope.common.keymaster.client.api.startstop.KeymasterStart;
import org.apache.syncope.common.keymaster.client.api.startstop.KeymasterStop;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.apache.syncope.wa.starter.rest.SyncopeServiceRegistry;
+import org.apache.syncope.wa.WARestClient;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-@Configuration(proxyBeanMethods = false)
+import java.util.Collection;
+
+@Configuration
public class SyncopeWAConfiguration {
+ @Autowired
+ private ConfigurableApplicationContext applicationContext;
+
+ @Autowired
+ @Qualifier("serviceRegistryListeners")
+ private Collection<ServiceRegistryListener> serviceRegistryListeners;
+
+ @Autowired
@Bean
- @ConditionalOnProperty(name = "cas.serviceRegistry.rest.url")
- public RegisteredServiceEntityMapper<RegisteredService, Serializable> registeredServiceEntityMapper() {
- return new DefaultRegisteredServiceEntityMapper();
+ public ServiceRegistryExecutionPlanConfigurer syncopeServiceRegistryConfigurer(final WARestClient restClient) {
+ SyncopeServiceRegistry registry = new SyncopeServiceRegistry(restClient,
+ applicationContext, serviceRegistryListeners);
+ return plan -> plan.registerServiceRegistry(registry);
}
@Bean
diff --git a/wa/starter/src/main/java/org/apache/syncope/wa/starter/rest/SyncopeServiceRegistry.java b/wa/starter/src/main/java/org/apache/syncope/wa/starter/rest/SyncopeServiceRegistry.java
index adf4007..500ab4d 100644
--- a/wa/starter/src/main/java/org/apache/syncope/wa/starter/rest/SyncopeServiceRegistry.java
+++ b/wa/starter/src/main/java/org/apache/syncope/wa/starter/rest/SyncopeServiceRegistry.java
@@ -17,12 +17,13 @@
* under the License.
*/
-package org.apache.syncope.wa.config.rest;
+package org.apache.syncope.wa.starter.rest;
import org.apereo.cas.services.AbstractServiceRegistry;
import org.apereo.cas.services.RegisteredService;
import org.apereo.cas.services.ServiceRegistryListener;
+import org.apache.syncope.wa.WARestClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ConfigurableApplicationContext;