Revision 5071
Added by daigle over 14 years ago
ClientViewHelper.java | ||
---|---|---|
19 | 19 |
import edu.ucsb.nceas.metacat.client.MetacatFactory; |
20 | 20 |
import edu.ucsb.nceas.metacat.client.MetacatInaccessibleException; |
21 | 21 |
import edu.ucsb.nceas.metacat.properties.PropertyService; |
22 |
import edu.ucsb.nceas.metacat.service.SessionService; |
|
23 |
import edu.ucsb.nceas.metacat.util.RequestUtil; |
|
24 |
import edu.ucsb.nceas.metacat.util.SessionData; |
|
22 | 25 |
import edu.ucsb.nceas.utilities.XMLUtilities; |
23 | 26 |
import edu.ucsb.nceas.utilities.PropertyNotFoundException; |
24 | 27 |
import java.io.BufferedReader; |
... | ... | |
34 | 37 |
import java.util.Stack; |
35 | 38 |
import java.util.TreeMap; |
36 | 39 |
import java.util.Vector; |
40 |
import javax.servlet.http.Cookie; |
|
37 | 41 |
import javax.servlet.http.HttpServletRequest; |
38 | 42 |
import javax.servlet.http.HttpServletResponse; |
39 | 43 |
import javax.servlet.http.HttpSession; |
... | ... | |
78 | 82 |
public ClientViewHelper(HttpServletRequest request) throws MetacatInaccessibleException { |
79 | 83 |
String host, context; |
80 | 84 |
|
81 |
clientSession = request.getSession(); |
|
85 |
clientSession = request.getSession(false);
|
|
82 | 86 |
host = request.getHeader("host"); |
83 | 87 |
context = request.getContextPath(); |
84 | 88 |
init(host, context); |
... | ... | |
122 | 126 |
public String clientRequest(HttpServletRequest request, HttpServletResponse response) { |
123 | 127 |
String result = null, action, contentType; |
124 | 128 |
MultipartParser multipartParser; |
125 |
HashMap responseMap;
|
|
129 |
HashMap<String, String> responseMap;
|
|
126 | 130 |
|
131 |
getMetacatClient().setSessionId(request.getSession().getId()); |
|
132 |
|
|
127 | 133 |
if (clientViewBean == null) { |
128 | 134 |
clientViewBean = (ClientView) clientSession.getAttribute(ClientView.CLIENT_VIEW_BEAN); |
129 | 135 |
|
... | ... | |
159 | 165 |
responseMap = handleClientRequest(null); |
160 | 166 |
//*** Now that the action has been processed, clear it. |
161 | 167 |
clientViewBean.setAction(""); |
168 |
if (isLoggedIn()) { |
|
169 |
// HttpSession session = request.getSession(false); |
|
170 |
// session.setAttribute("ClientViewHelper", this); |
|
171 |
Cookie jSessionCookie = new Cookie("JSESSIONID", clientViewBean.getSessionid()); |
|
172 |
response.addCookie(jSessionCookie); |
|
173 |
} |
|
162 | 174 |
} else if (action.equals("Logout")) { |
163 | 175 |
responseMap = handleClientRequest(null); |
164 | 176 |
clientViewBean.setAction(""); |
... | ... | |
168 | 180 |
multipartParser = new MultipartParser(request, sizeLimit * 1024 * 1024); |
169 | 181 |
responseMap = handleClientRequest(multipartParser); |
170 | 182 |
} catch (IOException ex) { |
171 |
responseMap = new HashMap(); |
|
183 |
responseMap = new HashMap<String, String>();
|
|
172 | 184 |
responseMap.put("message", ex.getMessage()); |
173 | 185 |
} |
174 | 186 |
clientViewBean.setAction(""); |
... | ... | |
177 | 189 |
try { |
178 | 190 |
handleDownloadResponse(responseMap, response); |
179 | 191 |
} catch (IOException ex) { |
180 |
responseMap = new HashMap(); |
|
192 |
responseMap = new HashMap<String, String>();
|
|
181 | 193 |
responseMap.put("message", ex.getMessage()); |
182 | 194 |
} |
183 | 195 |
|
... | ... | |
206 | 218 |
* the action is Download, than this will contain all needed values |
207 | 219 |
* to pass to handleDownloadResponse. |
208 | 220 |
*/ |
209 |
public HashMap handleClientRequest(MultipartParser multipartParser) { |
|
221 |
public HashMap<String, String> handleClientRequest(MultipartParser multipartParser) {
|
|
210 | 222 |
String result = "", serverResponse; |
211 |
String button, posted_ldapUserName, tmp, action; |
|
212 |
HashMap responseMap = new HashMap(); |
|
213 |
int fileIdx; |
|
223 |
String posted_ldapUserName, tmp, action; |
|
224 |
HashMap<String, String> responseMap = new HashMap<String, String>(); |
|
214 | 225 |
|
215 | 226 |
|
216 | 227 |
if (clientViewBean != null) { |
... | ... | |
221 | 232 |
tmp = LDAP_TEMPLATE.replaceFirst("%1s", clientViewBean.getUsername()); |
222 | 233 |
posted_ldapUserName = tmp.replaceFirst("%2s", clientViewBean.getOrganization()); |
223 | 234 |
|
235 |
// if (metacatSessionId != null) { |
|
236 |
// metacatClient.setSessionId(metacatSessionId); |
|
237 |
// } |
|
224 | 238 |
serverResponse = metacatClient.login(posted_ldapUserName, clientViewBean.getPassword()); |
225 | 239 |
setLoggedIn(serverResponse); |
226 | 240 |
result = parseXml("message", serverResponse); |
... | ... | |
229 | 243 |
clientViewBean.setMessage(ClientView.UPLOAD_MESSAGE, ""); |
230 | 244 |
if (isLoggedIn()) { |
231 | 245 |
clientViewBean.setSessionid(metacatClient.getSessionId()); |
246 |
|
|
232 | 247 |
} |
233 | 248 |
} else if (action.equals("Logout")) { |
234 | 249 |
result = metacatClient.logout(); |
... | ... | |
294 | 309 |
* @return ClientViewHelper instance. |
295 | 310 |
*/ |
296 | 311 |
public static ClientViewHelper clientViewHelperInstance(HttpServletRequest request) { |
297 |
ClientViewHelper result;
|
|
312 |
ClientViewHelper result; |
|
298 | 313 |
|
314 |
String sessionId = request.getSession(false).getId(); |
|
315 |
|
|
299 | 316 |
result = (ClientViewHelper) request.getSession().getAttribute("ClientViewHelper"); |
300 | 317 |
if (result == null) { |
301 | 318 |
try { |
... | ... | |
306 | 323 |
} |
307 | 324 |
} |
308 | 325 |
|
326 |
if (result.clientViewBean == null) { |
|
327 |
result.clientViewBean = (ClientView) request.getSession().getAttribute(ClientView.CLIENT_VIEW_BEAN); |
|
328 |
|
|
329 |
if (result.clientViewBean == null) { |
|
330 |
//make a new one and shove it in the session |
|
331 |
result.clientViewBean = new ClientView(); |
|
332 |
request.getSession().setAttribute(ClientView.CLIENT_VIEW_BEAN, result.clientViewBean); |
|
333 |
} |
|
334 |
} |
|
335 |
|
|
336 |
boolean oldLoginValue = result.loggedIn; |
|
337 |
result.setLoggedIn(SessionService.validateSession(sessionId)); |
|
338 |
if (result.isLoggedIn()) { |
|
339 |
SessionData sessionData = SessionService.getRegisteredSession(sessionId); |
|
340 |
result.setUserName(sessionData.getName()); |
|
341 |
} |
|
342 |
|
|
343 |
if (!oldLoginValue || result.loggedIn) { |
|
344 |
result.clientViewBean.setMessage(ClientView.UPLOAD_MESSAGE, ""); |
|
345 |
} |
|
346 |
|
|
309 | 347 |
return(result); |
310 | 348 |
} |
311 | 349 |
|
... | ... | |
331 | 369 |
loggedIn = (serverResponse != null && serverResponse.indexOf("login") > -1); |
332 | 370 |
} |
333 | 371 |
|
372 |
public void setLoggedIn(boolean isLoggedIn) { |
|
373 |
this.loggedIn = isLoggedIn; |
|
374 |
} |
|
375 |
|
|
376 |
public void setUserName(String userName) { |
|
377 |
clientViewBean.setUsername(userName); |
|
378 |
} |
|
379 |
|
|
334 | 380 |
public String parseXml(String elementName, String xml) { |
335 | 381 |
String result = null; |
336 | 382 |
Document doc; |
... | ... | |
979 | 1025 |
return(result); |
980 | 1026 |
} |
981 | 1027 |
|
982 |
private HashMap download(ClientView bean) { |
|
1028 |
private HashMap<String, String> download(ClientView bean) {
|
|
983 | 1029 |
Properties args; |
984 | 1030 |
InputStream inStream; |
985 | 1031 |
String docId, metaId, fNm = null, pth, txtLst[]; |
... | ... | |
987 | 1033 |
Node branchRoot, metaRoot; |
988 | 1034 |
ByteArrayOutputStream outStream; |
989 | 1035 |
int intMe; |
990 |
HashMap responseMap = new HashMap();
|
|
1036 |
HashMap<String, String> responseMap = new HashMap<String, String>();
|
|
991 | 1037 |
|
992 | 1038 |
docId = bean.getDocId(); |
993 | 1039 |
metaId = bean.getMetaFileDocId(); |
... | ... | |
1066 | 1112 |
} |
1067 | 1113 |
|
1068 | 1114 |
//*** Now, write the output stream to the response. |
1069 |
responseMap.put("outputStream", outStream); |
|
1115 |
responseMap.put("outputStream", outStream.toString());
|
|
1070 | 1116 |
|
1071 | 1117 |
//*** Finally, set the message for the user interface to display. |
1072 | 1118 |
msg = msg.replaceFirst("~", fNm); |
Also available in: Unified diff
Change sanparks skin to log in with browser session instead of metacat client session so session can be validated on other pages.