X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fcom%2Findexdata%2Fmkjsf%2Fpazpar2%2Fcommands%2Fsp%2FAuthCommand.java;h=67780e5cb21c1ceee793c567a76a2837da03108e;hb=017a20f6da489d3d968025f0442213aee7252c41;hp=9a4fad7d27e259ba8f108daa473a5d1d156ddd9e;hpb=11ff48b9d37193a89a4b74da75db8c58415c46a6;p=mkjsf-moved-to-github.git
diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/AuthCommand.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/AuthCommand.java
index 9a4fad7..67780e5 100644
--- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/AuthCommand.java
+++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/AuthCommand.java
@@ -1,36 +1,100 @@
package com.indexdata.mkjsf.pazpar2.commands.sp;
+import org.apache.log4j.Logger;
+
+import com.indexdata.mkjsf.pazpar2.ClientCommandResponse;
+import com.indexdata.mkjsf.pazpar2.Pz2Service;
import com.indexdata.mkjsf.pazpar2.commands.CommandParameter;
import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Command;
+import com.indexdata.mkjsf.pazpar2.data.ResponseParser;
+import com.indexdata.mkjsf.pazpar2.data.sp.SpResponseDataObject;
+/**
+ * Represents a Service Proxy auth
command.
+ *
+ *
Authenticates a user against a Pazpar2 Service Proxy
+ * + * @author Niels Erik + * + */ public class AuthCommand extends Pazpar2Command implements ServiceProxyCommand { private static final long serialVersionUID = 5487611235664162578L; + private static Logger logger = Logger.getLogger(AuthCommand.class); public AuthCommand() { super("auth"); } + public SpResponseDataObject run() { + Pz2Service.get().resetSearchAndRecordCommands(); + Pz2Service.get().getPzresp().getSp().resetAuthAndBeyond(true); + ClientCommandResponse response = (ClientCommandResponse) Pz2Service.get().getSearchClient().executeCommand(this); + String renamedResponse = renameResponseElement(response.getResponseString(), "auth"); + response.setResponseToParse(renamedResponse); + SpResponseDataObject responseObject = (SpResponseDataObject) ResponseParser.getParser().getDataObject(response); + if (ResponseParser.docTypes.contains(responseObject.getType())) { + Pz2Service.get().getPzresp().put(getCommandName(), responseObject); + } + if (responseObject.unsupportedCommand()) { + logger.error("auth command does not seem to be supported by this Service Proxy"); + } + return responseObject; + } + + /** + * Normalizes the response XML for the benefit of the SAX parser that creates data objects. + *The parser expects responses to have document element names corresponding to the names of + * the commands that created the responses.
+ * + * @param responseString + * @param newName + * @return + */ + private String renameResponseElement(String responseString, String newName) { + responseString = responseString.replace("action
. See Service Proxy documentation for details.
+ */
public void setAction (String action) {
setParameterInState(new CommandParameter("action","=",action));
}
+ /**
+ * Gets parameter value for action
+ */
public String getAction () {
return getParameterValue("action");
}
+ /**
+ * Sets Service Proxy command parameter username
. See Service Proxy documentation for details.
+ */
public void setUsername(String username) {
setParameterInState(new CommandParameter("username","=",username));
}
+ /**
+ * Gets parameter value for username
+ */
public String getUsername () {
return getParameterValue("username");
}
-
+
+ /**
+ * Sets Service Proxy command parameter password
. See Service Proxy documentation for details.
+ */
public void setPassword (String password) {
setParameterInState(new CommandParameter("password","=",password));
}
+ /**
+ * Gets parameter value for password
+ */
public String getPassword () {
return getParameterValue("password");
}