move LdapConnection to an interface
git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-core/trunk@1477971 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d1b77ab248
commit
4a57b05074
|
@ -21,6 +21,7 @@ package org.apache.archiva.redback.authentication.ldap;
|
|||
|
||||
import org.apache.archiva.redback.authentication.AbstractAuthenticator;
|
||||
import org.apache.archiva.redback.common.ldap.connection.DefaultLdapConnection;
|
||||
import org.apache.archiva.redback.common.ldap.connection.LdapConnection;
|
||||
import org.apache.archiva.redback.common.ldap.user.UserMapper;
|
||||
import org.apache.archiva.redback.common.ldap.connection.LdapConnectionFactory;
|
||||
import org.apache.archiva.redback.configuration.UserConfiguration;
|
||||
|
@ -103,8 +104,8 @@ public class LdapBindAuthenticator
|
|||
|
||||
log.debug( "Searching for users with filter: '{}' from base dn: {}", filter, mapper.getUserBaseDn() );
|
||||
|
||||
DefaultLdapConnection ldapConnection = null;
|
||||
DefaultLdapConnection authLdapConnection = null;
|
||||
LdapConnection ldapConnection = null;
|
||||
LdapConnection authLdapConnection = null;
|
||||
NamingEnumeration<SearchResult> results = null;
|
||||
try
|
||||
{
|
||||
|
@ -172,13 +173,13 @@ public class LdapBindAuthenticator
|
|||
return ( source instanceof PasswordBasedAuthenticationDataSource );
|
||||
}
|
||||
|
||||
private DefaultLdapConnection getLdapConnection()
|
||||
private LdapConnection getLdapConnection()
|
||||
throws LdapException
|
||||
{
|
||||
return connectionFactory.getConnection();
|
||||
}
|
||||
|
||||
private void closeLdapConnection( DefaultLdapConnection ldapConnection )
|
||||
private void closeLdapConnection( LdapConnection ldapConnection )
|
||||
{
|
||||
if ( ldapConnection != null )
|
||||
{
|
||||
|
|
|
@ -38,8 +38,10 @@ import java.util.Properties;
|
|||
* The configuration for a connection will not change.
|
||||
*
|
||||
* @author <a href="mailto:trygvis@inamo.no">trygvis</a>
|
||||
* @since 2.1
|
||||
*/
|
||||
public class DefaultLdapConnection
|
||||
implements LdapConnection
|
||||
{
|
||||
|
||||
private static LdapCtxFactory ctxFactory;// = new LdapCtxFactory();
|
||||
|
@ -132,6 +134,7 @@ public class DefaultLdapConnection
|
|||
// Connection Managment
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public Hashtable<Object, Object> getEnvironment()
|
||||
throws LdapException
|
||||
{
|
||||
|
@ -236,6 +239,7 @@ public class DefaultLdapConnection
|
|||
return env;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close()
|
||||
{
|
||||
try
|
||||
|
@ -259,16 +263,19 @@ public class DefaultLdapConnection
|
|||
// Utils
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public LdapConnectionConfiguration getConfiguration()
|
||||
{
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Rdn> getBaseDnRdns()
|
||||
{
|
||||
return baseDnRdns;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DirContext getDirContext()
|
||||
{
|
||||
return context;
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
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.directory.DirContext;
|
||||
import javax.naming.ldap.Rdn;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Olivier Lamy
|
||||
*/
|
||||
public interface LdapConnection
|
||||
{
|
||||
Hashtable<Object, Object> getEnvironment()
|
||||
throws LdapException;
|
||||
|
||||
void close();
|
||||
|
||||
LdapConnectionConfiguration getConfiguration();
|
||||
|
||||
List<Rdn> getBaseDnRdns();
|
||||
|
||||
DirContext getDirContext();
|
||||
}
|
|
@ -30,16 +30,16 @@ import javax.naming.spi.StateFactory;
|
|||
*/
|
||||
public interface LdapConnectionFactory
|
||||
{
|
||||
DefaultLdapConnection getConnection()
|
||||
LdapConnection getConnection()
|
||||
throws LdapException;
|
||||
|
||||
DefaultLdapConnection getConnection( LdapConnectionConfiguration ldapConnectionConfiguration )
|
||||
LdapConnection getConnection( LdapConnectionConfiguration ldapConnectionConfiguration )
|
||||
throws LdapException;
|
||||
|
||||
DefaultLdapConnection getConnection( Rdn subRdn )
|
||||
LdapConnection getConnection( Rdn subRdn )
|
||||
throws LdapException;
|
||||
|
||||
DefaultLdapConnection getConnection( String bindDn, String password )
|
||||
LdapConnection getConnection( String bindDn, String password )
|
||||
throws LdapException;
|
||||
|
||||
LdapName getBaseDnLdapName()
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
package org.apache.archiva.redback.common.ldap.role;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
@ -19,7 +20,7 @@ package org.apache.archiva.redback.common.ldap.role;
|
|||
*/
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.archiva.redback.common.ldap.connection.DefaultLdapConnection;
|
||||
import org.apache.archiva.redback.common.ldap.connection.LdapConnection;
|
||||
import org.apache.archiva.redback.common.ldap.connection.LdapConnectionFactory;
|
||||
import org.apache.archiva.redback.components.apacheds.ApacheDs;
|
||||
import org.apache.archiva.redback.policy.PasswordEncoder;
|
||||
|
@ -89,7 +90,7 @@ public class TestLdapRoleMapper
|
|||
List<String> roleNames =
|
||||
Arrays.asList( "Archiva System Administrator", "Internal Repo Manager", "Internal Repo Observer" );
|
||||
|
||||
DefaultLdapConnection ldapConnection;
|
||||
LdapConnection ldapConnection;
|
||||
|
||||
DirContext context;
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.apache.archiva.redback.rest.services;
|
|||
|
||||
import org.apache.archiva.redback.common.ldap.MappingException;
|
||||
import org.apache.archiva.redback.common.ldap.connection.DefaultLdapConnection;
|
||||
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.common.ldap.role.LdapRoleMapper;
|
||||
|
@ -67,7 +68,7 @@ public class DefaultLdapGroupMappingService
|
|||
public StringList getLdapGroups()
|
||||
throws RedbackServiceException
|
||||
{
|
||||
DefaultLdapConnection ldapConnection = null;
|
||||
LdapConnection ldapConnection = null;
|
||||
|
||||
DirContext context = null;
|
||||
|
||||
|
@ -170,7 +171,7 @@ public class DefaultLdapGroupMappingService
|
|||
// utils
|
||||
//------------------
|
||||
|
||||
protected void closeLdapConnection( DefaultLdapConnection ldapConnection )
|
||||
protected void closeLdapConnection( LdapConnection ldapConnection )
|
||||
{
|
||||
if ( ldapConnection != null )
|
||||
{
|
||||
|
|
|
@ -20,7 +20,7 @@ package org.apache.archiva.redback.rbac.ldap;
|
|||
*/
|
||||
|
||||
import org.apache.archiva.redback.common.ldap.MappingException;
|
||||
import org.apache.archiva.redback.common.ldap.connection.DefaultLdapConnection;
|
||||
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.common.ldap.role.LdapRoleMapper;
|
||||
|
@ -174,7 +174,7 @@ public class LdapRbacManager
|
|||
{
|
||||
if ( writableLdap )
|
||||
{
|
||||
DefaultLdapConnection ldapConnection = null;
|
||||
LdapConnection ldapConnection = null;
|
||||
DirContext context = null;
|
||||
try
|
||||
{
|
||||
|
@ -250,7 +250,7 @@ public class LdapRbacManager
|
|||
public List<Role> getAllRoles()
|
||||
throws RbacManagerException
|
||||
{
|
||||
DefaultLdapConnection ldapConnection = null;
|
||||
LdapConnection ldapConnection = null;
|
||||
DirContext context = null;
|
||||
try
|
||||
{
|
||||
|
@ -280,7 +280,7 @@ public class LdapRbacManager
|
|||
public List<UserAssignment> getAllUserAssignments()
|
||||
throws RbacManagerException
|
||||
{
|
||||
DefaultLdapConnection ldapConnection = null;
|
||||
LdapConnection ldapConnection = null;
|
||||
DirContext context = null;
|
||||
try
|
||||
{
|
||||
|
@ -313,7 +313,7 @@ public class LdapRbacManager
|
|||
}
|
||||
}
|
||||
|
||||
protected void closeLdapConnection( DefaultLdapConnection ldapConnection )
|
||||
protected void closeLdapConnection( LdapConnection ldapConnection )
|
||||
{
|
||||
if ( ldapConnection != null )
|
||||
{
|
||||
|
@ -420,7 +420,7 @@ public class LdapRbacManager
|
|||
throws RbacManagerException
|
||||
{
|
||||
|
||||
DefaultLdapConnection ldapConnection = null;
|
||||
LdapConnection ldapConnection = null;
|
||||
DirContext context = null;
|
||||
|
||||
try
|
||||
|
@ -528,7 +528,7 @@ public class LdapRbacManager
|
|||
{
|
||||
return role;
|
||||
}
|
||||
DefaultLdapConnection ldapConnection = null;
|
||||
LdapConnection ldapConnection = null;
|
||||
DirContext context = null;
|
||||
//verify it's a ldap group
|
||||
try
|
||||
|
@ -565,7 +565,7 @@ public class LdapRbacManager
|
|||
public Collection<Role> getUnassignedRoles( String username )
|
||||
throws RbacManagerException
|
||||
{
|
||||
DefaultLdapConnection ldapConnection = null;
|
||||
LdapConnection ldapConnection = null;
|
||||
|
||||
DirContext context = null;
|
||||
|
||||
|
@ -613,7 +613,7 @@ public class LdapRbacManager
|
|||
{
|
||||
return ua;
|
||||
}
|
||||
DefaultLdapConnection ldapConnection = null;
|
||||
LdapConnection ldapConnection = null;
|
||||
DirContext context = null;
|
||||
try
|
||||
{
|
||||
|
@ -786,7 +786,7 @@ public class LdapRbacManager
|
|||
rolesCache.remove( role.getName() );
|
||||
if ( writableLdap )
|
||||
{
|
||||
DefaultLdapConnection ldapConnection = null;
|
||||
LdapConnection ldapConnection = null;
|
||||
DirContext context = null;
|
||||
try
|
||||
{
|
||||
|
@ -868,7 +868,7 @@ public class LdapRbacManager
|
|||
{
|
||||
return true;
|
||||
}
|
||||
DefaultLdapConnection ldapConnection = null;
|
||||
LdapConnection ldapConnection = null;
|
||||
DirContext context = null;
|
||||
try
|
||||
{
|
||||
|
@ -918,7 +918,7 @@ public class LdapRbacManager
|
|||
{
|
||||
if ( writableLdap )
|
||||
{
|
||||
DefaultLdapConnection ldapConnection = null;
|
||||
LdapConnection ldapConnection = null;
|
||||
DirContext context = null;
|
||||
try
|
||||
{
|
||||
|
@ -956,7 +956,7 @@ public class LdapRbacManager
|
|||
{
|
||||
if ( writableLdap )
|
||||
{
|
||||
DefaultLdapConnection ldapConnection = null;
|
||||
LdapConnection ldapConnection = null;
|
||||
DirContext context = null;
|
||||
try
|
||||
{
|
||||
|
@ -985,7 +985,7 @@ public class LdapRbacManager
|
|||
public UserAssignment saveUserAssignment( UserAssignment userAssignment )
|
||||
throws RbacManagerException
|
||||
{
|
||||
DefaultLdapConnection ldapConnection = null;
|
||||
LdapConnection ldapConnection = null;
|
||||
DirContext context = null;
|
||||
try
|
||||
{
|
||||
|
@ -1052,7 +1052,7 @@ public class LdapRbacManager
|
|||
{
|
||||
return true;
|
||||
}
|
||||
DefaultLdapConnection ldapConnection = null;
|
||||
LdapConnection ldapConnection = null;
|
||||
DirContext context = null;
|
||||
try
|
||||
{
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.apache.archiva.redback.users.ldap;
|
|||
|
||||
|
||||
import org.apache.archiva.redback.common.ldap.connection.DefaultLdapConnection;
|
||||
import org.apache.archiva.redback.common.ldap.connection.LdapConnection;
|
||||
import org.apache.archiva.redback.common.ldap.user.LdapUser;
|
||||
import org.apache.archiva.redback.common.ldap.user.UserMapper;
|
||||
import org.apache.archiva.redback.configuration.UserConfiguration;
|
||||
|
@ -129,7 +130,7 @@ public class LdapUserManager
|
|||
return guestUser;
|
||||
}
|
||||
|
||||
DefaultLdapConnection ldapConnection = getLdapConnection();
|
||||
LdapConnection ldapConnection = getLdapConnection();
|
||||
try
|
||||
{
|
||||
DirContext context = ldapConnection.getDirContext();
|
||||
|
@ -168,7 +169,7 @@ public class LdapUserManager
|
|||
{
|
||||
clearFromCache( username );
|
||||
}
|
||||
DefaultLdapConnection ldapConnection = null;
|
||||
LdapConnection ldapConnection = null;
|
||||
try
|
||||
{
|
||||
ldapConnection = getLdapConnection();
|
||||
|
@ -211,7 +212,7 @@ public class LdapUserManager
|
|||
return ldapUser;
|
||||
}
|
||||
|
||||
DefaultLdapConnection ldapConnection = null;
|
||||
LdapConnection ldapConnection = null;
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -278,7 +279,7 @@ public class LdapUserManager
|
|||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
DefaultLdapConnection ldapConnection = null;
|
||||
LdapConnection ldapConnection = null;
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -329,7 +330,7 @@ public class LdapUserManager
|
|||
*/
|
||||
public List<User> getUsers()
|
||||
{
|
||||
DefaultLdapConnection ldapConnection = null;
|
||||
LdapConnection ldapConnection = null;
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -385,7 +386,7 @@ public class LdapUserManager
|
|||
clearFromCache( user.getUsername() );
|
||||
}
|
||||
|
||||
DefaultLdapConnection ldapConnection = null;
|
||||
LdapConnection ldapConnection = null;
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -429,7 +430,7 @@ public class LdapUserManager
|
|||
return true;
|
||||
}
|
||||
|
||||
DefaultLdapConnection ldapConnection = null;
|
||||
LdapConnection ldapConnection = null;
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -452,7 +453,7 @@ public class LdapUserManager
|
|||
}
|
||||
}
|
||||
|
||||
private DefaultLdapConnection getLdapConnection()
|
||||
private LdapConnection getLdapConnection()
|
||||
throws LdapException
|
||||
{
|
||||
try
|
||||
|
@ -466,7 +467,7 @@ public class LdapUserManager
|
|||
}
|
||||
}
|
||||
|
||||
private void closeLdapConnection( DefaultLdapConnection ldapConnection )
|
||||
private void closeLdapConnection( LdapConnection ldapConnection )
|
||||
{
|
||||
if ( ldapConnection != null )
|
||||
{
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.apache.archiva.redback.users.ldap;
|
|||
*/
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.archiva.redback.common.ldap.connection.LdapConnection;
|
||||
import org.apache.archiva.redback.policy.PasswordEncoder;
|
||||
import org.apache.archiva.redback.users.User;
|
||||
import org.apache.archiva.redback.common.ldap.connection.DefaultLdapConnection;
|
||||
|
@ -147,7 +148,8 @@ public class LdapUserManagerTest
|
|||
{
|
||||
assertNotNull( connectionFactory );
|
||||
|
||||
DefaultLdapConnection connection = null;
|
||||
LdapConnection connection = null;
|
||||
|
||||
try
|
||||
{
|
||||
connection = connectionFactory.getConnection();
|
||||
|
@ -168,7 +170,8 @@ public class LdapUserManagerTest
|
|||
public void testDirectUsersExistence()
|
||||
throws Exception
|
||||
{
|
||||
DefaultLdapConnection connection = null;
|
||||
LdapConnection connection = null;
|
||||
|
||||
try
|
||||
{
|
||||
connection = connectionFactory.getConnection();
|
||||
|
|
Loading…
Reference in New Issue