suggestions.add("Please check the service ID set in the configuration and compare it with the " +\r
" configuration on the Pazpar2 server-side.");\r
addConfigurationDocumentation(suggestions); \r
- break; \r
+ break;\r
+ case "100":\r
+ suggestions.add("Pazpar2 Service Proxy error");\r
+ suggestions.add("A request was made to the Pazpar2 Service Proxy, but the Service Proxy reports ");\r
+ suggestions.add(" that authentication is lacking. Could be no successful authentication request was made or");\r
+ suggestions.add(" that the Service Proxy session timed out.");\r
+ break;\r
default:\r
suggestions.add("Pazpar2 error: " + error.getPazpar2Error().getMsg() + " (Pazpar2 # "+error.getPazpar2Error().getCode()+")");\r
}\r
CommandResponse commandResponse = client.executeCommand(command, baos);\r
if (commandResponse.getStatusCode()==200) {\r
response.append(commandResponse.getResponseString()); \r
- } else if (commandResponse.getStatusCode()==417) {\r
+ } else if (commandResponse.getStatusCode()==417) { \r
logger.error("Pazpar2 status code 417: " + baos.toString("UTF-8"));\r
- response.append(CommandError.insertPazpar2ErrorXml(command.getName(), "Expectation failed (417)", baos.toString("UTF-8"))); \r
+ response.append(CommandError.insertPazpar2ErrorXml(command.getName(), "Expectation failed (417)", commandResponse.getResponseString())); \r
} else {\r
String resp = baos.toString("UTF-8");\r
logger.error("Pazpar2 status code was " + commandResponse.getStatusCode() + ": " + resp);\r
import java.util.Map;\r
\r
import javax.enterprise.context.SessionScoped;\r
-import javax.enterprise.inject.Alternative;\r
import javax.inject.Named;\r
\r
import org.apache.http.HttpEntity;\r
import com.indexdata.pz2utils4jsf.config.Configuration;\r
import com.indexdata.pz2utils4jsf.config.ConfigurationReader;\r
import com.indexdata.pz2utils4jsf.errors.ConfigurationException;\r
+import com.indexdata.pz2utils4jsf.pazpar2.sp.auth.AuthenticationEntity;\r
+import com.indexdata.pz2utils4jsf.pazpar2.sp.auth.ServiceProxyUser;\r
import com.indexdata.pz2utils4jsf.utils.Utils;\r
\r
-@Named @SessionScoped @Alternative\r
+@Named @SessionScoped \r
public class ProxyPz2Client implements SearchClient {\r
-\r
+ \r
private static final long serialVersionUID = -4031644009579840277L;\r
private static Logger logger = Logger.getLogger(ProxyPz2Client.class);\r
public static final String MODULENAME = "proxyclient";\r
\r
ProxyPz2ResponseHandler handler = new ProxyPz2ResponseHandler();\r
private HttpClient client;\r
+ private ServiceProxyUser user;\r
\r
public ProxyPz2Client () {\r
SchemeRegistry schemeRegistry = new SchemeRegistry();\r
schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));\r
ClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry);\r
- client = new DefaultHttpClient(cm);\r
+ client = new DefaultHttpClient(cm); \r
}\r
\r
@Override\r
logger.info(Utils.objectId(this) + " is configuring using the provided " + Utils.objectId(configReader));\r
try {\r
Configuration config = configReader.getConfiguration(this); \r
- serviceUrl = config.getMandatory("SERVICE_PROXY_URL");\r
- authenticate();\r
+ serviceUrl = config.getMandatory("SERVICE_PROXY_URL"); \r
} catch (ConfigurationException c) {\r
- // TODO Auto-generated catch block\r
c.printStackTrace();\r
} catch (MissingMandatoryParameterException mmp) {\r
mmp.printStackTrace();\r
- }\r
+ } \r
}\r
\r
- public void authenticate () {\r
- try {\r
+ public boolean authenticate (AuthenticationEntity user) {\r
+ try { \r
+ logger.info("Authenticating [" + user.getProperty("name") + "]");\r
+ this.user = (ServiceProxyUser) user;\r
Pazpar2Command auth = new Pazpar2Command("auth");\r
auth.setParameter(new CommandParameter("action","=","login"));\r
- auth.setParameter(new CommandParameter("username","=","demo"));\r
- auth.setParameter(new CommandParameter("password","=","demo"));\r
- send(auth);\r
+ auth.setParameter(new CommandParameter("username","=",user.getProperty("name")));\r
+ auth.setParameter(new CommandParameter("password","=",user.getProperty("password")));\r
+ byte[] response = send(auth);\r
+ String responseStr = new String(response,"UTF-8");\r
+ logger.info(responseStr); \r
+ if (responseStr.contains("FAIL")) {\r
+ return false;\r
+ } else {\r
+ return true;\r
+ } \r
} catch (ClientProtocolException e) {\r
// TODO Auto-generated catch block\r
e.printStackTrace();\r
+ return false;\r
} catch (IOException e) {\r
// TODO Auto-generated catch block\r
e.printStackTrace();\r
- }\r
+ return false;\r
+ } \r
+ }\r
+ \r
+ public boolean checkAuthentication () {\r
+ try {\r
+ Pazpar2Command check = new Pazpar2Command("auth");\r
+ check.setParameter(new CommandParameter("action","=","check"));\r
+ byte[] response = send(check);\r
+ logger.info(new String(response,"UTF-8"));\r
+ } catch (ClientProtocolException e) {\r
+ // TODO Auto-generated catch block\r
+ e.printStackTrace();\r
+ return false;\r
+ } catch (IOException e) {\r
+ // TODO Auto-generated catch block\r
+ e.printStackTrace();\r
+ return false;\r
+ } \r
+ return true;\r
\r
}\r
\r
+ public boolean isAuthenticatingClient () {\r
+ return true;\r
+ }\r
+ \r
+ public boolean isAuthenticated () {\r
+ if (user.getProperty("name") != null && user.getProperty("password") != null) {\r
+ return checkAuthentication();\r
+ } else {\r
+ return false;\r
+ }\r
+ }\r
+ \r
/**\r
* Makes the request\r
* @param request\r
* @throws ClientProtocolException\r
* @throws IOException\r
*/\r
- private String send(Pazpar2Command command) throws ClientProtocolException, IOException {\r
+ private byte[] send(Pazpar2Command command) throws ClientProtocolException, IOException {\r
String url = serviceUrl + "?" + command.getEncodedQueryString(); \r
logger.info("Sending request "+url); \r
HttpGet httpget = new HttpGet(url); \r
byte[] response = client.execute(httpget, handler); \r
- return new String(response);\r
+ return response;\r
}\r
\r
\r
@Override\r
public CommandResponse executeCommand(Pazpar2Command command,\r
ByteArrayOutputStream baos) throws Pazpar2ErrorException, IOException {\r
- String response = send(command);\r
- return new ProxyPz2ClientCommandResponse(getStatusCode(), response); \r
+ byte[] response = send(command);\r
+ baos.write(response);\r
+ return new ProxyPz2ClientCommandResponse(getStatusCode(), new String(response,"UTF-8")); \r
}\r
\r
public ProxyPz2Client cloneMe() {\r
\r
import javax.annotation.PostConstruct;\r
import javax.enterprise.context.SessionScoped;\r
+import javax.enterprise.inject.Alternative;\r
import javax.inject.Inject;\r
import javax.inject.Named;\r
\r
import com.indexdata.pz2utils4jsf.pazpar2.data.TermResponse;\r
import com.indexdata.pz2utils4jsf.utils.Utils;\r
\r
-@Named("pz2") @SessionScoped\r
+@Named("pz2") @SessionScoped @Alternative\r
public class Pz2Bean implements Pz2Interface, Serializable {\r
\r
private static final long serialVersionUID = 3440277287081557861L;\r
private static Logger logger = Logger.getLogger(Pz2Bean.class);\r
\r
- Pz2Session pz2; \r
@Inject ConfigurationReader configurator;\r
- @Inject SearchClient searchClient;\r
+ protected Pz2Session pz2; \r
+ protected SearchClient searchClient; \r
\r
public Pz2Bean () {\r
logger.info("Instantiating pz2 bean [" + Utils.objectId(this) + "]");\r
public void initiatePz2Session() {\r
logger.debug(Utils.objectId(this) + " will instantiate a Pz2Session next.");\r
pz2 = new Pz2Session();\r
+ searchClient = new StraightPz2Client();\r
logger.info("Using [" + Utils.objectId(searchClient) + "] configured by [" \r
+ Utils.objectId(configurator) + "] on session [" \r
+ Utils.objectId(pz2) + "]" ); \r
pz2.init(searchClient,configurator);\r
}\r
\r
+ \r
/* (non-Javadoc)\r
* @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#doSearch(java.lang.String)\r
*/\r
* @return\r
*/\r
public List<ErrorInterface> getConfigurationErrors();\r
- \r
+ \r
}\r
private static final long serialVersionUID = 3947514708343320514L;\r
private static Logger logger = Logger.getLogger(Pz2Session.class);\r
\r
- private Map<String,Pazpar2ResponseData> dataObjects = new ConcurrentHashMap<String,Pazpar2ResponseData>();\r
- private QueryStates queryStates = new QueryStates();\r
- private ErrorHelper errorHelper = null;\r
- \r
- private List<ErrorInterface> configurationErrors = null;\r
- private SearchClient searchClient = null; \r
- private TargetFilter targetFilter = null; \r
- private ResultsPager pager = null; \r
+ protected Map<String,Pazpar2ResponseData> dataObjects = new ConcurrentHashMap<String,Pazpar2ResponseData>();\r
+ protected QueryStates queryStates = new QueryStates();\r
+ protected ErrorHelper errorHelper = null;\r
+ \r
+ protected List<ErrorInterface> configurationErrors = null;\r
+ protected SearchClient searchClient = null; \r
+ protected TargetFilter targetFilter = null; \r
+ protected ResultsPager pager = null; \r
\r
public Pz2Session () {\r
logger.info("Instantiating pz2 session object [" + Utils.objectId(this) + "]"); \r
// To avoid that, a context free client is cloned from the context \r
// dependent one. \r
// If propagation to threads gets supported, the cloning can go. \r
- this.searchClient = searchClient.cloneMe();\r
+ this.searchClient = searchClient.cloneMe(); \r
\r
} catch (ConfigurationException e) {\r
configurationErrors.add(new ConfigurationError("Search Client","Configuration",e.getMessage(),new ErrorHelper(configReader))); \r
logger.info(configReader.document());\r
resetDataObjects();\r
}\r
- \r
+ \r
public void doSearch(String query) {\r
setCommandParameter("search",new CommandParameter("query","=",query)); \r
doSearch();\r
}\r
\r
\r
- private boolean hasTargetFilter(TargetFilter targetFilter) {\r
+ protected boolean hasTargetFilter(TargetFilter targetFilter) {\r
return hasTargetFilter() && targetFilter.equals(this.targetFilter);\r
}\r
\r
- private boolean hasQuery() {\r
+ protected boolean hasQuery() {\r
return !(getCommand("search").getParameter("query") == null);\r
}\r
\r
return errorHelper;\r
}\r
\r
- private void handleQueryStateChanges (String commands) {\r
+ protected void handleQueryStateChanges (String commands) {\r
if (queryStates.hasPendingStateChange("search")) { \r
logger.debug("Found pending search change. Doing search before updating " + commands);\r
doSearch();\r
} \r
}\r
\r
- private String getActiveClients() { \r
+ protected String getActiveClients() { \r
if (getShow()!=null) {\r
logger.debug("Active clients: "+getShow().getActiveClients());\r
return getShow().getActiveClients();\r
}\r
}\r
\r
- private Pazpar2Command getCommand(String name) {\r
+ protected Pazpar2Command getCommand(String name) {\r
return queryStates.getCurrentState().getCommand(name);\r
}\r
\r
- private void setCommandParameter(String commandName, CommandParameter parameter) {\r
+ protected void setCommandParameter(String commandName, CommandParameter parameter) {\r
logger.debug("Setting parameter for " + commandName + ": " + parameter);\r
queryStates.getCurrentState().setCommandParameter(commandName, parameter, queryStates); \r
}\r
\r
\r
- private void removeCommandParameter(String commandName, String parameterName) {\r
+ protected void removeCommandParameter(String commandName, String parameterName) {\r
queryStates.getCurrentState().removeCommandParameter(commandName,parameterName,queryStates); \r
}\r
\r
- private void removeCommand (String commandName) {\r
+ protected void removeCommand (String commandName) {\r
queryStates.getCurrentState().removeCommand(commandName, queryStates);\r
}\r
\r
- private String getCommandParameterValue (String commandName, String parameterName, String defaultValue) { \r
+ protected String getCommandParameterValue (String commandName, String parameterName, String defaultValue) { \r
Pazpar2Command command = getCommand(commandName);\r
if (command != null) {\r
CommandParameter parameter = command.getParameter(parameterName);\r
return defaultValue; \r
}\r
\r
- private String getCommandParameterValueSimple (String commandName, String parameterName, String defaultValue) { \r
+ protected String getCommandParameterValueSimple (String commandName, String parameterName, String defaultValue) { \r
Pazpar2Command command = getCommand(commandName);\r
if (command != null) {\r
CommandParameter parameter = command.getParameter(parameterName);\r
}\r
\r
\r
- private int getCommandParameterValue (String commandName, String parameterName, int defaultValue) {\r
+ protected int getCommandParameterValue (String commandName, String parameterName, int defaultValue) {\r
Pazpar2Command command = getCommand(commandName);\r
if (command != null) {\r
CommandParameter parameter = command.getParameter(parameterName);\r
return defaultValue; \r
}\r
\r
- private String doCommand(String commandName) { \r
+ protected String doCommand(String commandName) { \r
Pazpar2Command command = getCommand(commandName); \r
logger.debug(command.getEncodedQueryString() + ": Results for "+ getCommand("search").getEncodedQueryString());\r
- return update(commandName); \r
+ return update(commandName);\r
}\r
\r
- private void resetDataObjects() {\r
+ protected void resetDataObjects() {\r
logger.debug("Resetting show,stat,termlist,bytarget,search response objects.");\r
dataObjects = new ConcurrentHashMap<String,Pazpar2ResponseData>();\r
dataObjects.put("show", new ShowResponse());\r
public void setSearchCommand(Pazpar2Command command);\r
public CommandResponse executeCommand(Pazpar2Command command, ByteArrayOutputStream baos) throws Pazpar2ErrorException, IOException;\r
public SearchClient cloneMe();\r
- \r
+ public boolean isAuthenticatingClient(); \r
}\r
import java.util.Map;\r
\r
import javax.enterprise.context.SessionScoped;\r
-import javax.enterprise.inject.Alternative;\r
import javax.inject.Named;\r
\r
import org.apache.log4j.Logger;\r
import com.indexdata.pz2utils4jsf.errors.ConfigurationException;\r
import com.indexdata.pz2utils4jsf.utils.Utils;\r
\r
-@Named @SessionScoped @Alternative\r
+@Named @SessionScoped \r
public class StraightPz2Client implements SearchClient {\r
\r
private static final long serialVersionUID = 5414266730169982028L;\r
} \r
}\r
\r
+ public boolean isAuthenticatingClient () {\r
+ return false;\r
+ }\r
+ \r
+ public boolean isAuthenticated() {\r
+ return false;\r
+ }\r
+ \r
+ public boolean authenticate() {\r
+ throw new UnsupportedOperationException("No authentication mechanism for straight pazpar2 client");\r
+ }\r
\r
@Override\r
public void setSearchCommand(Pazpar2Command command) {\r
* \r
* @param commandName The name of the command during which's execution the error was encountered\r
* @param exceptionName The (possibly loosely defined) name of the exception that was thrown\r
- * @param pazpar2ErrorXml The error document as created by Pazpar2 -- or, for some errors, by the \r
- * Pazpar2 client. \r
+ * @param pazpar2ErrorXml The error document as created by Pazpar2, or the Service Proxy or \r
+ * by the Pazpar2 client itself. \r
* @return\r
*/\r
public static String insertPazpar2ErrorXml (String commandName, String exceptionName, String pazpar2ErrorXml) {\r
--- /dev/null
+package com.indexdata.pz2utils4jsf.pazpar2.sp.auth;\r
+\r
+import java.io.Serializable;\r
+import java.util.List;\r
+import java.util.Map;\r
+\r
+public interface AuthenticationEntity extends Serializable{\r
+ \r
+ \r
+ public String getProperty(String key); \r
+ \r
+ public Map<String,String> getPropertyMap();\r
+\r
+ public List<String> getPossibleProperties();\r
+ \r
+}\r
--- /dev/null
+package com.indexdata.pz2utils4jsf.pazpar2.sp.auth;\r
+\r
+import java.util.Arrays;\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
+\r
+import javax.enterprise.context.SessionScoped;\r
+import javax.inject.Named;\r
+\r
+@Named("user") @SessionScoped\r
+public class ServiceProxyUser implements AuthenticationEntity {\r
+\r
+ private static final long serialVersionUID = 2351542518778803071L;\r
+ private List<String> possibleProperties = Arrays.asList("name","password","realm");\r
+ private Map<String,String> actualProperties = new HashMap<String,String>();\r
+\r
+ public ServiceProxyUser() {}\r
+ \r
+ public void setAuthenticationMethod() {\r
+ \r
+ }\r
+\r
+ public String getName() { \r
+ return actualProperties.get("name"); \r
+ }\r
+ \r
+ public void setName(String newValue) { \r
+ actualProperties.put("name", newValue); \r
+ }\r
+ \r
+ public String getPassword() { \r
+ return actualProperties.get("password"); \r
+ }\r
+ \r
+ public void setPassword(String newValue) { \r
+ actualProperties.put("password", newValue);\r
+ }\r
+ \r
+ public void setRealm(String realm) {\r
+ actualProperties.put("realm", realm);\r
+ }\r
+ \r
+ public String getRealm() {\r
+ return actualProperties.get("realm");\r
+ }\r
+ \r
+\r
+ @Override\r
+ public String getProperty(String key) {\r
+ return actualProperties.get(key);\r
+ }\r
+\r
+ @Override\r
+ public Map<String, String> getPropertyMap() {\r
+ return actualProperties;\r
+ }\r
+\r
+ @Override\r
+ public List<String> getPossibleProperties() {\r
+ return possibleProperties;\r
+ } \r
+ \r
+\r
+}\r