1 package org.open_ils.util;
4 import org.opensrf.util.*;
6 import java.util.HashMap;
7 import java.security.MessageDigest;
13 * @param params Login arguments, which may consist of<br/>
15 * barcode - if username is provided, barcode will be ignored<br/>
17 * workstation - name of the workstation where the login is occuring<br/>
18 * type - type of login, currently "opac", "staff", and "temp"<br/>
19 * org - optional org ID to provide login context when no workstation is used.
20 * @return An Event object. On success, the event 'payload' will contain
21 * 'authtoken' and 'authtime' fields, which represent the session key and
22 * session inactivity timeout, respectively.
24 public static Event login(Map params) throws MethodException {
26 Map<String, String> initMap = new HashMap<String, String>();
27 String init = (params.get("username") != null) ?
28 params.get("username").toString() : params.get("barcode").toString();
30 Object resp = ClientSession.atomicRequest(
32 "open-ils.auth.authenticate.init", new Object [] {init});
34 /** see if the server responded with some type of unexpected event */
35 Event evt = Event.parseEvent(resp);
36 if(evt != null) return evt;
38 params.put("password", md5Hex(resp + md5Hex(params.get("password").toString())));
40 resp = ClientSession.atomicRequest(
42 "open-ils.auth.authenticate.complete", new Object[]{params});
44 return Event.parseEvent(resp);
49 * Generates the hex md5sum of a string.
50 * @param s The string to md5sum
51 * @return The 32-character hex md5sum
53 public static String md5Hex(String s) {
54 StringBuffer sb = new StringBuffer();
57 md = MessageDigest.getInstance("MD5");
58 } catch(Exception e) {
62 md.update(s.getBytes());
63 byte[] digest = md.digest();
64 for (int i = 0; i < digest.length; i++) {
65 int b = digest[i] & 0xff;
66 String hex = Integer.toHexString(b);
67 if (hex.length() == 1) sb.append("0");