This is an automated email from the ASF dual-hosted git repository.
ilgrosso pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/syncope.git
The following commit(s) were added to refs/heads/master by this push:
new 534c75c2f4 Align with CAS upstream
534c75c2f4 is described below
commit 534c75c2f4b1b0be0708cc6216f3f79ca3120bc5
Author: Francesco Chicchiriccò <[email protected]>
AuthorDate: Wed Oct 25 13:47:08 2023 +0200
Align with CAS upstream
---
.../mapping/AttrRepoPropertySourceMapper.java | 9 +--
.../mapping/AuthModulePropertySourceMapper.java | 31 ++++---
.../syncope/wa/bootstrap/mapping/WAConfUtils.java | 94 ++++++++++++++++++++++
3 files changed, 113 insertions(+), 21 deletions(-)
diff --git
a/wa/bootstrap/src/main/java/org/apache/syncope/wa/bootstrap/mapping/AttrRepoPropertySourceMapper.java
b/wa/bootstrap/src/main/java/org/apache/syncope/wa/bootstrap/mapping/AttrRepoPropertySourceMapper.java
index cbdf8bd665..b24ef8d064 100644
---
a/wa/bootstrap/src/main/java/org/apache/syncope/wa/bootstrap/mapping/AttrRepoPropertySourceMapper.java
+++
b/wa/bootstrap/src/main/java/org/apache/syncope/wa/bootstrap/mapping/AttrRepoPropertySourceMapper.java
@@ -30,7 +30,6 @@ import org.apache.syncope.common.lib.attr.SyncopeAttrRepoConf;
import org.apache.syncope.common.lib.to.AttrRepoTO;
import org.apache.syncope.common.lib.to.Item;
import org.apache.syncope.wa.bootstrap.WARestClient;
-import org.apereo.cas.configuration.CasCoreConfigurationUtils;
import
org.apereo.cas.configuration.model.core.authentication.AttributeRepositoryStates;
import
org.apereo.cas.configuration.model.core.authentication.StubPrincipalAttributesProperties;
import
org.apereo.cas.configuration.model.support.jdbc.JdbcPrincipalAttributesProperties;
@@ -53,7 +52,7 @@ public class AttrRepoPropertySourceMapper extends
PropertySourceMapper implement
props.setOrder(attrRepoTO.getOrder());
props.setAttributes(conf.getAttributes());
- return prefix("cas.authn.attribute-repository.stub.",
CasCoreConfigurationUtils.asMap(props));
+ return prefix("cas.authn.attribute-repository.stub.",
WAConfUtils.asMap(props));
}
@Override
@@ -68,7 +67,7 @@ public class AttrRepoPropertySourceMapper extends
PropertySourceMapper implement
collect(Collectors.toMap(Item::getIntAttrName,
Item::getExtAttrName)));
fill(props, conf);
- return prefix("cas.authn.attribute-repository.ldap[].",
CasCoreConfigurationUtils.asMap(props));
+ return prefix("cas.authn.attribute-repository.ldap[].",
WAConfUtils.asMap(props));
}
@Override
@@ -90,7 +89,7 @@ public class AttrRepoPropertySourceMapper extends
PropertySourceMapper implement
collect(Collectors.toMap(Item::getIntAttrName,
Item::getExtAttrName)));
fill(props, conf);
- return prefix("cas.authn.attribute-repository.jdbc[].",
CasCoreConfigurationUtils.asMap(props));
+ return prefix("cas.authn.attribute-repository.jdbc[].",
WAConfUtils.asMap(props));
}
@Override
@@ -114,6 +113,6 @@ public class AttrRepoPropertySourceMapper extends
PropertySourceMapper implement
props.setAttributeMappings(attrRepoTO.getItems().
stream().collect(Collectors.toMap(Item::getIntAttrName,
Item::getExtAttrName)));
- return prefix("cas.authn.attribute-repository.syncope.",
CasCoreConfigurationUtils.asMap(props));
+ return prefix("cas.authn.attribute-repository.syncope.",
WAConfUtils.asMap(props));
}
}
diff --git
a/wa/bootstrap/src/main/java/org/apache/syncope/wa/bootstrap/mapping/AuthModulePropertySourceMapper.java
b/wa/bootstrap/src/main/java/org/apache/syncope/wa/bootstrap/mapping/AuthModulePropertySourceMapper.java
index dc6f017a7f..dcd300afc6 100644
---
a/wa/bootstrap/src/main/java/org/apache/syncope/wa/bootstrap/mapping/AuthModulePropertySourceMapper.java
+++
b/wa/bootstrap/src/main/java/org/apache/syncope/wa/bootstrap/mapping/AuthModulePropertySourceMapper.java
@@ -45,7 +45,6 @@ import org.apache.syncope.common.lib.to.AuthModuleTO;
import org.apache.syncope.common.lib.to.Item;
import org.apache.syncope.common.lib.types.AuthModuleState;
import org.apache.syncope.wa.bootstrap.WARestClient;
-import org.apereo.cas.configuration.CasCoreConfigurationUtils;
import
org.apereo.cas.configuration.model.core.authentication.AuthenticationHandlerStates;
import
org.apereo.cas.configuration.model.support.generic.AcceptAuthenticationProperties;
import
org.apereo.cas.configuration.model.support.jaas.JaasAuthenticationProperties;
@@ -89,7 +88,7 @@ public class AuthModulePropertySourceMapper extends
PropertySourceMapper impleme
collect(Collectors.joining(","));
props.setUsers(users);
- return prefix("cas.authn.accept.",
CasCoreConfigurationUtils.asMap(props));
+ return prefix("cas.authn.accept.", WAConfUtils.asMap(props));
}
@Override
@@ -119,7 +118,7 @@ public class AuthModulePropertySourceMapper extends
PropertySourceMapper impleme
fill(props, conf);
- return prefix("cas.authn.ldap[].",
CasCoreConfigurationUtils.asMap(props));
+ return prefix("cas.authn.ldap[].", WAConfUtils.asMap(props));
}
@Override
@@ -136,7 +135,7 @@ public class AuthModulePropertySourceMapper extends
PropertySourceMapper impleme
map(item -> item.getIntAttrName() + ":" +
item.getExtAttrName()).collect(Collectors.toList()));
fill(props, conf);
- return prefix("cas.authn.jdbc.query[].",
CasCoreConfigurationUtils.asMap(props));
+ return prefix("cas.authn.jdbc.query[].", WAConfUtils.asMap(props));
}
@Override
@@ -151,7 +150,7 @@ public class AuthModulePropertySourceMapper extends
PropertySourceMapper impleme
props.setLoginConfigType(conf.getLoginConfigurationFile());
props.setRealm(conf.getRealm());
- return prefix("cas.authn.jaas[].",
CasCoreConfigurationUtils.asMap(props));
+ return prefix("cas.authn.jaas[].", WAConfUtils.asMap(props));
}
@Override
@@ -173,7 +172,7 @@ public class AuthModulePropertySourceMapper extends
PropertySourceMapper impleme
props.setProfileAttrs(authModuleTO.getItems().stream().
collect(Collectors.toMap(Item::getIntAttrName,
Item::getExtAttrName)));
- return prefix("cas.authn.pac4j.oauth2[].",
CasCoreConfigurationUtils.asMap(props));
+ return prefix("cas.authn.pac4j.oauth2[].", WAConfUtils.asMap(props));
}
protected void map(
@@ -205,7 +204,7 @@ public class AuthModulePropertySourceMapper extends
PropertySourceMapper impleme
Pac4jOidcClientProperties client = new Pac4jOidcClientProperties();
client.setGeneric(props);
- return prefix("cas.authn.pac4j.oidc[].generic.",
CasCoreConfigurationUtils.asMap(props));
+ return prefix("cas.authn.pac4j.oidc[].generic.",
WAConfUtils.asMap(props));
}
@Override
@@ -217,7 +216,7 @@ public class AuthModulePropertySourceMapper extends
PropertySourceMapper impleme
Pac4jOidcClientProperties client = new Pac4jOidcClientProperties();
client.setAzure(props);
- return prefix("cas.authn.pac4j.oidc[].azure.",
CasCoreConfigurationUtils.asMap(props));
+ return prefix("cas.authn.pac4j.oidc[].azure.",
WAConfUtils.asMap(props));
}
@Override
@@ -228,7 +227,7 @@ public class AuthModulePropertySourceMapper extends
PropertySourceMapper impleme
Pac4jOidcClientProperties client = new Pac4jOidcClientProperties();
client.setGoogle(props);
- return prefix("cas.authn.pac4j.oidc[].google.",
CasCoreConfigurationUtils.asMap(props));
+ return prefix("cas.authn.pac4j.oidc[].google.",
WAConfUtils.asMap(props));
}
@Override
@@ -241,7 +240,7 @@ public class AuthModulePropertySourceMapper extends
PropertySourceMapper impleme
Pac4jOidcClientProperties client = new Pac4jOidcClientProperties();
client.setKeycloak(props);
- return prefix("cas.authn.pac4j.oidc[].keycloak.",
CasCoreConfigurationUtils.asMap(props));
+ return prefix("cas.authn.pac4j.oidc[].keycloak.",
WAConfUtils.asMap(props));
}
@Override
@@ -256,7 +255,7 @@ public class AuthModulePropertySourceMapper extends
PropertySourceMapper impleme
Pac4jOidcClientProperties client = new Pac4jOidcClientProperties();
client.setApple(props);
- return prefix("cas.authn.pac4j.oidc[].apple.",
CasCoreConfigurationUtils.asMap(props));
+ return prefix("cas.authn.pac4j.oidc[].apple.",
WAConfUtils.asMap(props));
}
@Override
@@ -286,7 +285,7 @@ public class AuthModulePropertySourceMapper extends
PropertySourceMapper impleme
? TriStateBoolean.UNDEFINED
:
TriStateBoolean.valueOf(conf.getNameIdPolicyAllowCreate().toUpperCase()));
- return prefix("cas.authn.pac4j.saml[].",
CasCoreConfigurationUtils.asMap(props));
+ return prefix("cas.authn.pac4j.saml[].", WAConfUtils.asMap(props));
}
@Override
@@ -305,7 +304,7 @@ public class AuthModulePropertySourceMapper extends
PropertySourceMapper impleme
props.setAttributeMappings(authModuleTO.getItems().stream().
collect(Collectors.toMap(Item::getIntAttrName,
Item::getExtAttrName)));
- return prefix("cas.authn.syncope.",
CasCoreConfigurationUtils.asMap(props));
+ return prefix("cas.authn.syncope.", WAConfUtils.asMap(props));
}
@Override
@@ -326,7 +325,7 @@ public class AuthModulePropertySourceMapper extends
PropertySourceMapper impleme
props.setLdap(ldapProps);
}
- return prefix("cas.authn.mfa.gauth.",
CasCoreConfigurationUtils.asMap(props));
+ return prefix("cas.authn.mfa.gauth.", WAConfUtils.asMap(props));
}
@Override
@@ -338,7 +337,7 @@ public class AuthModulePropertySourceMapper extends
PropertySourceMapper impleme
props.setDuoIntegrationKey(conf.getIntegrationKey());
props.setDuoSecretKey(conf.getSecretKey());
- return prefix("cas.authn.mfa.duo.",
CasCoreConfigurationUtils.asMap(props));
+ return prefix("cas.authn.mfa.duo.", WAConfUtils.asMap(props));
}
@Override
@@ -364,6 +363,6 @@ public class AuthModulePropertySourceMapper extends
PropertySourceMapper impleme
}
}
- return prefix("cas.authn.mfa.simple.",
CasCoreConfigurationUtils.asMap(props));
+ return prefix("cas.authn.mfa.simple.", WAConfUtils.asMap(props));
}
}
diff --git
a/wa/bootstrap/src/main/java/org/apache/syncope/wa/bootstrap/mapping/WAConfUtils.java
b/wa/bootstrap/src/main/java/org/apache/syncope/wa/bootstrap/mapping/WAConfUtils.java
new file mode 100644
index 0000000000..b32ac090d5
--- /dev/null
+++
b/wa/bootstrap/src/main/java/org/apache/syncope/wa/bootstrap/mapping/WAConfUtils.java
@@ -0,0 +1,94 @@
+/*
+ * 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.
+ */
+package org.apache.syncope.wa.bootstrap.mapping;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.PropertyNamingStrategies;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import com.fasterxml.jackson.databind.module.SimpleModule;
+import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
+import com.fasterxml.jackson.databind.ser.std.StdSerializer;
+import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
+import java.io.IOException;
+import java.io.Serializable;
+import java.io.StringWriter;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apereo.cas.configuration.CasCoreConfigurationUtils;
+import org.apereo.cas.util.function.FunctionUtils;
+import org.springframework.core.io.ByteArrayResource;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
+import org.springframework.util.ResourceUtils;
+
+public final class WAConfUtils {
+
+ private static class ResourceSerializer extends StdSerializer<Resource> {
+
+ private static final long serialVersionUID = 7971411664567411958L;
+
+ ResourceSerializer() {
+ this(null);
+ }
+
+ ResourceSerializer(final Class<Resource> t) {
+ super(t);
+ }
+
+ @Override
+ public void serialize(final Resource value,
+ final JsonGenerator jgen,
+ final SerializerProvider provider) throws IOException {
+
+ if (value instanceof ClassPathResource) {
+ jgen.writeString(ResourceUtils.CLASSPATH_URL_PREFIX +
value.getFilename());
+ } else {
+ jgen.writeString(value.getURI().toString());
+ }
+ }
+ }
+
+ private static final YAMLMapper YAML_MAPPER;
+
+ static {
+ YAML_MAPPER = new YAMLMapper();
+ YAML_MAPPER.setFilterProvider(new
SimpleFilterProvider().setFailOnUnknownId(false));
+ YAML_MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL);
+
YAML_MAPPER.setPropertyNamingStrategy(PropertyNamingStrategies.KEBAB_CASE);
+
+ SimpleModule module = new SimpleModule();
+ module.addSerializer(Resource.class, new ResourceSerializer());
+ YAML_MAPPER.registerModule(module);
+ }
+
+ public static Map<String, Object> asMap(final Serializable properties) {
+ return FunctionUtils.doUnchecked(() -> {
+ try (StringWriter writer = new StringWriter()) {
+ YAML_MAPPER.writeValue(writer, properties);
+ ByteArrayResource resource = new
ByteArrayResource(writer.toString().getBytes(StandardCharsets.UTF_8));
+ return CasCoreConfigurationUtils.loadYamlProperties(resource);
+ }
+ });
+ }
+
+ private WAConfUtils() {
+ // private construcator for static utility class
+ }
+}