mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-10 03:23:13 +00:00
Remove long-deprecated ConfigurationManager.
This commit is contained in:
@@ -33,7 +33,6 @@ import org.apache.logging.log4j.Logger;
|
||||
import org.dspace.authenticate.factory.AuthenticateServiceFactory;
|
||||
import org.dspace.authenticate.service.AuthenticationService;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.core.ConfigurationManager;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.core.LogManager;
|
||||
import org.dspace.eperson.EPerson;
|
||||
@@ -41,19 +40,28 @@ import org.dspace.eperson.Group;
|
||||
import org.dspace.eperson.factory.EPersonServiceFactory;
|
||||
import org.dspace.eperson.service.EPersonService;
|
||||
import org.dspace.eperson.service.GroupService;
|
||||
import org.dspace.services.ConfigurationService;
|
||||
import org.dspace.services.factory.DSpaceServicesFactory;
|
||||
|
||||
/**
|
||||
* This combined LDAP authentication method supersedes both the 'LDAPAuthentication'
|
||||
* and the 'LDAPHierarchicalAuthentication' methods. It's capable of both:
|
||||
* - authenticaton against a flat LDAP tree where all users are in the same unit
|
||||
* (if search.user or search.password is not set)
|
||||
* - authentication against structured hierarchical LDAP trees of users.
|
||||
* <ul>
|
||||
* <li>authentication against a flat LDAP tree where all users are in the same unit
|
||||
* (if {@code search.user} or {@code search.password} is not set)</li>
|
||||
* <li>authentication against structured hierarchical LDAP trees of users.</li>
|
||||
* </ul>
|
||||
* An initial bind is required using a user name and password in order to
|
||||
* search the tree and find the DN of the user. A second bind is then required to
|
||||
* check the credentials of the user by binding directly to their DN.
|
||||
*
|
||||
* @author Stuart Lewis, Chris Yates, Alex Barbieri, Flavio Botelho, Reuben Pasquini, Samuel Ottenhoff, Ivan Masár
|
||||
* @version $Revision$
|
||||
* @author Stuart Lewis
|
||||
* @author Chris Yates
|
||||
* @author Alex Barbieri
|
||||
* @author Flavio Botelho
|
||||
* @author Reuben Pasquini
|
||||
* @author Samuel Ottenhoff
|
||||
* @author Ivan Masár
|
||||
*/
|
||||
public class LDAPAuthentication
|
||||
implements AuthenticationMethod {
|
||||
@@ -61,13 +69,17 @@ public class LDAPAuthentication
|
||||
/**
|
||||
* log4j category
|
||||
*/
|
||||
private static Logger log = org.apache.logging.log4j.LogManager.getLogger(LDAPAuthentication.class);
|
||||
|
||||
protected AuthenticationService authenticationService = AuthenticateServiceFactory.getInstance()
|
||||
.getAuthenticationService();
|
||||
protected EPersonService ePersonService = EPersonServiceFactory.getInstance().getEPersonService();
|
||||
protected GroupService groupService = EPersonServiceFactory.getInstance().getGroupService();
|
||||
private static final Logger log
|
||||
= org.apache.logging.log4j.LogManager.getLogger(LDAPAuthentication.class);
|
||||
|
||||
protected AuthenticationService authenticationService
|
||||
= AuthenticateServiceFactory.getInstance().getAuthenticationService();
|
||||
protected EPersonService ePersonService
|
||||
= EPersonServiceFactory.getInstance().getEPersonService();
|
||||
protected GroupService groupService
|
||||
= EPersonServiceFactory.getInstance().getGroupService();
|
||||
protected ConfigurationService configurationService
|
||||
= DSpaceServicesFactory.getInstance().getConfigurationService();
|
||||
|
||||
/**
|
||||
* Let a real auth method return true if it wants.
|
||||
@@ -80,7 +92,7 @@ public class LDAPAuthentication
|
||||
String username)
|
||||
throws SQLException {
|
||||
// Looks to see if autoregister is set or not
|
||||
return ConfigurationManager.getBooleanProperty("authentication-ldap", "autoregister");
|
||||
return configurationService.getBooleanProperty("authentication-ldap.autoregister");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -128,7 +140,7 @@ public class LDAPAuthentication
|
||||
// ensures they are LDAP users
|
||||
try {
|
||||
if (!context.getCurrentUser().getNetid().equals("")) {
|
||||
String groupName = ConfigurationManager.getProperty("authentication-ldap", "login.specialgroup");
|
||||
String groupName = configurationService.getProperty("authentication-ldap.login.specialgroup");
|
||||
if ((groupName != null) && (!groupName.trim().equals(""))) {
|
||||
Group ldapGroup = groupService.findByName(context, groupName);
|
||||
if (ldapGroup == null) {
|
||||
@@ -142,7 +154,7 @@ public class LDAPAuthentication
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception npe) {
|
||||
} catch (SQLException ex) {
|
||||
// The user is not an LDAP user, so we don't need to worry about them
|
||||
}
|
||||
return Collections.EMPTY_LIST;
|
||||
@@ -205,11 +217,11 @@ public class LDAPAuthentication
|
||||
SpeakerToLDAP ldap = new SpeakerToLDAP(log);
|
||||
|
||||
// Get the DN of the user
|
||||
boolean anonymousSearch = ConfigurationManager.getBooleanProperty("authentication-ldap", "search.anonymous");
|
||||
String adminUser = ConfigurationManager.getProperty("authentication-ldap", "search.user");
|
||||
String adminPassword = ConfigurationManager.getProperty("authentication-ldap", "search.password");
|
||||
String objectContext = ConfigurationManager.getProperty("authentication-ldap", "object_context");
|
||||
String idField = ConfigurationManager.getProperty("authentication-ldap", "id_field");
|
||||
boolean anonymousSearch = configurationService.getBooleanProperty("authentication-ldap.search.anonymous");
|
||||
String adminUser = configurationService.getProperty("authentication-ldap.search.user");
|
||||
String adminPassword = configurationService.getProperty("authentication-ldap.search.password");
|
||||
String objectContext = configurationService.getProperty("authentication-ldap.object_context");
|
||||
String idField = configurationService.getProperty("authentication-ldap.id_field");
|
||||
String dn = "";
|
||||
|
||||
// If adminUser is blank and anonymous search is not allowed, then we can't search so construct the DN
|
||||
@@ -263,9 +275,8 @@ public class LDAPAuthentication
|
||||
if (StringUtils.isEmpty(email)) {
|
||||
// If no email, check if we have a "netid_email_domain". If so, append it to the netid to create
|
||||
// email
|
||||
if (StringUtils
|
||||
.isNotEmpty(ConfigurationManager.getProperty("authentication-ldap", "netid_email_domain"))) {
|
||||
email = netid + ConfigurationManager.getProperty("authentication-ldap", "netid_email_domain");
|
||||
if (configurationService.hasProperty("authentication-ldap.netid_email_domain")) {
|
||||
email = netid + configurationService.getProperty("authentication-ldap.netid_email_domain");
|
||||
} else {
|
||||
// We don't have a valid email address. We'll default it to 'netid' but log a warning
|
||||
log.warn(LogManager.getHeader(context, "autoregister",
|
||||
@@ -365,21 +376,34 @@ public class LDAPAuthentication
|
||||
/**
|
||||
* LDAP settings
|
||||
*/
|
||||
String ldap_provider_url = ConfigurationManager.getProperty("authentication-ldap", "provider_url");
|
||||
String ldap_id_field = ConfigurationManager.getProperty("authentication-ldap", "id_field");
|
||||
String ldap_search_context = ConfigurationManager.getProperty("authentication-ldap", "search_context");
|
||||
String ldap_search_scope = ConfigurationManager.getProperty("authentication-ldap", "search_scope");
|
||||
final String ldap_provider_url;
|
||||
final String ldap_id_field;
|
||||
final String ldap_search_context;
|
||||
final String ldap_search_scope;
|
||||
|
||||
String ldap_email_field = ConfigurationManager.getProperty("authentication-ldap", "email_field");
|
||||
String ldap_givenname_field = ConfigurationManager.getProperty("authentication-ldap", "givenname_field");
|
||||
String ldap_surname_field = ConfigurationManager.getProperty("authentication-ldap", "surname_field");
|
||||
String ldap_phone_field = ConfigurationManager.getProperty("authentication-ldap", "phone_field");
|
||||
String ldap_group_field = ConfigurationManager.getProperty("authentication-ldap", "login.groupmap.attribute");
|
||||
final String ldap_email_field;
|
||||
final String ldap_givenname_field;
|
||||
final String ldap_surname_field;
|
||||
final String ldap_phone_field;
|
||||
final String ldap_group_field;
|
||||
|
||||
boolean useTLS = ConfigurationManager.getBooleanProperty("authentication-ldap", "starttls", false);
|
||||
final boolean useTLS;
|
||||
|
||||
SpeakerToLDAP(Logger thelog) {
|
||||
ConfigurationService configurationService
|
||||
= DSpaceServicesFactory.getInstance().getConfigurationService();
|
||||
log = thelog;
|
||||
|
||||
ldap_provider_url = configurationService.getProperty("authentication-ldap.provider_url");
|
||||
ldap_id_field = configurationService.getProperty("authentication-ldap.id_field");
|
||||
ldap_search_context = configurationService.getProperty("authentication-ldap.search_context");
|
||||
ldap_search_scope = configurationService.getProperty("authentication-ldap.search_scope");
|
||||
ldap_email_field = configurationService.getProperty("authentication-ldap.email_field");
|
||||
ldap_givenname_field = configurationService.getProperty("authentication-ldap.givenname_field");
|
||||
ldap_surname_field = configurationService.getProperty("authentication-ldap.surname_field");
|
||||
ldap_phone_field = configurationService.getProperty("authentication-ldap.phone_field");
|
||||
ldap_group_field = configurationService.getProperty("authentication-ldap.login.groupmap.attribute");
|
||||
useTLS = configurationService.getBooleanProperty("authentication-ldap.starttls", false);
|
||||
}
|
||||
|
||||
protected String getDNOfUser(String adminUser, String adminPassword, Context context, String netid) {
|
||||
@@ -399,7 +423,8 @@ public class LDAPAuthentication
|
||||
}
|
||||
|
||||
// Set up environment for creating initial context
|
||||
Hashtable<String, String> env = new Hashtable<String, String>();
|
||||
@SuppressWarnings("UseOfObsoleteCollectionType")
|
||||
Hashtable<String, String> env = new Hashtable<>();
|
||||
env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
|
||||
env.put(javax.naming.Context.PROVIDER_URL, ldap_provider_url);
|
||||
|
||||
@@ -447,7 +472,7 @@ public class LDAPAuthentication
|
||||
SearchControls ctrls = new SearchControls();
|
||||
ctrls.setSearchScope(ldap_search_scope_value);
|
||||
|
||||
String searchName = "";
|
||||
String searchName;
|
||||
if (useTLS) {
|
||||
searchName = ldap_search_context;
|
||||
} else {
|
||||
@@ -555,7 +580,8 @@ public class LDAPAuthentication
|
||||
|
||||
|
||||
// Set up environment for creating initial context
|
||||
Hashtable<String, String> env = new Hashtable<String, String>();
|
||||
@SuppressWarnings("UseOfObsoleteCollectionType")
|
||||
Hashtable<String, String> env = new Hashtable<>();
|
||||
env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
|
||||
"com.sun.jndi.ldap.LdapCtxFactory");
|
||||
env.put(javax.naming.Context.PROVIDER_URL, ldap_provider_url);
|
||||
@@ -652,7 +678,7 @@ public class LDAPAuthentication
|
||||
if (StringUtils.isNotBlank(dn)) {
|
||||
System.out.println("dn:" + dn);
|
||||
int i = 1;
|
||||
String groupMap = ConfigurationManager.getProperty("authentication-ldap", "login.groupmap." + i);
|
||||
String groupMap = configurationService.getProperty("authentication-ldap", "login.groupmap." + i);
|
||||
|
||||
boolean cmp;
|
||||
|
||||
@@ -692,7 +718,7 @@ public class LDAPAuthentication
|
||||
}
|
||||
}
|
||||
|
||||
groupMap = ConfigurationManager.getProperty("authentication-ldap", "login.groupmap." + ++i);
|
||||
groupMap = configurationService.getProperty("authentication-ldap", "login.groupmap." + ++i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user