Revision 9183
Added by ben leinfelder over 9 years ago
src/edu/ucsb/nceas/metacat/portal/FailureServlet.java | ||
---|---|---|
1 |
/** |
|
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.HttpServletRequest; |
|
26 |
import javax.servlet.http.HttpServletResponse; |
|
27 |
|
|
28 |
import edu.uiuc.ncsa.myproxy.oa4mp.client.servlet.ClientServlet; |
|
29 |
|
|
30 |
import java.io.PrintWriter; |
|
31 |
|
|
32 |
/** |
|
33 |
* <p>Created by Jeff Gaynor<br> |
|
34 |
* on Aug 11, 2010 at 10:11:13 AM |
|
35 |
*/ |
|
36 |
public class FailureServlet extends ClientServlet { |
|
37 |
protected void doIt(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Throwable { |
|
38 |
clearCookie(httpServletRequest, httpServletResponse); // clear out old session info |
|
39 |
httpServletResponse.setContentType("text/html"); |
|
40 |
PrintWriter printWriter = httpServletResponse.getWriter(); |
|
41 |
printWriter.println("<html>\n" + |
|
42 |
"<head><title>Failure</title></head>\n" + |
|
43 |
"<body><h1>Uh-oh...</h1>" + |
|
44 |
"<p>There was an error processing your request.</p>" + |
|
45 |
"<form name=\"input\" action=\""); |
|
46 |
printWriter.println(httpServletRequest.getContextPath() + "/\" method=\"get\">"); |
|
47 |
printWriter.println("Click to go back to the main page<br><br>\n" + |
|
48 |
"<input type=\"submit\" value=\"Submit\" />\n" + |
|
49 |
"</form>\n" + |
|
50 |
" </body>\n" + |
|
51 |
"</html>"); |
|
52 |
} |
|
53 |
} |
|
54 | 0 |
src/edu/ucsb/nceas/metacat/portal/SuccessServlet.java | ||
---|---|---|
1 |
/** |
|
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 org.dataone.portal.PortalCertificateManager; |
|
26 |
|
|
27 |
import edu.uiuc.ncsa.myproxy.oa4mp.client.Asset; |
|
28 |
import edu.uiuc.ncsa.myproxy.oa4mp.client.AssetResponse; |
|
29 |
import edu.uiuc.ncsa.myproxy.oa4mp.client.servlet.ClientServlet; |
|
30 |
import edu.uiuc.ncsa.security.core.exceptions.GeneralException; |
|
31 |
import edu.uiuc.ncsa.security.servlet.JSPUtil; |
|
32 |
|
|
33 |
import javax.servlet.ServletConfig; |
|
34 |
import javax.servlet.ServletException; |
|
35 |
import javax.servlet.http.HttpServletRequest; |
|
36 |
import javax.servlet.http.HttpServletResponse; |
|
37 |
import java.io.PrintWriter; |
|
38 |
import java.security.cert.X509Certificate; |
|
39 |
|
|
40 |
import static edu.uiuc.ncsa.security.util.pkcs.CertUtil.toPEM; |
|
41 |
|
|
42 |
/** |
|
43 |
* <p>Created by Jeff Gaynor<br> |
|
44 |
* on Jul 31, 2010 at 3:29:09 PM |
|
45 |
*/ |
|
46 |
public class SuccessServlet extends ClientServlet { |
|
47 |
|
|
48 |
public void init(ServletConfig config) throws ServletException { |
|
49 |
super.init(config); |
|
50 |
// TODO: anything needed? |
|
51 |
} |
|
52 |
|
|
53 |
protected void doIt(HttpServletRequest request, HttpServletResponse response) throws Throwable { |
|
54 |
String identifier = clearCookie(request, response); |
|
55 |
if (identifier == null) { |
|
56 |
throw new ServletException("Error: No identifier for this delegation request was found. "); |
|
57 |
} |
|
58 |
info("2.a. Getting token and verifier."); |
|
59 |
String token = request.getParameter(TOKEN_KEY); |
|
60 |
String verifier = request.getParameter(VERIFIER_KEY); |
|
61 |
if (token == null || verifier == null) { |
|
62 |
warn("2.a. The token is " + (token==null?"null":token) + " and the verifier is " + (verifier==null?"null":verifier)); |
|
63 |
GeneralException ge = new GeneralException("Error: This servlet requires parameters for the token and verifier. It cannot be called directly."); |
|
64 |
request.setAttribute("exception", ge); |
|
65 |
JSPUtil.handleException(ge, request, response, "/pages/client-error.jsp"); |
|
66 |
return; |
|
67 |
//throw ge; |
|
68 |
} |
|
69 |
info("2.a Token and verifier found."); |
|
70 |
X509Certificate cert = null; |
|
71 |
AssetResponse assetResponse = null; |
|
72 |
|
|
73 |
try { |
|
74 |
info("2.a. Getting the cert(s) from the service"); |
|
75 |
assetResponse = getOA4MPService().getCert(token, verifier); |
|
76 |
X509Certificate[] certificates = assetResponse.getX509Certificates(); |
|
77 |
// update the asset to include the returned certificate |
|
78 |
Asset asset = getOA4MPService().getEnvironment().getAssetStore().get(identifier); |
|
79 |
asset.setCertificates(certificates); |
|
80 |
getOA4MPService().getEnvironment().getAssetStore().save(asset); |
|
81 |
cert = certificates[0]; |
|
82 |
} catch (Throwable t) { |
|
83 |
warn("2.a. Exception from the server: " + t.getCause().getMessage()); |
|
84 |
error("Exception while trying to get cert. message:" + t.getMessage()); |
|
85 |
request.setAttribute("exception", t); |
|
86 |
JSPUtil.handleException(t, request, response, "/pages/client-error.jsp"); |
|
87 |
return; |
|
88 |
//throw t; |
|
89 |
} |
|
90 |
|
|
91 |
// add teh cookie for later request processing |
|
92 |
PortalCertificateManager.getInstance().setCookie(identifier, response); |
|
93 |
|
|
94 |
// find where we should end up |
|
95 |
String target = (String) request.getSession().getAttribute("target"); |
|
96 |
if (target != null) { |
|
97 |
// remove from the session once we use it |
|
98 |
request.getSession().removeAttribute("target"); |
|
99 |
// send the redirect |
|
100 |
response.sendRedirect(target); |
|
101 |
return; |
|
102 |
} |
|
103 |
|
|
104 |
// otherwise show us information |
|
105 |
response.setContentType("text/html"); |
|
106 |
PrintWriter pw = response.getWriter(); |
|
107 |
/* Put the key and certificate in the result, but allow them to be initially hidden. */ |
|
108 |
String y = "<html>\n" + |
|
109 |
"<style type=\"text/css\">\n" + |
|
110 |
".hidden { display: none; }\n" + |
|
111 |
".unhidden { display: block; }\n" + |
|
112 |
"</style>\n" + |
|
113 |
"<script type=\"text/javascript\">\n" + |
|
114 |
"function unhide(divID) {\n" + |
|
115 |
" var item = document.getElementById(divID);\n" + |
|
116 |
" if (item) {\n" + |
|
117 |
" item.className=(item.className=='hidden')?'unhidden':'hidden';\n" + |
|
118 |
" }\n" + |
|
119 |
"}\n" + |
|
120 |
"</script>\n" + |
|
121 |
"<body>\n" + |
|
122 |
"<h1>Success!</h1>\n" + |
|
123 |
"<p>You have successfully requested a DataONE certificate. It will be accessible for 18 hours using your cookie.</p>\n" + |
|
124 |
"<ul>\n" + |
|
125 |
" <li><a href=\"javascript:unhide('showSubject');\">Show/Hide subject</a></li>\n" + |
|
126 |
" <div id=\"showSubject\" class=\"unhidden\">\n" + |
|
127 |
" <p><pre>" + cert.getSubjectDN().toString() + "</pre>\n" + |
|
128 |
" </div>\n" + |
|
129 |
" <li><a href=\"javascript:unhide('showCert');\">Show/Hide certificate</a></li>\n" + |
|
130 |
" <div id=\"showCert\" class=\"hidden\">\n" + |
|
131 |
" <p><pre>" + toPEM(cert) + "</pre>\n" + |
|
132 |
" </div>\n" + |
|
133 |
" <li><a href=\"javascript:unhide('showKey');\">Show/Hide private key</a></li>\n" + |
|
134 |
" <div id=\"showKey\" class=\"hidden\">\n" + |
|
135 |
" <p><pre>" + "hidden for security" + "</pre>\n" + |
|
136 |
" </div>\n" + |
|
137 |
"\n" + |
|
138 |
"</ul>\n" + |
|
139 |
"<a href=" + request.getContextPath() + ">" + |
|
140 |
"Return to portal" + |
|
141 |
"</a> or " + |
|
142 |
"<a href=" + target + ">" + |
|
143 |
"Continue to target" + |
|
144 |
"</a>" + |
|
145 |
"</body>\n" + |
|
146 |
"</html>"; |
|
147 |
pw.println(y); |
|
148 |
pw.flush(); |
|
149 |
} |
|
150 |
|
|
151 |
|
|
152 |
} |
|
153 | 0 |
src/edu/ucsb/nceas/metacat/portal/StartRequest.java | ||
---|---|---|
1 |
/** |
|
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 |
} |
|
94 | 0 |
lib/web.xml.tomcat6 | ||
---|---|---|
323 | 323 |
</servlet-mapping> |
324 | 324 |
--> |
325 | 325 |
|
326 |
<!-- begin MyProxy portal delegation section. Uncomment to enable MyProxy --> |
|
327 |
<!-- |
|
328 |
<servlet> |
|
329 |
<servlet-name>startRequest</servlet-name> |
|
330 |
<servlet-class>edu.ucsb.nceas.metacat.portal.StartRequest</servlet-class> |
|
331 |
<load-on-startup>0</load-on-startup> |
|
332 |
</servlet> |
|
333 |
<servlet-mapping> |
|
334 |
<servlet-name>startRequest</servlet-name> |
|
335 |
<url-pattern>/startRequest</url-pattern> |
|
336 |
</servlet-mapping> |
|
337 |
|
|
338 |
<servlet> |
|
339 |
<servlet-name>ready</servlet-name> |
|
340 |
<servlet-class>edu.ucsb.nceas.metacat.portal.SuccessServlet</servlet-class> |
|
341 |
<load-on-startup>0</load-on-startup> |
|
342 |
</servlet> |
|
343 |
<servlet-mapping> |
|
344 |
<servlet-name>ready</servlet-name> |
|
345 |
<url-pattern>/ready</url-pattern> |
|
346 |
</servlet-mapping> |
|
347 | 326 |
|
348 |
<servlet> |
|
349 |
<servlet-name>error</servlet-name> |
|
350 |
<servlet-class>edu.ucsb.nceas.metacat.portal.FailureServlet</servlet-class> |
|
351 |
<load-on-startup>0</load-on-startup> |
|
352 |
</servlet> |
|
353 |
<servlet-mapping> |
|
354 |
<servlet-name>error</servlet-name> |
|
355 |
<url-pattern>/error</url-pattern> |
|
356 |
</servlet-mapping> |
|
357 |
|
|
358 |
<session-config> |
|
359 |
<session-timeout>30000</session-timeout> |
|
360 |
</session-config> |
|
361 |
|
|
362 |
<listener> |
|
363 |
<listener-class>edu.uiuc.ncsa.myproxy.oa4mp.client.loader.ClientBootstrapper</listener-class> |
|
364 |
</listener> |
|
365 |
|
|
366 |
<context-param> |
|
367 |
<param-name>oa4mp:client.config.file</param-name> |
|
368 |
<param-value>/WEB-INF/oa4mp_client.xml</param-value> |
|
369 |
</context-param> |
|
370 |
--> |
|
371 |
<!-- end MyProxy section --> |
|
372 |
|
|
373 | 327 |
<!-- currently the W3C havent settled on a media type for WSDL; |
374 | 328 |
http://www.w3.org/TR/2003/WD-wsdl12-20030303/#ietf-draft |
375 | 329 |
for now we go with the basic 'it's XML' response --> |
Also available in: Unified diff
remove portal servlet and configuration - no need for this if we are supporting auth tokens from authentication service.