mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-15 14:03:17 +00:00
Add a null check when assigning ldap groups
Prevent NullReferenceException by checking if the group list is null Fixes #8920
This commit is contained in:
@@ -713,8 +713,8 @@ public class LDAPAuthentication
|
|||||||
private void assignGroups(String dn, ArrayList<String> group, Context context) {
|
private void assignGroups(String dn, ArrayList<String> group, Context context) {
|
||||||
if (StringUtils.isNotBlank(dn)) {
|
if (StringUtils.isNotBlank(dn)) {
|
||||||
System.out.println("dn:" + dn);
|
System.out.println("dn:" + dn);
|
||||||
int i = 1;
|
int groupmapIndex = 1;
|
||||||
String groupMap = configurationService.getProperty("authentication-ldap.login.groupmap." + i);
|
String groupMap = configurationService.getProperty("authentication-ldap.login.groupmap." + groupmapIndex);
|
||||||
boolean cmp;
|
boolean cmp;
|
||||||
|
|
||||||
|
|
||||||
@@ -725,6 +725,13 @@ public class LDAPAuthentication
|
|||||||
String ldapSearchString = t[0];
|
String ldapSearchString = t[0];
|
||||||
String dspaceGroupName = t[1];
|
String dspaceGroupName = t[1];
|
||||||
|
|
||||||
|
if (group == null) {
|
||||||
|
cmp = StringUtils.containsIgnoreCase(dn, ldapSearchString + ",");
|
||||||
|
|
||||||
|
if (cmp) {
|
||||||
|
assignGroup(context, groupmapIndex, dspaceGroupName);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
// list of strings with dn from LDAP groups
|
// list of strings with dn from LDAP groups
|
||||||
// inner loop
|
// inner loop
|
||||||
Iterator<String> groupIterator = group.iterator();
|
Iterator<String> groupIterator = group.iterator();
|
||||||
@@ -741,7 +748,29 @@ public class LDAPAuthentication
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (cmp) {
|
if (cmp) {
|
||||||
// assign user to this group
|
assignGroup(context, groupmapIndex, dspaceGroupName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
groupMap = configurationService.getProperty("authentication-ldap.login.groupmap." + ++groupmapIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the current authenticated user to the specified group
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* DSpace context
|
||||||
|
*
|
||||||
|
* @param groupmapIndex
|
||||||
|
* authentication-ldap.login.groupmap.* key index defined in dspace.cfg
|
||||||
|
*
|
||||||
|
* @param dspaceGroupName
|
||||||
|
* The DSpace group to add the user to
|
||||||
|
*/
|
||||||
|
private void assignGroup(Context context, int groupmapIndex, String dspaceGroupName) {
|
||||||
try {
|
try {
|
||||||
Group ldapGroup = groupService.findByName(context, dspaceGroupName);
|
Group ldapGroup = groupService.findByName(context, dspaceGroupName);
|
||||||
if (ldapGroup != null) {
|
if (ldapGroup != null) {
|
||||||
@@ -751,7 +780,7 @@ public class LDAPAuthentication
|
|||||||
// The group does not exist
|
// The group does not exist
|
||||||
log.warn(LogHelper.getHeader(context,
|
log.warn(LogHelper.getHeader(context,
|
||||||
"ldap_assignGroupsBasedOnLdapDn",
|
"ldap_assignGroupsBasedOnLdapDn",
|
||||||
"Group defined in authentication-ldap.login.groupmap." + i
|
"Group defined in authentication-ldap.login.groupmap." + groupmapIndex
|
||||||
+ " does not exist :: " + dspaceGroupName));
|
+ " does not exist :: " + dspaceGroupName));
|
||||||
}
|
}
|
||||||
} catch (AuthorizeException ae) {
|
} catch (AuthorizeException ae) {
|
||||||
@@ -764,12 +793,6 @@ public class LDAPAuthentication
|
|||||||
dspaceGroupName));
|
dspaceGroupName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
groupMap = configurationService.getProperty("authentication-ldap.login.groupmap." + ++i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isUsed(final Context context, final HttpServletRequest request) {
|
public boolean isUsed(final Context context, final HttpServletRequest request) {
|
||||||
|
Reference in New Issue
Block a user