Quote all instances of the `service_proxy_auth` setting name.
[mkws-moved-to-github.git] / doc / library-configuration.markdown
1 MKWS Target Selection
2 =====================
3
4
5 MKWS accesses targets using the Pazpar2 metasearching engine. Although
6 Pazpar2 can be used directly, using a statically configured set of
7 targets, this usage is unusual. More often, Pazpar2 is fronted by the
8 Service Proxy (SP), which manages authentication, sessions, target
9 selection, etc.
10
11 This document assumes the SP is used, and explains how to go about
12 making a set of targets (a "library") available, how to connect your
13 MKWS application to that library, and how to choose which of the
14 available targets to use.
15
16
17 1. Maintaining the library
18 --------------------------
19
20 The service proxy accesses sets of targets that are known as
21 "libraries". In general, each customer will have their own library,
22 though some standard libraries may be shared between many customers --
23 for example, a library containing all open-access academic journals.
24 A library can also contain other configuration information, including
25 the set of categories by which targets are classified for the library.
26
27 Libraries are maintained using MKAdmin (MasterKey
28 Admin). Specifically, those used by MKWS are generally maintained on
29 the "MKC Admin" installation at
30 `http://mkx-admin.indexdata.com/console/`
31
32 In general, Index Data will create a library for each customer, then
33 give the customer a username/password pair that they can use to enter
34 MKAdmin and administrate that library.
35
36 Once logged in, customers can select which targets to include (from
37 the list of several thousand that MKAdmin knows about), and make
38 customer-specific modifications -- e.g. overriding the titles of the
39 targets.
40
41 Most importantly, customers' administrators can add authentication
42 credentials that the Service Proxy will used on their behalf when
43 accessing subscription resources -- username/password pairs or proxies
44 to use for IP-based authentication. Note that **it is then crucial to
45 secure the library from use by unauthorised clients**, otherwise the
46 customer's paid subscriptions will be exploited.
47
48 Access to libraries is managed by creating one or more "User Access"
49 records in MKAdmin, under the tab of that name. Each of these records
50 provides a combination of credentials and other data that allow an
51 incoming MKWS client to be identified as having legitimate access to
52 the library. The authentication process, described below, works by
53 searching for a matching User Access record.
54
55
56 2. Authenticating your MWKS application onto the library
57 --------------------------------------------------------
58
59 Some MKWS applications will be content to use the default library with
60 its selection of targets. Most, though, will want to define their own
61 library providing a different range of available targets. An important
62 case is that of applications that authenticate onto subscription
63 resources by means of backe-end site credentials stored in MKAdmin:
64 precautions must be taken so that such library accounts do not allow
65 unauthorised access.
66
67 Setting up such a library is a process of several stages.
68
69 ### Stage A: create the User Access account
70
71 Log in to MKAdmin administrate your library:
72
73 * Go to `http://mkc-admin.indexdata.com/console/`
74 * Enter the adminstrative username/password
75 * Go to the User Access tab
76 * Create an end-user account
77 * Depending on what authentication method it be used, set the
78   User Access account's username and password, or IP-address range, or
79   referring URL, or hostname.
80
81 If your MWKS application runs at a well-known, permanent address --
82 `http://yourname.com/app.html`, say -- you can set the User Access
83 record so that this originating URL is recognised by setting it into
84 the "Referring URL" field.
85
86 If your application accesses the Service Proxy by a unique virtual
87 hostname -- yourname.sp-mkws.indexdata.com, say -- you can tie the use
88 of this hostname to your library by setting the User Access record's
89 "Host Name" field to name of the host where the SP is accessed. **Note
90 that this is not secure, as other applications can use this virtual
91 hostname to gain access to your library.**
92
93 > TODO Authentication by IP address does not yet work correctly -- see
94 > bug MKWS-234 ("Improve SP configuration/proxying for better
95 > authentication").
96
97 Alternatively, your application can authenticate by username and
98 password credentials. This is a useful approach in several situations,
99 including when you need to specify the use of a different library from
100 usual one. To arrange for this, set the username and password as a
101 single string separated by a slash -- e.g. "mike/swordfish" -- into
102 the User Access record's Authentication field.
103
104 You can create multiple User Access records: for example, one that
105 uses Referring URL, and another that uses a username/password pair to
106 be used when running an application from a different URL.
107
108 ### Stage B: tell the application to use the library
109
110 In the HTML of the application, tell MKWS to authenticate on to the
111 Service Proxy. When IP-based, referer-based or hostname-based
112 authentication is used, this is very simple:
113
114         <script type="text/javascript">
115           var mkws_config = { service_proxy_auth:
116           "//sp-mkws.indexdata.com/service-proxy/?command=auth&action=perconfig" };
117         </script>
118
119 > TODO This should be the default setting
120
121 And ensure that access to the MWKS application is from the correct
122 Referrer URL or IP-range.
123
124 ### Stage C1 (optional): access by a different virtual hostname
125
126 When hostname-based authentication is in use, it's necessary to access
127 the Service Proxy as the correctly named virtual host. This can be
128 done by setting the `service_proxy_auth` configuration item to a
129 URL containing that hostname, such as
130 `//yourname.sp-mkws.indexdata.com/service-proxy/?command=auth&action=perconfig`
131
132 > TODO It should be possible to change just the hostname without
133 > needing to repeat the rest of the URL (protocol, path, query)
134
135 > TODO When changing the SP authentication URL, the Pazpar2 URL should
136 > in general change along with it.
137
138 ### Stage C2 (optional): embed credentials for access to the library
139
140 When credential-based authentication is in use (username and
141 password), it's necessary to pass these credentials into the Service
142 Proxy when establishing the session. This can most simply be done just
143 by setting the `service_proxy_auth` configuration item to a URL such as
144 `//sp-mkws.indexdata.com/service-proxy/?command=auth&action=perconfig&username=mike&password=swordfish`
145
146 > TODO It should be possible to add the username and password to the
147 > configuration without needing to repeat the rest of the URL.
148
149 ### Stage D (optional): conceal credentials from HTML source
150
151 Using a credential-based Service-Proxy authentication URL such as the
152 one above reveals the the credentials to public view -- to anyone who
153 does View Source on the MKWS application. This may be acceptable for
154 some libraries, but is intolerable for those which provide
155 authenticated access to subscription resources.
156
157 In these circumstances, a more elaborate approach is necessary. The
158 idea is to make a URL local to the customer that is used for
159 authentication onto the Service Proxy, hiding the credentials in a
160 local rewrite rule. Then local mechanisms can be used to limit access
161 to that local authentication URL. Here is one way to do it when
162 Apache2 is the application's web-server, which we will call
163 yourname.com:
164
165 - Add a rewriting authentication alias to the configuration:
166
167         RewriteEngine on
168         RewriteRule /spauth/ http://mkws.indexdata.com/service-proxy/?command=auth&action=check,login&username=U&password=PW [P]
169
170 - Set the MKWS configuration item `service_proxy_auth` to
171   `http://yourname.com/spauth/`
172 - Protect access to the local path `http://yourname.com/spauth/`
173   (e.g. using a .htaccess file).
174
175
176 3. Choosing targets from the library
177 ------------------------------------
178
179 MKWS applications can choose what subset of the library's targets to
180 use, by means of several alternative settings on individual widgets or
181 in the mkws_config structure:
182
183 * targets -- contains a Pazpar2 targets string, typically of the form
184   "pz:id=" or "pz:id~" followed by a pipe-separated list of low-level
185   target IDs.
186
187   At present, these IDs can take one of two forms, depending on the
188   configuration of the Service Proxy being used: they may be based on
189   ZURLs, so a typical value would be something like:
190         pz:id=josiah.brown.edu:210/innopac|lui.indexdata.com:8080/solr4/select?fq=database:4902
191   Or they may be UDBs, so a typical value would be something like:
192         pz:id=brown|artstor
193
194 * targetfilter -- contains a CQL query which is used to find relevant
195   targets from the relvant library. For example,
196         udb==Google_Images
197   Or
198         categories=news
199
200 * target -- contains a single UDB, that of the sole target to be
201   used. For example
202         Google_Images
203   This is merely syntactic sugar for "targetfilter" with the query
204         udb==NAME
205
206