DSpace refactored service api

This commit is contained in:
KevinVdV
2014-11-08 09:19:09 +01:00
parent fcb3717aad
commit 54222f3c1d
1145 changed files with 52233 additions and 57064 deletions

View File

@@ -29,15 +29,19 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.collections.ListUtils;
import org.apache.log4j.Logger;
import org.dspace.authenticate.AuthenticationMethod;
import org.dspace.authenticate.AuthenticationManager;
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;
import org.dspace.eperson.Group;
import org.dspace.eperson.factory.EPersonServiceFactory;
import org.dspace.eperson.service.EPersonService;
import org.dspace.eperson.service.GroupService;
/**
* Implicit authentication method that gets credentials from the X.509 client
@@ -111,6 +115,11 @@ public class X509Authentication implements AuthenticationMethod
private static String loginPageURL = null;
protected AuthenticationService authenticationService = AuthenticateServiceFactory.getInstance().getAuthenticationService();
protected EPersonService ePersonService = EPersonServiceFactory.getInstance().getEPersonService();
protected GroupService groupService = EPersonServiceFactory.getInstance().getGroupService();
/**
* Initialization: Set caPublicKey and/or keystore. This loads the
* information needed to check if a client cert presented is valid and
@@ -373,6 +382,7 @@ public class X509Authentication implements AuthenticationMethod
* advantage of a Web certificate infrastructure with many more users than
* are already known by DSpace.
*/
@Override
public boolean canSelfRegister(Context context, HttpServletRequest request,
String username) throws SQLException
{
@@ -383,6 +393,7 @@ public class X509Authentication implements AuthenticationMethod
/**
* Nothing extra to initialize.
*/
@Override
public void initEPerson(Context context, HttpServletRequest request,
EPerson eperson) throws SQLException
{
@@ -391,6 +402,7 @@ public class X509Authentication implements AuthenticationMethod
/**
* We don't use EPerson password so there is no reason to change it.
*/
@Override
public boolean allowSetPassword(Context context,
HttpServletRequest request, String username) throws SQLException
{
@@ -400,6 +412,7 @@ public class X509Authentication implements AuthenticationMethod
/**
* Returns true, this is an implicit method.
*/
@Override
public boolean isImplicit()
{
return true;
@@ -477,12 +490,13 @@ public class X509Authentication implements AuthenticationMethod
* @return An int array of group IDs
*
*/
public int[] getSpecialGroups(Context context, HttpServletRequest request)
@Override
public List<Group> getSpecialGroups(Context context, HttpServletRequest request)
throws SQLException
{
if (request == null)
{
return new int[0];
return ListUtils.EMPTY_LIST;
}
Boolean authenticated = false;
@@ -493,7 +507,7 @@ public class X509Authentication implements AuthenticationMethod
if (authenticated)
{
List<String> groupNames = getX509Groups();
List<Integer> groupIDs = new ArrayList<Integer>();
List<Group> groups = new ArrayList<>();
if (groupNames != null)
{
@@ -501,10 +515,10 @@ public class X509Authentication implements AuthenticationMethod
{
if (groupName != null)
{
Group group = Group.findByName(context, groupName);
Group group = groupService.findByName(context, groupName);
if (group != null)
{
groupIDs.add(Integer.valueOf(group.getID()));
groups.add(group);
}
else
{
@@ -516,33 +530,10 @@ public class X509Authentication implements AuthenticationMethod
}
}
int[] results = new int[groupIDs.size()];
for (int i = 0; i < groupIDs.size(); i++)
{
results[i] = (groupIDs.get(i)).intValue();
}
if (log.isDebugEnabled())
{
StringBuffer gsb = new StringBuffer();
for (int i = 0; i < results.length; i++)
{
if (i > 0)
{
gsb.append(",");
}
gsb.append(results[i]);
}
log.debug(LogManager.getHeader(context, "authenticated",
"special_groups=" + gsb.toString()));
}
return results;
return groups;
}
return new int[0];
return ListUtils.EMPTY_LIST;
}
/**
@@ -565,6 +556,7 @@ public class X509Authentication implements AuthenticationMethod
*
* @return One of: SUCCESS, BAD_CREDENTIALS, NO_SUCH_USER, BAD_ARGS
*/
@Override
public int authenticate(Context context, String username, String password,
String realm, HttpServletRequest request) throws SQLException
{
@@ -599,7 +591,7 @@ public class X509Authentication implements AuthenticationMethod
EPerson eperson = null;
if (email != null)
{
eperson = EPerson.findByEmail(context, email);
eperson = ePersonService.findByEmail(context, email);
}
if (eperson == null)
{
@@ -613,13 +605,13 @@ public class X509Authentication implements AuthenticationMethod
// TEMPORARILY turn off authorisation
context.setIgnoreAuthorization(true);
eperson = EPerson.create(context);
eperson = ePersonService.create(context);
eperson.setEmail(email);
eperson.setCanLogIn(true);
AuthenticationManager.initEPerson(context, request,
authenticationService.initEPerson(context, request,
eperson);
eperson.update();
context.commit();
ePersonService.update(context, eperson);
context.dispatchEvents();
context.setIgnoreAuthorization(false);
context.setCurrentUser(eperson);
setSpecialGroupsFlag(request, email);
@@ -679,6 +671,7 @@ public class X509Authentication implements AuthenticationMethod
*
* @return fully-qualified URL
*/
@Override
public String loginPageURL(Context context, HttpServletRequest request,
HttpServletResponse response)
{
@@ -694,6 +687,7 @@ public class X509Authentication implements AuthenticationMethod
*
* @return Message key to look up in i18n message catalog.
*/
@Override
public String loginPageTitle(Context context)
{
return loginPageTitle;