import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Command;\r
import com.indexdata.mkjsf.pazpar2.commands.sp.AuthCommand;\r
import com.indexdata.mkjsf.pazpar2.data.CommandError;\r
-import com.indexdata.mkjsf.pazpar2.sp.auth.ServiceProxyUser;\r
import com.indexdata.mkjsf.utils.Utils;\r
\r
public class ServiceProxyClient implements SearchClient {\r
c.printStackTrace();\r
} \r
}\r
- \r
- \r
- public boolean authenticate (ServiceProxyUser user) {\r
- logger.info("Authenticating [" + user.getProperty("name") + "]"); \r
- Pazpar2Command auth = new AuthCommand(null);\r
- auth.setParametersInState(new CommandParameter("action","=","login"), \r
- new CommandParameter("username","=",user.getProperty("name")), \r
- new CommandParameter("password","=",user.getProperty("password"))); \r
- ClientCommandResponse commandResponse = send(auth);\r
- String responseStr = commandResponse.getResponseString();\r
- logger.info(responseStr); \r
- if (responseStr.contains("FAIL")) {\r
- user.credentialsAuthenticationSucceeded(false);\r
- return false;\r
- } else {\r
- user.credentialsAuthenticationSucceeded(true);\r
- return true;\r
- } \r
- }\r
- \r
- public boolean checkAuthentication (ServiceProxyUser user) { \r
- ClientCommandResponse commandResponse = send(checkAuth); \r
- String responseStr = commandResponse.getResponseString(); \r
- logger.info(responseStr);\r
- if (responseStr.contains("FAIL")) { \r
- user.authenticationCheckFailed();\r
- return false;\r
- } else { \r
- return true;\r
- } \r
- }\r
- \r
- public boolean ipAuthenticate (ServiceProxyUser user) {\r
- ClientCommandResponse commandResponse = send(ipAuth); \r
- String responseStr = commandResponse.getResponseString();\r
- logger.info(responseStr);\r
- if (responseStr.contains("FAIL")) {\r
- user.ipAuthenticationSucceeded(false); \r
- return false;\r
- } else {\r
- user.ipAuthenticationSucceeded(true);\r
- return true;\r
- } \r
- }\r
- \r
+ \r
public boolean isAuthenticatingClient () {\r
return true;\r
}\r
- \r
- public boolean isAuthenticated (ServiceProxyUser user) {\r
- if (user.getProperty("name") != null && user.getProperty("password") != null) {\r
- return checkAuthentication(user);\r
- } else {\r
- return false;\r
- }\r
- }\r
- \r
+ \r
/**\r
* Makes the request\r
* @param request\r
* @throws ClientProtocolException\r
* @throws IOException\r
*/\r
- private ClientCommandResponse send(Pazpar2Command command) {\r
+ public ClientCommandResponse send(Pazpar2Command command) {\r
ClientCommandResponse commandResponse = null;\r
String url = serviceUrl + "?" + command.getEncodedQueryString(); \r
logger.info("Sending request "+url); \r
import org.apache.myfaces.custom.fileupload.UploadedFile;\r
\r
import com.indexdata.mkjsf.config.ConfigurationReader;\r
+import com.indexdata.mkjsf.pazpar2.commands.CommandParameter;\r
import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Commands;\r
+import com.indexdata.mkjsf.pazpar2.commands.sp.AuthCommand;\r
import com.indexdata.mkjsf.pazpar2.commands.sp.InitDocUpload;\r
+import com.indexdata.mkjsf.pazpar2.data.AuthResponse;\r
import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject;\r
import com.indexdata.mkjsf.pazpar2.data.ResponseParser;\r
import com.indexdata.mkjsf.pazpar2.data.Responses;\r
// TODO: \r
//stateMgr.addStateListener(this);\r
}\r
- \r
+ \r
+ /*\r
public void login(String un, String pw) {\r
if (user.isAuthenticated() && user.getName().equals(un) && pz2.spClient.checkAuthentication(user)) {\r
logger.info("Repeat request from UI to authenticate user. Auth verified for given user name so skipping log-in.");\r
login("dummy");\r
}\r
}\r
+ */\r
\r
- @Override\r
+ \r
+ @Override \r
public String login(String navigateTo) {\r
logger.info("doing login by " + user + " using " + pz2 + " and client " + pz2.getSpClient());\r
pz2.resetSearchAndRecordCommands();\r
pzresp.resetAllSessionData();\r
- pz2.getSpClient().authenticate(user); \r
+ AuthCommand auth = pzreq.getSp().getAuth(); \r
+ auth.setParametersInState(new CommandParameter("action","=","login"),\r
+ new CommandParameter("username","=",user.getName()),\r
+ new CommandParameter("password","=",user.getPassword()));\r
+ ClientCommandResponse commandResponse = pz2.getSpClient().send(auth);\r
+ AuthResponse responseObject = (AuthResponse) (ResponseParser.getParser().getDataObject(commandResponse.getResponseString()));\r
+ if (ResponseParser.docTypes.contains(responseObject.getType())) {\r
+ pzresp.put(auth.getCommandName(), responseObject);\r
+ }\r
+ String responseStr = commandResponse.getResponseString();\r
+ logger.info(responseStr); \r
+ if (responseStr.contains("FAIL")) {\r
+ user.credentialsAuthenticationSucceeded(false); \r
+ } else {\r
+ user.credentialsAuthenticationSucceeded(true); \r
+ } \r
return navigateTo;\r
}\r
\r
+ \r
public void ipAuthenticate (ServiceProxyUser user) {\r
if (!user.isIpAuthenticated()) {\r
if (user.isAuthenticated()) {\r
}\r
pz2.resetSearchAndRecordCommands();\r
pzresp.resetAllSessionData();\r
- pz2.getSpClient().ipAuthenticate(user);\r
+ AuthCommand auth = pzreq.getSp().getAuth(); \r
+ auth.setParameterInState(new CommandParameter("action","=","ipAuth"));\r
+ ClientCommandResponse commandResponse = pz2.getSpClient().send(auth);\r
+ AuthResponse responseObject = (AuthResponse) (ResponseParser.getParser().getDataObject(commandResponse.getResponseString()));\r
+ if (ResponseParser.docTypes.contains(responseObject.getType())) {\r
+ pzresp.put(auth.getCommandName(), responseObject);\r
+ }\r
+ String responseStr = commandResponse.getResponseString();\r
+ logger.info(responseStr); \r
+ if (responseStr.contains("FAIL")) {\r
+ user.credentialsAuthenticationSucceeded(false); \r
+ } else {\r
+ user.credentialsAuthenticationSucceeded(true); \r
+ } \r
}\r
}\r
\r
\r
import org.apache.log4j.Logger;\r
\r
+import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommands;\r
import com.indexdata.mkjsf.pazpar2.state.StateManager;\r
import com.indexdata.mkjsf.utils.Utils;\r
\r
\r
private static final long serialVersionUID = -5172466320351302413L;\r
private static Logger logger = Logger.getLogger(Pazpar2Commands.class);\r
-\r
+ \r
public static final String INIT = "init";\r
public static final String PING = "ping";\r
public static final String SETTINGS = "settings";\r
public static final String RECORD = "record";\r
public static final String TERMLIST = "termlist";\r
public static final String BYTARGET = "bytarget";\r
+ \r
+ private ServiceProxyCommands sp = null;\r
\r
- @Inject StateManager stateMgr; \r
+ @Inject\r
+ protected StateManager stateMgr; \r
\r
public Pazpar2Commands() {\r
logger.info("Initializing Pazpar2Commands [" + Utils.objectId(this) + "]");\r
public Pazpar2Command getCommand(String name) {\r
return stateMgr.getCommand(name);\r
}\r
+ \r
+ public ServiceProxyCommands getSp() {\r
+ if (sp == null) {\r
+ sp = new ServiceProxyCommands(stateMgr);\r
+ }\r
+ return sp;\r
+ }\r
\r
}\r
\r
public AuthCommand(StateManager stateMgr) {\r
super("auth", stateMgr);\r
- // TODO Auto-generated constructor stub\r
}\r
\r
public AuthCommand copy () {\r
public ServiceProxyCommand getSp() {\r
return this;\r
}\r
-\r
-\r
}\r
--- /dev/null
+package com.indexdata.mkjsf.pazpar2.commands.sp;\r
+\r
+import java.io.Serializable;\r
+\r
+import org.apache.log4j.Logger;\r
+\r
+import com.indexdata.mkjsf.pazpar2.state.StateManager;\r
+import com.indexdata.mkjsf.utils.Utils;\r
+\r
+public class ServiceProxyCommands implements Serializable {\r
+\r
+ public static final String AUTH = "auth";\r
+ private static final long serialVersionUID = 6223527018096841188L;\r
+ private static Logger logger = Logger.getLogger(ServiceProxyCommands.class);\r
+ private StateManager stateMgr = null; \r
+ \r
+ public ServiceProxyCommands(StateManager stateMgr) {\r
+ logger.info("Initializing ServiceProxyCommands [" + Utils.objectId(this) + "]");\r
+ this.stateMgr = stateMgr;\r
+ }\r
+\r
+ \r
+ public AuthCommand getAuth() {\r
+ return (AuthCommand) (stateMgr.getCommand(AUTH));\r
+ }\r
+\r
+\r
+}\r
--- /dev/null
+package com.indexdata.mkjsf.pazpar2.data;\r
+\r
+public class AuthResponse extends ResponseDataObject {\r
+\r
+ private static final long serialVersionUID = 8006774126022849936L;\r
+\r
+ public String getDisplayName () {\r
+ return getOneElementValue("displayName");\r
+ }\r
+ \r
+ public String getRealm () {\r
+ return getOneElementValue("realm");\r
+ }\r
+ \r
+ public String getStatus () {\r
+ return getOneElementValue("status");\r
+ }\r
+ \r
+ public String getAuthenticationType () {\r
+ return getOneElementValue("type");\r
+ }\r
+ \r
+\r
+ \r
+}\r
private String xml = null;\r
private static Logger logger = Logger.getLogger(ResponseParser.class);\r
\r
- public static final List<String> docTypes = \r
- Arrays.asList("bytarget","termlist","show","stat","record","search","init");\r
+ public static List<String> docTypes = Arrays.asList( "bytarget","termlist","show","stat","record","search","init",\r
+ /* SP extras */ "response" ); \r
\r
- public ResponseParser() { \r
+ public ResponseParser() {\r
try {\r
initSax();\r
} catch (ParserConfigurationException e) {\r
try { \r
xmlReader.parse(new InputSource(new ByteArrayInputStream(response.getBytes("UTF-8"))));\r
} catch (UnsupportedEncodingException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace(); \r
+ e.printStackTrace(); \r
} catch (IOException e) {\r
- // TODO Auto-generated catch block\r
e.printStackTrace();\r
} catch (SAXException e) {\r
- // TODO Auto-generated catch block\r
e.printStackTrace(); \r
}\r
return result;\r
} else if (localName.equals("applicationerror")) {\r
currentElement = new CommandError();\r
} else if (localName.equals("error") && dataElements.peek().getType().equals("applicationerror")) {\r
- currentElement = new Pazpar2Error(); \r
+ currentElement = new Pazpar2Error(); \r
+ } else if (localName.equals("response")) { // Note, document element not named 'auth'\r
+ currentElement = new AuthResponse();\r
} else {\r
currentElement = new ResponseDataObject();\r
}\r
\r
import com.indexdata.mkjsf.errors.ErrorHelper;\r
import com.indexdata.mkjsf.errors.ErrorInterface;\r
-import com.indexdata.mkjsf.pazpar2.data.sp.SpResponses;\r
import com.indexdata.mkjsf.utils.Utils;\r
\r
@Named("pzresp") @SessionScoped\r
dataObjects = new ConcurrentHashMap<String,ResponseDataObject>(); \r
resetSearchResponses();\r
dataObjects.put("init", new InitResponse());\r
+ dataObjects.put("auth", new AuthResponse());\r
}\r
\r
- public InitResponse getInit () {\r
- logger.info("Request to show init response from " + Utils.objectId(this));\r
+ public InitResponse getInit () { \r
return ((InitResponse) dataObjects.get("init"));\r
}\r
+ \r
+ public AuthResponse getAuth () {\r
+ return ((AuthResponse) dataObjects.get("auth"));\r
+ }\r
\r
public ShowResponse getShow () {\r
return ((ShowResponse) dataObjects.get("show"));\r
}\r
}\r
\r
- public SpResponses getSp() {\r
- // TODO:\r
- return null;\r
- }\r
-\r
public void download(String commandName) throws UnsupportedEncodingException, IOException {\r
logger.info(Utils.objectId(this) + " got a download request for "\r
+ commandName);\r
import com.indexdata.mkjsf.pazpar2.commands.ShowCommand;\r
import com.indexdata.mkjsf.pazpar2.commands.StatCommand;\r
import com.indexdata.mkjsf.pazpar2.commands.TermlistCommand;\r
+import com.indexdata.mkjsf.pazpar2.commands.sp.AuthCommand;\r
+import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommands;\r
\r
/**\r
* Holds a 'pazpar2 state', understood as a full set of pazpar2 commands and \r
commands.put(Pazpar2Commands.SHOW, new ShowCommand(mgr));\r
commands.put(Pazpar2Commands.RECORD, new RecordCommand(mgr));\r
commands.put(Pazpar2Commands.TERMLIST, new TermlistCommand(mgr));\r
- commands.put(Pazpar2Commands.BYTARGET, new BytargetCommand(mgr)); \r
+ commands.put(Pazpar2Commands.BYTARGET, new BytargetCommand(mgr)); \r
+\r
+ commands.put(ServiceProxyCommands.AUTH, new AuthCommand(mgr));\r
key = "#1";\r
}\r
\r
\r
Map<String, Pazpar2State> states = new HashMap<String, Pazpar2State>();\r
String currentKey = "";\r
- private static List<String> allCommands = new ArrayList<String>(Arrays.asList("init","ping","settings","search","stat","show","record","termlist","bytarget"));\r
+ private static List<String> allCommands = new ArrayList<String>(Arrays.asList("init","ping","settings","search","stat","show","record","termlist","bytarget","auth"));\r
Map<String,Boolean> pendingStateChanges = new HashMap<String,Boolean>();\r
private static Logger logger = Logger.getLogger(StateManager.class);\r
private List<StateListener> listeners = new ArrayList<StateListener>();\r