Refactoring of the lookup/json-mess, this is slightly experimental and the code base is so messy

it will likely end up needing a total re-write at some point.
Note: this currently fails many unit-tests due to some weird stuff in the development branch, needs to be fixed.
This commit is contained in:
Robin Eklund 2011-08-05 16:58:47 +02:00
parent e9273a97eb
commit d15f25e509
22 changed files with 142 additions and 134 deletions

@ -22,6 +22,8 @@ import se.su.dsv.scipro.data.dataobjects.Project;
import se.su.dsv.scipro.data.dataobjects.User;
import se.su.dsv.scipro.data.dataobjects.UserSettings;
import se.su.dsv.scipro.json.IUserLookupFromUsername;
import se.su.dsv.scipro.json.RemoteLookupOptions;
import se.su.dsv.scipro.json.RemoteLookupOptions.LOOKUP_DEPTH;
import se.su.dsv.scipro.security.auth.Authenticator;
import se.su.dsv.scipro.security.auth.roles.Admin;
import se.su.dsv.scipro.security.auth.roles.DefaultRole;
@ -191,7 +193,6 @@ public class SciProSession extends WebSession {
// With this userSettings.created() will return a users first login date and userSettings.modified() will return last login
userSettings.setLastModified(new Date());
userSettings = userSettingsDao.save(userSettings);
logger.info("User: "+getLoggedInIdentity()+ " logged in to "+this.getApplication().getClass().getSimpleName()+
" as: "+user.getFirstName()+" "+user.getLastName()+" "+user.getUserNames()+ " at: "+new Date());
loggedIn = true;
@ -265,7 +266,7 @@ public class SciProSession extends WebSession {
return false;
}
private User doUserLookup(final String username, final String realm) {
final User u = userLookupFromUsername.lookup(new KeyValuePair<String>(username,realm));
final User u = userLookupFromUsername.lookup(new KeyValuePair<String>(username,realm), new RemoteLookupOptions(LOOKUP_DEPTH.PROJECT_AND_PARTICIPANTS));
if(u == null)
logger.warn(username + " authenticated successfully, but the user was not available from remote system.");
return u;

@ -22,6 +22,8 @@ public interface Dao<T extends DomainObject>
public T reLoad(T object);
public void refresh(T object);
public List<T> findAll(int first, int count);
public List<T> findAll(int first, int count, String orderBy);

@ -56,6 +56,11 @@ public abstract class AbstractDaoJPAImp<T extends DomainObject> extends JpaDaoSu
else
return null;
}
@Transactional(readOnly=true)
public void refresh(T object){
if(object != null)
getJpaTemplate().refresh(object);
}
@Transactional( readOnly=false )
public T save(T object){

@ -8,7 +8,6 @@ import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.OneToMany;
import javax.persistence.Table;
@ -102,6 +101,9 @@ public class User extends LazyDeletableDomainObject implements Comparable<User>,
return emailAddress;
}
public void addUserName(Username username){
this.usernames.add(username);
}
public void setUserNames(Set<Username> usernames) {
this.usernames = usernames;

@ -73,6 +73,8 @@ public class Username extends DomainObject {
public void setUser(User user) {
this.user = user;
if(user!=null)
user.addUserName(this);
}
@Override

@ -16,13 +16,12 @@ abstract class DefaultUserLookupBase{
@Autowired
protected UserDao userDao;
@Autowired
protected JsonUserResponseHandler userResponseHandler;
private JsonUserResponseHandler userResponseHandler;
@Autowired
protected ApplicationSettings settings;
private ApplicationSettings settings;
protected boolean doRemoteRequest(final Map<String,String> params){
userResponseHandler.setLogResult(true);
RequestSender request = new RequestSender(userResponseHandler, settings.getRemoteLookupUrl(), params, RequestSender.REQUEST_TYPE_POST);
protected boolean doRemoteRequest(final Map<String,String> params, final RemoteLookupOptions options){
RequestSender request = new RequestSender(userResponseHandler, settings.getRemoteLookupUrl(), params, options, RequestSender.REQUEST_TYPE.POST);
try{
request.processRequest();
} catch (final IOException e){

@ -7,6 +7,7 @@ import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import se.su.dsv.scipro.data.dataobjects.User;
import se.su.dsv.scipro.json.RemoteLookupOptions.LOOKUP_DEPTH;
/**
* Default implementation of IUserLookupFromIdentifier queries remote defined by ApplicationSettings via JSon requests.
@ -15,18 +16,20 @@ import se.su.dsv.scipro.data.dataobjects.User;
public class DefaultUserLookupFromIdentifier extends DefaultUserLookupBase implements IUserLookupFromIdentifier {
private Logger logger = Logger.getLogger(DefaultUserLookupFromIdentifier.class);
public User lookup(final Long identifier){
public User lookup(final Long identifier, final RemoteLookupOptions options){
if(identifier == null){
throw new IllegalStateException("null values for user parameter not allowed");
}
logger.debug("Starting remote lookup for: " + identifier);
final Map<String, String> params = new HashMap<String, String>();
params.put("userid", identifier.toString());
if(!doRemoteRequest(params))
if(!doRemoteRequest(params,options)){
logger.warn("Remote lookup failed for identifier: "+identifier);
return null;
}
final User u = userDao.getUserByIdentifier(identifier);
if(u != null)
logger.info("Successfully imported user/username from remote system: " + u.getFirstName() + " " + u.getLastName() + "("+identifier+") id: " + u.getId());
logger.info("Successfully imported user/username from remote system: " + u.getId() + " " +u.getUserNames());
else
logger.warn("Failed to import a valid user from remote system: "+identifier);
return u;

@ -16,7 +16,7 @@ import se.su.dsv.scipro.util.KeyValuePair;
public class DefaultUserLookupFromUsername extends DefaultUserLookupBase implements IUserLookupFromUsername {
private Logger logger = Logger.getLogger(DefaultUserLookupFromUsername.class);
public User lookup(final KeyValuePair<String> userAtRealm){
public User lookup(final KeyValuePair<String> userAtRealm, final RemoteLookupOptions options){
if(userAtRealm == null || userAtRealm.getKey() == null){
throw new IllegalStateException("null values for user parameter not allowed");
}
@ -26,11 +26,11 @@ public class DefaultUserLookupFromUsername extends DefaultUserLookupBase impleme
final Map<String, String> params = new HashMap<String, String>();
params.put("username", user);
params.put("realm", realm);
if(!doRemoteRequest(params))
if(!doRemoteRequest(params,options))
return null;
final User u = userDao.getUserByUsername(user,realm);
if(u != null)
logger.info("Successfully imported user/username from remote system: " + u.getFirstName() + " " + u.getLastName() + "("+user+"@"+realm+") id: " + u.getId());
logger.info("Successfully imported user/username from remote system: " + user+"@"+realm+ " (id: " + u.getId()+") "+u.getUserNames());
else
logger.warn("Failed to import a valid user from remote system: "+userAtRealm);
return u;

@ -8,6 +8,6 @@ package se.su.dsv.scipro.json;
* @param <E> The lookup parameter, use compound types to support querying on multiple parameters.
*/
public interface ILookup<T, E> {
public T lookup(E lookupParam);
public T lookup(final E lookupParam, final RemoteLookupOptions options);
}

@ -4,5 +4,5 @@ package se.su.dsv.scipro.json;
* Interface for delegated callback handling of response-strings.
*/
public interface IResponseHandler {
public void handleResponse(String response);
public void handleResponse(final String response,final RemoteLookupOptions options);
}

@ -7,5 +7,5 @@ import se.su.dsv.scipro.data.dataobjects.User;
* See ILookup for more information on the implicit contract of this interface.
*/
public interface IUserLookupFromIdentifier extends ILookup<User,Long>{
public User lookup(final Long identifier);
public User lookup(final Long identifier, final RemoteLookupOptions options);
}

@ -9,5 +9,5 @@ import se.su.dsv.scipro.util.KeyValuePair;
* See ILookup for more information on the implicit contract of this interface.
*/
public interface IUserLookupFromUsername extends ILookup<User,KeyValuePair<String>>{
public User lookup(final KeyValuePair<String> userAtRealm);
public User lookup(final KeyValuePair<String> userAtRealm, final RemoteLookupOptions options);
}

@ -27,7 +27,7 @@ public class ImportUpdateStatsResponseHandler extends JsonResponseHandler {
*
* @param response the json string
*/
public void handleResponse(String response) {
public void handleResponse(final String response, final RemoteLookupOptions options) {
JsonUpdateStatsContainer statsContainer = null;
try{
Gson gson = new Gson();

@ -13,10 +13,11 @@ import se.su.dsv.scipro.ApplicationSettings;
/**
* This class does a lookup on a username against the remote remoteLookupUrl specified in
* the applicationContext, under ApplicationSettings.
*
*
*
* @author Dan Kjellman <dan-kjel@dsv.su.se>
*/
//TODO Make sure this worker successfully fails when it should
@Component
public class ImportWorkerLookup {
public static final String USERS = "users";
@ -52,7 +53,7 @@ public class ImportWorkerLookup {
}else{
//logger.log(Level.INFO,"Starting lookup for completeGet=true & type="+type+" & updatedAfter=" + updatedAfter);
}
RequestSender request = new RequestSender(importWorkerResponseHandler, applicationSettings.getRemoteLookupUrl(), params, RequestSender.REQUEST_TYPE_POST);
RequestSender request = new RequestSender(importWorkerResponseHandler, applicationSettings.getRemoteLookupUrl(), params, new RemoteLookupOptions(), RequestSender.REQUEST_TYPE.POST);
try{
request.processRequest();
} catch (IOException e) {
@ -66,7 +67,7 @@ public class ImportWorkerLookup {
params.put("updateStats", "true");
params.put("updatedAfter",""+updatedAfter.getTime());
RequestSender request = new RequestSender(importUpdateStatsResponseHandler, applicationSettings.getRemoteLookupUrl(), params, RequestSender.REQUEST_TYPE_POST);
RequestSender request = new RequestSender(importUpdateStatsResponseHandler, applicationSettings.getRemoteLookupUrl(), params, new RemoteLookupOptions(), RequestSender.REQUEST_TYPE.POST);
try{
request.processRequest();
} catch (IOException e) {

@ -34,7 +34,7 @@ public class ImportWorkerResponseHandler extends JsonResponseHandler {
*
* @param response the json string
*/
public void handleResponse(String response) {
public void handleResponse(final String response, final RemoteLookupOptions options) {
JsonCompleteGetContainer completeContainer = null;
try{
Gson gson = new Gson();
@ -101,7 +101,7 @@ public class ImportWorkerResponseHandler extends JsonResponseHandler {
if(user == null){
createThesisUser(jsonUser, false);
createThesisUser(jsonUser, new RemoteLookupOptions());
}else{
lookForChangesInUserAndSave(jsonUser);
}
@ -112,7 +112,7 @@ public class ImportWorkerResponseHandler extends JsonResponseHandler {
if(project == null){
//System.out.println("User does not exist... trying to create");
if(null == checkAndCreateProject(jsonThesis)){
if(null == checkAndCreateProject(jsonThesis,options)){
thesesCreationsErrors++;
} else {
thesesCreations++;

@ -1,13 +1,16 @@
package se.su.dsv.scipro.json;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.transaction.annotation.Transactional;
import se.su.dsv.scipro.ApplicationSettings;
import se.su.dsv.scipro.data.dao.interfaces.ProjectClassDao;
@ -31,7 +34,7 @@ import se.su.dsv.scipro.jsonobjects.JsonUser;
import se.su.dsv.scipro.jsonobjects.JsonUserRole;
import se.su.dsv.scipro.jsonobjects.JsonUsername;
/**
* Package-private sase class for JsonResponseHandlers.
* Package-private base class for JsonResponseHandlers.
* Contains a number of utility methods to lessen boilerplate code inside implementations.
*/
abstract class JsonResponseHandler implements IResponseHandler {
@ -67,9 +70,10 @@ abstract class JsonResponseHandler implements IResponseHandler {
/**
* Creates and persists a User from a JsonUser
* @param jsonUser the JsonUser to use for creation
* @param doFullCheck If true, checkAndCreateProject will be called on each project included in the query response.
* @return The created User or null if it cannot be persisted.
*/
protected User createThesisUser(JsonUser jsonUser, boolean doFullCheck){
protected User createThesisUser(final JsonUser jsonUser, final RemoteLookupOptions options){
User user = new User();
user.setFirstName(jsonUser.firstName);
user.setLastName(jsonUser.lastName);
@ -110,18 +114,21 @@ abstract class JsonResponseHandler implements IResponseHandler {
/*
* Create any projects of which the user is a member of
*/
if(doFullCheck){
if(options.getLookupDepth().equals(RemoteLookupOptions.LOOKUP_DEPTH.PROJECT_AND_PARTICIPANTS)){
for(JsonThesis jThesis : jsonUser.theses){
checkAndCreateProject(jThesis);
checkAndCreateProject(jThesis, options);
}
}
numUsersCreated++;
return user;
}
protected Project checkAndCreateProject(JsonThesis jThesis) {
/**
* Retrieve a Project matching the given JsonThesis ID, and create a project matching the supplied JsonThesis in full if it does not already exists.
* @param jThesis
* @return The retrieved (or newly created) project.
*/
protected Project checkAndCreateProject(JsonThesis jThesis, final RemoteLookupOptions options) {
Project project = null;
//System.out.println("Creating project:" + jThesis.thesisID);
project = projectDao.getProjectByIdentifier(jThesis.thesisID);
if(project == null){
project = new Project();
@ -139,48 +146,48 @@ abstract class JsonResponseHandler implements IResponseHandler {
if(jThesis.daisyStartDate > 0){
Date daisyStartDate = new Date(jThesis.daisyStartDate);
project.setDaisyStartDate(daisyStartDate);
}
project = projectDao.save(project);
//Synch participants
for(JsonThesisParticipant jtp : jThesis.participants){
User u = userDao.getUserByIdentifier(jtp.id);
//Attempt remote lookup if no user is found
if(u == null){
final Long id = Long.valueOf(jtp.id);
if( (u = userLookupFromIdentifier.lookup(id)) == null){
throw new RuntimeException("Cannot save jsonuser with jsonuserid: " + jtp.id);
}
}
//Move on
if(jtp.role.equals("SUPERVISOR")){
Employee e = roleDao.makeEmployee(u);
project.setHeadSupervisor(e);
}else if(jtp.role.equals("PARTICIPANT")){
Student s = roleDao.makeStudent(u);
project.getProjectParticipants().add(s);
}
else{
ProjectFollower pf = new ProjectFollower();
if(jtp.role.equals("ASSISTANT_SUPERVISOR")){
pf.setProjectRole(ProjectTeamMemberRoles.CO_SUPERVISOR);
pf.setFollower((Employee)roleDao.makeEmployee(u));
}else if(jtp.role.equals("OPPONENT")){
//TODO: OPPONENT
}else if (jtp.role.equals("EXAMINER")){
pf.setProjectRole(ProjectTeamMemberRoles.REVIEWER);
pf.setFollower(roleDao.makeEmployee(u));
}
if(pf.getFollower() != null && pf.getProjectRole() != null){
pf.setProject(project);
pf = projectFollowerDao.save(pf);
project.getProjectFollowers().add(pf);
if(options.getLookupDepth().equals(RemoteLookupOptions.LOOKUP_DEPTH.PROJECT_AND_PARTICIPANTS)){
for(JsonThesisParticipant jtp : jThesis.participants){
User u = userDao.getUserByIdentifier(jtp.id);
//Attempt remote lookup if no user is found
if(u == null){
final Long id = Long.valueOf(jtp.id);
if( (u = userLookupFromIdentifier.lookup(id, new RemoteLookupOptions(RemoteLookupOptions.LOOKUP_DEPTH.NONE))) == null){
logger.warn("Cannot create jsonuser with jsonuserid: " + jtp.id+" while adding participants for the project: "+project.getIdentifier());
continue;
}
}
//Move on, set participant roles
if(jtp.role.equals("SUPERVISOR")){
Employee e = roleDao.makeEmployee(u);
project.setHeadSupervisor(e);
}else if(jtp.role.equals("PARTICIPANT")){
Student s = roleDao.makeStudent(u);
project.getProjectParticipants().add(s);
}else{
ProjectFollower pf = new ProjectFollower();
if(jtp.role.equals("ASSISTANT_SUPERVISOR")){
pf.setProjectRole(ProjectTeamMemberRoles.CO_SUPERVISOR);
pf.setFollower((Employee)roleDao.makeEmployee(u));
}else if(jtp.role.equals("OPPONENT")){
//TODO: OPPONENT
}else if (jtp.role.equals("EXAMINER")){
pf.setProjectRole(ProjectTeamMemberRoles.REVIEWER);
pf.setFollower(roleDao.makeEmployee(u));
}
if(pf.getFollower() != null && pf.getProjectRole() != null){
pf.setProject(project);
pf = projectFollowerDao.save(pf);
project.getProjectFollowers().add(pf);
}
}
}
project = projectDao.save(project);
}
project = projectDao.save(project);
}
project = projectDao.getProjectByIdentifier(jThesis.thesisID);
return project;
@ -243,7 +250,7 @@ abstract class JsonResponseHandler implements IResponseHandler {
}else{
try {
checkAndCreateProject(jThesis);
checkAndCreateProject(jThesis,new RemoteLookupOptions());
} catch (Exception e) {
logger.error("Error when creating project: daisyId=" + jThesis.thesisID + "when looking up user:"
+jsonUser.firstName+ " "+jsonUser.lastName+" \n" + e.getMessage());
@ -376,9 +383,9 @@ abstract class JsonResponseHandler implements IResponseHandler {
if(u == null){
final Long id = Long.valueOf(jtp.id);
try {
u = userLookupFromIdentifier.lookup(id);
u = userLookupFromIdentifier.lookup(id, new RemoteLookupOptions(RemoteLookupOptions.LOOKUP_DEPTH.NONE));
} catch (Exception e) {
logger.error("Failed to save changes for project:" + current.getIdentifier() + " when looking up user whith idetifier:"+jtp.id+
logger.error("Failed to save changes for project:" + current.getIdentifier() + " when looking up user with identifier:"+jtp.id+
" Rolling back...\n" + e.getMessage());
throw new RuntimeException(e);
}
@ -458,7 +465,7 @@ abstract class JsonResponseHandler implements IResponseHandler {
/*
* Force subclasses to handle the response
*/
public abstract void handleResponse(String response);
public abstract void handleResponse(final String response, final RemoteLookupOptions options);
/*
* Getters for logging

@ -32,7 +32,7 @@ public class JsonUserFullResponseHandler extends JsonResponseHandler {
*
* @param response the json string
*/
public void handleResponse(String response) {
public void handleResponse(final String response, final RemoteLookupOptions options) {
JsonUserContainer userContainer = null;
try{
@ -52,13 +52,11 @@ public class JsonUserFullResponseHandler extends JsonResponseHandler {
//Loop all users in the response and look for changes...
for(JsonUser jsonUser : userContainer.users){
System.out.println("Checking: " + " id: " + jsonUser.id + " firstName: "+ jsonUser.firstName);
logger.debug("Checking: " + jsonUser);
User thesisUser = userDao.getUserByIdentifier(new Long(jsonUser.id));
for(JsonUsername jsonUsername : jsonUser.usernames){
System.out.println(jsonUsername.username);
logger.debug("\t"+jsonUsername.username);
String usernameString = jsonUsername.username.toLowerCase().trim();
String userRealmString = jsonUsername.realm.toUpperCase().trim();
User potentialDuplicateUser = userDao.getUserByUsername(usernameString, userRealmString);
@ -108,7 +106,7 @@ public class JsonUserFullResponseHandler extends JsonResponseHandler {
if(thesisUser == null){
//System.out.println("User does not exist... trying to create");
if(null == createThesisUser(jsonUser,true)){
if(null == createThesisUser(jsonUser,options)){
userCreationErrors++;
} else {
createdUsers++;

@ -29,16 +29,16 @@ public class JsonUserResponseHandler extends JsonResponseHandler {
*
* @param response the json string
*/
public void handleResponse(String response) {
public void handleResponse(final String response, final RemoteLookupOptions options) {
JsonUserContainer userContainer = null;
logger.debug(response);
try{
Gson gson = new Gson();
Type type = new TypeToken<JsonUserContainer>(){}.getType();
userContainer = gson.fromJson(response, type);
} catch (Exception e) {
logger.error("Gson error when creating objects from json \n" + e.getMessage());
logger.error("Gson error when creating objects from json response" + e.getMessage());
logger.error("Full response from remote:" + response);
return;
}
int createdUsers = 0;
@ -47,12 +47,11 @@ public class JsonUserResponseHandler extends JsonResponseHandler {
//Loop all users in the response and look for changes...
for(JsonUser jsonUser : userContainer.users){
logger.debug("Checking identifier: " + jsonUser.id);
logger.debug("Checking " + jsonUser.id);
User thesisUser = userDao.getUserByIdentifier(Long.valueOf(jsonUser.id));
if(thesisUser == null){
logger.debug("User '"+jsonUser.id+ "' does not exist, trying to create");
if(null == createThesisUser(jsonUser,false)){
logger.debug("User '"+jsonUser.id+ "' does not exist locally, trying to create");
if(null == createThesisUser(jsonUser,options)){
userCreationErrors++;
} else {
createdUsers++;

@ -0,0 +1,18 @@
package se.su.dsv.scipro.json;
/**
* Bla bla bla
*/
public final class RemoteLookupOptions {
public enum LOOKUP_DEPTH{NONE,PROJECT_AND_PARTICIPANTS};
private final LOOKUP_DEPTH depth;
public RemoteLookupOptions(){
this(LOOKUP_DEPTH.NONE);
}
public RemoteLookupOptions(final LOOKUP_DEPTH depth){
this.depth = depth;
}
public LOOKUP_DEPTH getLookupDepth(){
return depth;
}
}

@ -9,8 +9,6 @@ import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import javax.net.ssl.HttpsURLConnection;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
@ -20,66 +18,40 @@ import org.apache.log4j.Logger;
* @author Dan Kjellman
*
*/
public class RequestSender {
public final class RequestSender {
public static final int REQUEST_TYPE_POST = 0;
public static final int REQUEST_TYPE_GET = 1;
public static final String[] REQUEST_METHODS = new String[]{
"POST", "GET"
};
private Logger logger;
public enum REQUEST_TYPE{POST,GET};
private final REQUEST_TYPE requestType;
private Logger logger = Logger.getLogger(RequestSender.class);
/*
* The Handler for the response
*/
protected IResponseHandler responseHandler;
private IResponseHandler responseHandler;
/*
* The params
*/
protected Map<String, String> parameters;
private Map<String, String> parameters;
/*
* The url to call
*/
protected String url;
private String url;
//Options for performed lookups
private final RemoteLookupOptions remoteLookupOptions;
/*
* Type of request, use the static variables REQUEST_TYPE_POST or REQUEST_TYPE_GET
*/
protected int requestType;
public RequestSender(IResponseHandler responseHandler, String url, Map<String, String> parameters, int requestType){
logger = Logger.getLogger(this.getClass());
if(requestType != REQUEST_TYPE_GET && requestType != REQUEST_TYPE_POST){
logger.log(Level.ERROR, "Could not send request, no request type specified");
throw new IllegalArgumentException("Bad request type");
}
public RequestSender(final IResponseHandler responseHandler, final String url, final Map<String, String> parameters, final RemoteLookupOptions options, final REQUEST_TYPE requestType){
if(responseHandler == null){
logger.log(Level.ERROR, "Could not send request, no response handler was provided");
throw new IllegalArgumentException("You need no provide a handler for the response");
}
remoteLookupOptions = (options==null?new RemoteLookupOptions():options);
this.responseHandler = responseHandler;
this.url = url;
this.parameters = parameters;
this.requestType = requestType;
}
public RequestSender(IResponseHandler responseHandler, String url){
if(responseHandler == null){
throw new IllegalArgumentException("You need no provide a handler for the response");
}
this.responseHandler = responseHandler;
this.url = url;
this.parameters = new HashMap<String, String>();
this.requestType = REQUEST_TYPE_GET;
this(responseHandler,url,new HashMap<String,String>(),null,REQUEST_TYPE.GET);
}
/**
@ -100,7 +72,7 @@ public class RequestSender {
count++;
}
if(requestType == REQUEST_TYPE_GET && parameters.size() > 0){
if(requestType == REQUEST_TYPE.GET && parameters.size() > 0){
url += "?" + parameterData;
}
@ -112,7 +84,7 @@ public class RequestSender {
URL u = new URL(url);
conn = (HttpURLConnection) u.openConnection();
conn.setRequestMethod(REQUEST_METHODS[requestType]);
conn.setRequestMethod(requestType.name());
/*
* Set connect timeout to 60 seconds and read timeout to 120 sec
@ -122,7 +94,7 @@ public class RequestSender {
conn.setConnectTimeout(1000 * 60);
conn.setReadTimeout(1000 * 120);
if(requestType == REQUEST_TYPE_POST){
if(requestType == REQUEST_TYPE.POST){
conn.setDoOutput(true);
osr = new OutputStreamWriter(conn.getOutputStream());
osr.write(parameterData);
@ -136,7 +108,7 @@ public class RequestSender {
while((line = br.readLine()) != null){
response += line;
}
responseHandler.handleResponse(response);
responseHandler.handleResponse(response, remoteLookupOptions);
} catch (IOException e){
/*
@ -152,11 +124,9 @@ public class RequestSender {
if(conn != null){
conn.disconnect();
}
if(osr != null){
osr.close();
}
if(br != null){
br.close();
}

@ -33,7 +33,7 @@
By default it's turned off since we don't have access to the daisy search yet
-->
<property name="enableRemoteUserLookup" value="true"></property>
<!-- This property points to the location of the daisy json search -->
<!-- This property points to the location of the remote system used for json requests -->
<property name="remoteLookupUrl" value="https://thesis.dsv.su.se/match/json" />
<!-- External auth support (via J2EE standard mechanism REMOTE_USER), if true: other authentication mechanics will be bypassed.-->
<property name="acceptExternalAuthentication" value="true"/>

@ -34,6 +34,7 @@ import se.su.dsv.scipro.data.dataobjects.User;
import se.su.dsv.scipro.data.dataobjects.Username;
import se.su.dsv.scipro.json.IUserLookupFromIdentifier;
import se.su.dsv.scipro.json.IUserLookupFromUsername;
import se.su.dsv.scipro.json.RemoteLookupOptions;
import se.su.dsv.scipro.repository.util.RepositoryManager;
import se.su.dsv.scipro.util.KeyValuePair;
@ -54,7 +55,7 @@ public class TestAuthRoutines {
//Fake a lookup mechanism
fixedLookupFromUsername = new IUserLookupFromUsername(){
@Override
public User lookup(final KeyValuePair<String> userAtRealm){
public User lookup(final KeyValuePair<String> userAtRealm, final RemoteLookupOptions options){
if(userAtRealm.getKey().equals("kalle-kula"))
return user;
else
@ -63,7 +64,7 @@ public class TestAuthRoutines {
};
fixedLookupFromIdentifier = new IUserLookupFromIdentifier(){
@Override
public User lookup(final Long identifier){
public User lookup(final Long identifier, final RemoteLookupOptions options){
if(identifier.equals(666))
return user;
else