X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fcom%2Findexdata%2Fmkjsf%2Fpazpar2%2Fcommands%2Fsp%2FAuthCommand.java;h=75d46aa1db12b494ccfce4d2f2edfa0c6537f408;hb=86f289cd42ba95846c80d22129ed565e4e9d6dde;hp=4d72d614d6668d2a3b005e4b2b37f649a56daf42;hpb=bcb39bd9bde8071ac3a6741ce5d51ed9e763ba9c;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 4d72d61..75d46aa 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,18 +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, can be accessed by pzreq.sp.auth + * + *

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("", "<" + newName + ">"); + responseString = responseString.replace("", ""); + return responseString; + } + + /** + * Sets Service Proxy command parameter 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()); } @@ -23,4 +111,9 @@ public class AuthCommand extends Pazpar2Command implements ServiceProxyCommand { public ServiceProxyCommand getSp() { return this; } + + @Override + public boolean spOnly() { + return true; + } }