X-Git-Url: http://lists.indexdata.dk/cgi-bin?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fcom%2Findexdata%2Fmkjsf%2Fpazpar2%2Fcommands%2Fsp%2FAuthCommand.java;h=67780e5cb21c1ceee793c567a76a2837da03108e;hb=017a20f6da489d3d968025f0442213aee7252c41;hp=67ecb5423363f0dc67418960b77bfe4858f1d184;hpb=c0fc71b8daacb803033a7a6a95596e16fe5e08b0;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 67ecb54..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,43 +1,106 @@
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.state.StateManager;
+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(StateManager stateMgr) { - super("auth", stateMgr); + 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");
}
public AuthCommand copy () {
- AuthCommand newCommand = new AuthCommand(stateMgr);
+ AuthCommand newCommand = new AuthCommand();
for (String parameterName : parameters.keySet()) {
newCommand.setParameterInState(parameters.get(parameterName).copy());
}