You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by ol...@apache.org on 2012/04/06 11:59:32 UTC

svn commit: r1310268 [4/42] - in /archiva/redback/redback-core/trunk: ./ redback-authentication/ redback-authentication/redback-authentication-api/ redback-authentication/redback-authentication-api/src/ redback-authentication/redback-authentication-api...

Propchange: archiva/redback/redback-core/trunk/redback-authorization/redback-authorization-providers/redback-authorization-open/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-authorization/redback-authorization-providers/redback-authorization-open/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-authorization/redback-authorization-providers/redback-authorization-open/src/main/java/org/codehaus/plexus/redback/authorization/open/OpenAuthorizer.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-authorization/redback-authorization-providers/redback-authorization-open/src/main/java/org/codehaus/plexus/redback/authorization/open/OpenAuthorizer.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-authorization/redback-authorization-providers/redback-authorization-open/src/main/java/org/codehaus/plexus/redback/authorization/open/OpenAuthorizer.java (added)
+++ archiva/redback/redback-core/trunk/redback-authorization/redback-authorization-providers/redback-authorization-open/src/main/java/org/codehaus/plexus/redback/authorization/open/OpenAuthorizer.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,48 @@
+package org.codehaus.plexus.redback.authorization.open;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.authorization.AuthorizationDataSource;
+import org.codehaus.plexus.redback.authorization.AuthorizationException;
+import org.codehaus.plexus.redback.authorization.AuthorizationResult;
+import org.codehaus.plexus.redback.authorization.Authorizer;
+import org.springframework.stereotype.Service;
+
+/**
+ * OpenAuthorizer - No checks for authorization, everything passes. 
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ * 
+ */
+@Service("authorizer#rbac")
+public class OpenAuthorizer
+    implements Authorizer
+{
+
+    public String getId()
+    {
+        return "Open Authorizer";
+    }
+
+    public AuthorizationResult isAuthorized( AuthorizationDataSource source )
+        throws AuthorizationException
+    {
+        return new AuthorizationResult( true, source.getPermission(), null );
+    }
+
+}

Propchange: archiva/redback/redback-core/trunk/redback-authorization/redback-authorization-providers/redback-authorization-open/src/main/java/org/codehaus/plexus/redback/authorization/open/OpenAuthorizer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-authorization/redback-authorization-providers/redback-authorization-open/src/main/java/org/codehaus/plexus/redback/authorization/open/OpenAuthorizer.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-authorization/redback-authorization-providers/redback-authorization-open/src/main/resources/META-INF/spring-context.xml
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-authorization/redback-authorization-providers/redback-authorization-open/src/main/resources/META-INF/spring-context.xml?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-authorization/redback-authorization-providers/redback-authorization-open/src/main/resources/META-INF/spring-context.xml (added)
+++ archiva/redback/redback-core/trunk/redback-authorization/redback-authorization-providers/redback-authorization-open/src/main/resources/META-INF/spring-context.xml Fri Apr  6 09:58:14 2012
@@ -0,0 +1,34 @@
+<?xml version="1.0"?>
+
+<!--
+  ~ 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.
+  -->
+<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-2.5.xsd
+           http://www.springframework.org/schema/context 
+           http://www.springframework.org/schema/context/spring-context-2.5.xsd"
+       default-lazy-init="true">
+
+  <context:annotation-config />
+  <context:component-scan 
+    base-package="org.codehaus.plexus.redback.authorization.open"/>
+ 
+</beans>
\ No newline at end of file

Propchange: archiva/redback/redback-core/trunk/redback-authorization/redback-authorization-providers/redback-authorization-open/src/main/resources/META-INF/spring-context.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-authorization/redback-authorization-providers/redback-authorization-open/src/main/resources/META-INF/spring-context.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-common/pom.xml
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-common/pom.xml?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-common/pom.xml (added)
+++ archiva/redback/redback-core/trunk/redback-common/pom.xml Fri Apr  6 09:58:14 2012
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright 2006 The Codehaus.
+  ~ 
+  ~ Licensed 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.
+  -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.codehaus.redback</groupId>
+    <artifactId>redback</artifactId>
+    <version>1.5-SNAPSHOT</version>
+  </parent>
+  <artifactId>redback-common</artifactId>
+  <name>Redback :: Commons</name>
+  <packaging>pom</packaging>
+  <modules>
+    <module>redback-common-jdo</module>
+    <module>redback-common-ldap</module>
+    <module>redback-common-test-resources</module>
+  </modules>
+</project>
\ No newline at end of file

Propchange: archiva/redback/redback-core/trunk/redback-common/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-common/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-common/redback-common-jdo/pom.xml
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-common/redback-common-jdo/pom.xml?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-common/redback-common-jdo/pom.xml (added)
+++ archiva/redback/redback-core/trunk/redback-common/redback-common-jdo/pom.xml Fri Apr  6 09:58:14 2012
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright 2006 The Codehaus.
+  ~ 
+  ~ Licensed 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.
+  -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.codehaus.redback</groupId>
+    <artifactId>redback-common</artifactId>
+    <version>1.5-SNAPSHOT</version>
+  </parent>
+  <artifactId>redback-common-jdo</artifactId>
+  <name>Redback :: JDO Common API</name>
+  <packaging>jar</packaging>
+  <dependencies>
+    <dependency>
+      <groupId>org.codehaus.redback.components</groupId>
+      <artifactId>spring-jdo2</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>jpox</groupId>
+      <artifactId>jpox</artifactId>
+      <scope>compile</scope>
+      <exclusions>
+        <!-- targeting JDK 1.4 we don't need this -->
+        <exclusion>
+          <groupId>javax.sql</groupId>
+          <artifactId>jdbc-stdext</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>log4j</groupId>
+          <artifactId>log4j</artifactId>
+        </exclusion>
+
+        <exclusion>
+          <groupId>javax.resource</groupId>
+          <artifactId>connector</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>javax.transaction</groupId>
+          <artifactId>jta</artifactId>
+        </exclusion>
+
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>org.hsqldb</groupId>
+      <artifactId>hsqldb</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.redback</groupId>
+      <artifactId>redback-configuration</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-context-support</artifactId>
+    </dependency>   
+    <dependency>
+      <groupId>javax.annotation</groupId>
+      <artifactId>jsr250-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-lang</groupId>
+      <artifactId>commons-lang</artifactId>
+    </dependency>
+  </dependencies>
+</project>

Propchange: archiva/redback/redback-core/trunk/redback-common/redback-common-jdo/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-common/redback-common-jdo/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-common/redback-common-jdo/src/main/java/org/codehaus/plexus/redback/common/jdo/UserConfigurableJdoFactory.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-common/redback-common-jdo/src/main/java/org/codehaus/plexus/redback/common/jdo/UserConfigurableJdoFactory.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-common/redback-common-jdo/src/main/java/org/codehaus/plexus/redback/common/jdo/UserConfigurableJdoFactory.java (added)
+++ archiva/redback/redback-core/trunk/redback-common/redback-common-jdo/src/main/java/org/codehaus/plexus/redback/common/jdo/UserConfigurableJdoFactory.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,109 @@
+package org.codehaus.plexus.redback.common.jdo;
+
+import org.apache.commons.lang.StringUtils;
+import org.codehaus.plexus.interpolation.InterpolationException;
+import org.codehaus.plexus.interpolation.PropertiesBasedValueSource;
+import org.codehaus.plexus.interpolation.StringSearchInterpolator;
+import org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory;
+import org.codehaus.plexus.redback.configuration.UserConfiguration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.PostConstruct;
+import javax.inject.Inject;
+import javax.inject.Named;
+
+/**
+ * UserConfigurableJdoFactory
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+@Service( "jdoFactory#users" )
+public class UserConfigurableJdoFactory
+    extends DefaultConfigurableJdoFactory
+{
+
+    private Logger log = LoggerFactory.getLogger( getClass() );
+
+    @Inject
+    @Named( value = "userConfiguration" )
+    private UserConfiguration config;
+
+    private String getConfigString( String key, String currentValue, String defaultValue )
+    {
+        String valueFromSysProps = System.getProperty( "redback." + key );
+        if (StringUtils.isNotEmpty( valueFromSysProps ))
+        {
+            return valueFromSysProps;
+        }
+        String value = null;
+        if ( StringUtils.isNotEmpty( currentValue ) )
+        {
+            value = config.getString( key, currentValue );
+        }
+        else
+        {
+            value = config.getString( key, defaultValue );
+        }
+        // do some interpolation as we can have some ${plexus.home} etc...
+        StringSearchInterpolator interpolator = new StringSearchInterpolator();
+        interpolator.addValueSource( new PropertiesBasedValueSource( System.getProperties() ) );
+
+        try
+        {
+            return interpolator.interpolate( value );
+        }
+        catch ( InterpolationException e )
+        {
+            // ignore interpolation issue
+            log.warn( "skip issue during interpolation " + e.getMessage() );
+            return value;
+        }
+    }
+
+    @PostConstruct
+    public void initialize()
+    {
+        String jdbcDriverName =
+            getConfigString( "jdbc.driver.name", super.getDriverName(), "org.apache.derby.jdbc.EmbeddedDriver" );
+        String jdbcUrl =
+            getConfigString( "jdbc.url", super.getUrl(), "jdbc:derby:${plexus.home}/database;create=true" );
+
+        String jdbcUsername = getConfigString( "jdbc.username", super.getUserName(), "sa" );
+        String jdbcPassword = getConfigString( "jdbc.password", super.getPassword(), "" );
+
+        super.setDriverName( jdbcDriverName );
+        super.setUrl( jdbcUrl );
+        super.setUserName( jdbcUsername );
+        super.setPassword( jdbcPassword );
+
+        if ( StringUtils.isEmpty( super.persistenceManagerFactoryClass ) )
+        {
+            super.setPersistenceManagerFactoryClass( "org.jpox.PersistenceManagerFactoryImpl" );
+        }
+
+        if ( ( super.otherProperties == null ) || super.otherProperties.isEmpty() )
+        {
+            super.setProperty( "org.jpox.autoCreateSchema", "true" );
+            super.setProperty( "org.jpox.validateSchema", "false" );
+            super.setProperty( "org.jpox.validateTables", "false" );
+            super.setProperty( "org.jpox.validateConstraints", "false" );
+            super.setProperty( "org.jpox.transactionIsolation", "READ_COMMITTED" );
+            super.setProperty( "org.jpox.rdbms.dateTimezone", "JDK_DEFAULT_TIMEZONE" );
+        }
+
+        super.initialize();
+    }
+
+    public UserConfiguration getConfig()
+    {
+        return config;
+    }
+
+    public void setConfig( UserConfiguration config )
+    {
+        this.config = config;
+    }
+}

Propchange: archiva/redback/redback-core/trunk/redback-common/redback-common-jdo/src/main/java/org/codehaus/plexus/redback/common/jdo/UserConfigurableJdoFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-common/redback-common-jdo/src/main/java/org/codehaus/plexus/redback/common/jdo/UserConfigurableJdoFactory.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-common/redback-common-jdo/src/main/java/org/codehaus/plexus/redback/common/jdo/test/StoreManagerDebug.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-common/redback-common-jdo/src/main/java/org/codehaus/plexus/redback/common/jdo/test/StoreManagerDebug.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-common/redback-common-jdo/src/main/java/org/codehaus/plexus/redback/common/jdo/test/StoreManagerDebug.java (added)
+++ archiva/redback/redback-core/trunk/redback-common/redback-common-jdo/src/main/java/org/codehaus/plexus/redback/common/jdo/test/StoreManagerDebug.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,110 @@
+package org.codehaus.plexus.redback.common.jdo.test;
+
+/*
+ * Copyright 2009 The Codehaus
+ *
+ * Licensed 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 java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import javax.jdo.PersistenceManager;
+
+import org.jpox.AbstractPersistenceManagerFactory;
+import org.jpox.ClassLoaderResolver;
+import org.jpox.plugin.ConfigurationElement;
+import org.jpox.plugin.Extension;
+import org.jpox.store.rdbms.RDBMSManager;
+
+/**
+ * A extension to JPOX store manager that allows counting the SQL queries
+ * 
+ * @author Carlos Sanchez <a href="mailto:carlos@apache.org">
+ */
+public class StoreManagerDebug
+    extends RDBMSManager
+{
+    private static int counter;
+
+    public StoreManagerDebug( ClassLoaderResolver clr, AbstractPersistenceManagerFactory pmf, String userName,
+                              String password )
+    {
+        super( clr, pmf, userName, password );
+    }
+
+    /**
+     * This method will change JPOX store manager extension so it uses our class instead of whatever is configured in
+     * the plugin.xml
+     * 
+     * @param pmf
+     */
+    public static void setup( AbstractPersistenceManagerFactory pmf )
+    {
+        /* set our own Store Manager to allow counting SQL statements */
+        Extension[] extensions =
+            pmf.getPMFContext().getPluginManager().getExtensionPoint( "org.jpox.store_manager" ).getExtensions();
+        Extension e = extensions[0];
+        for ( ConfigurationElement element : e.getConfigurationElements() )
+        {
+            element.putAttribute( "class-name", StoreManagerDebug.class.getName() );
+        }
+    }
+
+    /**
+     * Get the currently configured store manager from JPOX. Will fail if
+     * {@link #setup(AbstractPersistenceManagerFactory)} is not called first.
+     * 
+     * @param persistenceManager
+     * @return
+     */
+    public static StoreManagerDebug getConfiguredStoreManager( PersistenceManager persistenceManager )
+    {
+        return (StoreManagerDebug) ( (org.jpox.PersistenceManager) persistenceManager ).getStoreManager();
+    }
+
+    @Override
+    public int[] executeStatementBatch( String stmt, PreparedStatement ps )
+        throws SQLException
+    {
+        counter++;
+        return super.executeStatementBatch( stmt, ps );
+    }
+
+    @Override
+    public ResultSet executeStatementQuery( String stmt, PreparedStatement ps )
+        throws SQLException
+    {
+        counter++;
+        return super.executeStatementQuery( stmt, ps );
+    }
+
+    @Override
+    public int executeStatementUpdate( String stmt, PreparedStatement ps )
+        throws SQLException
+    {
+        counter++;
+        return super.executeStatementUpdate( stmt, ps );
+    }
+
+    public void resetCounter()
+    {
+        counter = 0;
+    }
+
+    public int counter()
+    {
+        return counter;
+    }
+}

Propchange: archiva/redback/redback-core/trunk/redback-common/redback-common-jdo/src/main/java/org/codehaus/plexus/redback/common/jdo/test/StoreManagerDebug.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-common/redback-common-jdo/src/main/java/org/codehaus/plexus/redback/common/jdo/test/StoreManagerDebug.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-common/redback-common-jdo/src/main/resources/META-INF/spring-context.xml
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-common/redback-common-jdo/src/main/resources/META-INF/spring-context.xml?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-common/redback-common-jdo/src/main/resources/META-INF/spring-context.xml (added)
+++ archiva/redback/redback-core/trunk/redback-common/redback-common-jdo/src/main/resources/META-INF/spring-context.xml Fri Apr  6 09:58:14 2012
@@ -0,0 +1,33 @@
+<?xml version="1.0"?>
+
+<!--
+  ~ 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.
+  -->
+<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"
+        default-lazy-init="true">
+
+  <bean name="jdoFactory#users" class="org.codehaus.plexus.redback.common.jdo.UserConfigurableJdoFactory">
+    <property name="config" ref="userConfiguration"/>
+  </bean>
+</beans>
\ No newline at end of file

Propchange: archiva/redback/redback-core/trunk/redback-common/redback-common-jdo/src/main/resources/META-INF/spring-context.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-common/redback-common-jdo/src/main/resources/META-INF/spring-context.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/pom.xml
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/pom.xml?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/pom.xml (added)
+++ archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/pom.xml Fri Apr  6 09:58:14 2012
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright 2006 The Codehaus.
+  ~ 
+  ~ Licensed 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.
+  -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.codehaus.redback</groupId>
+    <artifactId>redback-common</artifactId>
+    <version>1.5-SNAPSHOT</version>
+  </parent>
+  <artifactId>redback-common-ldap</artifactId>
+  <name>Redback :: Ldap Common API</name>
+  <packaging>jar</packaging>
+  <dependencies>
+    <dependency>
+      <groupId>org.codehaus.redback</groupId>
+      <artifactId>redback-configuration</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.redback</groupId>
+      <artifactId>redback-users-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-context-support</artifactId>
+    </dependency>   
+    <dependency>
+      <groupId>javax.annotation</groupId>
+      <artifactId>jsr250-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-lang</groupId>
+      <artifactId>commons-lang</artifactId>
+    </dependency>
+    <!--
+    <dependency>
+      <groupId>org.apache.directory.shared</groupId>
+      <artifactId>shared-ldap-client-api</artifactId>
+    </dependency>
+    -->
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-simple</artifactId>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+</project>

Propchange: archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/LdapUser.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/LdapUser.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/LdapUser.java (added)
+++ archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/LdapUser.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,246 @@
+package org.codehaus.plexus.redback.common.ldap;
+
+/*
+ * Copyright 2001-2007 The Codehaus.
+ *
+ * Licensed 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.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;
+    }
+
+}

Propchange: archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/LdapUser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/LdapUser.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/LdapUserMapper.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/LdapUserMapper.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/LdapUserMapper.java (added)
+++ archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/LdapUserMapper.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,310 @@
+package org.codehaus.plexus.redback.common.ldap;
+
+/*
+ * Copyright 2001-2007 The Codehaus.
+ *
+ * Licensed 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.codehaus.plexus.redback.users.User;
+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;
+    }
+}

Propchange: archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/LdapUserMapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/LdapUserMapper.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/LdapUtils.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/LdapUtils.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/LdapUtils.java (added)
+++ archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/LdapUtils.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,129 @@
+package org.codehaus.plexus.redback.common.ldap;
+
+/*
+ * Copyright 2001-2007 The Codehaus.
+ *
+ * Licensed 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;
+    }
+}

Propchange: archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/LdapUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/LdapUtils.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/MappingException.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/MappingException.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/MappingException.java (added)
+++ archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/MappingException.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,36 @@
+package org.codehaus.plexus.redback.common.ldap;
+
+/*
+ * Copyright 2001-2007 The Codehaus.
+ *
+ * Licensed 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 );
+    }
+
+}

Propchange: archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/MappingException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/MappingException.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/UserMapper.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/UserMapper.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/UserMapper.java (added)
+++ archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/UserMapper.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,61 @@
+package org.codehaus.plexus.redback.common.ldap;
+
+/*
+ * Copyright 2001-2007 The Codehaus.
+ *
+ * Licensed 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.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();
+
+}

Propchange: archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/UserMapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/UserMapper.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/UserUpdate.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/UserUpdate.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/UserUpdate.java (added)
+++ archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/UserUpdate.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,67 @@
+package org.codehaus.plexus.redback.common.ldap;
+
+/*
+ * Copyright 2001-2007 The Codehaus.
+ *
+ * Licensed 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 );
+    }
+
+
+
+}

Propchange: archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/UserUpdate.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/UserUpdate.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/connection/ConfigurableLdapConnectionFactory.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/connection/ConfigurableLdapConnectionFactory.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/connection/ConfigurableLdapConnectionFactory.java (added)
+++ archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/connection/ConfigurableLdapConnectionFactory.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,283 @@
+package org.codehaus.plexus.redback.common.ldap.connection;
+
+/*
+ * The MIT License
+ * Copyright (c) 2005, The Codehaus
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is furnished to do
+ * so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+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;
+    }
+}

Propchange: archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/connection/ConfigurableLdapConnectionFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/connection/ConfigurableLdapConnectionFactory.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/connection/LdapConnection.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/connection/LdapConnection.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/connection/LdapConnection.java (added)
+++ archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/connection/LdapConnection.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,273 @@
+package org.codehaus.plexus.redback.common.ldap.connection;
+
+/*
+ * The MIT License
+ * Copyright (c) 2005, The Codehaus
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is furnished to do
+ * so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+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;
+    }
+}

Propchange: archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/connection/LdapConnection.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/connection/LdapConnection.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/connection/LdapConnectionConfiguration.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/connection/LdapConnectionConfiguration.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/connection/LdapConnectionConfiguration.java (added)
+++ archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/connection/LdapConnectionConfiguration.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,348 @@
+package org.codehaus.plexus.redback.common.ldap.connection;
+/*
+ * The MIT License
+ * Copyright (c) 2005, The Codehaus
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is furnished to do
+ * so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+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() + "}";
+    }
+}

Propchange: archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/connection/LdapConnectionConfiguration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/codehaus/plexus/redback/common/ldap/connection/LdapConnectionConfiguration.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision