[DS-3046] NPE upon first LDAP login with autoregistration

This commit is contained in:
KevinVdV
2016-02-12 12:25:35 +01:00
parent 8b99d79ab4
commit 28e16fe49b

View File

@@ -24,7 +24,6 @@ import org.dspace.eperson.Group;
import org.dspace.eperson.service.EPersonService; import org.dspace.eperson.service.EPersonService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
/** /**
@@ -54,10 +53,8 @@ import org.springframework.beans.factory.annotation.Autowired;
* @author Larry Stone * @author Larry Stone
* @version $Revision$ * @version $Revision$
*/ */
public class AuthenticationServiceImpl implements AuthenticationService, InitializingBean public class AuthenticationServiceImpl implements AuthenticationService
{ {
/** List of authentication methods, highest precedence first. */
protected List<AuthenticationMethod> methodStack;
/** SLF4J logging category */ /** SLF4J logging category */
private final Logger log = (Logger) LoggerFactory.getLogger(AuthenticationServiceImpl.class); private final Logger log = (Logger) LoggerFactory.getLogger(AuthenticationServiceImpl.class);
@@ -66,9 +63,8 @@ public class AuthenticationServiceImpl implements AuthenticationService, Initial
protected EPersonService ePersonService; protected EPersonService ePersonService;
@Override public List<AuthenticationMethod> getAuthenticationMethodStack() {
public void afterPropertiesSet() throws Exception { return Arrays.asList((AuthenticationMethod[])CoreServiceFactory.getInstance().getPluginService().getPluginSequence(AuthenticationMethod.class));
methodStack = Arrays.asList((AuthenticationMethod[])CoreServiceFactory.getInstance().getPluginService().getPluginSequence(AuthenticationMethod.class));
} }
@Override @Override
@@ -104,7 +100,7 @@ public class AuthenticationServiceImpl implements AuthenticationService, Initial
int bestRet = AuthenticationMethod.BAD_ARGS; int bestRet = AuthenticationMethod.BAD_ARGS;
// return on first success, otherwise "best" outcome. // return on first success, otherwise "best" outcome.
for (AuthenticationMethod aMethodStack : methodStack) { for (AuthenticationMethod aMethodStack : getAuthenticationMethodStack()) {
if (!implicitOnly || aMethodStack.isImplicit()) { if (!implicitOnly || aMethodStack.isImplicit()) {
int ret = 0; int ret = 0;
try { try {
@@ -138,9 +134,9 @@ public class AuthenticationServiceImpl implements AuthenticationService, Initial
String username) String username)
throws SQLException throws SQLException
{ {
for (int i = 0; i < methodStack.size(); ++i) for (AuthenticationMethod method : getAuthenticationMethodStack())
{ {
if (methodStack.get(i).canSelfRegister(context, request, username)) if (method.canSelfRegister(context, request, username))
{ {
return true; return true;
} }
@@ -154,9 +150,9 @@ public class AuthenticationServiceImpl implements AuthenticationService, Initial
String username) String username)
throws SQLException throws SQLException
{ {
for (int i = 0; i < methodStack.size(); ++i) for (AuthenticationMethod method : getAuthenticationMethodStack())
{ {
if (methodStack.get(i).allowSetPassword(context, request, username)) if (method.allowSetPassword(context, request, username))
{ {
return true; return true;
} }
@@ -170,7 +166,7 @@ public class AuthenticationServiceImpl implements AuthenticationService, Initial
EPerson eperson) EPerson eperson)
throws SQLException throws SQLException
{ {
for (AuthenticationMethod method : methodStack) for (AuthenticationMethod method : getAuthenticationMethodStack())
{ {
method.initEPerson(context, request, eperson); method.initEPerson(context, request, eperson);
} }
@@ -184,9 +180,9 @@ public class AuthenticationServiceImpl implements AuthenticationService, Initial
List<Group> result = new ArrayList<>(); List<Group> result = new ArrayList<>();
int totalLen = 0; int totalLen = 0;
for (int i = 0; i < methodStack.size(); ++i) for (AuthenticationMethod method : getAuthenticationMethodStack())
{ {
List<Group> gl = methodStack.get(i).getSpecialGroups(context, request); List<Group> gl = method.getSpecialGroups(context, request);
if (gl.size() > 0) if (gl.size() > 0)
{ {
result.addAll(gl); result.addAll(gl);
@@ -200,6 +196,6 @@ public class AuthenticationServiceImpl implements AuthenticationService, Initial
@Override @Override
public Iterator<AuthenticationMethod> authenticationMethodIterator() public Iterator<AuthenticationMethod> authenticationMethodIterator()
{ {
return methodStack.iterator(); return getAuthenticationMethodStack().iterator();
} }
} }