This is an automated email from the ASF dual-hosted git repository.
dimaayash 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 4213061 [SYNCOPE-1557] complete policies manipulating (#186)
4213061 is described below
commit 42130611fef3f3d7b5de62ae299f826f42bd5b10
Author: DimaAy <[email protected]>
AuthorDate: Fri May 8 16:22:38 2020 +0200
[SYNCOPE-1557] complete policies manipulating (#186)
* [SYNCOPE-1557] complete policies manipulating
remove
ITCase attempt
Cleanup + sample working test for ClientApp
SyncopeServiceRegistry tests
[SYNCOPE-1557] authModules manipulating
[SYNCOPE-1557] complete policies manipulating and adding more tests
* rename and fix
* remove unneeded parenthesis
---
.../apache/syncope/common/lib/wa/WAClientApp.java | 8 +
.../jpa/entity/auth/AbstractClientApp.java | 2 +-
.../java/data/wa/WAClientAppBinderImpl.java | 42 +++-
.../wa/src/main/resources/application.properties | 13 +-
.../org/apache/syncope/fit/AbstractITCase.java | 46 +++++
.../org/apache/syncope/fit/core/PolicyITCase.java | 44 +----
.../apache/syncope/fit/core/WAClientAppITCase.java | 75 ++++++++
.../bootstrap/SyncopeWAPropertySourceLocator.java | 127 +++++++-----
.../apache/syncope/wa/bootstrap/WARestClient.java | 39 ++--
wa/starter/pom.xml | 6 +
.../syncope/wa/starter/SyncopeServiceRegistry.java | 63 +++---
.../wa/starter/SyncopeWAAuditTrailManager.java | 35 ++--
.../syncope/wa/starter/SyncopeWAConfiguration.java | 19 +-
.../syncope/wa/starter/mapping/AccessMapFor.java | 3 -
.../syncope/wa/starter/mapping/AccessMapper.java | 2 -
.../starter/mapping/AllowedAttrReleaseMapper.java | 10 +-
.../wa/starter/mapping/AttrReleaseMapFor.java | 3 -
.../wa/starter/mapping/AttrReleaseMapper.java | 2 -
.../syncope/wa/starter/mapping/AuthMapFor.java | 3 -
.../syncope/wa/starter/mapping/AuthMapper.java | 2 -
.../wa/starter/mapping/ClientAppMapFor.java | 3 -
.../wa/starter/mapping/ClientAppMapper.java | 2 -
.../wa/starter/mapping/DefaultAccessMapper.java | 12 +-
.../wa/starter/mapping/DefaultAuthMapper.java | 18 +-
.../syncope/wa/starter/mapping/OIDCRPTOMapper.java | 23 +--
.../starter/mapping/RegisteredServiceMapper.java | 59 +-----
.../wa/starter/mapping/SAML2SPTOMapper.java | 32 +---
.../src/main/resources/application.properties | 5 +-
.../apache/syncope/wa/starter/AbstractTest.java} | 22 ++-
.../starter/{SyncopeWATest.java => BasicTest.java} | 15 +-
.../wa/starter/SyncopeCoreTestingServer.java | 90 +++++++++
.../wa/starter/SyncopeServiceRegistryTest.java | 212 +++++++++++++++++++++
32 files changed, 695 insertions(+), 342 deletions(-)
diff --git
a/common/am/lib/src/main/java/org/apache/syncope/common/lib/wa/WAClientApp.java
b/common/am/lib/src/main/java/org/apache/syncope/common/lib/wa/WAClientApp.java
index 55771de..82ab76e 100644
---
a/common/am/lib/src/main/java/org/apache/syncope/common/lib/wa/WAClientApp.java
+++
b/common/am/lib/src/main/java/org/apache/syncope/common/lib/wa/WAClientApp.java
@@ -19,6 +19,8 @@
package org.apache.syncope.common.lib.wa;
import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
import org.apache.syncope.common.lib.policy.AccessPolicyConf;
import org.apache.syncope.common.lib.policy.AttrReleasePolicyConf;
import org.apache.syncope.common.lib.policy.AuthPolicyConf;
@@ -36,6 +38,8 @@ public class WAClientApp implements Serializable {
private AttrReleasePolicyConf attrReleasePolicyConf;
+ private final Map<String, Object> releaseAttrs = new HashMap<>();
+
public ClientAppTO getClientAppTO() {
return clientAppTO;
}
@@ -67,4 +71,8 @@ public class WAClientApp implements Serializable {
public void setAttrReleasePolicyConf(final AttrReleasePolicyConf
attrReleasePolicyConf) {
this.attrReleasePolicyConf = attrReleasePolicyConf;
}
+
+ public Map<String, Object> getReleaseAttrs() {
+ return releaseAttrs;
+ }
}
diff --git
a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/auth/AbstractClientApp.java
b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/auth/AbstractClientApp.java
index e815c0f..1027a1b 100644
---
a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/auth/AbstractClientApp.java
+++
b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/auth/AbstractClientApp.java
@@ -114,7 +114,7 @@ public class AbstractClientApp extends
AbstractGeneratedKeyEntity implements Cli
@Override
public void setAttrReleasePolicy(final AttrReleasePolicy policy) {
- checkType(policy, JPAAccessPolicy.class);
+ checkType(policy, JPAAttrReleasePolicy.class);
this.attrReleasePolicy = (JPAAttrReleasePolicy) policy;
}
diff --git
a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/wa/WAClientAppBinderImpl.java
b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/wa/WAClientAppBinderImpl.java
index 4f7c225..1ed1418 100644
---
a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/wa/WAClientAppBinderImpl.java
+++
b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/wa/WAClientAppBinderImpl.java
@@ -18,7 +18,11 @@
*/
package org.apache.syncope.core.provisioning.java.data.wa;
+import org.apache.syncope.common.lib.policy.AuthPolicyConf;
+import org.apache.syncope.common.lib.policy.DefaultAuthPolicyConf;
import org.apache.syncope.common.lib.wa.WAClientApp;
+import org.apache.syncope.core.persistence.api.dao.auth.AuthModuleDAO;
+import org.apache.syncope.core.persistence.api.entity.auth.AuthModule;
import org.apache.syncope.core.persistence.api.entity.auth.ClientApp;
import org.apache.syncope.core.provisioning.api.data.ClientAppDataBinder;
import org.slf4j.Logger;
@@ -35,28 +39,54 @@ public class WAClientAppBinderImpl implements
WAClientAppBinder {
@Autowired
private ClientAppDataBinder clientAppDataBinder;
+ @Autowired
+ private AuthModuleDAO authModuleDAO;
+
@Override
public WAClientApp getWAClientApp(final ClientApp clientApp) {
WAClientApp waClientApp = new WAClientApp();
waClientApp.setClientAppTO(clientAppDataBinder.getClientAppTO(clientApp));
try {
+ AuthPolicyConf authPolicyConf = null;
if (clientApp.getAuthPolicy() != null) {
-
waClientApp.setAuthPolicyConf((clientApp.getAuthPolicy()).getConf());
+ authPolicyConf = clientApp.getAuthPolicy().getConf();
+
waClientApp.setAuthPolicyConf(clientApp.getAuthPolicy().getConf());
} else if (clientApp.getRealm().getAuthPolicy() != null) {
-
waClientApp.setAuthPolicyConf((clientApp.getRealm().getAuthPolicy()).getConf());
+ authPolicyConf =
clientApp.getRealm().getAuthPolicy().getConf();
+
waClientApp.setAuthPolicyConf(clientApp.getRealm().getAuthPolicy().getConf());
}
if (clientApp.getAccessPolicy() != null) {
-
waClientApp.setAccessPolicyConf((clientApp.getAccessPolicy()).getConf());
+
waClientApp.setAccessPolicyConf(clientApp.getAccessPolicy().getConf());
} else if (clientApp.getRealm().getAccessPolicy() != null) {
-
waClientApp.setAccessPolicyConf((clientApp.getRealm().getAccessPolicy()).getConf());
+
waClientApp.setAccessPolicyConf(clientApp.getRealm().getAccessPolicy().getConf());
}
if (clientApp.getAttrReleasePolicy() != null) {
-
waClientApp.setAttrReleasePolicyConf((clientApp.getAttrReleasePolicy()).getConf());
+
waClientApp.setAttrReleasePolicyConf(clientApp.getAttrReleasePolicy().getConf());
} else if (clientApp.getRealm().getAttrReleasePolicy() != null) {
-
waClientApp.setAttrReleasePolicyConf((clientApp.getRealm().getAttrReleasePolicy()).getConf());
+
waClientApp.setAttrReleasePolicyConf(clientApp.getRealm().getAttrReleasePolicy().getConf());
+ }
+
+ if (authPolicyConf instanceof DefaultAuthPolicyConf
+ && !((DefaultAuthPolicyConf)
authPolicyConf).getAuthModules().isEmpty()) {
+ ((DefaultAuthPolicyConf)
authPolicyConf).getAuthModules().forEach(authModuleKey -> {
+ AuthModule authModule = authModuleDAO.find(authModuleKey);
+ if (authModule == null) {
+ LOG.warn("AuthModule " + authModuleKey + " not found");
+ } else {
+ authModule.getItems().forEach(item ->
waClientApp.getReleaseAttrs().put(
+ item.getExtAttrName(), item.getIntAttrName()));
+ }
+ });
+ }
+ if (waClientApp.getReleaseAttrs().isEmpty()) {
+ if (clientApp.getAttrReleasePolicy() != null) {
+
waClientApp.setAttrReleasePolicyConf(clientApp.getAttrReleasePolicy().getConf());
+ } else if (clientApp.getRealm().getAttrReleasePolicy() !=
null) {
+
waClientApp.setAttrReleasePolicyConf(clientApp.getRealm().getAttrReleasePolicy().getConf());
+ }
}
} catch (Exception e) {
LOG.error("While building the configuration from an application's
policy ", e);
diff --git a/docker/wa/src/main/resources/application.properties
b/docker/wa/src/main/resources/application.properties
index 763602f..ef67775 100644
--- a/docker/wa/src/main/resources/application.properties
+++ b/docker/wa/src/main/resources/application.properties
@@ -26,8 +26,17 @@ spring.http.encoding.force=true
server.servlet.contextPath=/syncope-wa
-spring.resources.static-locations=classpath:/syncope/static,classpath:/static
-spring.thymeleaf.templateResolverOrder=1
+spring.resources.static-locations=classpath:/thymeleaf/static,classpath:/static
+
+management.endpoints.web.exposure.include=health,loggers,refresh,registeredServices
+management.endpoint.health.show-details=always
+
+management.endpoint.health.enabled=true
+management.endpoint.loggers.enabled=true
+management.endpoint.refresh.enabled=true
+management.endpoint.registeredServices.enabled=true
+
+cas.serviceRegistry.schedule.enabled=false
##
# Allow configuration classes to override bean definitions from Spring Boot
diff --git
a/fit/core-reference/src/test/java/org/apache/syncope/fit/AbstractITCase.java
b/fit/core-reference/src/test/java/org/apache/syncope/fit/AbstractITCase.java
index 90a865a..91c7dcf 100644
---
a/fit/core-reference/src/test/java/org/apache/syncope/fit/AbstractITCase.java
+++
b/fit/core-reference/src/test/java/org/apache/syncope/fit/AbstractITCase.java
@@ -31,6 +31,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
+import java.util.Set;
import java.util.UUID;
import javax.naming.Context;
import javax.naming.NamingException;
@@ -66,6 +67,11 @@ import org.apache.syncope.common.lib.to.SchemaTO;
import org.apache.syncope.common.lib.to.AnyObjectTO;
import org.apache.syncope.common.lib.Attr;
import org.apache.syncope.common.lib.policy.AccessPolicyTO;
+import org.apache.syncope.common.lib.SyncopeClientException;
+import org.apache.syncope.common.lib.policy.AllowedAttrReleasePolicyConf;
+import org.apache.syncope.common.lib.policy.AttrReleasePolicyTO;
+import org.apache.syncope.common.lib.policy.DefaultAccessPolicyConf;
+import org.apache.syncope.common.lib.policy.DefaultAuthPolicyConf;
import org.apache.syncope.common.lib.to.ConnInstanceTO;
import org.apache.syncope.common.lib.to.ResourceTO;
import org.apache.syncope.common.lib.to.GroupTO;
@@ -78,11 +84,13 @@ import org.apache.syncope.common.lib.to.UserTO;
import org.apache.syncope.common.lib.to.AuthModuleTO;
import org.apache.syncope.common.lib.policy.AuthPolicyTO;
import org.apache.syncope.common.lib.to.SAML2IdPMetadataTO;
+import org.apache.syncope.common.lib.to.ImplementationTO;
import org.apache.syncope.common.lib.to.client.ClientAppTO;
import org.apache.syncope.common.lib.to.client.OIDCRPTO;
import org.apache.syncope.common.lib.to.client.SAML2SPTO;
import org.apache.syncope.common.lib.types.AnyTypeKind;
import org.apache.syncope.common.lib.types.ClientAppType;
+import org.apache.syncope.common.lib.types.ImplementationEngine;
import org.apache.syncope.common.lib.types.OIDCSubjectType;
import org.apache.syncope.common.lib.types.PatchOperation;
import org.apache.syncope.common.lib.types.PolicyType;
@@ -132,6 +140,7 @@ import
org.apache.syncope.common.rest.api.service.GatewayRouteService;
import org.apache.syncope.common.rest.api.service.SAML2IdPMetadataConfService;
import org.apache.syncope.common.rest.api.service.SAML2IdPMetadataService;
import org.apache.syncope.common.rest.api.service.UserWorkflowTaskService;
+import org.apache.syncope.core.provisioning.api.serialization.POJOHelper;
import org.apache.syncope.fit.core.CoreITContext;
import org.apache.syncope.fit.core.UserITCase;
import org.identityconnectors.common.security.Encryptor;
@@ -814,4 +823,41 @@ public abstract class AbstractITCase {
}
return (T) getObject(response.getLocation(), ClientAppService.class,
clientAppTO.getClass());
}
+
+ protected static AuthPolicyTO buildAuthPolicyTO(final String
authModuleKey) {
+ AuthPolicyTO policy = new AuthPolicyTO();
+ policy.setDescription("Test Authentication policy");
+
+ DefaultAuthPolicyConf conf = new DefaultAuthPolicyConf();
+ conf.setName("TestAuthConf");
+ conf.getAuthModules().add(authModuleKey);
+ policy.setConf(conf);
+
+ return policy;
+ }
+
+ protected static AttrReleasePolicyTO buildAttributeReleasePolicyTO(final
String policyName) {
+ AttrReleasePolicyTO policy = new AttrReleasePolicyTO();
+ policy.setDescription("Test Attribute Release policy");
+
+ AllowedAttrReleasePolicyConf conf = new AllowedAttrReleasePolicyConf();
+ conf.setName("MyDefaultAttrReleasePolicyConf");
+ conf.getAllowedAttrs().addAll(List.of("cn", "givenName"));
+ policy.setConf(conf);
+
+ return policy;
+ }
+
+ protected static AccessPolicyTO buildAccessPolicyTO() {
+ AccessPolicyTO policy = new AccessPolicyTO();
+ policy.setDescription("Test Access policy");
+
+ DefaultAccessPolicyConf conf = new DefaultAccessPolicyConf();
+ conf.setEnabled(true);
+ conf.setName("TestAccessPolicyConf");
+ conf.getRequiredAttrs().put("cn", Set.of("admin", "Admin",
"TheAdmin"));
+ policy.setConf(conf);
+
+ return policy;
+ }
}
diff --git
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PolicyITCase.java
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PolicyITCase.java
index 9df4990..9dfb160 100644
---
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PolicyITCase.java
+++
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PolicyITCase.java
@@ -59,43 +59,7 @@ import org.apache.syncope.common.lib.policy.AuthPolicyTO;
import org.apache.syncope.common.lib.policy.DefaultAuthPolicyConf;
public class PolicyITCase extends AbstractITCase {
-
- private static AuthPolicyTO buildAuthPolicyTO() {
- AuthPolicyTO policy = new AuthPolicyTO();
- policy.setDescription("Test Authentication policy");
-
- DefaultAuthPolicyConf conf = new DefaultAuthPolicyConf();
- conf.getAuthModules().addAll(List.of("LdapAuthentication1"));
- policy.setConf(conf);
-
- return policy;
- }
-
- private static AttrReleasePolicyTO buildAttributeReleasePolicyTO(final
String policyName) {
- AttrReleasePolicyTO policy = new AttrReleasePolicyTO();
- policy.setDescription("Test Attribute Release policy");
-
- AllowedAttrReleasePolicyConf conf = new AllowedAttrReleasePolicyConf();
- conf.setName("MyDefaultAttrReleasePolicyConf");
- conf.getAllowedAttrs().addAll(List.of("cn", "givenName"));
- policy.setConf(conf);
-
- return policy;
- }
-
- private static AccessPolicyTO buildAccessPolicyTO() {
- AccessPolicyTO policy = new AccessPolicyTO();
- policy.setDescription("Test Access policy");
-
- DefaultAccessPolicyConf conf = new DefaultAccessPolicyConf();
- conf.setEnabled(true);
- conf.setName("TestAccessPolicyConf");
- conf.getRequiredAttrs().put("cn", Set.of("admin", "Admin",
"TheAdmin"));
- policy.setConf(conf);
-
- return policy;
- }
-
+
private PullPolicyTO buildPullPolicyTO() throws IOException {
ImplementationTO corrRule = null;
try {
@@ -222,7 +186,7 @@ public class PolicyITCase extends AbstractITCase {
assertEquals("TestPushRule",
pushPolicyTO.getCorrelationRules().get(AnyTypeKind.USER.name()));
AuthPolicyTO authPolicyTO = createPolicy(PolicyType.AUTH,
- buildAuthPolicyTO());
+ buildAuthPolicyTO("LdapAuthentication1"));
assertNotNull(authPolicyTO);
assertEquals("Test Authentication policy",
authPolicyTO.getDescription());
@@ -263,7 +227,7 @@ public class PolicyITCase extends AbstractITCase {
@Test
public void updateAuthPolicy() {
- AuthPolicyTO newAuthPolicyTO = buildAuthPolicyTO();
+ AuthPolicyTO newAuthPolicyTO =
buildAuthPolicyTO("LdapAuthentication1");
assertNotNull(newAuthPolicyTO);
newAuthPolicyTO = createPolicy(PolicyType.AUTH, newAuthPolicyTO);
@@ -341,7 +305,7 @@ public class PolicyITCase extends AbstractITCase {
assertNotNull(e);
}
- AuthPolicyTO authPolicy = buildAuthPolicyTO();
+ AuthPolicyTO authPolicy = buildAuthPolicyTO("LdapAuthentication1");
AuthPolicyTO authPolicyTO = createPolicy(PolicyType.AUTH, authPolicy);
assertNotNull(authPolicyTO);
diff --git
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/WAClientAppITCase.java
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/WAClientAppITCase.java
index 99d4ded..b3c0029 100644
---
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/WAClientAppITCase.java
+++
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/WAClientAppITCase.java
@@ -18,16 +18,24 @@
*/
package org.apache.syncope.fit.core;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.List;
import org.apache.syncope.client.lib.AnonymousAuthenticationHandler;
import org.apache.syncope.client.lib.SyncopeClient;
+import org.apache.syncope.common.lib.policy.AccessPolicyTO;
+import org.apache.syncope.common.lib.policy.AttrReleasePolicyTO;
+import org.apache.syncope.common.lib.policy.AuthPolicyTO;
+import org.apache.syncope.common.lib.to.AuthModuleTO;
+import org.apache.syncope.common.lib.to.ItemTO;
import org.apache.syncope.common.lib.wa.WAClientApp;
import org.apache.syncope.common.lib.to.client.OIDCRPTO;
import org.apache.syncope.common.lib.to.client.SAML2SPTO;
import org.apache.syncope.common.lib.types.ClientAppType;
+import org.apache.syncope.common.lib.types.PolicyType;
import org.apache.syncope.fit.AbstractITCase;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -80,4 +88,71 @@ public class WAClientAppITCase extends AbstractITCase {
registeredSamlClientApp = waClientAppService.read(samlspto.getName(),
ClientAppType.SAML2SP);
assertNotNull(registeredSamlClientApp);
}
+
+ @Test
+ public void readWithPolicies() {
+ OIDCRPTO oidcrpto = buildOIDCRP();
+
+ AuthPolicyTO authPolicyTO = createPolicy(PolicyType.AUTH,
+ buildAuthPolicyTO("be456831-593d-4003-b273-4c3fb61700df"));
+
+ AccessPolicyTO accessPolicyTO = createPolicy(PolicyType.ACCESS,
+ buildAccessPolicyTO());
+
+ String policyName = "TestAttrReleasePolicy" + getUUIDString();
+ AttrReleasePolicyTO attrReleasePolicyTO =
createPolicy(PolicyType.ATTR_RELEASE,
+ buildAttributeReleasePolicyTO(policyName));
+
+ oidcrpto.setAuthPolicy(authPolicyTO.getKey());
+ oidcrpto.setAccessPolicy(accessPolicyTO.getKey());
+ oidcrpto.setAttrReleasePolicy(attrReleasePolicyTO.getKey());
+
+ oidcrpto = createClientApp(ClientAppType.OIDCRP, oidcrpto);
+
+ WAClientApp waClientApp =
waClientAppService.read(oidcrpto.getClientAppId(), null);
+ assertNotNull(waClientApp);
+ assertEquals("TestAuthConf",
waClientApp.getAuthPolicyConf().getName());
+ assertEquals("TestAccessPolicyConf",
waClientApp.getAccessPolicyConf().getName());
+ assertEquals("MyDefaultAttrReleasePolicyConf",
waClientApp.getAttrReleasePolicyConf().getName());
+ assertTrue(waClientApp.getReleaseAttrs().isEmpty());
+
+ // add items to the authentication module
+ addItems();
+ waClientApp = waClientAppService.read(oidcrpto.getClientAppId(), null);
+ assertNotNull(waClientApp);
+ assertFalse(waClientApp.getReleaseAttrs().isEmpty());
+ assertEquals("uid", waClientApp.getReleaseAttrs().get("username"));
+ assertEquals("cn", waClientApp.getReleaseAttrs().get("fullname"));
+ removeItems();
+ }
+
+ private void addItems() {
+ AuthModuleTO authModuleTO =
authModuleService.read("be456831-593d-4003-b273-4c3fb61700df");
+
+ ItemTO keyMapping = new ItemTO();
+ keyMapping.setIntAttrName("uid");
+ keyMapping.setExtAttrName("username");
+ authModuleTO.add(keyMapping);
+
+ ItemTO fullnameMapping = new ItemTO();
+ fullnameMapping.setIntAttrName("cn");
+ fullnameMapping.setExtAttrName("fullname");
+ authModuleTO.add(fullnameMapping);
+
+ authModuleService.update(authModuleTO);
+
+ authModuleTO =
authModuleService.read("be456831-593d-4003-b273-4c3fb61700df");
+ assertFalse(authModuleTO.getItems().isEmpty());
+ }
+
+ private void removeItems() {
+ AuthModuleTO authModuleTO =
authModuleService.read("be456831-593d-4003-b273-4c3fb61700df");
+ authModuleTO.getItems().clear();
+
+ authModuleService.update(authModuleTO);
+
+ authModuleTO =
authModuleService.read("be456831-593d-4003-b273-4c3fb61700df");
+ assertTrue(authModuleTO.getItems().isEmpty());
+ }
+
}
diff --git
a/wa/bootstrap/src/main/java/org/apache/syncope/wa/bootstrap/SyncopeWAPropertySourceLocator.java
b/wa/bootstrap/src/main/java/org/apache/syncope/wa/bootstrap/SyncopeWAPropertySourceLocator.java
index 76ff64d..f4190b0 100644
---
a/wa/bootstrap/src/main/java/org/apache/syncope/wa/bootstrap/SyncopeWAPropertySourceLocator.java
+++
b/wa/bootstrap/src/main/java/org/apache/syncope/wa/bootstrap/SyncopeWAPropertySourceLocator.java
@@ -7,7 +7,7 @@
* "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
+ * 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
@@ -18,6 +18,9 @@
*/
package org.apache.syncope.wa.bootstrap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
import org.apereo.cas.configuration.CasConfigurationProperties;
import org.apereo.cas.configuration.CasCoreConfigurationUtils;
import
org.apereo.cas.configuration.model.support.generic.AcceptAuthenticationProperties;
@@ -32,8 +35,8 @@ import
org.apereo.cas.configuration.model.support.pac4j.saml.Pac4jSamlClientProp
import org.apereo.cas.configuration.model.support.radius.RadiusProperties;
import
org.apereo.cas.configuration.model.support.syncope.SyncopeAuthenticationProperties;
import org.apereo.cas.util.model.TriStateBoolean;
-
import org.apache.commons.lang3.StringUtils;
+import org.apache.syncope.client.lib.SyncopeClient;
import org.apache.syncope.common.lib.auth.AuthModuleConf;
import org.apache.syncope.common.lib.auth.GoogleMfaAuthModuleConf;
import org.apache.syncope.common.lib.auth.JDBCAuthModuleConf;
@@ -54,10 +57,6 @@ import org.springframework.core.env.Environment;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.PropertySource;
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
-import java.util.stream.Collectors;
-
@Order
public class SyncopeWAPropertySourceLocator implements PropertySourceLocator {
@@ -69,46 +68,59 @@ public class SyncopeWAPropertySourceLocator implements
PropertySourceLocator {
this.waRestClient = waRestClient;
}
- private static void mapSyncopeAuthModuleConf(final
CasConfigurationProperties casProperties,
- final AuthModuleConf
authConf) {
+ private static void mapSyncopeAuthModuleConf(
+ final CasConfigurationProperties casProperties,
+ final AuthModuleConf authConf) {
+
SyncopeAuthModuleConf conf =
SyncopeAuthModuleConf.class.cast(authConf);
+
SyncopeAuthenticationProperties syncopeProps = new
SyncopeAuthenticationProperties();
syncopeProps.setName(conf.getName());
syncopeProps.setDomain(conf.getDomain());
syncopeProps.setUrl(conf.getUrl());
+
casProperties.getAuthn().setSyncope(syncopeProps);
}
- private static void mapStaticAuthModuleConf(final
CasConfigurationProperties casProperties,
- final AuthModuleConf authConf)
{
+ private static void mapStaticAuthModuleConf(
+ final CasConfigurationProperties casProperties,
+ final AuthModuleConf authConf) {
+
StaticAuthModuleConf conf = StaticAuthModuleConf.class.cast(authConf);
+
AcceptAuthenticationProperties staticProps = new
AcceptAuthenticationProperties();
staticProps.setName(conf.getName());
String users = conf.getUsers().entrySet().stream().
- map(entry -> entry.getKey() + "::" + entry.getValue()).
- collect(Collectors.joining(","));
+ map(entry -> entry.getKey() + "::" + entry.getValue()).
+ collect(Collectors.joining(","));
staticProps.setUsers(users);
+
casProperties.getAuthn().setAccept(staticProps);
}
- private static void mapLdapAuthModuleConf(final CasConfigurationProperties
casProperties,
- final AuthModuleConf authConf) {
- LDAPAuthModuleConf ldapConf = LDAPAuthModuleConf.class.cast(authConf);
+ private static void mapLdapAuthModuleConf(
+ final CasConfigurationProperties casProperties,
+ final AuthModuleConf authConf) {
+
+ LDAPAuthModuleConf conf = LDAPAuthModuleConf.class.cast(authConf);
LdapAuthenticationProperties ldapProps = new
LdapAuthenticationProperties();
- ldapProps.setName(ldapConf.getName());
- ldapProps.setBaseDn(ldapConf.getBaseDn());
- ldapProps.setBindCredential(ldapConf.getBindCredential());
- ldapProps.setSearchFilter(ldapConf.getSearchFilter());
- ldapProps.setPrincipalAttributeId(ldapConf.getUserIdAttribute());
- ldapProps.setLdapUrl(ldapConf.getLdapUrl());
- ldapProps.setSubtreeSearch(ldapConf.isSubtreeSearch());
-
ldapProps.setPrincipalAttributeList(ldapConf.getPrincipalAttributeList());
+ ldapProps.setName(conf.getName());
+ ldapProps.setBaseDn(conf.getBaseDn());
+ ldapProps.setBindCredential(conf.getBindCredential());
+ ldapProps.setSearchFilter(conf.getSearchFilter());
+ ldapProps.setPrincipalAttributeId(conf.getUserIdAttribute());
+ ldapProps.setLdapUrl(conf.getLdapUrl());
+ ldapProps.setSubtreeSearch(conf.isSubtreeSearch());
+ ldapProps.setPrincipalAttributeList(conf.getPrincipalAttributeList());
+
casProperties.getAuthn().getLdap().add(ldapProps);
}
- private static void mapGoogleMfaAuthModuleConf(final
CasConfigurationProperties casProperties,
- final AuthModuleConf
authConf) {
+ private static void mapGoogleMfaAuthModuleConf(
+ final CasConfigurationProperties casProperties,
+ final AuthModuleConf authConf) {
+
GoogleMfaAuthModuleConf conf =
GoogleMfaAuthModuleConf.class.cast(authConf);
GoogleAuthenticatorMultifactorProperties props = new
GoogleAuthenticatorMultifactorProperties();
@@ -122,8 +134,10 @@ public class SyncopeWAPropertySourceLocator implements
PropertySourceLocator {
casProperties.getAuthn().getMfa().setGauth(props);
}
- private static void mapU2fAuthModuleConf(final CasConfigurationProperties
casProperties,
- final AuthModuleConf authConf) {
+ private static void mapU2fAuthModuleConf(
+ final CasConfigurationProperties casProperties,
+ final AuthModuleConf authConf) {
+
U2FAuthModuleConf conf = U2FAuthModuleConf.class.cast(authConf);
U2FMultifactorProperties props = new U2FMultifactorProperties();
@@ -132,12 +146,16 @@ public class SyncopeWAPropertySourceLocator implements
PropertySourceLocator {
props.setExpireDevicesTimeUnit(TimeUnit.valueOf(conf.getExpireDevicesTimeUnit()));
props.setExpireRegistrations(conf.getExpireRegistrations());
props.setExpireRegistrationsTimeUnit(TimeUnit.valueOf(conf.getExpireRegistrationsTimeUnit()));
+
casProperties.getAuthn().getMfa().setU2f(props);
}
- private static void mapJaasAuthModuleConf(final CasConfigurationProperties
casProperties,
- final AuthModuleConf authConf) {
+ private static void mapJaasAuthModuleConf(
+ final CasConfigurationProperties casProperties,
+ final AuthModuleConf authConf) {
+
JaasAuthModuleConf conf = JaasAuthModuleConf.class.cast(authConf);
+
JaasAuthenticationProperties props = new
JaasAuthenticationProperties();
props.setName(conf.getName());
props.setLoginConfigType(conf.getLoginConfigType());
@@ -145,12 +163,16 @@ public class SyncopeWAPropertySourceLocator implements
PropertySourceLocator {
props.setKerberosRealmSystemProperty(conf.getKerberosRealmSystemProperty());
props.setLoginConfigType(conf.getLoginConfigurationFile());
props.setRealm(conf.getRealm());
+
casProperties.getAuthn().getJaas().add(props);
}
- private static void mapJdbcAuthModuleConf(final CasConfigurationProperties
casProperties,
- final AuthModuleConf authConf) {
+ private static void mapJdbcAuthModuleConf(
+ final CasConfigurationProperties casProperties,
+ final AuthModuleConf authConf) {
+
JDBCAuthModuleConf conf = JDBCAuthModuleConf.class.cast(authConf);
+
QueryJdbcAuthenticationProperties props = new
QueryJdbcAuthenticationProperties();
props.setName(conf.getName());
props.setSql(conf.getSql());
@@ -163,12 +185,16 @@ public class SyncopeWAPropertySourceLocator implements
PropertySourceLocator {
props.setUrl(conf.getUrl());
props.setUser(conf.getUser());
props.setPrincipalAttributeList(conf.getPrincipalAttributeList());
+
casProperties.getAuthn().getJdbc().getQuery().add(props);
}
- private static void mapOidcAuthModuleConf(final CasConfigurationProperties
casProperties,
- final AuthModuleConf authConf) {
+ private static void mapOidcAuthModuleConf(
+ final CasConfigurationProperties casProperties,
+ final AuthModuleConf authConf) {
+
OIDCAuthModuleConf conf = OIDCAuthModuleConf.class.cast(authConf);
+
Pac4jGenericOidcClientProperties props = new
Pac4jGenericOidcClientProperties();
props.setId(conf.getId());
props.setCustomParams(conf.getCustomParams());
@@ -183,12 +209,16 @@ public class SyncopeWAPropertySourceLocator implements
PropertySourceLocator {
props.setPrincipalAttributeId(conf.getUserIdAttribute());
Pac4jOidcClientProperties client = new Pac4jOidcClientProperties();
client.setGeneric(props);
+
casProperties.getAuthn().getPac4j().getOidc().add(client);
}
- private static void mapRadiusAuthModuleConf(final
CasConfigurationProperties casProperties,
- final AuthModuleConf authConf)
{
+ private static void mapRadiusAuthModuleConf(
+ final CasConfigurationProperties casProperties,
+ final AuthModuleConf authConf) {
+
RadiusAuthModuleConf conf = RadiusAuthModuleConf.class.cast(authConf);
+
RadiusProperties props = new RadiusProperties();
props.setName(conf.getName());
@@ -211,9 +241,12 @@ public class SyncopeWAPropertySourceLocator implements
PropertySourceLocator {
casProperties.getAuthn().setRadius(props);
}
- private static void mapSaml2IdPAuthModuleConf(final
CasConfigurationProperties casProperties,
- final AuthModuleConf
authConf) {
+ private static void mapSaml2IdPAuthModuleConf(
+ final CasConfigurationProperties casProperties,
+ final AuthModuleConf authConf) {
+
SAML2IdPAuthModuleConf conf =
SAML2IdPAuthModuleConf.class.cast(authConf);
+
Pac4jSamlClientProperties props = new Pac4jSamlClientProperties();
props.setAcceptedSkew(conf.getAcceptedSkew());
props.setAssertionConsumerServiceIndex(conf.getAssertionConsumerServiceIndex());
@@ -236,28 +269,28 @@ public class SyncopeWAPropertySourceLocator implements
PropertySourceLocator {
props.setSignatureCanonicalizationAlgorithm(conf.getSignatureCanonicalizationAlgorithm());
props.setSignatureReferenceDigestMethods(conf.getSignatureReferenceDigestMethods());
props.setPrincipalAttributeId(conf.getUserIdAttribute());
- if (StringUtils.isBlank(conf.getNameIdPolicyAllowCreate())) {
- props.setNameIdPolicyAllowCreate(TriStateBoolean.UNDEFINED);
- } else {
-
props.setNameIdPolicyAllowCreate(TriStateBoolean.valueOf(conf.getNameIdPolicyAllowCreate().toUpperCase()));
- }
+
props.setNameIdPolicyAllowCreate(StringUtils.isBlank(conf.getNameIdPolicyAllowCreate())
+ ? TriStateBoolean.UNDEFINED
+ :
TriStateBoolean.valueOf(conf.getNameIdPolicyAllowCreate().toUpperCase()));
+
casProperties.getAuthn().getPac4j().getSaml().add(props);
}
@Override
public PropertySource<?> locate(final Environment environment) {
- if (!WARestClient.isReady()) {
+ SyncopeClient syncopeClient = waRestClient.getSyncopeClient();
+ if (syncopeClient == null) {
LOG.warn("Application context is not ready to bootstrap WA
configuration");
return null;
}
+
LOG.info("Bootstrapping WA configuration");
- AuthModuleService authService =
waRestClient.getSyncopeClient().getService(AuthModuleService.class);
+ AuthModuleService authService =
syncopeClient.getService(AuthModuleService.class);
CasConfigurationProperties casProperties = new
CasConfigurationProperties();
authService.list().forEach(authModuleTO -> {
-
AuthModuleConf authConf = authModuleTO.getConf();
- LOG.debug("Mapping auth module {}:{} as conf {}",
authModuleTO.getKey(),
- authModuleTO.getName(), authConf.getName());
+ LOG.debug("Mapping auth module {}:{} as conf {}",
+ authModuleTO.getKey(), authModuleTO.getName(),
authConf.getName());
if (authConf instanceof LDAPAuthModuleConf) {
mapLdapAuthModuleConf(casProperties, authConf);
}
diff --git
a/wa/bootstrap/src/main/java/org/apache/syncope/wa/bootstrap/WARestClient.java
b/wa/bootstrap/src/main/java/org/apache/syncope/wa/bootstrap/WARestClient.java
index 4ad7369..b5e8d6e 100644
---
a/wa/bootstrap/src/main/java/org/apache/syncope/wa/bootstrap/WARestClient.java
+++
b/wa/bootstrap/src/main/java/org/apache/syncope/wa/bootstrap/WARestClient.java
@@ -18,6 +18,7 @@
*/
package org.apache.syncope.wa.bootstrap;
+import java.util.Optional;
import org.apereo.cas.util.spring.ApplicationContextProvider;
import org.apache.syncope.client.lib.AnonymousAuthenticationHandler;
import org.apache.syncope.client.lib.SyncopeClient;
@@ -54,43 +55,45 @@ public class WARestClient {
public SyncopeClient getSyncopeClient() {
synchronized (this) {
- if (client == null && isReady()) {
- try {
- client = new SyncopeClientFactoryBean().
- setAddress(getCore().getAddress()).
- setUseCompression(useGZIPCompression).
- create(new
AnonymousAuthenticationHandler(anonymousUser, anonymousKey));
- } catch (Exception e) {
- LOG.error("Could not init SyncopeClient", e);
- }
+ if (client == null) {
+ getCore().ifPresent(core -> {
+ try {
+ client = new SyncopeClientFactoryBean().
+ setAddress(core.getAddress()).
+ setUseCompression(useGZIPCompression).
+ create(new
AnonymousAuthenticationHandler(anonymousUser, anonymousKey));
+ } catch (Exception e) {
+ LOG.error("Could not init SyncopeClient", e);
+ }
+ });
}
- }
- return client;
+ return client;
+ }
}
- private static NetworkService getCore() {
+ private static Optional<NetworkService> getCore() {
try {
- final ApplicationContext context =
ApplicationContextProvider.getApplicationContext();
+ ApplicationContext context =
ApplicationContextProvider.getApplicationContext();
if (context == null) {
- return null;
+ return Optional.empty();
}
Collection<ServiceOps> serviceOpsList =
context.getBeansOfType(ServiceOps.class).values();
if (serviceOpsList.isEmpty()) {
- return null;
+ return Optional.empty();
}
ServiceOps serviceOps = serviceOpsList.iterator().next();
- return serviceOps.get(NetworkService.Type.CORE);
+ return Optional.of(serviceOps.get(NetworkService.Type.CORE));
} catch (KeymasterException e) {
LOG.trace(e.getMessage());
}
- return null;
+ return Optional.empty();
}
public static boolean isReady() {
try {
- return getCore() != null;
+ return getCore().isPresent();
} catch (Exception e) {
LOG.trace(e.getMessage());
}
diff --git a/wa/starter/pom.xml b/wa/starter/pom.xml
index 1ebee71..180672f 100644
--- a/wa/starter/pom.xml
+++ b/wa/starter/pom.xml
@@ -244,6 +244,12 @@ under the License.
</dependency>
<dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-transports-http-jetty</artifactId>
+ <version>${cxf.version}</version>
+ <scope>test</scope>
+ </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/SyncopeServiceRegistry.java
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/SyncopeServiceRegistry.java
index a10a7ff..11e1fc2 100644
---
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/SyncopeServiceRegistry.java
+++
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/SyncopeServiceRegistry.java
@@ -22,6 +22,7 @@ import
org.apache.syncope.wa.starter.mapping.RegisteredServiceMapper;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
+import org.apache.syncope.client.lib.SyncopeClient;
import org.apache.syncope.common.lib.types.ClientAppType;
import org.apache.syncope.wa.bootstrap.WARestClient;
import org.apereo.cas.services.AbstractServiceRegistry;
@@ -38,7 +39,7 @@ public class SyncopeServiceRegistry extends
AbstractServiceRegistry {
private static final Logger LOG =
LoggerFactory.getLogger(SyncopeServiceRegistry.class);
- private final WARestClient restClient;
+ private final WARestClient waRestClient;
private final RegisteredServiceMapper registeredServiceMapper;
@@ -49,7 +50,7 @@ public class SyncopeServiceRegistry extends
AbstractServiceRegistry {
final Collection<ServiceRegistryListener>
serviceRegistryListeners) {
super(applicationContext, serviceRegistryListeners);
- this.restClient = restClient;
+ this.waRestClient = restClient;
this.registeredServiceMapper = registeredServiceMapper;
}
@@ -65,69 +66,83 @@ public class SyncopeServiceRegistry extends
AbstractServiceRegistry {
@Override
public Collection<RegisteredService> load() {
- if (WARestClient.isReady()) {
+ SyncopeClient syncopeClient = waRestClient.getSyncopeClient();
+ if (syncopeClient == null) {
+ LOG.debug("Syncope client is not yet ready to fetch application
definitions");
+ return List.of();
+ } else {
LOG.info("Loading application definitions");
- return
restClient.getSyncopeClient().getService(WAClientAppService.class).list().stream().
+ return
waRestClient.getSyncopeClient().getService(WAClientAppService.class).list().stream().
map(clientApp ->
registeredServiceMapper.toRegisteredService(clientApp)).
collect(Collectors.toList());
}
- LOG.debug("Syncope client is not yet ready to fetch application
definitions");
- return List.of();
}
@Override
public RegisteredService findServiceById(final long id) {
- if (WARestClient.isReady()) {
+ SyncopeClient syncopeClient = waRestClient.getSyncopeClient();
+ if (syncopeClient == null) {
+ LOG.debug("Syncope client is not yet ready to fetch application
definitions");
+ return null;
+ } else {
LOG.info("Searching for application definition by id {}", id);
- return
registeredServiceMapper.toRegisteredService(restClient.getSyncopeClient().
+ return
registeredServiceMapper.toRegisteredService(waRestClient.getSyncopeClient().
getService(WAClientAppService.class).read(id, null));
}
- LOG.debug("Syncope client is not yet ready to fetch application
definitions");
- return null;
}
@Override
@SuppressWarnings("unchecked")
public <T extends RegisteredService> T findServiceById(final long id,
final Class<T> clazz) {
- if (WARestClient.isReady()) {
+ SyncopeClient syncopeClient = waRestClient.getSyncopeClient();
+ if (syncopeClient == null) {
+ LOG.debug("Syncope client is not yet ready to fetch application
definitions");
+ return null;
+ } else {
LOG.info("Searching for application definition by id {} and type
{}", id, clazz);
if (clazz.isInstance(OidcRegisteredService.class)) {
- return (T)
registeredServiceMapper.toRegisteredService(restClient.getSyncopeClient().
+ return (T)
registeredServiceMapper.toRegisteredService(waRestClient.getSyncopeClient().
getService(WAClientAppService.class).read(id,
ClientAppType.OIDCRP));
} else if (clazz.isInstance(SamlRegisteredService.class)) {
- return (T)
registeredServiceMapper.toRegisteredService(restClient.getSyncopeClient().
+ return (T)
registeredServiceMapper.toRegisteredService(waRestClient.getSyncopeClient().
getService(WAClientAppService.class).read(id,
ClientAppType.SAML2SP));
+ } else {
+ return null;
}
}
- LOG.debug("Syncope client is not yet ready to fetch application
definitions");
- return null;
}
@Override
@SuppressWarnings("unchecked")
public <T extends RegisteredService> T findServiceByExactServiceName(final
String name, final Class<T> clazz) {
- if (WARestClient.isReady()) {
+ SyncopeClient syncopeClient = waRestClient.getSyncopeClient();
+ if (syncopeClient == null) {
+ LOG.debug("Syncope client is not yet ready to fetch application
definitions");
+ return null;
+ } else {
LOG.info("Searching for application definition by name {} and type
{}", name, clazz);
if (clazz.isInstance(OidcRegisteredService.class)) {
- return (T)
registeredServiceMapper.toRegisteredService(restClient.getSyncopeClient().
+ return (T)
registeredServiceMapper.toRegisteredService(waRestClient.getSyncopeClient().
getService(WAClientAppService.class).read(name,
ClientAppType.OIDCRP));
} else if (clazz.isInstance(SamlRegisteredService.class)) {
- return (T)
registeredServiceMapper.toRegisteredService(restClient.getSyncopeClient().
+ return (T)
registeredServiceMapper.toRegisteredService(waRestClient.getSyncopeClient().
getService(WAClientAppService.class).read(name,
ClientAppType.SAML2SP));
+ } else {
+ return null;
}
}
- LOG.debug("Syncope client is not yet ready to fetch application
definitions");
- return null;
}
@Override
public RegisteredService findServiceByExactServiceName(final String name) {
- if (WARestClient.isReady()) {
+ SyncopeClient syncopeClient = waRestClient.getSyncopeClient();
+ if (syncopeClient == null) {
+ LOG.debug("Syncope client is not yet ready to fetch application
definitions");
+ return null;
+ } else {
LOG.info("Searching for application definition by name {}", name);
- return
registeredServiceMapper.toRegisteredService(restClient.getSyncopeClient().
+ return
registeredServiceMapper.toRegisteredService(waRestClient.getSyncopeClient().
getService(WAClientAppService.class).read(name, null));
}
- LOG.debug("Syncope client is not yet ready to fetch application
definitions");
- return null;
}
}
diff --git
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/SyncopeWAAuditTrailManager.java
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/SyncopeWAAuditTrailManager.java
index 731eadd..1dd690f 100644
---
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/SyncopeWAAuditTrailManager.java
+++
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/SyncopeWAAuditTrailManager.java
@@ -16,11 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.syncope.wa.starter;
+import java.time.LocalDate;
+import java.util.Map;
+import java.util.Set;
import org.apereo.cas.audit.spi.AbstractAuditTrailManager;
-
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.StringUtils;
import org.apache.syncope.common.lib.log.AuditEntry;
@@ -32,48 +33,48 @@ import org.apereo.inspektr.audit.AuditActionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.time.LocalDate;
-import java.util.Map;
-import java.util.Set;
+import org.apache.syncope.client.lib.SyncopeClient;
public class SyncopeWAAuditTrailManager extends AbstractAuditTrailManager {
+
private static final Logger LOG =
LoggerFactory.getLogger(SyncopeWAAuditTrailManager.class);
+
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
- private final WARestClient restClient;
+ private final WARestClient waRestClient;
SyncopeWAAuditTrailManager(final WARestClient restClient) {
super(true);
- this.restClient = restClient;
+ this.waRestClient = restClient;
}
@Override
protected void saveAuditRecord(final AuditActionContext audit) {
- if (!WARestClient.isReady()) {
+ SyncopeClient syncopeClient = waRestClient.getSyncopeClient();
+ if (syncopeClient == null) {
LOG.debug("Syncope client is not yet ready to store audit record");
return;
}
LOG.info("Loading application definitions");
- LoggerService loggerService = restClient.getSyncopeClient().
- getService(LoggerService.class);
+ LoggerService loggerService =
syncopeClient.getService(LoggerService.class);
- try {
+ try {
String output =
OBJECT_MAPPER.writeValueAsString(Map.of("resource",
audit.getResourceOperatedUpon(),
- "clientIpAddress", audit.getClientIpAddress(),
- "serverIpAddress", audit.getServerIpAddress()));
+ "clientIpAddress", audit.getClientIpAddress(),
+ "serverIpAddress", audit.getServerIpAddress()));
AuditEntry auditEntry = new AuditEntry();
auditEntry.setWho(audit.getPrincipal());
auditEntry.setDate(audit.getWhenActionWasPerformed());
auditEntry.setOutput(output);
AuditElements.Result result =
StringUtils.containsIgnoreCase(audit.getActionPerformed(), "fail")
- ? AuditElements.Result.FAILURE
- : AuditElements.Result.SUCCESS;
+ ? AuditElements.Result.FAILURE
+ : AuditElements.Result.SUCCESS;
AuditLoggerName auditLogger = new
AuditLoggerName(AuditElements.EventCategoryType.WA,
- "LoggerLogic",
AuditElements.AUTHENTICATION_CATEGORY.toUpperCase(),
- audit.getActionPerformed(), result);
+ "LoggerLogic",
AuditElements.AUTHENTICATION_CATEGORY.toUpperCase(),
+ audit.getActionPerformed(), result);
auditEntry.setLogger(auditLogger);
loggerService.create(auditEntry);
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 6a615cc..62e2d7b 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
@@ -82,53 +82,42 @@ public class SyncopeWAConfiguration {
@Bean
public RegisteredServiceMapper registeredServiceMapper() {
Map<String, AuthMapper> authPolicyConfMappers = new HashMap<>();
- Map<String, AuthMapper> registeredServiceAuthenticationPolicyMappers =
new HashMap<>();
ctx.getBeansOfType(AuthMapper.class).forEach((name, bean) -> {
AuthMapFor authMapFor = ctx.findAnnotationOnBean(name,
AuthMapFor.class);
if (authMapFor != null) {
authPolicyConfMappers.put(authMapFor.authPolicyConfClass().getName(), bean);
- registeredServiceAuthenticationPolicyMappers.put(
-
authMapFor.registeredServiceAuthenticationPolicyClass().getName(), bean);
}
});
Map<String, AccessMapper> accessPolicyConfMappers = new HashMap<>();
- Map<String, AccessMapper> registeredServiceAccessStrategyMappers = new
HashMap<>();
ctx.getBeansOfType(AccessMapper.class).forEach((name, bean) -> {
AccessMapFor accessMapFor = ctx.findAnnotationOnBean(name,
AccessMapFor.class);
if (accessMapFor != null) {
accessPolicyConfMappers.put(accessMapFor.accessPolicyConfClass().getName(),
bean);
- registeredServiceAccessStrategyMappers.put(
-
accessMapFor.registeredServiceAccessStrategyClass().getName(), bean);
}
});
Map<String, AttrReleaseMapper> attrReleasePolicyConfMappers = new
HashMap<>();
- Map<String, AttrReleaseMapper>
registeredServiceAttributeReleasePolicyMappers = new HashMap<>();
ctx.getBeansOfType(AttrReleaseMapper.class).forEach((name, bean) -> {
AttrReleaseMapFor attrReleaseMapFor =
ctx.findAnnotationOnBean(name, AttrReleaseMapFor.class);
if (attrReleaseMapFor != null) {
attrReleasePolicyConfMappers.put(attrReleaseMapFor.attrReleasePolicyConfClass().getName(),
bean);
- registeredServiceAttributeReleasePolicyMappers.put(
-
attrReleaseMapFor.registeredServiceAttributeReleasePolicyClass().getName(),
bean);
}
});
Map<String, ClientAppMapper> clientAppTOMappers = new HashMap<>();
- Map<String, ClientAppMapper> registeredServiceMappers = new
HashMap<>();
ctx.getBeansOfType(ClientAppMapper.class).forEach((name, bean) -> {
ClientAppMapFor clientAppMapFor = ctx.findAnnotationOnBean(name,
ClientAppMapFor.class);
if (clientAppMapFor != null) {
clientAppTOMappers.put(clientAppMapFor.clientAppClass().getName(), bean);
-
registeredServiceMappers.put(clientAppMapFor.registeredServiceClass().getName(),
bean);
}
});
return new RegisteredServiceMapper(
- authPolicyConfMappers,
registeredServiceAuthenticationPolicyMappers,
- accessPolicyConfMappers,
registeredServiceAccessStrategyMappers,
- attrReleasePolicyConfMappers,
registeredServiceAttributeReleasePolicyMappers,
- clientAppTOMappers, registeredServiceMappers);
+ authPolicyConfMappers,
+ accessPolicyConfMappers,
+ attrReleasePolicyConfMappers,
+ clientAppTOMappers);
}
@Autowired
diff --git
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/AccessMapFor.java
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/AccessMapFor.java
index 72626b4..9ed2543 100644
---
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/AccessMapFor.java
+++
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/AccessMapFor.java
@@ -23,13 +23,10 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.apache.syncope.common.lib.policy.AccessPolicyConf;
-import org.apereo.cas.services.RegisteredServiceAccessStrategy;
@Target({ ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
public @interface AccessMapFor {
Class<? extends AccessPolicyConf> accessPolicyConfClass();
-
- Class<? extends RegisteredServiceAccessStrategy>
registeredServiceAccessStrategyClass();
}
diff --git
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/AccessMapper.java
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/AccessMapper.java
index 7ef07ff..d0eb5ab 100644
---
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/AccessMapper.java
+++
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/AccessMapper.java
@@ -24,6 +24,4 @@ import
org.apereo.cas.services.RegisteredServiceAccessStrategy;
public interface AccessMapper {
RegisteredServiceAccessStrategy build(AccessPolicyConf conf);
-
- AccessPolicyConf build(RegisteredServiceAccessStrategy strategy);
}
diff --git
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/AllowedAttrReleaseMapper.java
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/AllowedAttrReleaseMapper.java
index 9908f51..bcb44c8 100644
---
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/AllowedAttrReleaseMapper.java
+++
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/AllowedAttrReleaseMapper.java
@@ -25,9 +25,7 @@ import
org.apereo.cas.services.RegisteredServiceAttributeReleasePolicy;
import org.apereo.cas.services.ReturnAllowedAttributeReleasePolicy;
import org.springframework.stereotype.Component;
-@AttrReleaseMapFor(
- attrReleasePolicyConfClass = AllowedAttrReleasePolicyConf.class,
- registeredServiceAttributeReleasePolicyClass =
ReturnAllowedAttributeReleasePolicy.class)
+@AttrReleaseMapFor(attrReleasePolicyConfClass =
AllowedAttrReleasePolicyConf.class)
@Component
public class AllowedAttrReleaseMapper implements AttrReleaseMapper {
@@ -45,10 +43,4 @@ public class AllowedAttrReleaseMapper implements
AttrReleaseMapper {
return attributeReleasePolicy;
}
- @Override
- public AttrReleasePolicyConf build(final
RegisteredServiceAttributeReleasePolicy policy) {
- AllowedAttrReleasePolicyConf conf = new AllowedAttrReleasePolicyConf();
- conf.getAllowedAttrs().addAll(((ReturnAllowedAttributeReleasePolicy)
policy).getAllowedAttributes());
- return conf;
- }
}
diff --git
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/AttrReleaseMapFor.java
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/AttrReleaseMapFor.java
index 2060fea..f28390d 100644
---
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/AttrReleaseMapFor.java
+++
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/AttrReleaseMapFor.java
@@ -23,13 +23,10 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.apache.syncope.common.lib.policy.AttrReleasePolicyConf;
-import org.apereo.cas.services.RegisteredServiceAttributeReleasePolicy;
@Target({ ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
public @interface AttrReleaseMapFor {
Class<? extends AttrReleasePolicyConf> attrReleasePolicyConfClass();
-
- Class<? extends RegisteredServiceAttributeReleasePolicy>
registeredServiceAttributeReleasePolicyClass();
}
diff --git
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/AttrReleaseMapper.java
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/AttrReleaseMapper.java
index 50dd5bd..ba5e916 100644
---
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/AttrReleaseMapper.java
+++
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/AttrReleaseMapper.java
@@ -24,6 +24,4 @@ import
org.apereo.cas.services.RegisteredServiceAttributeReleasePolicy;
public interface AttrReleaseMapper {
RegisteredServiceAttributeReleasePolicy build(AttrReleasePolicyConf conf);
-
- AttrReleasePolicyConf build(RegisteredServiceAttributeReleasePolicy
policy);
}
diff --git
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/AuthMapFor.java
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/AuthMapFor.java
index 95c9baf..f5fb5e4 100644
---
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/AuthMapFor.java
+++
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/AuthMapFor.java
@@ -23,13 +23,10 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.apache.syncope.common.lib.policy.AuthPolicyConf;
-import org.apereo.cas.services.RegisteredServiceAuthenticationPolicy;
@Target({ ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
public @interface AuthMapFor {
Class<? extends AuthPolicyConf> authPolicyConfClass();
-
- Class<? extends RegisteredServiceAuthenticationPolicy>
registeredServiceAuthenticationPolicyClass();
}
diff --git
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/AuthMapper.java
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/AuthMapper.java
index dacb020..c021b66 100644
---
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/AuthMapper.java
+++
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/AuthMapper.java
@@ -24,6 +24,4 @@ import
org.apereo.cas.services.RegisteredServiceAuthenticationPolicy;
public interface AuthMapper {
RegisteredServiceAuthenticationPolicy build(AuthPolicyConf conf);
-
- AuthPolicyConf build(RegisteredServiceAuthenticationPolicy policy);
}
diff --git
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/ClientAppMapFor.java
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/ClientAppMapFor.java
index f4526ad..0d61c29 100644
---
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/ClientAppMapFor.java
+++
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/ClientAppMapFor.java
@@ -23,13 +23,10 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.apache.syncope.common.lib.to.client.ClientAppTO;
-import org.apereo.cas.services.RegisteredService;
@Target({ ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
public @interface ClientAppMapFor {
Class<? extends ClientAppTO> clientAppClass();
-
- Class<? extends RegisteredService> registeredServiceClass();
}
diff --git
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/ClientAppMapper.java
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/ClientAppMapper.java
index 4041eff..b783136 100644
---
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/ClientAppMapper.java
+++
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/ClientAppMapper.java
@@ -31,6 +31,4 @@ public interface ClientAppMapper {
RegisteredServiceAuthenticationPolicy authPolicy,
RegisteredServiceAccessStrategy accessStrategy,
RegisteredServiceAttributeReleasePolicy attributeReleasePolicy);
-
- ClientAppTO buid(RegisteredService service);
}
diff --git
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/DefaultAccessMapper.java
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/DefaultAccessMapper.java
index 9c44199..323b3b1 100644
---
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/DefaultAccessMapper.java
+++
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/DefaultAccessMapper.java
@@ -24,9 +24,7 @@ import
org.apereo.cas.services.DefaultRegisteredServiceAccessStrategy;
import org.apereo.cas.services.RegisteredServiceAccessStrategy;
import org.springframework.stereotype.Component;
-@AccessMapFor(
- accessPolicyConfClass = DefaultAccessPolicyConf.class,
- registeredServiceAccessStrategyClass =
DefaultRegisteredServiceAccessStrategy.class)
+@AccessMapFor(accessPolicyConfClass = DefaultAccessPolicyConf.class)
@Component
public class DefaultAccessMapper implements AccessMapper {
@@ -38,12 +36,4 @@ public class DefaultAccessMapper implements AccessMapper {
return accessStrategy;
}
- @Override
- public AccessPolicyConf build(final RegisteredServiceAccessStrategy
strategy) {
- DefaultAccessPolicyConf conf = new DefaultAccessPolicyConf();
- conf.setEnabled(((DefaultRegisteredServiceAccessStrategy)
strategy).isEnabled());
- conf.setSsoEnabled(((DefaultRegisteredServiceAccessStrategy)
strategy).isSsoEnabled());
-
conf.getRequiredAttrs().putAll(((DefaultRegisteredServiceAccessStrategy)
strategy).getRejectedAttributes());
- return conf;
- }
}
diff --git
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/DefaultAuthMapper.java
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/DefaultAuthMapper.java
index 95c2f7e..10945e7 100644
---
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/DefaultAuthMapper.java
+++
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/DefaultAuthMapper.java
@@ -18,6 +18,7 @@
*/
package org.apache.syncope.wa.starter.mapping;
+import java.util.HashSet;
import org.apache.syncope.common.lib.policy.AuthPolicyConf;
import org.apache.syncope.common.lib.policy.DefaultAuthPolicyConf;
import org.apache.syncope.common.lib.policy.DefaultAuthPolicyCriteriaConf;
@@ -26,9 +27,7 @@ import
org.apereo.cas.services.DefaultRegisteredServiceAuthenticationPolicy;
import org.apereo.cas.services.RegisteredServiceAuthenticationPolicy;
import org.springframework.stereotype.Component;
-@AuthMapFor(
- authPolicyConfClass = DefaultAuthPolicyConf.class,
- registeredServiceAuthenticationPolicyClass =
DefaultRegisteredServiceAuthenticationPolicy.class)
+@AuthMapFor(authPolicyConfClass = DefaultAuthPolicyConf.class)
@Component
public class DefaultAuthMapper implements AuthMapper {
@@ -39,15 +38,12 @@ public class DefaultAuthMapper implements AuthMapper {
new
AnyAuthenticationHandlerRegisteredServiceAuthenticationPolicyCriteria();
criteria.setTryAll(((DefaultAuthPolicyCriteriaConf)
conf.getCriteria()).isAll());
authPolicy.setCriteria(criteria);
+
+ if (conf instanceof DefaultAuthPolicyConf && !((DefaultAuthPolicyConf)
conf).getAuthModules().isEmpty()) {
+ authPolicy.setRequiredAuthenticationHandlers(
+ new HashSet<>(((DefaultAuthPolicyConf)
conf).getAuthModules()));
+ }
return authPolicy;
}
- @Override
- public AuthPolicyConf build(final RegisteredServiceAuthenticationPolicy
policy) {
- DefaultAuthPolicyConf conf = new DefaultAuthPolicyConf();
- DefaultAuthPolicyCriteriaConf criteria = new
DefaultAuthPolicyCriteriaConf();
- criteria.setAll(((DefaultAuthPolicyCriteriaConf)
policy.getCriteria()).isAll());
- conf.setCriteria(criteria);
- return conf;
- }
}
diff --git
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/OIDCRPTOMapper.java
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/OIDCRPTOMapper.java
index 850e9d7..a14923e 100644
---
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/OIDCRPTOMapper.java
+++
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/OIDCRPTOMapper.java
@@ -18,11 +18,9 @@
*/
package org.apache.syncope.wa.starter.mapping;
-import java.util.Arrays;
import java.util.HashSet;
import org.apache.syncope.common.lib.to.client.ClientAppTO;
import org.apache.syncope.common.lib.to.client.OIDCRPTO;
-import org.apache.syncope.common.lib.types.OIDCSubjectType;
import org.apereo.cas.services.OidcRegisteredService;
import org.apereo.cas.services.RegisteredService;
import org.apereo.cas.services.RegisteredServiceAccessStrategy;
@@ -30,7 +28,7 @@ import
org.apereo.cas.services.RegisteredServiceAttributeReleasePolicy;
import org.apereo.cas.services.RegisteredServiceAuthenticationPolicy;
import org.springframework.stereotype.Component;
-@ClientAppMapFor(clientAppClass = OIDCRPTO.class, registeredServiceClass =
OidcRegisteredService.class)
+@ClientAppMapFor(clientAppClass = OIDCRPTO.class)
@Component
public class OIDCRPTOMapper implements ClientAppMapper {
@@ -47,6 +45,7 @@ public class OIDCRPTOMapper implements ClientAppMapper {
String redirectURIs = String.join("|", rp.getRedirectUris());
service.setServiceId(redirectURIs);
+ service.setId(rp.getClientAppId());
service.setName(rp.getName());
service.setDescription(rp.getDescription());
service.setAccessStrategy(accessStrategy);
@@ -65,22 +64,4 @@ public class OIDCRPTOMapper implements ClientAppMapper {
return service;
}
- public ClientAppTO buid(final RegisteredService service) {
- OidcRegisteredService oidc = OidcRegisteredService.class.cast(service);
-
- OIDCRPTO oidcrpto = new OIDCRPTO();
-
-
oidcrpto.getRedirectUris().addAll(Arrays.asList(oidc.getServiceId().split("|")));
- oidcrpto.setName(oidc.getName());
- oidcrpto.setDescription(oidc.getDescription());
- oidcrpto.setClientId(oidc.getClientId());
- oidcrpto.setClientSecret(oidc.getClientSecret());
- oidcrpto.setSignIdToken(oidc.isSignIdToken());
- oidcrpto.setJwks(oidc.getJwks());
-
oidcrpto.setSubjectType(OIDCSubjectType.valueOf(oidc.getSubjectType()));
-
oidcrpto.getSupportedGrantTypes().addAll(oidc.getSupportedGrantTypes());
-
oidcrpto.getSupportedResponseTypes().addAll(oidc.getSupportedResponseTypes());
-
- return oidcrpto;
- }
}
diff --git
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/RegisteredServiceMapper.java
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/RegisteredServiceMapper.java
index 8b6bc65..3a31009 100644
---
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/RegisteredServiceMapper.java
+++
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/RegisteredServiceMapper.java
@@ -21,49 +21,33 @@ package org.apache.syncope.wa.starter.mapping;
import java.util.Map;
import java.util.Optional;
import org.apache.syncope.common.lib.wa.WAClientApp;
+import org.apereo.cas.services.DenyAllAttributeReleasePolicy;
import org.apereo.cas.services.RegisteredService;
import org.apereo.cas.services.RegisteredServiceAccessStrategy;
import org.apereo.cas.services.RegisteredServiceAttributeReleasePolicy;
import org.apereo.cas.services.RegisteredServiceAuthenticationPolicy;
-import org.springframework.stereotype.Component;
+import org.apereo.cas.services.ReturnMappedAttributeReleasePolicy;
-@Component
public class RegisteredServiceMapper {
protected final Map<String, AuthMapper> authPolicyConfMappers;
- protected final Map<String, AuthMapper>
registeredServiceAuthenticationPolicyMappers;
-
protected final Map<String, AccessMapper> accessPolicyConfMappers;
- protected final Map<String, AccessMapper>
registeredServiceAccessStrategyMappers;
-
protected final Map<String, AttrReleaseMapper>
attrReleasePolicyConfMappers;
- protected final Map<String, AttrReleaseMapper>
registeredServiceAttributeReleasePolicyMappers;
-
protected final Map<String, ClientAppMapper> clientAppTOMappers;
- protected final Map<String, ClientAppMapper> registeredServiceMappers;
-
public RegisteredServiceMapper(
final Map<String, AuthMapper> authPolicyConfMappers,
- final Map<String, AuthMapper>
registeredServiceAuthenticationPolicyMappers,
final Map<String, AccessMapper> accessPolicyConfMappers,
- final Map<String, AccessMapper>
registeredServiceAccessStrategyMappers,
final Map<String, AttrReleaseMapper> attrReleasePolicyConfMappers,
- final Map<String, AttrReleaseMapper>
registeredServiceAttributeReleasePolicyMappers,
- final Map<String, ClientAppMapper> clientAppTOMappers,
- final Map<String, ClientAppMapper> registeredServiceMappers) {
+ final Map<String, ClientAppMapper> clientAppTOMappers) {
this.authPolicyConfMappers = authPolicyConfMappers;
- this.registeredServiceAuthenticationPolicyMappers =
registeredServiceAuthenticationPolicyMappers;
this.accessPolicyConfMappers = accessPolicyConfMappers;
- this.registeredServiceAccessStrategyMappers =
registeredServiceAccessStrategyMappers;
this.attrReleasePolicyConfMappers = attrReleasePolicyConfMappers;
- this.registeredServiceAttributeReleasePolicyMappers =
registeredServiceAttributeReleasePolicyMappers;
this.clientAppTOMappers = clientAppTOMappers;
- this.registeredServiceMappers = registeredServiceMappers;
}
public RegisteredService toRegisteredService(final WAClientApp clientApp) {
@@ -84,11 +68,15 @@ public class RegisteredServiceMapper {
}
RegisteredServiceAttributeReleasePolicy attributeReleasePolicy = null;
- if (clientApp.getAttrReleasePolicyConf() != null) {
+ if (!clientApp.getReleaseAttrs().isEmpty()) {
+ attributeReleasePolicy = new
ReturnMappedAttributeReleasePolicy(clientApp.getReleaseAttrs());
+ } else if (clientApp.getAttrReleasePolicyConf() != null) {
AttrReleaseMapper attrReleasePolicyConfMapper =
attrReleasePolicyConfMappers.get(clientApp.getAttrReleasePolicyConf().getClass().getName());
attributeReleasePolicy =
Optional.ofNullable(attrReleasePolicyConfMapper).
map(mapper ->
mapper.build(clientApp.getAttrReleasePolicyConf())).orElse(null);
+ } else {
+ attributeReleasePolicy = new DenyAllAttributeReleasePolicy();
}
ClientAppMapper clientAppMapper =
clientAppTOMappers.get(clientApp.getClientAppTO().getClass().getName());
@@ -97,35 +85,4 @@ public class RegisteredServiceMapper {
}
return clientAppMapper.build(clientApp.getClientAppTO(), authPolicy,
accessStrategy, attributeReleasePolicy);
}
-
- public WAClientApp fromRegisteredService(final RegisteredService service) {
- WAClientApp clientApp = new WAClientApp();
-
- if (service.getAuthenticationPolicy() != null) {
- AuthMapper authMapper =
registeredServiceAuthenticationPolicyMappers.get(
- service.getAuthenticationPolicy().getClass().getName());
- clientApp.setAuthPolicyConf(Optional.ofNullable(authMapper).
- map(mapper ->
mapper.build(service.getAuthenticationPolicy())).orElse(null));
- }
-
- if (service.getAccessStrategy() != null) {
- AccessMapper accessPolicyConfMapper =
registeredServiceAccessStrategyMappers.get(
- service.getAccessStrategy().getClass().getName());
-
clientApp.setAccessPolicyConf(Optional.ofNullable(accessPolicyConfMapper).
- map(mapper ->
mapper.build(service.getAccessStrategy())).orElse(null));
- }
-
- if (service.getAttributeReleasePolicy() != null) {
- AttrReleaseMapper attrReleasePolicyConfMapper =
registeredServiceAttributeReleasePolicyMappers.get(
- service.getAttributeReleasePolicy().getClass().getName());
-
clientApp.setAttrReleasePolicyConf(Optional.ofNullable(attrReleasePolicyConfMapper).
- map(mapper ->
mapper.build(service.getAttributeReleasePolicy())).orElse(null));
- }
-
- ClientAppMapper clientAppMapper =
registeredServiceMappers.get(service.getClass().getName());
- clientApp.setClientAppTO(Optional.ofNullable(clientAppMapper).
- map(mapper -> mapper.buid(service)).orElse(null));
-
- return clientApp;
- }
}
diff --git
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/SAML2SPTOMapper.java
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/SAML2SPTOMapper.java
index 96df87d..170bb28 100644
---
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/SAML2SPTOMapper.java
+++
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/SAML2SPTOMapper.java
@@ -20,7 +20,6 @@ package org.apache.syncope.wa.starter.mapping;
import org.apache.syncope.common.lib.to.client.ClientAppTO;
import org.apache.syncope.common.lib.to.client.SAML2SPTO;
-import org.apache.syncope.common.lib.types.SAML2SPNameId;
import org.apereo.cas.services.RegisteredService;
import org.apereo.cas.services.RegisteredServiceAccessStrategy;
import org.apereo.cas.services.RegisteredServiceAttributeReleasePolicy;
@@ -28,7 +27,7 @@ import
org.apereo.cas.services.RegisteredServiceAuthenticationPolicy;
import org.apereo.cas.support.saml.services.SamlRegisteredService;
import org.springframework.stereotype.Component;
-@ClientAppMapFor(clientAppClass = SAML2SPTO.class, registeredServiceClass =
SamlRegisteredService.class)
+@ClientAppMapFor(clientAppClass = SAML2SPTO.class)
@Component
public class SAML2SPTOMapper implements ClientAppMapper {
@@ -44,6 +43,7 @@ public class SAML2SPTOMapper implements ClientAppMapper {
SamlRegisteredService service = new SamlRegisteredService();
service.setServiceId(sp.getEntityId());
+ service.setId(sp.getClientAppId());
service.setName(sp.getName());
service.setDescription(sp.getDescription());
service.setAccessStrategy(accessStrategy);
@@ -58,37 +58,11 @@ public class SAML2SPTOMapper implements ClientAppMapper {
service.setEncryptAssertions(sp.isEncryptAssertions());
service.setRequiredAuthenticationContextClass(sp.getRequiredAuthenticationContextClass());
service.setRequiredNameIdFormat(sp.getRequiredNameIdFormat().getNameId());
- service.setSkewAllowance(sp.getSkewAllowance());
+ service.setSkewAllowance(sp.getSkewAllowance() == null ? 0 :
sp.getSkewAllowance());
service.setNameIdQualifier(sp.getNameIdQualifier());
service.setAssertionAudiences(sp.getAssertionAudiences());
service.setServiceProviderNameIdQualifier(sp.getServiceProviderNameIdQualifier());
return service;
}
-
- @Override
- public ClientAppTO buid(final RegisteredService service) {
- SamlRegisteredService saml = SamlRegisteredService.class.cast(service);
-
- SAML2SPTO saml2spto = new SAML2SPTO();
-
- saml2spto.setEntityId(saml.getServiceId());
- saml2spto.setName(saml.getName());
- saml2spto.setDescription(saml.getDescription());
-
- saml2spto.setMetadataLocation(saml.getMetadataLocation());
-
saml2spto.setMetadataSignatureLocation(saml.getMetadataSignatureLocation());
- saml2spto.setSignAssertions(saml.isSignAssertions());
- saml2spto.setSignResponses(saml.isSignResponses());
- saml2spto.setEncryptionOptional(saml.isEncryptionOptional());
- saml2spto.setEncryptAssertions(saml.isEncryptAssertions());
-
saml2spto.setRequiredAuthenticationContextClass(saml.getRequiredAuthenticationContextClass());
-
saml2spto.setRequiredNameIdFormat(SAML2SPNameId.valueOf(saml.getRequiredNameIdFormat()));
- saml2spto.setSkewAllowance(saml.getSkewAllowance());
- saml2spto.setNameIdQualifier(saml.getNameIdQualifier());
- saml2spto.setAssertionAudiences(saml.getAssertionAudiences());
-
saml2spto.setServiceProviderNameIdQualifier(saml.getServiceProviderNameIdQualifier());
-
- return saml2spto;
- }
}
diff --git a/wa/starter/src/main/resources/application.properties
b/wa/starter/src/main/resources/application.properties
index 1104f29..a3fee6b 100644
--- a/wa/starter/src/main/resources/application.properties
+++ b/wa/starter/src/main/resources/application.properties
@@ -28,12 +28,15 @@ server.servlet.contextPath=/syncope-wa
spring.resources.static-locations=classpath:/thymeleaf/static,classpath:/static
-management.endpoints.web.exposure.include=health,loggers,refresh
+management.endpoints.web.exposure.include=health,loggers,refresh,registeredServices
management.endpoint.health.show-details=always
management.endpoint.health.enabled=true
management.endpoint.loggers.enabled=true
management.endpoint.refresh.enabled=true
+management.endpoint.registeredServices.enabled=true
+
+cas.serviceRegistry.schedule.enabled=false
##
# Allow configuration classes to override bean definitions from Spring Boot
diff --git
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/AttrReleaseMapper.java
b/wa/starter/src/test/java/org/apache/syncope/wa/starter/AbstractTest.java
similarity index 53%
copy from
wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/AttrReleaseMapper.java
copy to wa/starter/src/test/java/org/apache/syncope/wa/starter/AbstractTest.java
index 50dd5bd..990c7fd 100644
---
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/AttrReleaseMapper.java
+++ b/wa/starter/src/test/java/org/apache/syncope/wa/starter/AbstractTest.java
@@ -16,14 +16,24 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.syncope.wa.starter.mapping;
+package org.apache.syncope.wa.starter;
-import org.apache.syncope.common.lib.policy.AttrReleasePolicyConf;
-import org.apereo.cas.services.RegisteredServiceAttributeReleasePolicy;
+import java.util.UUID;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.web.server.LocalServerPort;
+import org.springframework.test.context.ContextConfiguration;
-public interface AttrReleaseMapper {
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = {
+ "cas.authn.accept.users=mrossi::password",
+ "cas.sso.allow-missing-service-parameter=true"
+})
+@ContextConfiguration(initializers = ZookeeperTestingServer.class)
+public abstract class AbstractTest {
- RegisteredServiceAttributeReleasePolicy build(AttrReleasePolicyConf conf);
+ @LocalServerPort
+ protected int port;
- AttrReleasePolicyConf build(RegisteredServiceAttributeReleasePolicy
policy);
+ protected static String getUUIDString() {
+ return UUID.randomUUID().toString().substring(0, 8);
+ }
}
diff --git
a/wa/starter/src/test/java/org/apache/syncope/wa/starter/SyncopeWATest.java
b/wa/starter/src/test/java/org/apache/syncope/wa/starter/BasicTest.java
similarity index 92%
rename from
wa/starter/src/test/java/org/apache/syncope/wa/starter/SyncopeWATest.java
rename to wa/starter/src/test/java/org/apache/syncope/wa/starter/BasicTest.java
index 93799d4..938f850 100644
--- a/wa/starter/src/test/java/org/apache/syncope/wa/starter/SyncopeWATest.java
+++ b/wa/starter/src/test/java/org/apache/syncope/wa/starter/BasicTest.java
@@ -44,19 +44,8 @@ import org.apache.http.message.BasicHeader;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.junit.jupiter.api.Test;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.boot.web.server.LocalServerPort;
-import org.springframework.test.context.ContextConfiguration;
-
-@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = {
- "cas.authn.accept.users=mrossi::password",
- "cas.sso.allow-missing-service-parameter=true"
-})
-@ContextConfiguration(initializers = ZookeeperTestingServer.class)
-public class SyncopeWATest {
-
- @LocalServerPort
- private int port;
+
+public class BasicTest extends AbstractTest {
private String getLoginURL() {
return "http://localhost:" + port + "/syncope-wa/login";
diff --git
a/wa/starter/src/test/java/org/apache/syncope/wa/starter/SyncopeCoreTestingServer.java
b/wa/starter/src/test/java/org/apache/syncope/wa/starter/SyncopeCoreTestingServer.java
new file mode 100644
index 0000000..16d4cab
--- /dev/null
+++
b/wa/starter/src/test/java/org/apache/syncope/wa/starter/SyncopeCoreTestingServer.java
@@ -0,0 +1,90 @@
+/*
+ * 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.starter;
+
+import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import javax.ws.rs.NotFoundException;
+import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
+import org.apache.syncope.common.keymaster.client.api.ServiceOps;
+import org.apache.syncope.common.keymaster.client.api.model.NetworkService;
+import org.apache.syncope.common.lib.types.ClientAppType;
+import org.apache.syncope.common.lib.wa.WAClientApp;
+import org.apache.syncope.common.rest.api.service.wa.WAClientAppService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.event.ContextRefreshedEvent;
+import org.springframework.stereotype.Component;
+
+@Component
+public class SyncopeCoreTestingServer implements
ApplicationListener<ContextRefreshedEvent> {
+
+ public static final String ADDRESS = "http://localhost:9080/syncope/rest";
+
+ public static final List<WAClientApp> APPS = new ArrayList<>();
+
+ @Autowired
+ private ServiceOps serviceOps;
+
+ @Override
+ public void onApplicationEvent(final ContextRefreshedEvent event) {
+ synchronized (serviceOps) {
+ if (serviceOps.list(NetworkService.Type.CORE).isEmpty()) {
+ // 1. start (mocked) Core as embedded CXF
+ JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
+ sf.setAddress(ADDRESS);
+ sf.setResourceClasses(WAClientAppService.class);
+ sf.setResourceProvider(
+ WAClientAppService.class,
+ new SingletonResourceProvider(new
StubWAClientAppService(), true));
+ sf.setProviders(List.of(new JacksonJsonProvider()));
+ sf.create();
+
+ // 2. register Core in Keymaster
+ NetworkService core = new NetworkService();
+ core.setType(NetworkService.Type.CORE);
+ core.setAddress(ADDRESS);
+ serviceOps.register(core);
+ }
+ }
+ }
+
+ public class StubWAClientAppService implements WAClientAppService {
+
+ @Override
+ public List<WAClientApp> list() {
+ return APPS;
+ }
+
+ @Override
+ public WAClientApp read(final Long clientAppId, final ClientAppType
type) {
+ return APPS.stream().filter(app -> Objects.equals(clientAppId,
app.getClientAppTO().getClientAppId())).
+ findFirst().orElseThrow(() -> new
NotFoundException("ClientApp with clientId " + clientAppId));
+ }
+
+ @Override
+ public WAClientApp read(final String name, final ClientAppType type) {
+ return APPS.stream().filter(app -> Objects.equals(name,
app.getClientAppTO().getName())).
+ findFirst().orElseThrow(() -> new
NotFoundException("ClientApp with name " + name));
+ }
+ }
+}
diff --git
a/wa/starter/src/test/java/org/apache/syncope/wa/starter/SyncopeServiceRegistryTest.java
b/wa/starter/src/test/java/org/apache/syncope/wa/starter/SyncopeServiceRegistryTest.java
new file mode 100644
index 0000000..0d0e372
--- /dev/null
+++
b/wa/starter/src/test/java/org/apache/syncope/wa/starter/SyncopeServiceRegistryTest.java
@@ -0,0 +1,212 @@
+/*
+ * 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.starter;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.syncope.client.lib.SyncopeClient;
+import org.apache.syncope.common.lib.policy.AllowedAttrReleasePolicyConf;
+import org.apache.syncope.common.lib.policy.DefaultAccessPolicyConf;
+import org.apache.syncope.common.lib.policy.DefaultAuthPolicyConf;
+import org.apache.syncope.common.lib.policy.DefaultAuthPolicyCriteriaConf;
+import org.apache.syncope.common.lib.to.client.OIDCRPTO;
+import org.apache.syncope.common.lib.to.client.SAML2SPTO;
+import org.apache.syncope.common.lib.types.OIDCSubjectType;
+import org.apache.syncope.common.lib.types.SAML2SPNameId;
+import org.apache.syncope.common.lib.wa.WAClientApp;
+import org.apache.syncope.common.rest.api.service.wa.WAClientAppService;
+import org.apache.syncope.wa.bootstrap.WARestClient;
+import
org.apereo.cas.services.AnyAuthenticationHandlerRegisteredServiceAuthenticationPolicyCriteria;
+import org.apereo.cas.services.DenyAllAttributeReleasePolicy;
+import org.apereo.cas.services.OidcRegisteredService;
+import org.apereo.cas.services.RegisteredService;
+import org.apereo.cas.services.ReturnAllowedAttributeReleasePolicy;
+import org.apereo.cas.services.ReturnMappedAttributeReleasePolicy;
+import org.apereo.cas.services.ServicesManager;
+import org.apereo.cas.support.saml.services.SamlRegisteredService;
+import org.apereo.cas.util.RandomUtils;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+public class SyncopeServiceRegistryTest extends AbstractTest {
+
+ @Autowired
+ private WARestClient wARestClient;
+
+ @Autowired
+ private ServicesManager servicesManager;
+
+ private static OIDCRPTO buildOIDCRP() {
+ OIDCRPTO oidcrpTO = new OIDCRPTO();
+ oidcrpTO.setName("ExampleRP_" + getUUIDString());
+ oidcrpTO.setClientAppId(RandomUtils.nextLong());
+ oidcrpTO.setDescription("Example OIDC RP application");
+ oidcrpTO.setClientId("clientId_" + getUUIDString());
+ oidcrpTO.setClientSecret("secret");
+ oidcrpTO.getRedirectUris().addAll(List.of("uri1", "uri2"));
+ oidcrpTO.setSubjectType(OIDCSubjectType.PUBLIC);
+ oidcrpTO.getSupportedGrantTypes().add("something");
+ oidcrpTO.getSupportedResponseTypes().add("something");
+
+ return oidcrpTO;
+ }
+
+ protected SAML2SPTO buildSAML2SP() {
+ SAML2SPTO saml2spto = new SAML2SPTO();
+ saml2spto.setName("ExampleSAML2SP_" + getUUIDString());
+ saml2spto.setClientAppId(RandomUtils.nextLong());
+ saml2spto.setDescription("Example SAML 2.0 service provider");
+ saml2spto.setEntityId("SAML2SPEntityId_" + getUUIDString());
+ saml2spto.setMetadataLocation("file:./test.xml");
+ saml2spto.setRequiredNameIdFormat(SAML2SPNameId.EMAIL_ADDRESS);
+ saml2spto.setEncryptionOptional(true);
+ saml2spto.setEncryptAssertions(true);
+
+ return saml2spto;
+ }
+
+ private void addAttributes(final boolean withReleaseAttributes,
+ final boolean withAttrReleasePolicy,
+ final WAClientApp waClientApp) {
+ DefaultAuthPolicyConf authPolicyConf = new DefaultAuthPolicyConf();
+ DefaultAuthPolicyCriteriaConf criteria = new
DefaultAuthPolicyCriteriaConf();
+ criteria.setAll(true);
+ authPolicyConf.setCriteria(criteria);
+ authPolicyConf.getAuthModules().add("TestAuthModule");
+
+ waClientApp.setAuthPolicyConf(authPolicyConf);
+
+ if (withReleaseAttributes) {
+ Map<String, Object> releaseAttrs;
+ releaseAttrs = new HashMap<>();
+ releaseAttrs.put("uid", "username");
+ releaseAttrs.put("cn", "fullname");
+ waClientApp.getReleaseAttrs().putAll(releaseAttrs);
+ }
+
+ DefaultAccessPolicyConf accessPolicyConf = new
DefaultAccessPolicyConf();
+ accessPolicyConf.setEnabled(true);
+ accessPolicyConf.getRequiredAttrs().put("cn", Set.of("admin", "Admin",
"TheAdmin"));
+ waClientApp.setAccessPolicyConf(accessPolicyConf);
+
+ if (withAttrReleasePolicy) {
+ AllowedAttrReleasePolicyConf attrReleasePolicyConf = new
AllowedAttrReleasePolicyConf();
+ attrReleasePolicyConf.getAllowedAttrs().add("cn");
+ waClientApp.setAttrReleasePolicyConf(attrReleasePolicyConf);
+ }
+ }
+
+ @Test
+ public void addClientApp() {
+ // 1. start with no client apps defined on mocked Core
+ SyncopeClient syncopeClient = wARestClient.getSyncopeClient();
+ assertNotNull(syncopeClient);
+
+ SyncopeCoreTestingServer.APPS.clear();
+
+ WAClientAppService service =
syncopeClient.getService(WAClientAppService.class);
+ assertTrue(service.list().isEmpty());
+
+ // 2. add one client app on mocked Core, nothing on WA yet
+ WAClientApp waClientApp = new WAClientApp();
+ waClientApp.setClientAppTO(buildOIDCRP());
+ Long clientAppId = waClientApp.getClientAppTO().getClientAppId();
+ addAttributes(true, true, waClientApp);
+
+ SyncopeCoreTestingServer.APPS.add(waClientApp);
+ List<WAClientApp> apps = service.list();
+ assertEquals(1, apps.size());
+
+ assertNull(servicesManager.findServiceBy(clientAppId));
+
+ // 3. trigger client app refresh
+ Collection<RegisteredService> load = servicesManager.load();
+ assertEquals(3, load.size());
+
+ // 4. look for the service created above
+ RegisteredService found = servicesManager.findServiceBy(clientAppId);
+ assertNotNull(found);
+ assertTrue(found instanceof OidcRegisteredService);
+ OidcRegisteredService oidcRegisteredService =
OidcRegisteredService.class.cast(found);
+ OIDCRPTO oidcrpto = OIDCRPTO.class.cast(waClientApp.getClientAppTO());
+ assertEquals("uri1|uri2", oidcRegisteredService.getServiceId());
+ assertEquals(oidcrpto.getClientId(),
oidcRegisteredService.getClientId());
+ assertEquals(oidcrpto.getClientSecret(),
oidcRegisteredService.getClientSecret());
+
assertTrue(oidcRegisteredService.getAuthenticationPolicy().getRequiredAuthenticationHandlers().
+ contains("TestAuthModule"));
+
assertTrue(((AnyAuthenticationHandlerRegisteredServiceAuthenticationPolicyCriteria)
oidcRegisteredService.
+ getAuthenticationPolicy().getCriteria()).isTryAll());
+ assertTrue(oidcRegisteredService.getAttributeReleasePolicy()
instanceof ReturnMappedAttributeReleasePolicy);
+ assertFalse(oidcRegisteredService.getAttributeReleasePolicy()
instanceof ReturnAllowedAttributeReleasePolicy);
+ assertFalse(oidcRegisteredService.getAttributeReleasePolicy()
instanceof DenyAllAttributeReleasePolicy);
+
+ // 5. more client with different attributes
+ waClientApp = new WAClientApp();
+ waClientApp.setClientAppTO(buildSAML2SP());
+ clientAppId = waClientApp.getClientAppTO().getClientAppId();
+ addAttributes(false, true, waClientApp);
+
+ SyncopeCoreTestingServer.APPS.add(waClientApp);
+ apps = service.list();
+ assertEquals(2, apps.size());
+
+ load = servicesManager.load();
+ assertEquals(4, load.size());
+
+ found = servicesManager.findServiceBy(clientAppId);
+ assertTrue(found instanceof SamlRegisteredService);
+ SamlRegisteredService samlRegisteredService =
SamlRegisteredService.class.cast(found);
+ SAML2SPTO samlspto =
SAML2SPTO.class.cast(waClientApp.getClientAppTO());
+ assertEquals(samlspto.getMetadataLocation(),
samlRegisteredService.getMetadataLocation());
+ assertEquals(samlspto.getEntityId(),
samlRegisteredService.getServiceId());
+
assertTrue(samlRegisteredService.getAuthenticationPolicy().getRequiredAuthenticationHandlers().
+ contains("TestAuthModule"));
+ assertNotNull(found.getAccessStrategy());
+ assertFalse(samlRegisteredService.getAttributeReleasePolicy()
instanceof ReturnMappedAttributeReleasePolicy);
+ assertTrue(samlRegisteredService.getAttributeReleasePolicy()
instanceof ReturnAllowedAttributeReleasePolicy);
+ assertFalse(samlRegisteredService.getAttributeReleasePolicy()
instanceof DenyAllAttributeReleasePolicy);
+
+ waClientApp = new WAClientApp();
+ waClientApp.setClientAppTO(buildSAML2SP());
+ clientAppId = waClientApp.getClientAppTO().getClientAppId();
+ addAttributes(false, false, waClientApp);
+
+ SyncopeCoreTestingServer.APPS.add(waClientApp);
+ apps = service.list();
+ assertEquals(3, apps.size());
+
+ load = servicesManager.load();
+ assertEquals(5, load.size());
+
+ found = servicesManager.findServiceBy(clientAppId);
+ assertFalse(found.getAttributeReleasePolicy() instanceof
ReturnMappedAttributeReleasePolicy);
+ assertFalse(found.getAttributeReleasePolicy() instanceof
ReturnAllowedAttributeReleasePolicy);
+ assertTrue(found.getAttributeReleasePolicy() instanceof
DenyAllAttributeReleasePolicy);
+
+ }
+}