]> source.dussan.org Git - archiva.git/commitdiff
package move to o.a.a.r module redback-common-ldap
authorOlivier Lamy <olamy@apache.org>
Sat, 7 Apr 2012 21:21:24 +0000 (21:21 +0000)
committerOlivier Lamy <olamy@apache.org>
Sat, 7 Apr 2012 21:21:24 +0000 (21:21 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-core/trunk@1310870 13f79535-47bb-0310-9956-ffa450edef68

40 files changed:
redback-authentication/redback-authentication-providers/redback-authentication-ldap/src/main/java/org/apache/archiva/redback/authentication/ldap/LdapBindAuthenticator.java
redback-authentication/redback-authentication-providers/redback-authentication-ldap/src/test/resources/META-INF/spring-context.xml
redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/LdapUser.java [new file with mode: 0644]
redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/LdapUserMapper.java [new file with mode: 0644]
redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/LdapUtils.java [new file with mode: 0644]
redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/MappingException.java [new file with mode: 0644]
redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/UserMapper.java [new file with mode: 0644]
redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/UserUpdate.java [new file with mode: 0644]
redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/connection/ConfigurableLdapConnectionFactory.java [new file with mode: 0644]
redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/connection/LdapConnection.java [new file with mode: 0644]
redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/connection/LdapConnectionConfiguration.java [new file with mode: 0644]
redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/connection/LdapConnectionFactory.java [new file with mode: 0644]
redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/connection/LdapException.java [new file with mode: 0644]
redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/LdapUser.java [deleted file]
redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/LdapUserMapper.java [deleted file]
redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/LdapUtils.java [deleted file]
redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/MappingException.java [deleted file]
redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/UserMapper.java [deleted file]
redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/UserUpdate.java [deleted file]
redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/connection/ConfigurableLdapConnectionFactory.java [deleted file]
redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/connection/LdapConnection.java [deleted file]
redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/connection/LdapConnectionConfiguration.java [deleted file]
redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/connection/LdapConnectionFactory.java [deleted file]
redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/connection/LdapException.java [deleted file]
redback-common/redback-common-ldap/src/main/resources/META-INF/spring-context.xml
redback-common/redback-common-ldap/src/test/java/org/apache/archiva/redback/common/ldap/LdapUserMapperTest.java [new file with mode: 0644]
redback-common/redback-common-ldap/src/test/java/org/apache/archiva/redback/common/ldap/connection/ConfigurableLdapConnectionFactoryTest.java [new file with mode: 0644]
redback-common/redback-common-ldap/src/test/java/org/codehaus/plexus/redback/common/ldap/LdapUserMapperTest.java [deleted file]
redback-common/redback-common-ldap/src/test/java/org/codehaus/plexus/redback/common/ldap/connection/ConfigurableLdapConnectionFactoryTest.java [deleted file]
redback-common/redback-common-ldap/src/test/resources/spring-context.xml
redback-integrations/redback-struts2/redback-struts2-integration/src/test/resources/org/codehaus/plexus/redback/struts2/action/admin/SystemInfoActionTest.xml
redback-users/redback-users-providers/redback-users-ldap/src/main/java/org/apache/archiva/redback/users/ldap/LdapUserManager.java
redback-users/redback-users-providers/redback-users-ldap/src/main/java/org/apache/archiva/redback/users/ldap/LdapUserQuery.java
redback-users/redback-users-providers/redback-users-ldap/src/main/java/org/apache/archiva/redback/users/ldap/ctl/DefaultLdapController.java
redback-users/redback-users-providers/redback-users-ldap/src/main/java/org/apache/archiva/redback/users/ldap/ctl/LdapController.java
redback-users/redback-users-providers/redback-users-ldap/src/main/java/org/apache/archiva/redback/users/ldap/service/DefaultLdapCacheService.java
redback-users/redback-users-providers/redback-users-ldap/src/main/java/org/apache/archiva/redback/users/ldap/service/LdapCacheService.java
redback-users/redback-users-providers/redback-users-ldap/src/test/java/org/apache/archiva/redback/users/ldap/LdapUserManagerTest.java
redback-users/redback-users-providers/redback-users-ldap/src/test/java/org/apache/archiva/redback/users/ldap/service/LdapCacheServiceTest.java
redback-users/redback-users-providers/redback-users-ldap/src/test/resources/spring-context.xml

index 7b9b9464ab14cffeb7046e489b2a620e879e8b52..217ffdaa86199f2040c0b4aa5ce885b5e14366ba 100644 (file)
@@ -19,16 +19,16 @@ package org.apache.archiva.redback.authentication.ldap;
  * under the License.
  */
 
+import org.apache.archiva.redback.common.ldap.UserMapper;
+import org.apache.archiva.redback.common.ldap.connection.LdapConnectionFactory;
 import org.apache.commons.lang.StringUtils;
 import org.apache.archiva.redback.authentication.AuthenticationDataSource;
 import org.apache.archiva.redback.authentication.AuthenticationException;
 import org.apache.archiva.redback.authentication.AuthenticationResult;
 import org.apache.archiva.redback.authentication.Authenticator;
 import org.apache.archiva.redback.authentication.PasswordBasedAuthenticationDataSource;
-import org.codehaus.plexus.redback.common.ldap.UserMapper;
-import org.codehaus.plexus.redback.common.ldap.connection.LdapConnection;
-import org.codehaus.plexus.redback.common.ldap.connection.LdapConnectionFactory;
-import org.codehaus.plexus.redback.common.ldap.connection.LdapException;
+import org.apache.archiva.redback.common.ldap.connection.LdapConnection;
+import org.apache.archiva.redback.common.ldap.connection.LdapException;
 import org.codehaus.plexus.redback.configuration.UserConfiguration;
 import org.apache.archiva.redback.users.ldap.service.LdapCacheService;
 import org.slf4j.Logger;
index 5cea038f0b70072e480312b18de8011f35add79b..1d1e2dc4f81afbb62605d44b79a3ceaf833ac22e 100644 (file)
@@ -36,7 +36,7 @@
     <property name="password" value="secret"/>
   </bean>
 
-  <bean name="ldapConnectionFactory#configurable" class="org.codehaus.plexus.redback.common.ldap.connection.ConfigurableLdapConnectionFactory">
+  <bean name="ldapConnectionFactory#configurable" class="org.apache.archiva.redback.common.ldap.connection.ConfigurableLdapConnectionFactory">
     <property name="hostname" value="localhost"/>
     <property name="port" value="${ldapPort}"/>
     <property name="baseDn" value="dc=redback,dc=plexus,dc=codehaus,dc=org"/>
@@ -46,7 +46,7 @@
     <property name="userConf" ref="userConfiguration"/>
   </bean>
 
-  <bean name="userMapper#ldap" class="org.codehaus.plexus.redback.common.ldap.LdapUserMapper">
+  <bean name="userMapper#ldap" class="org.apache.archiva.redback.common.ldap.LdapUserMapper">
     <property name="emailAttribute" value="mail"/>
     <property name="fullNameAttribute" value="givenName"/>
     <property name="passwordAttribute" value="userPassword"/>
diff --git a/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/LdapUser.java b/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/LdapUser.java
new file mode 100644 (file)
index 0000000..5622236
--- /dev/null
@@ -0,0 +1,249 @@
+package org.apache.archiva.redback.common.ldap;
+
+/*
+ * 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.users.User;
+
+import javax.naming.directory.Attributes;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+// TODO this class should be able to be replaced with a model
+public class LdapUser
+    implements User, Serializable
+{
+
+    private String key;
+
+    private String username;
+
+    private String fullName;
+
+    private String email;
+
+    private String encodedPassword;
+
+    private List<String> previousEncodedPasswords;
+
+    private boolean locked = false;
+
+    private boolean requiresPasswordChange = false;
+
+    private boolean permanent = true;
+
+    private boolean valid = true;
+
+    private Date creationDate = null;
+
+    private int failedLoginAttempts;
+
+    private Date lastLoginDate = null;
+
+    private Date lastPasswordChange = null;
+
+    // DO NOT STORE AS SUCH!!!
+    private String newPassword;
+
+    private Attributes originalAttributes;
+
+    public LdapUser( String username )
+    {
+        key = username;
+        this.username = username;
+        previousEncodedPasswords = new ArrayList<String>( 0 );
+        failedLoginAttempts = 0;
+    }
+
+    public LdapUser( String username, String fullName, String email )
+    {
+        this( username );
+        this.fullName = fullName;
+        this.email = email;
+    }
+
+    public LdapUser()
+    {
+        previousEncodedPasswords = new ArrayList<String>( 0 );
+        failedLoginAttempts = Integer.MIN_VALUE;
+    }
+
+    public void addPreviousEncodedPassword( String encodedPassword )
+    {
+        previousEncodedPasswords.add( encodedPassword );
+    }
+
+    public Date getAccountCreationDate()
+    {
+        return creationDate;
+    }
+
+    public int getCountFailedLoginAttempts()
+    {
+        return failedLoginAttempts;
+    }
+
+    public String getEmail()
+    {
+        return email;
+    }
+
+    public String getEncodedPassword()
+    {
+        return encodedPassword;
+    }
+
+    public String getFullName()
+    {
+        return fullName;
+    }
+
+    public Date getLastLoginDate()
+    {
+        return lastLoginDate;
+    }
+
+    public Date getLastPasswordChange()
+    {
+        return lastPasswordChange;
+    }
+
+    public String getPassword()
+    {
+        return newPassword;
+    }
+
+    public List<String> getPreviousEncodedPasswords()
+    {
+        return previousEncodedPasswords;
+    }
+
+    public Object getPrincipal()
+    {
+        return key;
+    }
+
+    public String getUsername()
+    {
+        return username;
+    }
+
+    public boolean isLocked()
+    {
+        return locked;
+    }
+
+    public boolean isPasswordChangeRequired()
+    {
+        return requiresPasswordChange;
+    }
+
+    public boolean isPermanent()
+    {
+        return permanent;
+    }
+
+    public boolean isValidated()
+    {
+        return valid;
+    }
+
+    public void setCountFailedLoginAttempts( int count )
+    {
+        failedLoginAttempts = count;
+    }
+
+    public void setEmail( String address )
+    {
+        email = address;
+    }
+
+    public void setEncodedPassword( String encodedPassword )
+    {
+        this.encodedPassword = encodedPassword;
+    }
+
+    public void setFullName( String name )
+    {
+        fullName = name;
+    }
+
+    public void setAccountCreationDate( Date date )
+    {
+        creationDate = date;
+    }
+
+    public void setLastLoginDate( Date date )
+    {
+        lastLoginDate = date;
+    }
+
+    public void setLastPasswordChange( Date passwordChangeDate )
+    {
+        lastPasswordChange = passwordChangeDate;
+    }
+
+    public void setLocked( boolean locked )
+    {
+        this.locked = locked;
+    }
+
+    public void setPassword( String rawPassword )
+    {
+        newPassword = rawPassword;
+    }
+
+    public void setPasswordChangeRequired( boolean changeRequired )
+    {
+        requiresPasswordChange = changeRequired;
+    }
+
+    public void setPermanent( boolean permanent )
+    {
+        this.permanent = permanent;
+    }
+
+    public void setPreviousEncodedPasswords( List<String> encodedPasswordList )
+    {
+        previousEncodedPasswords = new ArrayList<String>( encodedPasswordList );
+    }
+
+    public void setUsername( String name )
+    {
+        username = name;
+    }
+
+    public void setValidated( boolean valid )
+    {
+        this.valid = valid;
+    }
+
+    public Attributes getOriginalAttributes()
+    {
+        return originalAttributes;
+    }
+
+    public void setOriginalAttributes( Attributes originalAttributes )
+    {
+        this.originalAttributes = originalAttributes;
+    }
+
+}
diff --git a/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/LdapUserMapper.java b/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/LdapUserMapper.java
new file mode 100644 (file)
index 0000000..1faf5eb
--- /dev/null
@@ -0,0 +1,313 @@
+package org.apache.archiva.redback.common.ldap;
+
+/*
+ * 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.users.User;
+import org.codehaus.plexus.redback.configuration.UserConfiguration;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.PostConstruct;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttributes;
+import java.util.Date;
+
+/**
+ * @author <a href="jesse@codehaus.org"> jesse
+ * @version $Id$
+ */
+@Service( "userMapper#ldap" )
+public class LdapUserMapper
+    implements UserMapper
+{
+    /**
+     *
+     */
+    String emailAttribute = "mail";
+
+    /**
+     *
+     */
+    String fullNameAttribute = "givenName";
+
+    /**
+     *
+     */
+    String passwordAttribute = "userPassword";
+
+    /**
+     *
+     */
+    String userIdAttribute = "cn";
+
+    /**
+     *
+     */
+    String userBaseDn;
+
+    /**
+     *
+     */
+    String userObjectClass = "inetOrgPerson";
+
+    /**
+     *
+     */
+    String userFilter;
+
+    /**
+     *
+     */
+    int maxResultCount = 0;
+
+    @Inject
+    @Named( value = "userConfiguration" )
+    private UserConfiguration userConf;
+
+    @PostConstruct
+    public void initialize()
+    {
+        emailAttribute = userConf.getString( "ldap.config.mapper.attribute.email", emailAttribute );
+        fullNameAttribute = userConf.getString( "ldap.config.mapper.attribute.fullname", fullNameAttribute );
+        passwordAttribute = userConf.getString( "ldap.config.mapper.attribute.password", passwordAttribute );
+        userIdAttribute = userConf.getString( "ldap.config.mapper.attribute.user.id", userIdAttribute );
+        userBaseDn = userConf.getConcatenatedList( "ldap.config.mapper.attribute.user.base.dn",
+                                                   userConf.getConcatenatedList( "ldap.config.base.dn", userBaseDn ) );
+        userObjectClass = userConf.getString( "ldap.config.mapper.attribute.user.object.class", userObjectClass );
+        userFilter = userConf.getString( "ldap.config.mapper.attribute.user.filter", userFilter );
+        maxResultCount = userConf.getInt( "ldap.config.max.result.count", maxResultCount );
+    }
+
+    public Attributes getCreationAttributes( User user, boolean encodePasswordIfChanged )
+        throws MappingException
+    {
+        Attributes userAttrs = new BasicAttributes();
+
+        boolean passwordSet = false;
+
+        if ( !passwordSet && ( user.getEncodedPassword() != null ) )
+        {
+            userAttrs.put( getPasswordAttribute(), user.getEncodedPassword() );
+        }
+
+        if ( !StringUtils.isEmpty( user.getFullName() ) )
+        {
+            userAttrs.put( getUserFullNameAttribute(), user.getFullName() );
+        }
+
+        if ( !StringUtils.isEmpty( user.getEmail() ) )
+        {
+            userAttrs.put( getEmailAddressAttribute(), user.getEmail() );
+        }
+
+        return userAttrs;
+    }
+
+    public String getEmailAddressAttribute()
+    {
+        return emailAttribute;
+    }
+
+    public String getUserFullNameAttribute()
+    {
+        return fullNameAttribute;
+    }
+
+    public String getPasswordAttribute()
+    {
+        return passwordAttribute;
+    }
+
+    public String[] getUserAttributeNames()
+    {
+        return new String[]{ emailAttribute, fullNameAttribute, passwordAttribute, userIdAttribute };
+    }
+
+    public int getMaxResultCount()
+    {
+        return maxResultCount;
+    }
+
+    public UserUpdate getUpdate( LdapUser user )
+        throws MappingException
+    {
+
+        Attributes addAttrs = new BasicAttributes();
+
+        Attributes modAttrs = new BasicAttributes();
+
+        if ( !StringUtils.isEmpty( user.getFullName() ) )
+        {
+            if ( user.getFullName() == null )
+            {
+                addAttrs.put( getUserFullNameAttribute(), user.getFullName() );
+            }
+            else if ( !user.getFullName().equals( user.getFullName() ) )
+            {
+                modAttrs.put( getUserFullNameAttribute(), user.getFullName() );
+            }
+        }
+
+        if ( !StringUtils.isEmpty( user.getEmail() ) )
+        {
+            if ( user.getEmail() == null )
+            {
+                addAttrs.put( getEmailAddressAttribute(), user.getEmail() );
+            }
+            else if ( !user.getEmail().equals( user.getEmail() ) )
+            {
+                modAttrs.put( getEmailAddressAttribute(), user.getEmail() );
+            }
+        }
+
+        return null;
+    }
+
+    public LdapUser getUser( Attributes attributes )
+        throws MappingException
+    {
+        String userIdAttribute = getUserIdAttribute();
+        String emailAddressAttribute = getEmailAddressAttribute();
+        String nameAttribute = getUserFullNameAttribute();
+        String passwordAttribute = getPasswordAttribute();
+
+        String userId = ( LdapUtils.getAttributeValue( attributes, userIdAttribute, "username" ) );
+
+        LdapUser user = new LdapUser( userId );
+        user.setOriginalAttributes( attributes );
+
+        user.setEmail( LdapUtils.getAttributeValue( attributes, emailAddressAttribute, "email address" ) );
+        user.setFullName( LdapUtils.getAttributeValue( attributes, nameAttribute, "name" ) );
+
+        String encodedPassword = LdapUtils.getAttributeValueFromByteArray( attributes, passwordAttribute, "password" );
+
+        // it seems to be a common convention for the password to come back prepended with the encoding type..
+        // however we deal with that via configuration right now so just smoke it.
+        if ( encodedPassword != null && encodedPassword.startsWith( "{" ) )
+        {
+            encodedPassword = encodedPassword.substring( encodedPassword.indexOf( "}" ) + 1 );
+        }
+
+        user.setEncodedPassword( encodedPassword );
+
+        // REDBACK-215: skip NPE
+        user.setLastPasswordChange( new Date() );
+
+        return user;
+    }
+
+    public String getUserIdAttribute()
+    {
+        return userIdAttribute;
+    }
+
+    public String getEmailAttribute()
+    {
+        return emailAttribute;
+    }
+
+    public void setEmailAttribute( String emailAttribute )
+    {
+        this.emailAttribute = emailAttribute;
+    }
+
+    public String getFullNameAttribute()
+    {
+        return fullNameAttribute;
+    }
+
+    public void setFullNameAttribute( String fullNameAttribute )
+    {
+        this.fullNameAttribute = fullNameAttribute;
+    }
+
+    public void setMaxResultCount( int maxResultCount )
+    {
+        this.maxResultCount = maxResultCount;
+    }
+
+    public String getUserBaseDn()
+    {
+        return userBaseDn;
+    }
+
+    public void setUserBaseDn( String userBaseDn )
+    {
+        this.userBaseDn = userBaseDn;
+    }
+
+    public String getUserObjectClass()
+    {
+        return userObjectClass;
+    }
+
+    public String getUserFilter()
+    {
+        return userFilter;
+    }
+
+    public void setUserFilter( String userFilter )
+    {
+        this.userFilter = userFilter;
+    }
+
+    public void setUserObjectClass( String userObjectClass )
+    {
+        this.userObjectClass = userObjectClass;
+    }
+
+    public void setPasswordAttribute( String passwordAttribute )
+    {
+        this.passwordAttribute = passwordAttribute;
+    }
+
+    public void setUserIdAttribute( String userIdAttribute )
+    {
+        this.userIdAttribute = userIdAttribute;
+    }
+
+    public LdapUser newUserInstance( String username, String fullName, String email )
+    {
+        return new LdapUser( username, fullName, email );
+    }
+
+    public LdapUser newTemplateUserInstance()
+    {
+        return new LdapUser();
+    }
+
+    public String[] getReturningAttributes()
+    {
+        return new String[]{ getUserIdAttribute(), getEmailAttribute(), getFullNameAttribute(),
+            getPasswordAttribute() };
+    }
+
+    public UserConfiguration getUserConf()
+    {
+        return userConf;
+    }
+
+    public void setUserConf( UserConfiguration userConf )
+    {
+        this.userConf = userConf;
+    }
+}
diff --git a/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/LdapUtils.java b/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/LdapUtils.java
new file mode 100644 (file)
index 0000000..9c12c27
--- /dev/null
@@ -0,0 +1,132 @@
+package org.apache.archiva.redback.common.ldap;
+
+/*
+ * 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 javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+
+/**
+ * 
+ * @version $Id$
+ */
+public final class LdapUtils
+{
+    private LdapUtils()
+    {
+        // no op
+    }
+
+    @SuppressWarnings("unchecked")
+    public static String getLabeledUriValue( Attributes attributes, String attrName, String label,
+                                             String attributeDescription )
+        throws MappingException
+    {
+        if ( attrName == null )
+        {
+            return null;
+        }
+
+        Attribute attribute = attributes.get( attrName );
+        if ( attribute != null )
+        {
+            NamingEnumeration attrs;
+            try
+            {
+                attrs = attribute.getAll();
+            }
+            catch ( NamingException e )
+            {
+                throw new MappingException(
+                    "Failed to retrieve " + attributeDescription + " (attribute: \'" + attrName + "\').", e );
+            }
+
+            while ( attrs.hasMoreElements() )
+            {
+                Object value = attrs.nextElement();
+
+                String val = String.valueOf( value );
+
+                if ( val.endsWith( " " + label ) )
+                {
+                    return val.substring( 0, val.length() - ( label.length() + 1 ) );
+                }
+            }
+        }
+
+        return null;
+    }
+
+    public static String getAttributeValue( Attributes attributes, String attrName, String attributeDescription )
+        throws MappingException
+    {
+        if ( attrName == null )
+        {
+            return null;
+        }
+
+        Attribute attribute = attributes.get( attrName );
+        if ( attribute != null )
+        {
+            try
+            {
+                Object value = attribute.get();
+
+                return String.valueOf( value );
+            }
+            catch ( NamingException e )
+            {
+                throw new MappingException(
+                    "Failed to retrieve " + attributeDescription + " (attribute: \'" + attrName + "\').", e );
+            }
+        }
+
+        return null;
+    }
+
+    public static String getAttributeValueFromByteArray( Attributes attributes, String attrName,
+                                                         String attributeDescription )
+        throws MappingException
+    {
+        if ( attrName == null )
+        {
+            return null;
+        }
+
+        Attribute attribute = attributes.get( attrName );
+        if ( attribute != null )
+        {
+            try
+            {
+                byte[] value = (byte[]) attribute.get();
+
+                return new String( value );
+            }
+            catch ( NamingException e )
+            {
+                throw new MappingException(
+                    "Failed to retrieve " + attributeDescription + " (attribute: \'" + attrName + "\').", e );
+            }
+        }
+
+        return null;
+    }
+}
diff --git a/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/MappingException.java b/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/MappingException.java
new file mode 100644 (file)
index 0000000..1345a5e
--- /dev/null
@@ -0,0 +1,39 @@
+package org.apache.archiva.redback.common.ldap;
+
+/*
+ * 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.
+ */
+
+/**
+ * @version $Id$
+ */
+public class MappingException
+    extends Exception
+{
+
+    public MappingException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
+
+    public MappingException( String message )
+    {
+        super( message );
+    }
+
+}
diff --git a/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/UserMapper.java b/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/UserMapper.java
new file mode 100644 (file)
index 0000000..2514634
--- /dev/null
@@ -0,0 +1,64 @@
+package org.apache.archiva.redback.common.ldap;
+
+/*
+ * 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.users.User;
+
+import javax.naming.directory.Attributes;
+
+/**
+ * @version $Id$
+ */
+public interface UserMapper
+{
+    LdapUser getUser( Attributes attributes )
+        throws MappingException;
+
+    Attributes getCreationAttributes( User user, boolean encodePasswordIfChanged )
+        throws MappingException;
+
+    UserUpdate getUpdate( LdapUser user )
+        throws MappingException;
+
+    String[] getUserAttributeNames();
+
+    String getEmailAddressAttribute();
+
+    String getUserFullNameAttribute();
+
+    String getPasswordAttribute();
+
+    String getUserIdAttribute();
+
+    String getEmailAttribute();
+
+    String getUserBaseDn();
+
+    String getUserObjectClass();
+
+    String getUserFilter();
+
+    LdapUser newUserInstance( String username, String fullName, String email );
+
+    LdapUser newTemplateUserInstance();
+
+    String[] getReturningAttributes();
+
+}
diff --git a/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/UserUpdate.java b/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/UserUpdate.java
new file mode 100644 (file)
index 0000000..2249cda
--- /dev/null
@@ -0,0 +1,70 @@
+package org.apache.archiva.redback.common.ldap;
+
+/*
+ * 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 javax.naming.directory.Attributes;
+
+/**
+ * @version $Id$
+ */
+public class UserUpdate
+{
+
+    private final Attributes created;
+
+    private final Attributes modified;
+
+    private final Attributes removed;
+
+    public UserUpdate( Attributes created, Attributes modified, Attributes removed )
+    {
+        this.created = created;
+        this.modified = modified;
+        this.removed = removed;
+    }
+
+    public Attributes getAddedAttributes()
+    {
+        return created;
+    }
+
+    public Attributes getModifiedAttributes()
+    {
+        return modified;
+    }
+
+    public Attributes getRemovedAttributes()
+    {
+        return removed;
+    }
+
+    public boolean hasAdditions()
+    {
+        return ( created != null ) && ( created.size() > 0 );
+    }
+
+    public boolean hasModifications()
+    {
+        return ( modified != null ) && ( modified.size() > 0 );
+    }
+
+
+
+}
diff --git a/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/connection/ConfigurableLdapConnectionFactory.java b/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/connection/ConfigurableLdapConnectionFactory.java
new file mode 100644 (file)
index 0000000..6e784c9
--- /dev/null
@@ -0,0 +1,279 @@
+package org.apache.archiva.redback.common.ldap.connection;
+
+/*
+ * 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.codehaus.plexus.redback.configuration.UserConfiguration;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.PostConstruct;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.naming.InvalidNameException;
+import javax.naming.ldap.LdapName;
+import javax.naming.ldap.Rdn;
+import javax.naming.spi.ObjectFactory;
+import javax.naming.spi.StateFactory;
+import java.util.Properties;
+
+/**
+ * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
+ * @version $Id$
+ */
+@Service( "ldapConnectionFactory#configurable" )
+public class ConfigurableLdapConnectionFactory
+    implements LdapConnectionFactory
+{
+    /**
+     *
+     */
+    private String hostname;
+
+    /**
+     *
+     */
+    private int port;
+
+    /**
+     *
+     */
+    private boolean ssl;
+
+    /**
+     *
+     */
+    private String baseDn;
+
+    /**
+     *
+     */
+    private String contextFactory;
+
+    /**
+     *
+     */
+    private String bindDn;
+
+    /**
+     *
+     */
+    private String password;
+
+    /**
+     *
+     */
+    private String authenticationMethod;
+
+    /**
+     *
+     */
+    private Properties extraProperties;
+
+    private LdapConnectionConfiguration configuration;
+
+
+    @Inject
+    @Named( value = "userConfiguration" )
+    private UserConfiguration userConf;
+
+    // ----------------------------------------------------------------------
+    // Component Lifecycle
+    // ----------------------------------------------------------------------
+    @PostConstruct
+    public void initialize()
+    {
+        try
+        {
+            configuration = new LdapConnectionConfiguration();
+            configuration.setHostname( userConf.getString( "ldap.config.hostname", hostname ) );
+            configuration.setPort( userConf.getInt( "ldap.config.port", port ) );
+            configuration.setSsl( userConf.getBoolean( "ldap.config.ssl", ssl ) );
+            configuration.setBaseDn( userConf.getConcatenatedList( "ldap.config.base.dn", baseDn ) );
+            configuration.setContextFactory( userConf.getString( "ldap.config.context.factory", contextFactory ) );
+            configuration.setBindDn( userConf.getConcatenatedList( "ldap.config.bind.dn", bindDn ) );
+            configuration.setPassword( userConf.getString( "ldap.config.password", password ) );
+            configuration.setAuthenticationMethod(
+                userConf.getString( "ldap.config.authentication.method", authenticationMethod ) );
+            configuration.setExtraProperties( extraProperties );
+        }
+        catch ( InvalidNameException e )
+        {
+            throw new RuntimeException( "Error while initializing connection factory.", e );
+        }
+    }
+
+    // ----------------------------------------------------------------------
+    // LdapConnectionFactory Implementation
+    // ----------------------------------------------------------------------
+
+    public LdapConnection getConnection()
+        throws LdapException
+    {
+        return new LdapConnection( configuration, null );
+    }
+
+    public LdapConnection getConnection( Rdn subRdn )
+        throws LdapException
+    {
+        return new LdapConnection( configuration, subRdn );
+    }
+
+    public LdapConnection getConnection( String bindDn, String password )
+        throws LdapException
+    {
+        return new LdapConnection( configuration, bindDn, password );
+    }
+
+    public LdapName getBaseDnLdapName()
+        throws LdapException
+    {
+        try
+        {
+            return new LdapName( baseDn );
+        }
+        catch ( InvalidNameException e )
+        {
+            throw new LdapException( "The base DN is not a valid name.", e );
+        }
+    }
+
+    public void addObjectFactory( Class<? extends ObjectFactory> objectFactoryClass )
+    {
+        configuration.getObjectFactories().add( objectFactoryClass );
+    }
+
+    public void addStateFactory( Class<? extends StateFactory> stateFactoryClass )
+    {
+        configuration.getStateFactories().add( stateFactoryClass );
+    }
+
+    // ----------------------------------------------------------------------
+    //
+    // ----------------------------------------------------------------------
+
+    public String toString()
+    {
+        return "{ConfigurableLdapConnectionFactory: configuration: " + configuration + "}";
+    }
+
+    public LdapConnectionConfiguration getConfiguration()
+    {
+        return configuration;
+    }
+
+    public String getHostname()
+    {
+        return hostname;
+    }
+
+    public void setHostname( String hostname )
+    {
+        this.hostname = hostname;
+    }
+
+    public int getPort()
+    {
+        return port;
+    }
+
+    public void setPort( int port )
+    {
+        this.port = port;
+    }
+
+    public boolean isSsl()
+    {
+        return ssl;
+    }
+
+    public void setSsl( boolean ssl )
+    {
+        this.ssl = ssl;
+    }
+
+    public String getBaseDn()
+    {
+        return baseDn;
+    }
+
+    public void setBaseDn( String baseDn )
+    {
+        this.baseDn = baseDn;
+    }
+
+    public String getContextFactory()
+    {
+        return contextFactory;
+    }
+
+    public void setContextFactory( String contextFactory )
+    {
+        this.contextFactory = contextFactory;
+    }
+
+    public String getBindDn()
+    {
+        return bindDn;
+    }
+
+    public void setBindDn( String bindDn )
+    {
+        this.bindDn = bindDn;
+    }
+
+    public String getPassword()
+    {
+        return password;
+    }
+
+    public void setPassword( String password )
+    {
+        this.password = password;
+    }
+
+    public String getAuthenticationMethod()
+    {
+        return authenticationMethod;
+    }
+
+    public void setAuthenticationMethod( String authenticationMethod )
+    {
+        this.authenticationMethod = authenticationMethod;
+    }
+
+    public Properties getExtraProperties()
+    {
+        return extraProperties;
+    }
+
+    public void setExtraProperties( Properties extraProperties )
+    {
+        this.extraProperties = extraProperties;
+    }
+
+    public UserConfiguration getUserConf()
+    {
+        return userConf;
+    }
+
+    public void setUserConf( UserConfiguration userConf )
+    {
+        this.userConf = userConf;
+    }
+}
diff --git a/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/connection/LdapConnection.java b/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/connection/LdapConnection.java
new file mode 100644 (file)
index 0000000..1d64074
--- /dev/null
@@ -0,0 +1,269 @@
+package org.apache.archiva.redback.common.ldap.connection;
+
+/*
+ * 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.sun.jndi.ldap.LdapCtxFactory;
+import org.jvnet.animal_sniffer.IgnoreJRERequirement;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.directory.DirContext;
+import javax.naming.ldap.LdapName;
+import javax.naming.ldap.Rdn;
+import java.util.Collections;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Properties;
+
+/**
+ * The configuration for a connection will not change.
+ *
+ * @author <a href="mailto:trygvis@inamo.no">trygvis</a>
+ * @version $Id$
+ */
+public class LdapConnection
+{
+
+    private static LdapCtxFactory ctxFactory;// = new LdapCtxFactory();
+
+
+    static
+    {
+        initCtxFactory();
+    }
+
+
+    private Logger log = LoggerFactory.getLogger( getClass() );
+
+    private LdapConnectionConfiguration config;
+
+    private DirContext context;
+
+    private List<Rdn> baseDnRdns;
+
+    @IgnoreJRERequirement
+    private static void initCtxFactory()
+    {
+        ctxFactory = new LdapCtxFactory();
+    }
+
+    @IgnoreJRERequirement
+    public LdapConnection( LdapConnectionConfiguration config, Rdn subRdn )
+        throws LdapException
+    {
+        this.config = config;
+
+        LdapName baseDn = new LdapName( config.getBaseDn().getRdns() );
+
+        if ( subRdn != null )
+        {
+            baseDn.add( subRdn );
+        }
+
+        baseDnRdns = Collections.unmodifiableList( baseDn.getRdns() );
+
+        if ( context != null )
+        {
+            throw new LdapException( "Already connected." );
+        }
+
+        Hashtable<Object, Object> e = getEnvironment();
+
+        try
+        {
+            context = (DirContext) ctxFactory.getInitialContext( e );
+        }
+        catch ( NamingException ex )
+        {
+            throw new LdapException( "Could not connect to the server.", ex );
+        }
+    }
+
+    /**
+     * This ldap connection will attempt to establish a connection using the configuration,
+     * replacing the principal and the password
+     *
+     * @param config
+     * @param bindDn
+     * @param password
+     * @throws LdapException
+     */
+    @IgnoreJRERequirement
+    public LdapConnection( LdapConnectionConfiguration config, String bindDn, String password )
+        throws LdapException
+    {
+        this.config = config;
+
+        Hashtable<Object, Object> e = getEnvironment();
+
+        e.put( Context.SECURITY_PRINCIPAL, bindDn );
+        e.put( Context.SECURITY_CREDENTIALS, password );
+
+        try
+        {
+            context = (DirContext) ctxFactory.getInitialContext( e );
+        }
+        catch ( NamingException ex )
+        {
+            throw new LdapException( "Could not connect to the server.", ex );
+        }
+    }
+
+    // ----------------------------------------------------------------------
+    // Connection Managment
+    // ----------------------------------------------------------------------
+
+    public Hashtable<Object, Object> getEnvironment()
+        throws LdapException
+    {
+        Properties env = new Properties();
+
+        env.putAll( config.getExtraProperties() );
+
+        config.check();
+
+        env.put( Context.INITIAL_CONTEXT_FACTORY, config.getContextFactory() );
+
+        // REDBACK-289/MRM-1488
+        // enable connection pooling when using Sun's LDAP context factory
+        if( config.getContextFactory().equals( "com.sun.jndi.ldap.LdapCtxFactory" ) )
+        {
+            env.put( "com.sun.jndi.ldap.connect.pool", "true");
+
+            env.put( "com.sun.jndi.ldap.connect.pool.timeout", "3600" );
+        }
+
+        if ( config.getHostname() != null )
+        {
+            String protocol = config.isSsl() ? "ldaps" : "ldap";
+            if ( config.getPort() != 0 )
+            {
+                env.put( Context.PROVIDER_URL, protocol + "://" + config.getHostname() + ":" + config.getPort() + "/" );
+            }
+            else
+            {
+                env.put( Context.PROVIDER_URL, protocol + "://" + config.getHostname() + "/" );
+            }
+        }
+
+        if ( config.getAuthenticationMethod() != null )
+        {
+            env.put( Context.SECURITY_AUTHENTICATION, config.getAuthenticationMethod() );
+        }
+
+        if ( config.getBindDn() != null )
+        {
+            env.put( Context.SECURITY_PRINCIPAL, config.getBindDn().toString() );
+        }
+
+        if ( config.getPassword() != null )
+        {
+            env.put( Context.SECURITY_CREDENTIALS, config.getPassword() );
+        }
+
+        // ----------------------------------------------------------------------
+        // Object Factories
+        // ----------------------------------------------------------------------
+
+        String objectFactories = null;
+
+        for ( Class<?> objectFactoryClass : config.getObjectFactories() )
+        {
+            if ( objectFactories == null )
+            {
+                objectFactories = objectFactoryClass.getName();
+            }
+            else
+            {
+                objectFactories += ":" + objectFactoryClass.getName();
+            }
+        }
+
+        if ( objectFactories != null )
+        {
+            env.setProperty( Context.OBJECT_FACTORIES, objectFactories );
+        }
+
+        // ----------------------------------------------------------------------
+        // State Factories
+        // ----------------------------------------------------------------------
+
+        String stateFactories = null;
+
+        for ( Class<?> stateFactoryClass : config.getStateFactories() )
+        {
+            if ( stateFactories == null )
+            {
+                stateFactories = stateFactoryClass.getName();
+            }
+            else
+            {
+                stateFactories += ":" + stateFactoryClass.getName();
+            }
+        }
+
+        if ( stateFactories != null )
+        {
+            env.setProperty( Context.STATE_FACTORIES, stateFactories );
+        }
+
+        return env;
+    }
+
+    public void close()
+    {
+        try
+        {
+            if ( context != null )
+            {
+                context.close();
+            }
+        }
+        catch ( NamingException ex )
+        {
+            log.info( "skip error closing ldap connection {}", ex.getMessage() );
+        }
+        finally
+        {
+            context = null;
+        }
+    }
+
+    // ----------------------------------------------------------------------
+    // Utils
+    // ----------------------------------------------------------------------
+
+    public LdapConnectionConfiguration getConfiguration()
+    {
+        return config;
+    }
+
+    public List<Rdn> getBaseDnRdns()
+    {
+        return baseDnRdns;
+    }
+
+    public DirContext getDirContext()
+    {
+        return context;
+    }
+}
diff --git a/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/connection/LdapConnectionConfiguration.java b/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/connection/LdapConnectionConfiguration.java
new file mode 100644 (file)
index 0000000..64c298b
--- /dev/null
@@ -0,0 +1,345 @@
+package org.apache.archiva.redback.common.ldap.connection;
+
+/*
+ * 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.commons.lang.StringUtils;
+
+import javax.naming.InvalidNameException;
+import javax.naming.ldap.LdapName;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.TreeMap;
+
+/**
+ * This class contains the configuration for a ldap connection.
+ * <p/>
+ * Properties of a ldap connection:
+ * <ul>
+ * <li>Hostname - String, required.
+ * <li>Port - int, not required. If 0 then the default value is used by the ldap driver.
+ * <li>Ssl - boolean, not required. If true then the ldaps will be used.
+ * <li>Base DN - String, required.
+ * <li>Context factory - String, required.
+ * <li>Bind DN - String, not required.
+ * <li>Password - String, not required.
+ * </ul>
+ * Note that both the bind dn and password must be set if any are set.
+ *
+ * @author <a href="mailto:trygvis@inamo.no">trygvis</a>
+ * @version $Id$
+ */
+public class LdapConnectionConfiguration
+{
+    private String hostname;
+
+    private int port;
+
+    private boolean ssl;
+
+    private LdapName baseDn;
+
+    private String contextFactory;
+
+    private LdapName bindDn;
+
+    private String password;
+
+    private String authenticationMethod;
+
+    private List<Class<?>> objectFactories;
+
+    private List<Class<?>> stateFactories;
+
+    private Properties extraProperties;
+
+    public LdapConnectionConfiguration()
+    {
+    }
+
+    public LdapConnectionConfiguration( String hostname, int port, LdapName baseDn, String contextFactory,
+                                        LdapName bindDn, String password, String authenticationMethod,
+                                        Properties extraProperties )
+        throws LdapException
+    {
+        this.hostname = hostname;
+
+        this.port = port;
+
+        if ( baseDn != null )
+        {
+            this.baseDn = new LdapName( baseDn.getRdns() );
+        }
+
+        this.contextFactory = contextFactory;
+
+        if ( bindDn != null )
+        {
+            this.bindDn = new LdapName( bindDn.getRdns() );
+        }
+
+        this.password = password;
+
+        this.authenticationMethod = authenticationMethod;
+
+        this.extraProperties = extraProperties;
+
+        check();
+    }
+
+    public LdapConnectionConfiguration( String hostname, int port, String baseDn, String contextFactory, String bindDn,
+                                        String password, String authenticationMethod, Properties extraProperties )
+        throws InvalidNameException, LdapException
+    {
+        this.hostname = hostname;
+        this.port = port;
+
+        if ( baseDn != null )
+        {
+            this.baseDn = new LdapName( baseDn );
+        }
+
+        if ( bindDn != null )
+        {
+            this.bindDn = new LdapName( bindDn );
+        }
+
+        this.contextFactory = contextFactory;
+
+        this.password = password;
+
+        this.authenticationMethod = authenticationMethod;
+
+        this.extraProperties = extraProperties;
+
+        check();
+    }
+
+    public LdapConnectionConfiguration( String hostname, int port, LdapName baseDn, String contextFactory )
+        throws LdapException
+    {
+        this.hostname = hostname;
+
+        this.port = port;
+
+        this.baseDn = baseDn;
+
+        this.contextFactory = contextFactory;
+
+        check();
+    }
+
+    // ----------------------------------------------------------------------
+    // Accessors
+    // ----------------------------------------------------------------------
+
+    public String getHostname()
+    {
+        return hostname;
+    }
+
+    public void setHostname( String hostname )
+    {
+        this.hostname = hostname;
+    }
+
+    public int getPort()
+    {
+        return port;
+    }
+
+    public void setPort( int port )
+    {
+        this.port = port;
+    }
+
+    public boolean isSsl()
+    {
+        return ssl;
+    }
+
+    public void setSsl( boolean ssl )
+    {
+        this.ssl = ssl;
+    }
+
+    public LdapName getBaseDn()
+    {
+        return baseDn;
+    }
+
+    public void setBaseDn( LdapName baseDn )
+    {
+        this.baseDn = baseDn;
+    }
+
+    public void setBaseDn( String baseDn )
+        throws InvalidNameException
+    {
+        if ( baseDn != null )
+        {
+            this.baseDn = new LdapName( baseDn );
+        }
+    }
+
+    public String getContextFactory()
+    {
+        return contextFactory;
+    }
+
+    public void setContextFactory( String contextFactory )
+    {
+        this.contextFactory = contextFactory;
+    }
+
+    public LdapName getBindDn()
+    {
+        return bindDn;
+    }
+
+    public void setBindDn( LdapName bindDn )
+    {
+        this.bindDn = bindDn;
+    }
+
+    public void setBindDn( String bindDn )
+        throws InvalidNameException
+    {
+        if ( bindDn != null )
+        {
+            this.bindDn = new LdapName( bindDn );
+        }
+    }
+
+    public String getPassword()
+    {
+        return password;
+    }
+
+    public void setPassword( String password )
+    {
+        this.password = password;
+    }
+
+    public String getAuthenticationMethod()
+    {
+        return authenticationMethod;
+    }
+
+    public void setAuthenticationMethod( String authenticationMethod )
+    {
+        this.authenticationMethod = authenticationMethod;
+    }
+
+    public List<Class<?>> getObjectFactories()
+    {
+        if ( objectFactories == null )
+        {
+            objectFactories = new ArrayList<Class<?>>( 0 );
+        }
+
+        return objectFactories;
+    }
+
+    public void setObjectFactories( List<Class<?>> objectFactories )
+    {
+        this.objectFactories = objectFactories;
+    }
+
+    public List<Class<?>> getStateFactories()
+    {
+        if ( stateFactories == null )
+        {
+            stateFactories = new ArrayList<Class<?>>( 0 );
+        }
+
+        return stateFactories;
+    }
+
+    public void setStateFactories( List<Class<?>> stateFactories )
+    {
+        this.stateFactories = stateFactories;
+    }
+
+    public Properties getExtraProperties()
+    {
+        if ( extraProperties == null )
+        {
+            extraProperties = new Properties();
+        }
+
+        return extraProperties;
+    }
+
+    public void setExtraProperties( Properties extraProperties )
+    {
+        this.extraProperties = extraProperties;
+    }
+
+    // ----------------------------------------------------------------------
+    //
+    // ----------------------------------------------------------------------
+
+    public void check()
+        throws LdapException
+    {
+        if ( port < 0 || port > 65535 )
+        {
+            throw new LdapException( "The port must be between 1 and 65535." );
+        }
+        if ( baseDn == null )
+        {
+            throw new LdapException( "The base DN must be set." );
+        }
+        if ( StringUtils.isEmpty( contextFactory ) )
+        {
+            throw new LdapException( "The context factory must be set." );
+        }
+        if ( password != null && bindDn == null )
+        {
+            throw new LdapException( "The password cant be set unless the bind dn is." );
+        }
+
+        if ( extraProperties == null )
+        {
+            extraProperties = new Properties();
+        }
+    }
+
+    // ----------------------------------------------------------------------
+    //
+    // ----------------------------------------------------------------------
+
+    public String toString()
+    {
+        return "{LdapConnectionConfiguration: " +
+            "hostname: " + getHostname() + ", " +
+            "port: " + getPort() + ", " +
+            "ssl: " + isSsl() + ", " +
+            "baseDn: " + getBaseDn() + ", " +
+            "contextFactory: " + getContextFactory() + ", " +
+            "bindDn: " + getBindDn() + ", " +
+            "password: " + getPassword() + ", " +
+            "authenticationMethod: " + getAuthenticationMethod() + ", " +
+            "objectFactories: " + getObjectFactories() + ", " +
+            "stateFactories: " + getStateFactories() + ", " +
+            "extraProperties: " + new TreeMap<Object, Object>( extraProperties ).toString() + "}";
+    }
+}
diff --git a/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/connection/LdapConnectionFactory.java b/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/connection/LdapConnectionFactory.java
new file mode 100644 (file)
index 0000000..3821adf
--- /dev/null
@@ -0,0 +1,52 @@
+package org.apache.archiva.redback.common.ldap.connection;
+
+/*
+ * 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 javax.naming.ldap.LdapName;
+import javax.naming.ldap.Rdn;
+import javax.naming.spi.ObjectFactory;
+import javax.naming.spi.StateFactory;
+
+
+/**
+ * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
+ * @version $Id$
+ */
+public interface LdapConnectionFactory
+{
+    String ROLE = LdapConnectionFactory.class.getName();
+
+    LdapConnection getConnection()
+        throws LdapException;
+
+    LdapConnection getConnection( Rdn subRdn )
+        throws LdapException;
+
+    LdapConnection getConnection( String bindDn, String password )
+        throws LdapException;
+
+    LdapName getBaseDnLdapName()
+        throws LdapException;
+
+    void addObjectFactory( Class<? extends ObjectFactory> objectFactoryClass );
+
+    void addStateFactory( Class<? extends StateFactory> objectFactoryClass );
+
+}
diff --git a/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/connection/LdapException.java b/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/connection/LdapException.java
new file mode 100644 (file)
index 0000000..654f95a
--- /dev/null
@@ -0,0 +1,41 @@
+package org.apache.archiva.redback.common.ldap.connection;
+
+/*
+ * 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 javax.naming.NamingException;
+
+/**
+ * @author <a href="mailto:trygvis@inamo.no">trygvis</a>
+ * @version $Id$
+ */
+public class LdapException
+    extends NamingException
+{
+    public LdapException( String message )
+    {
+        super( message );
+    }
+
+    public LdapException( String message, Throwable t )
+    {
+        super( message );
+        setRootCause( t );
+    }
+}
diff --git a/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/LdapUser.java b/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/LdapUser.java
deleted file mode 100644 (file)
index 0d7d2d8..0000000
+++ /dev/null
@@ -1,249 +0,0 @@
-package org.codehaus.plexus.redback.common.ldap;
-
-/*
- * 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.users.User;
-
-import javax.naming.directory.Attributes;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-// TODO this class should be able to be replaced with a model
-public class LdapUser
-    implements User, Serializable
-{
-
-    private String key;
-
-    private String username;
-
-    private String fullName;
-
-    private String email;
-
-    private String encodedPassword;
-
-    private List<String> previousEncodedPasswords;
-
-    private boolean locked = false;
-
-    private boolean requiresPasswordChange = false;
-
-    private boolean permanent = true;
-
-    private boolean valid = true;
-
-    private Date creationDate = null;
-
-    private int failedLoginAttempts;
-
-    private Date lastLoginDate = null;
-
-    private Date lastPasswordChange = null;
-
-    // DO NOT STORE AS SUCH!!!
-    private String newPassword;
-
-    private Attributes originalAttributes;
-
-    public LdapUser( String username )
-    {
-        key = username;
-        this.username = username;
-        previousEncodedPasswords = new ArrayList<String>( 0 );
-        failedLoginAttempts = 0;
-    }
-
-    public LdapUser( String username, String fullName, String email )
-    {
-        this( username );
-        this.fullName = fullName;
-        this.email = email;
-    }
-
-    public LdapUser()
-    {
-        previousEncodedPasswords = new ArrayList<String>( 0 );
-        failedLoginAttempts = Integer.MIN_VALUE;
-    }
-
-    public void addPreviousEncodedPassword( String encodedPassword )
-    {
-        previousEncodedPasswords.add( encodedPassword );
-    }
-
-    public Date getAccountCreationDate()
-    {
-        return creationDate;
-    }
-
-    public int getCountFailedLoginAttempts()
-    {
-        return failedLoginAttempts;
-    }
-
-    public String getEmail()
-    {
-        return email;
-    }
-
-    public String getEncodedPassword()
-    {
-        return encodedPassword;
-    }
-
-    public String getFullName()
-    {
-        return fullName;
-    }
-
-    public Date getLastLoginDate()
-    {
-        return lastLoginDate;
-    }
-
-    public Date getLastPasswordChange()
-    {
-        return lastPasswordChange;
-    }
-
-    public String getPassword()
-    {
-        return newPassword;
-    }
-
-    public List<String> getPreviousEncodedPasswords()
-    {
-        return previousEncodedPasswords;
-    }
-
-    public Object getPrincipal()
-    {
-        return key;
-    }
-
-    public String getUsername()
-    {
-        return username;
-    }
-
-    public boolean isLocked()
-    {
-        return locked;
-    }
-
-    public boolean isPasswordChangeRequired()
-    {
-        return requiresPasswordChange;
-    }
-
-    public boolean isPermanent()
-    {
-        return permanent;
-    }
-
-    public boolean isValidated()
-    {
-        return valid;
-    }
-
-    public void setCountFailedLoginAttempts( int count )
-    {
-        failedLoginAttempts = count;
-    }
-
-    public void setEmail( String address )
-    {
-        email = address;
-    }
-
-    public void setEncodedPassword( String encodedPassword )
-    {
-        this.encodedPassword = encodedPassword;
-    }
-
-    public void setFullName( String name )
-    {
-        fullName = name;
-    }
-
-    public void setAccountCreationDate( Date date )
-    {
-        creationDate = date;
-    }
-
-    public void setLastLoginDate( Date date )
-    {
-        lastLoginDate = date;
-    }
-
-    public void setLastPasswordChange( Date passwordChangeDate )
-    {
-        lastPasswordChange = passwordChangeDate;
-    }
-
-    public void setLocked( boolean locked )
-    {
-        this.locked = locked;
-    }
-
-    public void setPassword( String rawPassword )
-    {
-        newPassword = rawPassword;
-    }
-
-    public void setPasswordChangeRequired( boolean changeRequired )
-    {
-        requiresPasswordChange = changeRequired;
-    }
-
-    public void setPermanent( boolean permanent )
-    {
-        this.permanent = permanent;
-    }
-
-    public void setPreviousEncodedPasswords( List<String> encodedPasswordList )
-    {
-        previousEncodedPasswords = new ArrayList<String>( encodedPasswordList );
-    }
-
-    public void setUsername( String name )
-    {
-        username = name;
-    }
-
-    public void setValidated( boolean valid )
-    {
-        this.valid = valid;
-    }
-
-    public Attributes getOriginalAttributes()
-    {
-        return originalAttributes;
-    }
-
-    public void setOriginalAttributes( Attributes originalAttributes )
-    {
-        this.originalAttributes = originalAttributes;
-    }
-
-}
diff --git a/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/LdapUserMapper.java b/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/LdapUserMapper.java
deleted file mode 100644 (file)
index 7326ff4..0000000
+++ /dev/null
@@ -1,313 +0,0 @@
-package org.codehaus.plexus.redback.common.ldap;
-
-/*
- * 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.users.User;
-import org.codehaus.plexus.redback.configuration.UserConfiguration;
-import org.apache.commons.lang.StringUtils;
-import org.springframework.stereotype.Service;
-
-import javax.annotation.PostConstruct;
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.naming.directory.Attributes;
-import javax.naming.directory.BasicAttributes;
-import java.util.Date;
-
-/**
- * @author <a href="jesse@codehaus.org"> jesse
- * @version $Id$
- */
-@Service( "userMapper#ldap" )
-public class LdapUserMapper
-    implements UserMapper
-{
-    /**
-     *
-     */
-    String emailAttribute = "mail";
-
-    /**
-     *
-     */
-    String fullNameAttribute = "givenName";
-
-    /**
-     *
-     */
-    String passwordAttribute = "userPassword";
-
-    /**
-     *
-     */
-    String userIdAttribute = "cn";
-
-    /**
-     *
-     */
-    String userBaseDn;
-
-    /**
-     *
-     */
-    String userObjectClass = "inetOrgPerson";
-
-    /**
-     *
-     */
-    String userFilter;
-
-    /**
-     *
-     */
-    int maxResultCount = 0;
-
-    @Inject
-    @Named( value = "userConfiguration" )
-    private UserConfiguration userConf;
-
-    @PostConstruct
-    public void initialize()
-    {
-        emailAttribute = userConf.getString( "ldap.config.mapper.attribute.email", emailAttribute );
-        fullNameAttribute = userConf.getString( "ldap.config.mapper.attribute.fullname", fullNameAttribute );
-        passwordAttribute = userConf.getString( "ldap.config.mapper.attribute.password", passwordAttribute );
-        userIdAttribute = userConf.getString( "ldap.config.mapper.attribute.user.id", userIdAttribute );
-        userBaseDn = userConf.getConcatenatedList( "ldap.config.mapper.attribute.user.base.dn",
-                                                   userConf.getConcatenatedList( "ldap.config.base.dn", userBaseDn ) );
-        userObjectClass = userConf.getString( "ldap.config.mapper.attribute.user.object.class", userObjectClass );
-        userFilter = userConf.getString( "ldap.config.mapper.attribute.user.filter", userFilter );
-        maxResultCount = userConf.getInt( "ldap.config.max.result.count", maxResultCount );
-    }
-
-    public Attributes getCreationAttributes( User user, boolean encodePasswordIfChanged )
-        throws MappingException
-    {
-        Attributes userAttrs = new BasicAttributes();
-
-        boolean passwordSet = false;
-
-        if ( !passwordSet && ( user.getEncodedPassword() != null ) )
-        {
-            userAttrs.put( getPasswordAttribute(), user.getEncodedPassword() );
-        }
-
-        if ( !StringUtils.isEmpty( user.getFullName() ) )
-        {
-            userAttrs.put( getUserFullNameAttribute(), user.getFullName() );
-        }
-
-        if ( !StringUtils.isEmpty( user.getEmail() ) )
-        {
-            userAttrs.put( getEmailAddressAttribute(), user.getEmail() );
-        }
-
-        return userAttrs;
-    }
-
-    public String getEmailAddressAttribute()
-    {
-        return emailAttribute;
-    }
-
-    public String getUserFullNameAttribute()
-    {
-        return fullNameAttribute;
-    }
-
-    public String getPasswordAttribute()
-    {
-        return passwordAttribute;
-    }
-
-    public String[] getUserAttributeNames()
-    {
-        return new String[]{ emailAttribute, fullNameAttribute, passwordAttribute, userIdAttribute };
-    }
-
-    public int getMaxResultCount()
-    {
-        return maxResultCount;
-    }
-
-    public UserUpdate getUpdate( LdapUser user )
-        throws MappingException
-    {
-
-        Attributes addAttrs = new BasicAttributes();
-
-        Attributes modAttrs = new BasicAttributes();
-
-        if ( !StringUtils.isEmpty( user.getFullName() ) )
-        {
-            if ( user.getFullName() == null )
-            {
-                addAttrs.put( getUserFullNameAttribute(), user.getFullName() );
-            }
-            else if ( !user.getFullName().equals( user.getFullName() ) )
-            {
-                modAttrs.put( getUserFullNameAttribute(), user.getFullName() );
-            }
-        }
-
-        if ( !StringUtils.isEmpty( user.getEmail() ) )
-        {
-            if ( user.getEmail() == null )
-            {
-                addAttrs.put( getEmailAddressAttribute(), user.getEmail() );
-            }
-            else if ( !user.getEmail().equals( user.getEmail() ) )
-            {
-                modAttrs.put( getEmailAddressAttribute(), user.getEmail() );
-            }
-        }
-
-        return null;
-    }
-
-    public LdapUser getUser( Attributes attributes )
-        throws MappingException
-    {
-        String userIdAttribute = getUserIdAttribute();
-        String emailAddressAttribute = getEmailAddressAttribute();
-        String nameAttribute = getUserFullNameAttribute();
-        String passwordAttribute = getPasswordAttribute();
-
-        String userId = ( LdapUtils.getAttributeValue( attributes, userIdAttribute, "username" ) );
-
-        LdapUser user = new LdapUser( userId );
-        user.setOriginalAttributes( attributes );
-
-        user.setEmail( LdapUtils.getAttributeValue( attributes, emailAddressAttribute, "email address" ) );
-        user.setFullName( LdapUtils.getAttributeValue( attributes, nameAttribute, "name" ) );
-
-        String encodedPassword = LdapUtils.getAttributeValueFromByteArray( attributes, passwordAttribute, "password" );
-
-        // it seems to be a common convention for the password to come back prepended with the encoding type..
-        // however we deal with that via configuration right now so just smoke it.
-        if ( encodedPassword != null && encodedPassword.startsWith( "{" ) )
-        {
-            encodedPassword = encodedPassword.substring( encodedPassword.indexOf( "}" ) + 1 );
-        }
-
-        user.setEncodedPassword( encodedPassword );
-
-        // REDBACK-215: skip NPE
-        user.setLastPasswordChange( new Date() );
-
-        return user;
-    }
-
-    public String getUserIdAttribute()
-    {
-        return userIdAttribute;
-    }
-
-    public String getEmailAttribute()
-    {
-        return emailAttribute;
-    }
-
-    public void setEmailAttribute( String emailAttribute )
-    {
-        this.emailAttribute = emailAttribute;
-    }
-
-    public String getFullNameAttribute()
-    {
-        return fullNameAttribute;
-    }
-
-    public void setFullNameAttribute( String fullNameAttribute )
-    {
-        this.fullNameAttribute = fullNameAttribute;
-    }
-
-    public void setMaxResultCount( int maxResultCount )
-    {
-        this.maxResultCount = maxResultCount;
-    }
-
-    public String getUserBaseDn()
-    {
-        return userBaseDn;
-    }
-
-    public void setUserBaseDn( String userBaseDn )
-    {
-        this.userBaseDn = userBaseDn;
-    }
-
-    public String getUserObjectClass()
-    {
-        return userObjectClass;
-    }
-
-    public String getUserFilter()
-    {
-        return userFilter;
-    }
-
-    public void setUserFilter( String userFilter )
-    {
-        this.userFilter = userFilter;
-    }
-
-    public void setUserObjectClass( String userObjectClass )
-    {
-        this.userObjectClass = userObjectClass;
-    }
-
-    public void setPasswordAttribute( String passwordAttribute )
-    {
-        this.passwordAttribute = passwordAttribute;
-    }
-
-    public void setUserIdAttribute( String userIdAttribute )
-    {
-        this.userIdAttribute = userIdAttribute;
-    }
-
-    public LdapUser newUserInstance( String username, String fullName, String email )
-    {
-        return new LdapUser( username, fullName, email );
-    }
-
-    public LdapUser newTemplateUserInstance()
-    {
-        return new LdapUser();
-    }
-
-    public String[] getReturningAttributes()
-    {
-        return new String[]{ getUserIdAttribute(), getEmailAttribute(), getFullNameAttribute(),
-            getPasswordAttribute() };
-    }
-
-    public UserConfiguration getUserConf()
-    {
-        return userConf;
-    }
-
-    public void setUserConf( UserConfiguration userConf )
-    {
-        this.userConf = userConf;
-    }
-}
diff --git a/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/LdapUtils.java b/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/LdapUtils.java
deleted file mode 100644 (file)
index eecf1cb..0000000
+++ /dev/null
@@ -1,132 +0,0 @@
-package org.codehaus.plexus.redback.common.ldap;
-
-/*
- * 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 javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
-import javax.naming.directory.Attribute;
-import javax.naming.directory.Attributes;
-
-/**
- * 
- * @version $Id$
- */
-public final class LdapUtils
-{
-    private LdapUtils()
-    {
-        // no op
-    }
-
-    @SuppressWarnings("unchecked")
-    public static String getLabeledUriValue( Attributes attributes, String attrName, String label,
-                                             String attributeDescription )
-        throws MappingException
-    {
-        if ( attrName == null )
-        {
-            return null;
-        }
-
-        Attribute attribute = attributes.get( attrName );
-        if ( attribute != null )
-        {
-            NamingEnumeration attrs;
-            try
-            {
-                attrs = attribute.getAll();
-            }
-            catch ( NamingException e )
-            {
-                throw new MappingException(
-                    "Failed to retrieve " + attributeDescription + " (attribute: \'" + attrName + "\').", e );
-            }
-
-            while ( attrs.hasMoreElements() )
-            {
-                Object value = attrs.nextElement();
-
-                String val = String.valueOf( value );
-
-                if ( val.endsWith( " " + label ) )
-                {
-                    return val.substring( 0, val.length() - ( label.length() + 1 ) );
-                }
-            }
-        }
-
-        return null;
-    }
-
-    public static String getAttributeValue( Attributes attributes, String attrName, String attributeDescription )
-        throws MappingException
-    {
-        if ( attrName == null )
-        {
-            return null;
-        }
-
-        Attribute attribute = attributes.get( attrName );
-        if ( attribute != null )
-        {
-            try
-            {
-                Object value = attribute.get();
-
-                return String.valueOf( value );
-            }
-            catch ( NamingException e )
-            {
-                throw new MappingException(
-                    "Failed to retrieve " + attributeDescription + " (attribute: \'" + attrName + "\').", e );
-            }
-        }
-
-        return null;
-    }
-
-    public static String getAttributeValueFromByteArray( Attributes attributes, String attrName,
-                                                         String attributeDescription )
-        throws MappingException
-    {
-        if ( attrName == null )
-        {
-            return null;
-        }
-
-        Attribute attribute = attributes.get( attrName );
-        if ( attribute != null )
-        {
-            try
-            {
-                byte[] value = (byte[]) attribute.get();
-
-                return new String( value );
-            }
-            catch ( NamingException e )
-            {
-                throw new MappingException(
-                    "Failed to retrieve " + attributeDescription + " (attribute: \'" + attrName + "\').", e );
-            }
-        }
-
-        return null;
-    }
-}
diff --git a/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/MappingException.java b/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/MappingException.java
deleted file mode 100644 (file)
index 7778508..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-package org.codehaus.plexus.redback.common.ldap;
-
-/*
- * 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.
- */
-
-/**
- * @version $Id$
- */
-public class MappingException
-    extends Exception
-{
-
-    public MappingException( String message, Throwable cause )
-    {
-        super( message, cause );
-    }
-
-    public MappingException( String message )
-    {
-        super( message );
-    }
-
-}
diff --git a/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/UserMapper.java b/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/UserMapper.java
deleted file mode 100644 (file)
index 124b2f2..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-package org.codehaus.plexus.redback.common.ldap;
-
-/*
- * 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.users.User;
-
-import javax.naming.directory.Attributes;
-
-/**
- * @version $Id$
- */
-public interface UserMapper
-{
-    LdapUser getUser( Attributes attributes )
-        throws MappingException;
-
-    Attributes getCreationAttributes( User user, boolean encodePasswordIfChanged )
-        throws MappingException;
-
-    UserUpdate getUpdate( LdapUser user )
-        throws MappingException;
-
-    String[] getUserAttributeNames();
-
-    String getEmailAddressAttribute();
-
-    String getUserFullNameAttribute();
-
-    String getPasswordAttribute();
-
-    String getUserIdAttribute();
-
-    String getEmailAttribute();
-
-    String getUserBaseDn();
-
-    String getUserObjectClass();
-
-    String getUserFilter();
-
-    LdapUser newUserInstance( String username, String fullName, String email );
-
-    LdapUser newTemplateUserInstance();
-
-    String[] getReturningAttributes();
-
-}
diff --git a/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/UserUpdate.java b/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/UserUpdate.java
deleted file mode 100644 (file)
index 83c0c13..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-package org.codehaus.plexus.redback.common.ldap;
-
-/*
- * 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 javax.naming.directory.Attributes;
-
-/**
- * @version $Id$
- */
-public class UserUpdate
-{
-
-    private final Attributes created;
-
-    private final Attributes modified;
-
-    private final Attributes removed;
-
-    public UserUpdate( Attributes created, Attributes modified, Attributes removed )
-    {
-        this.created = created;
-        this.modified = modified;
-        this.removed = removed;
-    }
-
-    public Attributes getAddedAttributes()
-    {
-        return created;
-    }
-
-    public Attributes getModifiedAttributes()
-    {
-        return modified;
-    }
-
-    public Attributes getRemovedAttributes()
-    {
-        return removed;
-    }
-
-    public boolean hasAdditions()
-    {
-        return ( created != null ) && ( created.size() > 0 );
-    }
-
-    public boolean hasModifications()
-    {
-        return ( modified != null ) && ( modified.size() > 0 );
-    }
-
-
-
-}
diff --git a/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/connection/ConfigurableLdapConnectionFactory.java b/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/connection/ConfigurableLdapConnectionFactory.java
deleted file mode 100644 (file)
index 2537509..0000000
+++ /dev/null
@@ -1,279 +0,0 @@
-package org.codehaus.plexus.redback.common.ldap.connection;
-
-/*
- * 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.codehaus.plexus.redback.configuration.UserConfiguration;
-import org.springframework.stereotype.Service;
-
-import javax.annotation.PostConstruct;
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.naming.InvalidNameException;
-import javax.naming.ldap.LdapName;
-import javax.naming.ldap.Rdn;
-import javax.naming.spi.ObjectFactory;
-import javax.naming.spi.StateFactory;
-import java.util.Properties;
-
-/**
- * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
- * @version $Id$
- */
-@Service( "ldapConnectionFactory#configurable" )
-public class ConfigurableLdapConnectionFactory
-    implements LdapConnectionFactory
-{
-    /**
-     *
-     */
-    private String hostname;
-
-    /**
-     *
-     */
-    private int port;
-
-    /**
-     *
-     */
-    private boolean ssl;
-
-    /**
-     *
-     */
-    private String baseDn;
-
-    /**
-     *
-     */
-    private String contextFactory;
-
-    /**
-     *
-     */
-    private String bindDn;
-
-    /**
-     *
-     */
-    private String password;
-
-    /**
-     *
-     */
-    private String authenticationMethod;
-
-    /**
-     *
-     */
-    private Properties extraProperties;
-
-    private LdapConnectionConfiguration configuration;
-
-
-    @Inject
-    @Named( value = "userConfiguration" )
-    private UserConfiguration userConf;
-
-    // ----------------------------------------------------------------------
-    // Component Lifecycle
-    // ----------------------------------------------------------------------
-    @PostConstruct
-    public void initialize()
-    {
-        try
-        {
-            configuration = new LdapConnectionConfiguration();
-            configuration.setHostname( userConf.getString( "ldap.config.hostname", hostname ) );
-            configuration.setPort( userConf.getInt( "ldap.config.port", port ) );
-            configuration.setSsl( userConf.getBoolean( "ldap.config.ssl", ssl ) );
-            configuration.setBaseDn( userConf.getConcatenatedList( "ldap.config.base.dn", baseDn ) );
-            configuration.setContextFactory( userConf.getString( "ldap.config.context.factory", contextFactory ) );
-            configuration.setBindDn( userConf.getConcatenatedList( "ldap.config.bind.dn", bindDn ) );
-            configuration.setPassword( userConf.getString( "ldap.config.password", password ) );
-            configuration.setAuthenticationMethod(
-                userConf.getString( "ldap.config.authentication.method", authenticationMethod ) );
-            configuration.setExtraProperties( extraProperties );
-        }
-        catch ( InvalidNameException e )
-        {
-            throw new RuntimeException( "Error while initializing connection factory.", e );
-        }
-    }
-
-    // ----------------------------------------------------------------------
-    // LdapConnectionFactory Implementation
-    // ----------------------------------------------------------------------
-
-    public LdapConnection getConnection()
-        throws LdapException
-    {
-        return new LdapConnection( configuration, null );
-    }
-
-    public LdapConnection getConnection( Rdn subRdn )
-        throws LdapException
-    {
-        return new LdapConnection( configuration, subRdn );
-    }
-
-    public LdapConnection getConnection( String bindDn, String password )
-        throws LdapException
-    {
-        return new LdapConnection( configuration, bindDn, password );
-    }
-
-    public LdapName getBaseDnLdapName()
-        throws LdapException
-    {
-        try
-        {
-            return new LdapName( baseDn );
-        }
-        catch ( InvalidNameException e )
-        {
-            throw new LdapException( "The base DN is not a valid name.", e );
-        }
-    }
-
-    public void addObjectFactory( Class<? extends ObjectFactory> objectFactoryClass )
-    {
-        configuration.getObjectFactories().add( objectFactoryClass );
-    }
-
-    public void addStateFactory( Class<? extends StateFactory> stateFactoryClass )
-    {
-        configuration.getStateFactories().add( stateFactoryClass );
-    }
-
-    // ----------------------------------------------------------------------
-    //
-    // ----------------------------------------------------------------------
-
-    public String toString()
-    {
-        return "{ConfigurableLdapConnectionFactory: configuration: " + configuration + "}";
-    }
-
-    public LdapConnectionConfiguration getConfiguration()
-    {
-        return configuration;
-    }
-
-    public String getHostname()
-    {
-        return hostname;
-    }
-
-    public void setHostname( String hostname )
-    {
-        this.hostname = hostname;
-    }
-
-    public int getPort()
-    {
-        return port;
-    }
-
-    public void setPort( int port )
-    {
-        this.port = port;
-    }
-
-    public boolean isSsl()
-    {
-        return ssl;
-    }
-
-    public void setSsl( boolean ssl )
-    {
-        this.ssl = ssl;
-    }
-
-    public String getBaseDn()
-    {
-        return baseDn;
-    }
-
-    public void setBaseDn( String baseDn )
-    {
-        this.baseDn = baseDn;
-    }
-
-    public String getContextFactory()
-    {
-        return contextFactory;
-    }
-
-    public void setContextFactory( String contextFactory )
-    {
-        this.contextFactory = contextFactory;
-    }
-
-    public String getBindDn()
-    {
-        return bindDn;
-    }
-
-    public void setBindDn( String bindDn )
-    {
-        this.bindDn = bindDn;
-    }
-
-    public String getPassword()
-    {
-        return password;
-    }
-
-    public void setPassword( String password )
-    {
-        this.password = password;
-    }
-
-    public String getAuthenticationMethod()
-    {
-        return authenticationMethod;
-    }
-
-    public void setAuthenticationMethod( String authenticationMethod )
-    {
-        this.authenticationMethod = authenticationMethod;
-    }
-
-    public Properties getExtraProperties()
-    {
-        return extraProperties;
-    }
-
-    public void setExtraProperties( Properties extraProperties )
-    {
-        this.extraProperties = extraProperties;
-    }
-
-    public UserConfiguration getUserConf()
-    {
-        return userConf;
-    }
-
-    public void setUserConf( UserConfiguration userConf )
-    {
-        this.userConf = userConf;
-    }
-}
diff --git a/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/connection/LdapConnection.java b/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/connection/LdapConnection.java
deleted file mode 100644 (file)
index 61964d7..0000000
+++ /dev/null
@@ -1,269 +0,0 @@
-package org.codehaus.plexus.redback.common.ldap.connection;
-
-/*
- * 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.sun.jndi.ldap.LdapCtxFactory;
-import org.jvnet.animal_sniffer.IgnoreJRERequirement;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.naming.Context;
-import javax.naming.NamingException;
-import javax.naming.directory.DirContext;
-import javax.naming.ldap.LdapName;
-import javax.naming.ldap.Rdn;
-import java.util.Collections;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Properties;
-
-/**
- * The configuration for a connection will not change.
- *
- * @author <a href="mailto:trygvis@inamo.no">trygvis</a>
- * @version $Id$
- */
-public class LdapConnection
-{
-
-    private static LdapCtxFactory ctxFactory;// = new LdapCtxFactory();
-
-
-    static
-    {
-        initCtxFactory();
-    }
-
-
-    private Logger log = LoggerFactory.getLogger( getClass() );
-
-    private LdapConnectionConfiguration config;
-
-    private DirContext context;
-
-    private List<Rdn> baseDnRdns;
-
-    @IgnoreJRERequirement
-    private static void initCtxFactory()
-    {
-        ctxFactory = new LdapCtxFactory();
-    }
-
-    @IgnoreJRERequirement
-    public LdapConnection( LdapConnectionConfiguration config, Rdn subRdn )
-        throws LdapException
-    {
-        this.config = config;
-
-        LdapName baseDn = new LdapName( config.getBaseDn().getRdns() );
-
-        if ( subRdn != null )
-        {
-            baseDn.add( subRdn );
-        }
-
-        baseDnRdns = Collections.unmodifiableList( baseDn.getRdns() );
-
-        if ( context != null )
-        {
-            throw new LdapException( "Already connected." );
-        }
-
-        Hashtable<Object, Object> e = getEnvironment();
-
-        try
-        {
-            context = (DirContext) ctxFactory.getInitialContext( e );
-        }
-        catch ( NamingException ex )
-        {
-            throw new LdapException( "Could not connect to the server.", ex );
-        }
-    }
-
-    /**
-     * This ldap connection will attempt to establish a connection using the configuration,
-     * replacing the principal and the password
-     *
-     * @param config
-     * @param bindDn
-     * @param password
-     * @throws LdapException
-     */
-    @IgnoreJRERequirement
-    public LdapConnection( LdapConnectionConfiguration config, String bindDn, String password )
-        throws LdapException
-    {
-        this.config = config;
-
-        Hashtable<Object, Object> e = getEnvironment();
-
-        e.put( Context.SECURITY_PRINCIPAL, bindDn );
-        e.put( Context.SECURITY_CREDENTIALS, password );
-
-        try
-        {
-            context = (DirContext) ctxFactory.getInitialContext( e );
-        }
-        catch ( NamingException ex )
-        {
-            throw new LdapException( "Could not connect to the server.", ex );
-        }
-    }
-
-    // ----------------------------------------------------------------------
-    // Connection Managment
-    // ----------------------------------------------------------------------
-
-    public Hashtable<Object, Object> getEnvironment()
-        throws LdapException
-    {
-        Properties env = new Properties();
-
-        env.putAll( config.getExtraProperties() );
-
-        config.check();
-
-        env.put( Context.INITIAL_CONTEXT_FACTORY, config.getContextFactory() );
-
-        // REDBACK-289/MRM-1488
-        // enable connection pooling when using Sun's LDAP context factory
-        if( config.getContextFactory().equals( "com.sun.jndi.ldap.LdapCtxFactory" ) )
-        {
-            env.put( "com.sun.jndi.ldap.connect.pool", "true");
-
-            env.put( "com.sun.jndi.ldap.connect.pool.timeout", "3600" );
-        }
-
-        if ( config.getHostname() != null )
-        {
-            String protocol = config.isSsl() ? "ldaps" : "ldap";
-            if ( config.getPort() != 0 )
-            {
-                env.put( Context.PROVIDER_URL, protocol + "://" + config.getHostname() + ":" + config.getPort() + "/" );
-            }
-            else
-            {
-                env.put( Context.PROVIDER_URL, protocol + "://" + config.getHostname() + "/" );
-            }
-        }
-
-        if ( config.getAuthenticationMethod() != null )
-        {
-            env.put( Context.SECURITY_AUTHENTICATION, config.getAuthenticationMethod() );
-        }
-
-        if ( config.getBindDn() != null )
-        {
-            env.put( Context.SECURITY_PRINCIPAL, config.getBindDn().toString() );
-        }
-
-        if ( config.getPassword() != null )
-        {
-            env.put( Context.SECURITY_CREDENTIALS, config.getPassword() );
-        }
-
-        // ----------------------------------------------------------------------
-        // Object Factories
-        // ----------------------------------------------------------------------
-
-        String objectFactories = null;
-
-        for ( Class<?> objectFactoryClass : config.getObjectFactories() )
-        {
-            if ( objectFactories == null )
-            {
-                objectFactories = objectFactoryClass.getName();
-            }
-            else
-            {
-                objectFactories += ":" + objectFactoryClass.getName();
-            }
-        }
-
-        if ( objectFactories != null )
-        {
-            env.setProperty( Context.OBJECT_FACTORIES, objectFactories );
-        }
-
-        // ----------------------------------------------------------------------
-        // State Factories
-        // ----------------------------------------------------------------------
-
-        String stateFactories = null;
-
-        for ( Class<?> stateFactoryClass : config.getStateFactories() )
-        {
-            if ( stateFactories == null )
-            {
-                stateFactories = stateFactoryClass.getName();
-            }
-            else
-            {
-                stateFactories += ":" + stateFactoryClass.getName();
-            }
-        }
-
-        if ( stateFactories != null )
-        {
-            env.setProperty( Context.STATE_FACTORIES, stateFactories );
-        }
-
-        return env;
-    }
-
-    public void close()
-    {
-        try
-        {
-            if ( context != null )
-            {
-                context.close();
-            }
-        }
-        catch ( NamingException ex )
-        {
-            log.info( "skip error closing ldap connection {}", ex.getMessage() );
-        }
-        finally
-        {
-            context = null;
-        }
-    }
-
-    // ----------------------------------------------------------------------
-    // Utils
-    // ----------------------------------------------------------------------
-
-    public LdapConnectionConfiguration getConfiguration()
-    {
-        return config;
-    }
-
-    public List<Rdn> getBaseDnRdns()
-    {
-        return baseDnRdns;
-    }
-
-    public DirContext getDirContext()
-    {
-        return context;
-    }
-}
diff --git a/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/connection/LdapConnectionConfiguration.java b/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/connection/LdapConnectionConfiguration.java
deleted file mode 100644 (file)
index 1fb0f59..0000000
+++ /dev/null
@@ -1,345 +0,0 @@
-package org.codehaus.plexus.redback.common.ldap.connection;
-
-/*
- * 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.commons.lang.StringUtils;
-
-import javax.naming.InvalidNameException;
-import javax.naming.ldap.LdapName;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
-import java.util.TreeMap;
-
-/**
- * This class contains the configuration for a ldap connection.
- * <p/>
- * Properties of a ldap connection:
- * <ul>
- * <li>Hostname - String, required.
- * <li>Port - int, not required. If 0 then the default value is used by the ldap driver.
- * <li>Ssl - boolean, not required. If true then the ldaps will be used.
- * <li>Base DN - String, required.
- * <li>Context factory - String, required.
- * <li>Bind DN - String, not required.
- * <li>Password - String, not required.
- * </ul>
- * Note that both the bind dn and password must be set if any are set.
- *
- * @author <a href="mailto:trygvis@inamo.no">trygvis</a>
- * @version $Id$
- */
-public class LdapConnectionConfiguration
-{
-    private String hostname;
-
-    private int port;
-
-    private boolean ssl;
-
-    private LdapName baseDn;
-
-    private String contextFactory;
-
-    private LdapName bindDn;
-
-    private String password;
-
-    private String authenticationMethod;
-
-    private List<Class<?>> objectFactories;
-
-    private List<Class<?>> stateFactories;
-
-    private Properties extraProperties;
-
-    public LdapConnectionConfiguration()
-    {
-    }
-
-    public LdapConnectionConfiguration( String hostname, int port, LdapName baseDn, String contextFactory,
-                                        LdapName bindDn, String password, String authenticationMethod,
-                                        Properties extraProperties )
-        throws LdapException
-    {
-        this.hostname = hostname;
-
-        this.port = port;
-
-        if ( baseDn != null )
-        {
-            this.baseDn = new LdapName( baseDn.getRdns() );
-        }
-
-        this.contextFactory = contextFactory;
-
-        if ( bindDn != null )
-        {
-            this.bindDn = new LdapName( bindDn.getRdns() );
-        }
-
-        this.password = password;
-
-        this.authenticationMethod = authenticationMethod;
-
-        this.extraProperties = extraProperties;
-
-        check();
-    }
-
-    public LdapConnectionConfiguration( String hostname, int port, String baseDn, String contextFactory, String bindDn,
-                                        String password, String authenticationMethod, Properties extraProperties )
-        throws InvalidNameException, LdapException
-    {
-        this.hostname = hostname;
-        this.port = port;
-
-        if ( baseDn != null )
-        {
-            this.baseDn = new LdapName( baseDn );
-        }
-
-        if ( bindDn != null )
-        {
-            this.bindDn = new LdapName( bindDn );
-        }
-
-        this.contextFactory = contextFactory;
-
-        this.password = password;
-
-        this.authenticationMethod = authenticationMethod;
-
-        this.extraProperties = extraProperties;
-
-        check();
-    }
-
-    public LdapConnectionConfiguration( String hostname, int port, LdapName baseDn, String contextFactory )
-        throws LdapException
-    {
-        this.hostname = hostname;
-
-        this.port = port;
-
-        this.baseDn = baseDn;
-
-        this.contextFactory = contextFactory;
-
-        check();
-    }
-
-    // ----------------------------------------------------------------------
-    // Accessors
-    // ----------------------------------------------------------------------
-
-    public String getHostname()
-    {
-        return hostname;
-    }
-
-    public void setHostname( String hostname )
-    {
-        this.hostname = hostname;
-    }
-
-    public int getPort()
-    {
-        return port;
-    }
-
-    public void setPort( int port )
-    {
-        this.port = port;
-    }
-
-    public boolean isSsl()
-    {
-        return ssl;
-    }
-
-    public void setSsl( boolean ssl )
-    {
-        this.ssl = ssl;
-    }
-
-    public LdapName getBaseDn()
-    {
-        return baseDn;
-    }
-
-    public void setBaseDn( LdapName baseDn )
-    {
-        this.baseDn = baseDn;
-    }
-
-    public void setBaseDn( String baseDn )
-        throws InvalidNameException
-    {
-        if ( baseDn != null )
-        {
-            this.baseDn = new LdapName( baseDn );
-        }
-    }
-
-    public String getContextFactory()
-    {
-        return contextFactory;
-    }
-
-    public void setContextFactory( String contextFactory )
-    {
-        this.contextFactory = contextFactory;
-    }
-
-    public LdapName getBindDn()
-    {
-        return bindDn;
-    }
-
-    public void setBindDn( LdapName bindDn )
-    {
-        this.bindDn = bindDn;
-    }
-
-    public void setBindDn( String bindDn )
-        throws InvalidNameException
-    {
-        if ( bindDn != null )
-        {
-            this.bindDn = new LdapName( bindDn );
-        }
-    }
-
-    public String getPassword()
-    {
-        return password;
-    }
-
-    public void setPassword( String password )
-    {
-        this.password = password;
-    }
-
-    public String getAuthenticationMethod()
-    {
-        return authenticationMethod;
-    }
-
-    public void setAuthenticationMethod( String authenticationMethod )
-    {
-        this.authenticationMethod = authenticationMethod;
-    }
-
-    public List<Class<?>> getObjectFactories()
-    {
-        if ( objectFactories == null )
-        {
-            objectFactories = new ArrayList<Class<?>>( 0 );
-        }
-
-        return objectFactories;
-    }
-
-    public void setObjectFactories( List<Class<?>> objectFactories )
-    {
-        this.objectFactories = objectFactories;
-    }
-
-    public List<Class<?>> getStateFactories()
-    {
-        if ( stateFactories == null )
-        {
-            stateFactories = new ArrayList<Class<?>>( 0 );
-        }
-
-        return stateFactories;
-    }
-
-    public void setStateFactories( List<Class<?>> stateFactories )
-    {
-        this.stateFactories = stateFactories;
-    }
-
-    public Properties getExtraProperties()
-    {
-        if ( extraProperties == null )
-        {
-            extraProperties = new Properties();
-        }
-
-        return extraProperties;
-    }
-
-    public void setExtraProperties( Properties extraProperties )
-    {
-        this.extraProperties = extraProperties;
-    }
-
-    // ----------------------------------------------------------------------
-    //
-    // ----------------------------------------------------------------------
-
-    public void check()
-        throws LdapException
-    {
-        if ( port < 0 || port > 65535 )
-        {
-            throw new LdapException( "The port must be between 1 and 65535." );
-        }
-        if ( baseDn == null )
-        {
-            throw new LdapException( "The base DN must be set." );
-        }
-        if ( StringUtils.isEmpty( contextFactory ) )
-        {
-            throw new LdapException( "The context factory must be set." );
-        }
-        if ( password != null && bindDn == null )
-        {
-            throw new LdapException( "The password cant be set unless the bind dn is." );
-        }
-
-        if ( extraProperties == null )
-        {
-            extraProperties = new Properties();
-        }
-    }
-
-    // ----------------------------------------------------------------------
-    //
-    // ----------------------------------------------------------------------
-
-    public String toString()
-    {
-        return "{LdapConnectionConfiguration: " +
-            "hostname: " + getHostname() + ", " +
-            "port: " + getPort() + ", " +
-            "ssl: " + isSsl() + ", " +
-            "baseDn: " + getBaseDn() + ", " +
-            "contextFactory: " + getContextFactory() + ", " +
-            "bindDn: " + getBindDn() + ", " +
-            "password: " + getPassword() + ", " +
-            "authenticationMethod: " + getAuthenticationMethod() + ", " +
-            "objectFactories: " + getObjectFactories() + ", " +
-            "stateFactories: " + getStateFactories() + ", " +
-            "extraProperties: " + new TreeMap<Object, Object>( extraProperties ).toString() + "}";
-    }
-}
diff --git a/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/connection/LdapConnectionFactory.java b/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/connection/LdapConnectionFactory.java
deleted file mode 100644 (file)
index f25e923..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-package org.codehaus.plexus.redback.common.ldap.connection;
-
-/*
- * 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 javax.naming.ldap.LdapName;
-import javax.naming.ldap.Rdn;
-import javax.naming.spi.ObjectFactory;
-import javax.naming.spi.StateFactory;
-
-
-/**
- * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
- * @version $Id$
- */
-public interface LdapConnectionFactory
-{
-    String ROLE = LdapConnectionFactory.class.getName();
-
-    LdapConnection getConnection()
-        throws LdapException;
-
-    LdapConnection getConnection( Rdn subRdn )
-        throws LdapException;
-
-    LdapConnection getConnection( String bindDn, String password )
-        throws LdapException;
-
-    LdapName getBaseDnLdapName()
-        throws LdapException;
-
-    void addObjectFactory( Class<? extends ObjectFactory> objectFactoryClass );
-
-    void addStateFactory( Class<? extends StateFactory> objectFactoryClass );
-
-}
diff --git a/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/connection/LdapException.java b/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/connection/LdapException.java
deleted file mode 100644 (file)
index 2241a77..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-package org.codehaus.plexus.redback.common.ldap.connection;
-
-/*
- * 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 javax.naming.NamingException;
-
-/**
- * @author <a href="mailto:trygvis@inamo.no">trygvis</a>
- * @version $Id$
- */
-public class LdapException
-    extends NamingException
-{
-    public LdapException( String message )
-    {
-        super( message );
-    }
-
-    public LdapException( String message, Throwable t )
-    {
-        super( message );
-        setRootCause( t );
-    }
-}
index 93f3a6276691d00441d528c2947e0d6ed9e8880f..c749098584d6a5b45103c7f0af44581996d59a6b 100644 (file)
@@ -28,6 +28,6 @@
        default-lazy-init="true">
 
   <context:annotation-config />
-  <context:component-scan base-package="org.codehaus.plexus.redback.common.ldap"/>
+  <context:component-scan base-package="org.apache.archiva.redback.common.ldap"/>
  
 </beans>
\ No newline at end of file
diff --git a/redback-common/redback-common-ldap/src/test/java/org/apache/archiva/redback/common/ldap/LdapUserMapperTest.java b/redback-common/redback-common-ldap/src/test/java/org/apache/archiva/redback/common/ldap/LdapUserMapperTest.java
new file mode 100644 (file)
index 0000000..56d475f
--- /dev/null
@@ -0,0 +1,45 @@
+package org.apache.archiva.redback.common.ldap;
+
+/*
+ * 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 junit.framework.TestCase;
+import org.apache.archiva.redback.common.ldap.LdapUserMapper;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+@RunWith( SpringJUnit4ClassRunner.class )
+@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
+public class LdapUserMapperTest
+    extends TestCase
+{
+    @Inject @Named(value = "userMapper#ldap")
+    LdapUserMapper mapper;
+
+    @Test
+    public void testConfiguration()
+    {
+        assertEquals( "o=People,dc=codehaus,dc=org", mapper.getUserBaseDn() );
+    }
+}
diff --git a/redback-common/redback-common-ldap/src/test/java/org/apache/archiva/redback/common/ldap/connection/ConfigurableLdapConnectionFactoryTest.java b/redback-common/redback-common-ldap/src/test/java/org/apache/archiva/redback/common/ldap/connection/ConfigurableLdapConnectionFactoryTest.java
new file mode 100644 (file)
index 0000000..f76b1cf
--- /dev/null
@@ -0,0 +1,48 @@
+package org.apache.archiva.redback.common.ldap.connection;
+
+/*
+ * 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 junit.framework.TestCase;
+import org.apache.archiva.redback.common.ldap.connection.ConfigurableLdapConnectionFactory;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+@RunWith( SpringJUnit4ClassRunner.class )
+@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
+public class ConfigurableLdapConnectionFactoryTest
+    extends TestCase
+{
+
+    @Inject
+    @Named( value = "ldapConnectionFactory#configurable" )
+    ConfigurableLdapConnectionFactory factory;
+
+    @Test
+    public void testConfiguration()
+    {
+        assertEquals( "dc=codehaus,dc=org", factory.getConfiguration().getBaseDn().toString() );
+        assertEquals( "uid=user,dc=codehaus,dc=org", factory.getConfiguration().getBindDn().toString() );
+    }
+}
diff --git a/redback-common/redback-common-ldap/src/test/java/org/codehaus/plexus/redback/common/ldap/LdapUserMapperTest.java b/redback-common/redback-common-ldap/src/test/java/org/codehaus/plexus/redback/common/ldap/LdapUserMapperTest.java
deleted file mode 100644 (file)
index cc44d39..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-package org.codehaus.plexus.redback.common.ldap;
-
-/*
- * 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 junit.framework.TestCase;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-
-@RunWith( SpringJUnit4ClassRunner.class )
-@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
-public class LdapUserMapperTest
-    extends TestCase
-{
-    @Inject @Named(value = "userMapper#ldap")
-    LdapUserMapper mapper;
-
-    @Test
-    public void testConfiguration()
-    {
-        assertEquals( "o=People,dc=codehaus,dc=org", mapper.getUserBaseDn() );
-    }
-}
diff --git a/redback-common/redback-common-ldap/src/test/java/org/codehaus/plexus/redback/common/ldap/connection/ConfigurableLdapConnectionFactoryTest.java b/redback-common/redback-common-ldap/src/test/java/org/codehaus/plexus/redback/common/ldap/connection/ConfigurableLdapConnectionFactoryTest.java
deleted file mode 100644 (file)
index ba849e3..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-package org.codehaus.plexus.redback.common.ldap.connection;
-
-/*
- * 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 junit.framework.TestCase;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-
-@RunWith( SpringJUnit4ClassRunner.class )
-@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
-public class ConfigurableLdapConnectionFactoryTest
-    extends TestCase
-{
-
-    @Inject
-    @Named( value = "ldapConnectionFactory#configurable" )
-    ConfigurableLdapConnectionFactory factory;
-
-    @Test
-    public void testConfiguration()
-    {
-        assertEquals( "dc=codehaus,dc=org", factory.getConfiguration().getBaseDn().toString() );
-        assertEquals( "uid=user,dc=codehaus,dc=org", factory.getConfiguration().getBindDn().toString() );
-    }
-}
index 817b798bb7394c08a83a9b036a67a2d220c94740..a4ed12b68c23b291b46b14e01cb53516de2de7f8 100644 (file)
   -->
 <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-       xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
-           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
-           http://www.springframework.org/schema/context 
-           http://www.springframework.org/schema/context/spring-context-3.0.xsd">
+           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
 
   <bean name="userConfiguration" class="org.codehaus.plexus.redback.configuration.UserConfiguration">
     <property name="configs">
index da295542b9bbcac5a806785b91543d4685a187bf..4228ff888a1d584bb271ff8841fd1f4ab1049cdb 100644 (file)
@@ -63,9 +63,9 @@
       </configuration>
     </component>
            <component>
-      <role>org.codehaus.plexus.redback.common.ldap.connection.LdapConnectionFactory</role>
+      <role>org.apache.archiva.redback.common.ldap.connection.LdapConnectionFactory</role>
       <role-hint>configurable</role-hint>
-      <implementation>org.codehaus.plexus.redback.common.ldap.connection.ConfigurableLdapConnectionFactory</implementation>
+      <implementation>org.apache.archiva.redback.common.ldap.connection.ConfigurableLdapConnectionFactory</implementation>
       <description></description>
       <configuration>
         <hostname>localhost</hostname>
index 4d84a386d0abffe55c00f49d7f9ede062b09c5d0..691c242b02e7e591b3d4c78e0efec261973a0688 100644 (file)
@@ -20,15 +20,15 @@ package org.apache.archiva.redback.users.ldap;
  */
 
 
+import org.apache.archiva.redback.common.ldap.LdapUser;
+import org.apache.archiva.redback.common.ldap.UserMapper;
 import org.apache.archiva.redback.users.AbstractUserManager;
 import org.apache.archiva.redback.users.User;
 import org.apache.archiva.redback.users.UserNotFoundException;
-import org.codehaus.plexus.redback.common.ldap.LdapUser;
-import org.codehaus.plexus.redback.common.ldap.MappingException;
-import org.codehaus.plexus.redback.common.ldap.UserMapper;
-import org.codehaus.plexus.redback.common.ldap.connection.LdapConnection;
-import org.codehaus.plexus.redback.common.ldap.connection.LdapConnectionFactory;
-import org.codehaus.plexus.redback.common.ldap.connection.LdapException;
+import org.apache.archiva.redback.common.ldap.MappingException;
+import org.apache.archiva.redback.common.ldap.connection.LdapConnection;
+import org.apache.archiva.redback.common.ldap.connection.LdapConnectionFactory;
+import org.apache.archiva.redback.common.ldap.connection.LdapException;
 import org.apache.archiva.redback.users.UserQuery;
 import org.apache.archiva.redback.users.ldap.ctl.LdapController;
 import org.apache.archiva.redback.users.ldap.ctl.LdapControllerException;
index 93b0748b5c670aae3207a35eafb185574c0bf408..153b540bd42ce2ed548c46702fb1c8adfdee5cc2 100644 (file)
@@ -19,7 +19,7 @@ package org.apache.archiva.redback.users.ldap;
  * under the License.
  */
 
-import org.codehaus.plexus.redback.common.ldap.UserMapper;
+import org.apache.archiva.redback.common.ldap.UserMapper;
 import org.apache.archiva.redback.users.AbstractUserQuery;
 
 public class LdapUserQuery
index cca85ad060cd85b254cafe3ba552f3d23336b2a3..5ada8b58d6f1e4d75838c71559367f3c242f8919 100644 (file)
@@ -33,12 +33,12 @@ import javax.naming.directory.DirContext;
 import javax.naming.directory.SearchControls;
 import javax.naming.directory.SearchResult;
 
+import org.apache.archiva.redback.common.ldap.LdapUser;
+import org.apache.archiva.redback.common.ldap.LdapUserMapper;
+import org.apache.archiva.redback.common.ldap.UserMapper;
 import org.apache.archiva.redback.users.User;
 import org.apache.archiva.redback.users.UserManager;
-import org.codehaus.plexus.redback.common.ldap.LdapUser;
-import org.codehaus.plexus.redback.common.ldap.LdapUserMapper;
-import org.codehaus.plexus.redback.common.ldap.MappingException;
-import org.codehaus.plexus.redback.common.ldap.UserMapper;
+import org.apache.archiva.redback.common.ldap.MappingException;
 import org.apache.archiva.redback.users.ldap.LdapUserQuery;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -139,7 +139,7 @@ public class DefaultLdapController
         ctls.setDerefLinkFlag( true );
         ctls.setSearchScope( SearchControls.SUBTREE_SCOPE );
         ctls.setReturningAttributes( mapper.getReturningAttributes() );
-        ctls.setCountLimit( ( ( LdapUserMapper ) mapper ).getMaxResultCount() );
+        ctls.setCountLimit( ( (LdapUserMapper) mapper ).getMaxResultCount() );
 
         String finalFilter = "(&(objectClass=" + mapper.getUserObjectClass() + ")" +
             ( mapper.getUserFilter() != null ? mapper.getUserFilter() : "" ) + query.getLdapFilter(mapper) + ")";
index 702028c035f07ca9ef52308fa101c4b348c6c25e..4abf5493519e3594bbdd833e7817fa63277c7a1d 100644 (file)
@@ -19,9 +19,9 @@ package org.apache.archiva.redback.users.ldap.ctl;
  * under the License.
  */
 
+import org.apache.archiva.redback.common.ldap.LdapUser;
 import org.apache.archiva.redback.users.User;
-import org.codehaus.plexus.redback.common.ldap.LdapUser;
-import org.codehaus.plexus.redback.common.ldap.MappingException;
+import org.apache.archiva.redback.common.ldap.MappingException;
 import org.apache.archiva.redback.users.ldap.LdapUserQuery;
 
 import javax.naming.directory.DirContext;
index d43d84755b10dc3f0891d10fd1d05617fb405bcd..b9b50dc7125f27481762a22c5562c873fc57f358 100644 (file)
@@ -19,9 +19,8 @@ package org.apache.archiva.redback.users.ldap.service;
  * under the License.
  */
 
-import org.apache.archiva.redback.users.ldap.service.LdapCacheService;
+import org.apache.archiva.redback.common.ldap.LdapUser;
 import org.codehaus.plexus.cache.builder.CacheBuilder;
-import org.codehaus.plexus.redback.common.ldap.LdapUser;
 import org.springframework.stereotype.Service;
 
 import javax.inject.Inject;
@@ -66,7 +65,7 @@ public class DefaultLdapCacheService
     }
 
     /**
-     * @see LdapCacheService#addUser(org.codehaus.plexus.redback.common.ldap.LdapUser)
+     * @see LdapCacheService#addUser(org.apache.archiva.redback.common.ldap.LdapUser)
      */
     public void addUser( LdapUser user )
     {
index 642ac41dae7f0819eea34b1227780c0b20440721..5075ba2bbc2b124e1cf6ae8c551b194eb787df53 100644 (file)
@@ -19,7 +19,7 @@ package org.apache.archiva.redback.users.ldap.service;
  * under the License.
  */
 
-import org.codehaus.plexus.redback.common.ldap.LdapUser;
+import org.apache.archiva.redback.common.ldap.LdapUser;
 
 /**
  * LdapCacheService
index d9bb76606a91fe79f1c2180fbe62b3b7110ca576..a347150dbbc2cfcd9feffec88f5dffee26b5740e 100644 (file)
@@ -21,8 +21,8 @@ package org.apache.archiva.redback.users.ldap;
 
 import junit.framework.TestCase;
 import org.apache.archiva.redback.users.User;
-import org.codehaus.plexus.redback.common.ldap.connection.LdapConnection;
-import org.codehaus.plexus.redback.common.ldap.connection.LdapConnectionFactory;
+import org.apache.archiva.redback.common.ldap.connection.LdapConnection;
+import org.apache.archiva.redback.common.ldap.connection.LdapConnectionFactory;
 import org.codehaus.plexus.redback.policy.PasswordEncoder;
 import org.codehaus.plexus.redback.policy.encoders.SHA1PasswordEncoder;
 import org.apache.archiva.redback.users.UserManager;
index b27d72cc672ead7341ae929b96e0795c86cb4868..de529f8387403287ed3b5b52fc19a2b6a7d8026f 100644 (file)
@@ -20,8 +20,7 @@ package org.apache.archiva.redback.users.ldap.service;
  */
 
 import junit.framework.TestCase;
-import org.apache.archiva.redback.users.ldap.service.LdapCacheService;
-import org.codehaus.plexus.redback.common.ldap.LdapUser;
+import org.apache.archiva.redback.common.ldap.LdapUser;
 import org.junit.After;
 import org.junit.Test;
 import org.junit.runner.RunWith;
index 9eb0fb26181a5b29dbacb8f998a7a724a86bd876..de6aad93e772e1acc067179b619b380cade7f77d 100644 (file)
@@ -36,7 +36,7 @@
     <property name="password" value="secret"/>
   </bean>
 
-  <bean name="ldapConnectionFactory#configurable" class="org.codehaus.plexus.redback.common.ldap.connection.ConfigurableLdapConnectionFactory">
+  <bean name="ldapConnectionFactory#configurable" class="org.apache.archiva.redback.common.ldap.connection.ConfigurableLdapConnectionFactory">
     <property name="hostname" value="localhost"/>
     <property name="port" value="${ldapPort}"/>
     <property name="baseDn" value="dc=redback,dc=plexus,dc=codehaus,dc=org"/>
@@ -46,7 +46,7 @@
     <property name="userConf" ref="userConfiguration"/>
   </bean>
 
-  <bean name="userMapper#ldap" class="org.codehaus.plexus.redback.common.ldap.LdapUserMapper">
+  <bean name="userMapper#ldap" class="org.apache.archiva.redback.common.ldap.LdapUserMapper">
     <property name="emailAttribute" value="mail"/>
     <property name="fullNameAttribute" value="givenName"/>
     <property name="passwordAttribute" value="userPassword"/>