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
commit 4e9d7702c72f884c99be431b693bb8878d0097a6 Author: Francesco Chicchiriccò <ilgro...@apache.org> AuthorDate: Thu Sep 22 09:17:26 2022 +0200 Working around CAS bug --- wa/bootstrap/pom.xml | 11 +++++ .../bootstrap/AuthModulePropertySourceMapper.java | 8 +++- .../AuthModulePropertySourceMapperTest.java | 49 ++++++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/wa/bootstrap/pom.xml b/wa/bootstrap/pom.xml index 5fe2a70b71..4837838294 100644 --- a/wa/bootstrap/pom.xml +++ b/wa/bootstrap/pom.xml @@ -57,6 +57,17 @@ under the License. <groupId>org.apereo.cas</groupId> <artifactId>cas-server-core-util-api</artifactId> </dependency> + + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-simple</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter</artifactId> + <scope>test</scope> + </dependency> </dependencies> <build> diff --git a/wa/bootstrap/src/main/java/org/apache/syncope/wa/bootstrap/AuthModulePropertySourceMapper.java b/wa/bootstrap/src/main/java/org/apache/syncope/wa/bootstrap/AuthModulePropertySourceMapper.java index b14c7fe137..bb3179cf74 100644 --- a/wa/bootstrap/src/main/java/org/apache/syncope/wa/bootstrap/AuthModulePropertySourceMapper.java +++ b/wa/bootstrap/src/main/java/org/apache/syncope/wa/bootstrap/AuthModulePropertySourceMapper.java @@ -18,6 +18,8 @@ */ package org.apache.syncope.wa.bootstrap; +import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter; +import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; import java.util.Map; import java.util.Optional; import java.util.concurrent.TimeUnit; @@ -266,6 +268,10 @@ public class AuthModulePropertySourceMapper extends PropertySourceMapper impleme } } - return prefix("cas.authn.mfa.simple.", CasCoreConfigurationUtils.asMap(props)); + // workaround to remove with CAS >= 6.6.1 + return prefix("cas.authn.mfa.simple.", CasCoreConfigurationUtils.asMap( + props, + new SimpleFilterProvider().setDefaultFilter( + SimpleBeanPropertyFilter.filterOutAllExcept("defined", "undefined")))); } } diff --git a/wa/bootstrap/src/test/java/org/apache/syncope/wa/bootstrap/AuthModulePropertySourceMapperTest.java b/wa/bootstrap/src/test/java/org/apache/syncope/wa/bootstrap/AuthModulePropertySourceMapperTest.java new file mode 100644 index 0000000000..a5175ebe98 --- /dev/null +++ b/wa/bootstrap/src/test/java/org/apache/syncope/wa/bootstrap/AuthModulePropertySourceMapperTest.java @@ -0,0 +1,49 @@ +/* + * 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; + +import static org.junit.jupiter.api.Assertions.assertFalse; + +import java.util.Map; +import org.apache.syncope.common.lib.auth.SimpleMfaAuthModuleConf; +import org.apache.syncope.common.lib.to.AuthModuleTO; +import org.junit.jupiter.api.Test; + +public class AuthModulePropertySourceMapperTest { + + @Test + public void mapSimpleMfaAuthModuleConf() { + AuthModuleTO authModuleTO = new AuthModuleTO(); + authModuleTO.setKey("key"); + authModuleTO.setOrder(0); + + SimpleMfaAuthModuleConf conf = new SimpleMfaAuthModuleConf(); + + conf.setEmailAttribute("email"); + conf.setEmailFrom("sync...@apache.org"); + conf.setEmailSubject("Subject"); + conf.setEmailText("Text body"); + + conf.setTokenLength(256); + conf.setTimeToKillInSeconds(600); + + Map<String, Object> map = new AuthModulePropertySourceMapper(null).map(authModuleTO, conf); + assertFalse(map.keySet().stream().anyMatch(k -> k.endsWith("defined"))); + } +}