[java-idp-plugin-duo] 07/15: Commit of the old client registry before change to factory.

Phil Smart philip.smart at jisc.ac.uk
Tue Jul 14 14:29:03 UTC 2020


This is an automated email from the git hooks/post-receive script.

philsmart pushed a commit to branch master
in repository java-idp-plugin-duo.

View the commit online:
http://git.shibboleth.net/view/?p=java-idp-plugin-duo.git;a=commit;h=5af4e04e3221b3b2352a03c2fc101e32a55431d4

commit 5af4e04e3221b3b2352a03c2fc101e32a55431d4
Author: Phil Smart <philip.smart at jisc.ac.uk>
AuthorDate: Mon Jun 29 11:42:43 2020 +0100

    Commit of the old client registry before change to factory.
---
 .../duo/impl/DefaultDuoOIDCClientRegistry.java     | 64 +++++++++++++++-------
 1 file changed, 44 insertions(+), 20 deletions(-)

diff --git a/idp-duo-impl/src/main/java/net/shibboleth/idp/plugin/authn/duo/impl/DefaultDuoOIDCClientRegistry.java b/idp-duo-impl/src/main/java/net/shibboleth/idp/plugin/authn/duo/impl/DefaultDuoOIDCClientRegistry.java
index 76e01cd..cbe0ff0 100644
--- a/idp-duo-impl/src/main/java/net/shibboleth/idp/plugin/authn/duo/impl/DefaultDuoOIDCClientRegistry.java
+++ b/idp-duo-impl/src/main/java/net/shibboleth/idp/plugin/authn/duo/impl/DefaultDuoOIDCClientRegistry.java
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID 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 net.shibboleth.idp.plugin.authn.duo.impl;
 
 import java.lang.annotation.Inherited;
@@ -30,11 +47,15 @@ import net.shibboleth.utilities.java.support.logic.ConstraintViolationException;
  * 
  * Instance of registry used for auto-creation of
  *
- * Supports lazy generation of {@link DuoOIDCClient}s. Clients are tied to and hence reused per {@link DuoOIDCIntegration}.
+ * Supports lazy generation of {@link DuoOIDCClient}s. Clients are tied to and 
+ * hence reused per {@link DuoOIDCIntegration}.
+ * 
+ * TODO: FINISH WHEN WE DECIDE IF THIS IS GOOD.
  */
 @ThreadSafe
 //TODO: this is like a factory and a registry. See PrincipalEvalPredicateFactoryRegistry.
-public class DefaultDuoOIDCClientRegistry extends AbstractIdentifiableInitializableComponent implements DuoOIDCClientRegistry{
+public class DefaultDuoOIDCClientRegistry extends AbstractIdentifiableInitializableComponent 
+    implements DuoOIDCClientRegistry{
     
     /** Class logger. */
     @Nonnull private final Logger log = LoggerFactory.getLogger(DefaultDuoOIDCClientRegistry.class);
@@ -42,7 +63,7 @@ public class DefaultDuoOIDCClientRegistry extends AbstractIdentifiableInitializa
     /** Registry of Duo client to Duo integration.*/
     @Nonnull @NonnullElements private final ConcurrentMap<DuoOIDCIntegration, DuoOIDCClient> clientRegistry;
     
-    /** Create clients of the specific type.*/
+    /** Create clients of this type.*/
     @NonnullAfterInit private Class<? extends DuoOIDCClient> clientType;
     
     /** Function for creating a DuoClient from a DuoIntegration. */
@@ -72,19 +93,20 @@ public class DefaultDuoOIDCClientRegistry extends AbstractIdentifiableInitializa
         Constraint.isNotEmpty(type, "OIDC Client type can not be null or empty");
         try {
             clientType = Class.forName(type).asSubclass(DuoOIDCClient.class);
-        } catch (ClassNotFoundException | ClassCastException e) {
+        } catch (final ClassNotFoundException | ClassCastException e) {
             log.error("Duo client type '{}' could not be initialised",type,e);
             throw new ConstraintViolationException("Duo Client type '"+type+"' could not be located or is"
                     + " the wrong type");
         }
     }
     
-    /** {@link Inherited}.*/
     //TODO: review the 'business key' of the integration used to lookup the client. Should that be immutable?
+    /** {@link Inherited}.*/
     @Nonnull public DuoOIDCClient getIntegrationClientOrCreate(@Nonnull final DuoOIDCIntegration integration) 
             throws DuoRegistryException {
-        //this is an atomic call, avoiding the need to synchronise here 
-        DuoOIDCClient client = clientRegistry.computeIfAbsent(integration,clientRegistryMappingFunction);
+        Constraint.isNotNull(integration, "Duo integration can not be null");
+        //this is an atomic call, avoiding the need to synchronise here.
+        final DuoOIDCClient client = clientRegistry.computeIfAbsent(integration,clientRegistryMappingFunction);
         if (client == null) {
             throw new DuoRegistryException("DuoClient could not be found or created in the registry");
         }
@@ -101,19 +123,21 @@ public class DefaultDuoOIDCClientRegistry extends AbstractIdentifiableInitializa
         @Nonnull private final Logger log = LoggerFactory.getLogger(CreateNewClientRegistryMappingFunction.class);
         
         @Override
-        public DuoOIDCClient apply(DuoOIDCIntegration integration) {
-            try {
-                DuoOIDCClient client = clientType.getDeclaredConstructor().newInstance();
-                client.initialize(integration);
-                log.debug("Created new client {}",client);
-                return client;
-            } catch (InstantiationException | IllegalAccessException | IllegalArgumentException
-                    | InvocationTargetException | NoSuchMethodException | SecurityException e) {
-                log.warn("Could not create a DuoClient instance for the integration '{}'",integration.getIntegrationKey(),e);
-                
-            } catch (DuoClientException e) {
-                log.warn("Could not initialise the DuoClient for the integration '{}'",integration.getIntegrationKey(),e);  
-            }
+        public DuoOIDCClient apply(@Nonnull final DuoOIDCIntegration integration) {
+//            try {
+//                final DuoOIDCClient client = clientType.getDeclaredConstructor().newInstance();
+//                client.initialize(integration);
+//                log.debug("Created new client {}",client);
+//                return client;
+//            } catch (final InstantiationException | IllegalAccessException | IllegalArgumentException
+//                    | InvocationTargetException | NoSuchMethodException | SecurityException e) {
+//                log.warn("Could not create a DuoClient instance for the integration '{}'",
+//                        integration.getClientId(),e);
+//                
+//            } catch (final DuoClientException e) {
+//                log.warn("Could not initialise the DuoClient for the integration '{}'",
+//                        integration.getClientId(),e);  
+//            }
             //nothing added, nothing returned.
             return null;
         }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list