Merge pull request #1293 from KevinVdV/DS-3046-service-init-ldap

[DS-3046] NPE upon first LDAP login with autoregistration
This commit is contained in:
helix84
2016-02-12 12:42:08 +01:00

View File

@@ -24,7 +24,6 @@ import org.dspace.eperson.Group;
import org.dspace.eperson.service.EPersonService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
/**
@@ -54,10 +53,8 @@ import org.springframework.beans.factory.annotation.Autowired;
* @author Larry Stone
* @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 */
private final Logger log = (Logger) LoggerFactory.getLogger(AuthenticationServiceImpl.class);
@@ -70,9 +67,8 @@ public class AuthenticationServiceImpl implements AuthenticationService, Initial
}
@Override
public void afterPropertiesSet() throws Exception {
methodStack = Arrays.asList((AuthenticationMethod[])CoreServiceFactory.getInstance().getPluginService().getPluginSequence(AuthenticationMethod.class));
public List<AuthenticationMethod> getAuthenticationMethodStack() {
return Arrays.asList((AuthenticationMethod[])CoreServiceFactory.getInstance().getPluginService().getPluginSequence(AuthenticationMethod.class));
}
@Override
@@ -108,7 +104,7 @@ public class AuthenticationServiceImpl implements AuthenticationService, Initial
int bestRet = AuthenticationMethod.BAD_ARGS;
// return on first success, otherwise "best" outcome.
for (AuthenticationMethod aMethodStack : methodStack) {
for (AuthenticationMethod aMethodStack : getAuthenticationMethodStack()) {
if (!implicitOnly || aMethodStack.isImplicit()) {
int ret = 0;
try {
@@ -142,9 +138,9 @@ public class AuthenticationServiceImpl implements AuthenticationService, Initial
String username)
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;
}
@@ -158,9 +154,9 @@ public class AuthenticationServiceImpl implements AuthenticationService, Initial
String username)
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;
}
@@ -174,7 +170,7 @@ public class AuthenticationServiceImpl implements AuthenticationService, Initial
EPerson eperson)
throws SQLException
{
for (AuthenticationMethod method : methodStack)
for (AuthenticationMethod method : getAuthenticationMethodStack())
{
method.initEPerson(context, request, eperson);
}
@@ -188,9 +184,9 @@ public class AuthenticationServiceImpl implements AuthenticationService, Initial
List<Group> result = new ArrayList<>();
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)
{
result.addAll(gl);
@@ -204,6 +200,6 @@ public class AuthenticationServiceImpl implements AuthenticationService, Initial
@Override
public Iterator<AuthenticationMethod> authenticationMethodIterator()
{
return methodStack.iterator();
return getAuthenticationMethodStack().iterator();
}
}