1 package com.indexdata.mkjsf.pazpar2.commands.sp;
\r
3 import org.apache.log4j.Logger;
\r
5 import com.indexdata.mkjsf.pazpar2.ClientCommandResponse;
\r
6 import com.indexdata.mkjsf.pazpar2.Pz2Service;
\r
7 import com.indexdata.mkjsf.pazpar2.commands.CommandParameter;
\r
8 import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Command;
\r
9 import com.indexdata.mkjsf.pazpar2.data.ResponseParser;
\r
10 import com.indexdata.mkjsf.pazpar2.data.sp.SpResponseDataObject;
\r
13 * Represents a Service Proxy <code>auth</code> command, can be accessed by <code>pzreq.sp.auth</code>
\r
15 * <p>Authenticates a user against a Pazpar2 Service Proxy</p>
\r
17 * @author Niels Erik
\r
20 public class AuthCommand extends Pazpar2Command implements ServiceProxyCommand {
\r
22 private static final long serialVersionUID = 5487611235664162578L;
\r
23 private static Logger logger = Logger.getLogger(AuthCommand.class);
\r
25 public AuthCommand() {
\r
29 public SpResponseDataObject run() {
\r
30 Pz2Service.get().resetSearchAndRecordCommands();
\r
31 Pz2Service.get().getPzresp().getSp().resetAuthAndBeyond(true);
\r
32 ClientCommandResponse response = (ClientCommandResponse) Pz2Service.get().getSearchClient().executeCommand(this);
\r
33 String renamedResponse = renameResponseElement(response.getResponseString(), "auth");
\r
34 response.setResponseToParse(renamedResponse);
\r
35 SpResponseDataObject responseObject = (SpResponseDataObject) ResponseParser.getParser().getDataObject(response);
\r
36 if (ResponseParser.docTypes.contains(responseObject.getType())) {
\r
37 Pz2Service.get().getPzresp().put(getCommandName(), responseObject);
\r
39 if (responseObject.unsupportedCommand()) {
\r
40 logger.error("auth command does not seem to be supported by this Service Proxy");
\r
42 return responseObject;
\r
46 * Normalizes the response XML for the benefit of the SAX parser that creates data objects.
\r
47 * <p>The parser expects responses to have document element names corresponding to the names of
\r
48 * the commands that created the responses.</p>
\r
50 * @param responseString
\r
54 private String renameResponseElement(String responseString, String newName) {
\r
55 responseString = responseString.replace("<response>", "<" + newName + ">");
\r
56 responseString = responseString.replace("</response>", "</" + newName + ">");
\r
57 return responseString;
\r
61 * Sets Service Proxy command parameter <code>action</code>. See Service Proxy documentation for details.
\r
63 public void setAction (String action) {
\r
64 setParameterInState(new CommandParameter("action","=",action));
\r
68 * Gets parameter value for <code>action</cod>
\r
70 public String getAction () {
\r
71 return getParameterValue("action");
\r
75 * Sets Service Proxy command parameter <code>username</code>. See Service Proxy documentation for details.
\r
77 public void setUsername(String username) {
\r
78 setParameterInState(new CommandParameter("username","=",username));
\r
82 * Gets parameter value for <code>username</cod>
\r
84 public String getUsername () {
\r
85 return getParameterValue("username");
\r
89 * Sets Service Proxy command parameter <code>password</code>. See Service Proxy documentation for details.
\r
91 public void setPassword (String password) {
\r
92 setParameterInState(new CommandParameter("password","=",password));
\r
96 * Gets parameter value for <code>password</cod>
\r
98 public String getPassword () {
\r
99 return getParameterValue("password");
\r
102 public AuthCommand copy () {
\r
103 AuthCommand newCommand = new AuthCommand();
\r
104 for (String parameterName : parameters.keySet()) {
\r
105 newCommand.setParameterInState(parameters.get(parameterName).copy());
\r
111 public ServiceProxyCommand getSp() {
\r
116 public boolean spOnly() {
\r