]> source.dussan.org Git - archiva.git/commitdiff
add classes
authorOlivier Lamy <olamy@apache.org>
Mon, 28 Jan 2013 23:55:10 +0000 (23:55 +0000)
committerOlivier Lamy <olamy@apache.org>
Mon, 28 Jan 2013 23:55:10 +0000 (23:55 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-core/trunk@1439701 13f79535-47bb-0310-9956-ffa450edef68

redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/role/DefaultLdapRoleMapperConfiguration.java [new file with mode: 0644]
redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/role/LdapRoleMapperConfiguration.java [new file with mode: 0644]

diff --git a/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/role/DefaultLdapRoleMapperConfiguration.java b/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/role/DefaultLdapRoleMapperConfiguration.java
new file mode 100644 (file)
index 0000000..430cc02
--- /dev/null
@@ -0,0 +1,88 @@
+package org.apache.archiva.redback.common.ldap.role;
+/*
+ * 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.
+ */
+
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Multimap;
+import org.apache.archiva.redback.common.ldap.MappingException;
+import org.apache.archiva.redback.configuration.UserConfiguration;
+import org.apache.archiva.redback.configuration.UserConfigurationKeys;
+import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * @author Olivier Lamy
+ */
+@Service( "ldapRoleMapperConfiguration#default" )
+public class DefaultLdapRoleMapperConfiguration
+    implements LdapRoleMapperConfiguration
+{
+
+    private Logger log = LoggerFactory.getLogger( getClass() );
+
+    @Inject
+    @Named( value = "userConfiguration#default" )
+    private UserConfiguration userConf;
+
+    public void addLdapMapping( String role, String ldapGroup )
+    {
+        log.warn( "addLdapMapping not implemented" );
+    }
+
+    public void removeLdapMapping( String role )
+    {
+        log.warn( "removeLdapMapping not implemented" );
+    }
+
+    public void setLdapGroupMappings( Map<String, Collection<String>> mappings )
+        throws MappingException
+    {
+        log.warn( "setLdapGroupMappings not implemented" );
+    }
+
+    public Map<String, Collection<String>> getLdapGroupMappings()
+    {
+        Multimap<String, String> map = ArrayListMultimap.create();
+
+        Collection<String> keys = userConf.getKeys();
+
+        for ( String key : keys )
+        {
+            if ( key.startsWith( UserConfigurationKeys.LDAP_GROUPS_ROLE_START_KEY ) )
+            {
+                String val = userConf.getString( key );
+                String[] roles = StringUtils.split( val, ',' );
+                for ( String role : roles )
+                {
+                    map.put( StringUtils.substringAfter( key, UserConfigurationKeys.LDAP_GROUPS_ROLE_START_KEY ),
+                             role );
+                }
+            }
+        }
+
+        return map.asMap();
+    }
+}
diff --git a/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/role/LdapRoleMapperConfiguration.java b/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/role/LdapRoleMapperConfiguration.java
new file mode 100644 (file)
index 0000000..baab693
--- /dev/null
@@ -0,0 +1,57 @@
+package org.apache.archiva.redback.common.ldap.role;
+/*
+ * 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.
+ */
+
+import org.apache.archiva.redback.common.ldap.MappingException;
+
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * @author Olivier Lamy
+ * @since 2.1
+ */
+public interface LdapRoleMapperConfiguration
+{
+    /**
+     * add mapping redback role <-> ldap group
+     *
+     * @param role      redback role
+     * @param ldapGroup ldap group
+     */
+    void addLdapMapping( String role, String ldapGroup )
+        throws MappingException;
+
+    /**
+     * remove a mapping
+     *
+     * @param role redback role
+     */
+    void removeLdapMapping( String role )
+        throws MappingException;
+
+    /**
+     * @return Map of corresponding LDAP group (key) and Redback roles (value)
+     */
+    Map<String, Collection<String>> getLdapGroupMappings()
+        throws MappingException;
+
+    void setLdapGroupMappings( Map<String, Collection<String>> mappings )
+        throws MappingException;
+}