You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@syncope.apache.org by GitBox <gi...@apache.org> on 2020/05/06 10:27:20 UTC

[GitHub] [syncope] mmoayyed commented on a change in pull request #184: [SYNCOPE-1557] Allowing for flexing Auth, Access, AttrRelease and ClientApp translation

mmoayyed commented on a change in pull request #184:
URL: https://github.com/apache/syncope/pull/184#discussion_r420685720



##########
File path: wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/AllowedAttrReleaseMapper.java
##########
@@ -0,0 +1,55 @@
+/*
+ * 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.mapping;
+
+import org.apache.syncope.common.lib.policy.AllowedAttrReleasePolicyConf;
+import org.apache.syncope.common.lib.policy.AttrReleasePolicyConf;
+import org.apereo.cas.services.DenyAllAttributeReleasePolicy;
+import org.apereo.cas.services.RegisteredServiceAttributeReleasePolicy;
+import org.apereo.cas.services.ReturnAllowedAttributeReleasePolicy;
+import org.springframework.stereotype.Component;
+
+@AttrReleaseMapFor(
+        attrReleasePolicyConfClass = AllowedAttrReleasePolicyConf.class,
+        registeredServiceAttributeReleasePolicyClass = ReturnAllowedAttributeReleasePolicy.class)
+@Component
+public class AllowedAttrReleaseMapper implements AttrReleaseMapper {
+
+    @Override
+    public RegisteredServiceAttributeReleasePolicy build(final AttrReleasePolicyConf conf) {
+        RegisteredServiceAttributeReleasePolicy attributeReleasePolicy;
+        if (!((AllowedAttrReleasePolicyConf) conf).getAllowedAttrs().isEmpty()) {
+            attributeReleasePolicy = new ReturnAllowedAttributeReleasePolicy();
+            ((AllowedAttrReleasePolicyConf) conf).getAllowedAttrs();

Review comment:
       This seems like a dangling line? 

##########
File path: wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/RegisteredServiceMapper.java
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.mapping;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import org.apache.syncope.common.lib.wa.WAClientApp;
+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.beans.BeansException;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.stereotype.Component;
+
+@Component
+public class RegisteredServiceMapper implements ApplicationContextAware, InitializingBean {
+
+    protected ApplicationContext ctx;
+
+    protected final Map<String, AuthMapper> authPolicyConfMappers = new HashMap<>();
+
+    protected final Map<String, AuthMapper> registeredServiceAuthenticationPolicyMappers = new HashMap<>();
+
+    protected final Map<String, AccessMapper> accessPolicyConfMappers = new HashMap<>();
+
+    protected final Map<String, AccessMapper> registeredServiceAccessStrategyMappers = new HashMap<>();
+
+    protected final Map<String, AttrReleaseMapper> attrReleasePolicyConfMappers = new HashMap<>();
+
+    protected final Map<String, AttrReleaseMapper> registeredServiceAttributeReleasePolicyMappers = new HashMap<>();
+
+    protected final Map<String, ClientAppMapper> clientAppTOMappers = new HashMap<>();
+
+    protected final Map<String, ClientAppMapper> registeredServiceMappers = new HashMap<>();
+
+    @Override
+    public void setApplicationContext(final ApplicationContext ctx) throws BeansException {
+        this.ctx = ctx;
+    }
+
+    @Override
+    public void afterPropertiesSet() throws Exception {
+        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);
+            }
+        });
+
+        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);
+            }
+        });
+
+        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);
+            }
+        });
+
+        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);
+            }
+        });
+    }

Review comment:
       I think it would be better if all of this was moved to the configuration class that creates the bean instance, removing the need to implement an interface and inject an application context. Injecting the application context is a discouraged practice, and should be avoided when possible. It also makes it more difficult to write unit tests for this.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org