From 7e91f0024a1da347fc373c3ff4e920fd00443c15 Mon Sep 17 00:00:00 2001 From: "Niels Erik G. Nielsen" Date: Tue, 21 May 2013 16:43:22 -0400 Subject: [PATCH] Further reducing auth code --- .../mkjsf/pazpar2/ServiceProxyExtensions.java | 55 ++++++++------------ 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyExtensions.java b/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyExtensions.java index da21541..d283b29 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyExtensions.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyExtensions.java @@ -19,7 +19,6 @@ import com.indexdata.mkjsf.pazpar2.commands.sp.InitDocUpload; import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject; import com.indexdata.mkjsf.pazpar2.data.ResponseParser; import com.indexdata.mkjsf.pazpar2.data.Responses; -import com.indexdata.mkjsf.pazpar2.data.sp.AuthResponse; import com.indexdata.mkjsf.pazpar2.data.sp.CategoriesResponse; import com.indexdata.mkjsf.utils.Utils; @@ -44,51 +43,43 @@ public class ServiceProxyExtensions implements ServiceProxyInterface, Serializab //stateMgr.addStateListener(this); } - - - public void login(String un, String pw) { - logger.info("doing un/pw login"); - pzreq.getSp().getAuth().setUsername(un); - pzreq.getSp().getAuth().setPassword(pw); - login(""); - } - - - - @Override - public String login(String navigateTo) { - logger.info("doing login using " + pz2 + " and client " + pz2.getSpClient()); + public void authenticate() { pz2.resetSearchAndRecordCommands(); pzresp.getSp().resetAuthAndBeyond(true); - AuthCommand auth = pzreq.getSp().getAuth(); - auth.setParameterInState(new CommandParameter("action","=","login")); - ClientCommandResponse commandResponse = pz2.getSpClient().send(auth); + AuthCommand auth = pzreq.getSp().getAuth(); + ClientCommandResponse commandResponse = pz2.getSpClient().send(auth); String renamedResponse = renameResponseElement(commandResponse.getResponseString(), "auth"); commandResponse.setResponseToParse(renamedResponse); - AuthResponse responseObject = (AuthResponse) ResponseParser.getParser().getDataObject(commandResponse); + ResponseDataObject responseObject = ResponseParser.getParser().getDataObject(commandResponse); if (ResponseParser.docTypes.contains(responseObject.getType())) { pzresp.put(auth.getCommandName(), responseObject); } String responseStr = commandResponse.getResponseString(); - logger.info(responseStr); - return navigateTo; + logger.info(responseStr); } + public void login(String un, String pw) { + login(un,pw,""); + } + public void login(String un, String pw, String navigateTo) { + pzreq.getSp().getAuth().setUsername(un); + pzreq.getSp().getAuth().setPassword(pw); + login(""); + } + + @Override + public String login(String navigateTo) { + AuthCommand auth = pzreq.getSp().getAuth(); + auth.setParameterInState(new CommandParameter("action","=","login")); + authenticate(); + return navigateTo; + } + public void ipAuthenticate () { - pz2.resetSearchAndRecordCommands(); - pzresp.getSp().resetAuthAndBeyond(true); AuthCommand auth = pzreq.getSp().getAuth(); auth.setParameterInState(new CommandParameter("action","=","ipAuth")); - ClientCommandResponse commandResponse = pz2.getSpClient().send(auth); - String renamedResponse = renameResponseElement(commandResponse.getResponseString(), "auth"); - commandResponse.setResponseToParse(renamedResponse); - ResponseDataObject responseObject = ResponseParser.getParser().getDataObject(commandResponse); - if (ResponseParser.docTypes.contains(responseObject.getType())) { - pzresp.put(auth.getCommandName(), responseObject); - } - String responseStr = commandResponse.getResponseString(); - logger.info(responseStr); + authenticate(); } private String renameResponseElement(String responseString, String newName) { -- 1.7.10.4