1 |
7737
|
leinfelder
|
/**
|
2 |
|
|
* This work was created by participants in the DataONE project, and is
|
3 |
|
|
* jointly copyrighted by participating institutions in DataONE. For
|
4 |
|
|
* more information on DataONE, see our web site at http://dataone.org.
|
5 |
|
|
*
|
6 |
|
|
* Copyright ${year}
|
7 |
|
|
*
|
8 |
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
9 |
|
|
* you may not use this file except in compliance with the License.
|
10 |
|
|
* You may obtain a copy of the License at
|
11 |
|
|
*
|
12 |
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
13 |
|
|
*
|
14 |
|
|
* Unless required by applicable law or agreed to in writing, software
|
15 |
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
16 |
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
17 |
|
|
* See the License for the specific language governing permissions and
|
18 |
|
|
* limitations under the License.
|
19 |
|
|
*
|
20 |
|
|
* $Id$
|
21 |
|
|
*/
|
22 |
|
|
|
23 |
|
|
package edu.ucsb.nceas.metacat.portal;
|
24 |
|
|
|
25 |
|
|
import javax.servlet.http.Cookie;
|
26 |
|
|
import javax.servlet.http.HttpServletRequest;
|
27 |
|
|
import javax.servlet.http.HttpServletResponse;
|
28 |
|
|
|
29 |
|
|
import edu.uiuc.ncsa.myproxy.oa4mp.client.OA4MPResponse;
|
30 |
|
|
import edu.uiuc.ncsa.myproxy.oa4mp.client.servlet.ClientServlet;
|
31 |
|
|
import edu.uiuc.ncsa.myproxy.oa4mp.client.storage.AssetStoreUtil;
|
32 |
|
|
import edu.uiuc.ncsa.security.core.Identifier;
|
33 |
|
|
import edu.uiuc.ncsa.security.core.exceptions.ServerSideException;
|
34 |
|
|
import edu.uiuc.ncsa.security.servlet.JSPUtil;
|
35 |
|
|
|
36 |
|
|
/**
|
37 |
|
|
* A very simple sample servlet showing how a portal can start delegation. This just does the
|
38 |
|
|
* initial request then a redirect
|
39 |
|
|
* so there is nothing to display to the user.
|
40 |
|
|
* <p>Created by Jeff Gaynor<br>
|
41 |
|
|
* on Jun 18, 2010 at 2:10:58 PM
|
42 |
|
|
*/
|
43 |
|
|
public class StartRequest extends ClientServlet {
|
44 |
|
|
|
45 |
|
|
@Override
|
46 |
|
|
protected void doIt(HttpServletRequest request, HttpServletResponse response) throws Throwable {
|
47 |
|
|
info("1.a. Starting transaction");
|
48 |
|
|
OA4MPResponse gtwResp = null;
|
49 |
|
|
// Drumroll please: here is the work for this call.
|
50 |
|
|
try {
|
51 |
|
|
Identifier id = AssetStoreUtil.createID();
|
52 |
|
|
gtwResp = getOA4MPService().requestCert(id);
|
53 |
|
|
// if there is a store, store something in it.
|
54 |
|
|
Cookie cookie = new Cookie(OA4MP_CLIENT_REQUEST_ID, id.getUri().toString());
|
55 |
|
|
response.addCookie(cookie);
|
56 |
|
|
|
57 |
|
|
} catch (Throwable t) {
|
58 |
|
|
|
59 |
|
|
if (t instanceof ServerSideException) {
|
60 |
|
|
ServerSideException sse = (ServerSideException) t;
|
61 |
|
|
//nothing was, in fact, returned from the server.
|
62 |
|
|
if (!sse.isTrivial()) {
|
63 |
|
|
if (getCE().isDebugOn()) {
|
64 |
|
|
t.printStackTrace();
|
65 |
|
|
}
|
66 |
|
|
for (String key : sse.getQueryParameters().keySet()) {
|
67 |
|
|
request.setAttribute(key, sse.getQueryParameters().get(key));
|
68 |
|
|
}
|
69 |
|
|
String contextPath = request.getContextPath();
|
70 |
|
|
if (!contextPath.endsWith("/")) {
|
71 |
|
|
contextPath = contextPath + "/";
|
72 |
|
|
}
|
73 |
|
|
request.setAttribute("action", contextPath);
|
74 |
|
|
JSPUtil.handleException(sse.getCause(), request, response, "/pages/client-error.jsp");
|
75 |
|
|
if (sse.getRedirect() != null) {
|
76 |
|
|
response.sendRedirect(sse.getRedirect().toString());
|
77 |
|
|
}
|
78 |
|
|
return;
|
79 |
|
|
}
|
80 |
|
|
|
81 |
|
|
JSPUtil.handleException(t, request, response, "/pages/client-error.jsp");
|
82 |
|
|
return;
|
83 |
|
|
}
|
84 |
|
|
throw t;
|
85 |
|
|
}
|
86 |
|
|
|
87 |
|
|
String target = request.getParameter("target");
|
88 |
|
|
if (target != null) {
|
89 |
|
|
request.getSession().setAttribute("target", target);
|
90 |
|
|
}
|
91 |
|
|
response.sendRedirect(gtwResp.getRedirect().toString());
|
92 |
|
|
}
|
93 |
|
|
}
|