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=8869d83f970065ed42e48068d1ddd3e5100c22b3;hb=c04872faf566a8d312f5f3f82eb652fae7327ce3;hp=698f265c2f383c9792d6a1953e611b78a7086ad8;hpb=78cce328039810027616b0dfe4fb3362f5b573af;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 698f265..8869d83 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,19 +1,107 @@ 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.AuthResponse; +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); - // TODO Auto-generated constructor stub + 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); + AuthResponse responseObject = (AuthResponse) 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()); } @@ -25,5 +113,8 @@ public class AuthCommand extends Pazpar2Command implements ServiceProxyCommand { return this; } - + @Override + public boolean spOnly() { + return true; + } }