]> source.dussan.org Git - archiva.git/commitdiff
Adapting to redback LDAP group mapping change
authorMartin Stockhammer <martin_s@apache.org>
Tue, 7 Jul 2020 04:52:37 +0000 (06:52 +0200)
committerMartin Stockhammer <martin_s@apache.org>
Tue, 7 Jul 2020 04:52:58 +0000 (06:52 +0200)
archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/security/ArchivaLdapRoleMapperConfiguration.java

index e168003905cd1fc9e81cc7263320b5242002b8b5..34d33c0daf9f5791ff1ec02c4755e7332a85cdc6 100644 (file)
@@ -36,6 +36,7 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 
 /**
  * @author Olivier Lamy
@@ -151,6 +152,34 @@ public class ArchivaLdapRoleMapperConfiguration
         }
     }
 
+    @Override
+    public Collection<String> getLdapGroupMapping( final String groupName ) throws MappingException
+    {
+        try
+        {
+            RedbackRuntimeConfiguration redbackRuntimeConfiguration =
+                redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration();
+
+            List<LdapGroupMapping> ldapGroupMappings = redbackRuntimeConfiguration.getLdapGroupMappings();
+
+            if ( ldapGroupMappings == null )
+            {
+                return Collections.EMPTY_LIST;
+            }
+
+            Optional<LdapGroupMapping> result = ldapGroupMappings.stream( ).filter( mapping -> mapping.getGroup( ).equals( groupName ) ).findFirst( );
+            if (result.isPresent()) {
+                return result.get( ).getRoleNames( );
+            } else {
+                throw new MappingException( "Group " + groupName + " not found" );
+            }
+        }
+        catch ( RepositoryAdminException e )
+        {
+            throw new MappingException( e.getMessage(), e );
+        }
+    }
+
     @Override
     public void setLdapGroupMappings( Map<String, List<String>> mappings )
         throws MappingException