Project

General

Profile

« Previous | Next » 

Revision 7737

first pass at integrating CILogon/MyProxy certificates in Metacat. Configuration is specific to mn-demo-4.test.dataone.org for the time being (this will cause localhost deployments to fail webapp deployment). https://projects.ecoinformatics.org/ecoinfo/issues/5936

View differences:

lib/web.xml.tomcat6
288 288
    <url-pattern>/dataProvider</url-pattern>
289 289
  </servlet-mapping>
290 290
  -->
291
  
292
	<!-- begin MyProxy portal delegation section -->
293
	<servlet>
294
        <servlet-name>startRequest</servlet-name>
295
        <servlet-class>edu.ucsb.nceas.metacat.portal.StartRequest</servlet-class>
296
        <load-on-startup>1</load-on-startup>
297
    </servlet>
298
    <servlet-mapping>
299
        <servlet-name>startRequest</servlet-name>
300
        <url-pattern>/startRequest</url-pattern>
301
    </servlet-mapping>
302

  
303
    <servlet>
304
        <servlet-name>ready</servlet-name>
305
        <servlet-class>edu.ucsb.nceas.metacat.portal.SuccessServlet</servlet-class>
306
        <load-on-startup>1</load-on-startup>
307
    </servlet>
308
    <servlet-mapping>
309
        <servlet-name>ready</servlet-name>
310
        <url-pattern>/ready</url-pattern>
311
    </servlet-mapping>
312
    
313
    <servlet>
314
        <servlet-name>error</servlet-name>
315
        <servlet-class>edu.ucsb.nceas.metacat.portal.FailureServlet</servlet-class>
316
        <load-on-startup>1</load-on-startup>
317
    </servlet>
318
    <servlet-mapping>
319
        <servlet-name>error</servlet-name>
320
        <url-pattern>/error</url-pattern>
321
    </servlet-mapping>
291 322
      
292 323
    <session-config>
293 324
      <session-timeout>30000</session-timeout>
294 325
    </session-config>
326
    
327
    <listener>
328
        <listener-class>edu.uiuc.ncsa.myproxy.oa4mp.client.loader.ClientBootstrapper</listener-class>
329
    </listener>
295 330

  
331
	<!-- TODO: make relative path if possible -->
332
	<context-param>
333
        <param-name>oa4mp:client.config.file</param-name>
334
        <param-value>/var/lib/tomcat6/webapps/knb/WEB-INF/oa4mp_client.xml</param-value>
335
    </context-param>
296 336
    
337
    <!-- end MyProxy section -->
338
    
297 339
   <!-- currently the W3C havent settled on a media type for WSDL;
298 340
    http://www.w3.org/TR/2003/WD-wsdl12-20030303/#ietf-draft
299 341
    for now we go with the basic 'it's XML' response -->
src/edu/ucsb/nceas/metacat/restservice/D1ResourceHandler.java
29 29
import java.io.InputStream;
30 30
import java.io.OutputStream;
31 31
import java.io.PrintWriter;
32
import java.security.PrivateKey;
33
import java.security.cert.X509Certificate;
32 34
import java.util.Enumeration;
33 35
import java.util.Hashtable;
34 36
import java.util.Iterator;
......
47 49
import org.dataone.client.auth.CertificateManager;
48 50
import org.dataone.mimemultipart.MultipartRequest;
49 51
import org.dataone.mimemultipart.MultipartRequestResolver;
52
import org.dataone.portal.PortalCertificateManager;
50 53
import org.dataone.service.exceptions.BaseException;
51 54
import org.dataone.service.exceptions.InvalidRequest;
52 55
import org.dataone.service.exceptions.ServiceFailure;
......
132 135
        logMetacat = Logger.getLogger(D1ResourceHandler.class);
133 136
        try {
134 137
  
138
        	// check for session-based certificate from the portal
139
        	String configurationFile = servletContext.getInitParameter("oa4mp:client.config.file");
140
        	PortalCertificateManager portalManager = new PortalCertificateManager(configurationFile);
141
        	X509Certificate certificate = portalManager.getCertificate(request);
142
	    	PrivateKey key = portalManager.getPrivateKey(request);
143
	    	if (certificate != null && key != null) {
144
	        	request.setAttribute("javax.servlet.request.X509Certificate", certificate);
145
	    	}
146
	    	
135 147
            // load session from certificate in request
136 148
            session = CertificateManager.getInstance().getSession(request);
137 149

  
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
}
0 94

  
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
}
0 54

  
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
}
0 153

  
pom.xml
12 12
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13 13
        <d1_libclient_version>1.3.0-SNAPSHOT</d1_libclient_version>
14 14
        <d1_common_java_version>1.2.0-SNAPSHOT</d1_common_java_version>
15
        <d1_portal_version>1.2.0-SNAPSHOT</d1_portal_version>        
15 16
    </properties>
16 17
    <repositories>
17 18
        <repository>
......
35 36
    </repositories>
36 37
    <dependencies>
37 38
    	<dependency>
39
            <artifactId>d1_portal</artifactId>
40
            <groupId>org.dataone</groupId>
41
            <version>${d1_portal_version}</version>
42
            <type>jar</type>
43
            <!-- exclude extraneous artifacts (jars) -->
44
			<exclusions>
45
		        <exclusion>
46
		          <groupId>org.jibx</groupId>
47
		          <artifactId>jibx-tools</artifactId>
48
		        </exclusion>
49
		        <exclusion>
50
		          <groupId>org.jibx</groupId>
51
		          <artifactId>jibx-schema</artifactId>
52
		        </exclusion>
53
		        <exclusion>
54
		          <groupId>org.jibx</groupId>
55
		          <artifactId>jibx-extras</artifactId>
56
		        </exclusion>
57
		        <exclusion>
58
		          <groupId>org.jibx</groupId>
59
		          <artifactId>jibx-bind</artifactId>
60
		        </exclusion>
61
		        <exclusion>
62
		        	<groupId>org.apache.maven.plugins</groupId>
63
					<artifactId>maven-compiler-plugin</artifactId>
64
		        </exclusion>
65
		        <exclusion>
66
		        	<groupId>org.apache.maven.plugins</groupId>
67
					<artifactId>maven-jar-plugin</artifactId>
68
		        </exclusion>
69
		        <exclusion>
70
		        	<groupId>org.apache.maven.plugins</groupId>
71
					<artifactId>maven-clean-plugin</artifactId>
72
		        </exclusion>
73
		        <exclusion>
74
		        	<groupId>org.jibx</groupId>
75
					<artifactId>maven-jibx-plugin</artifactId>
76
		        </exclusion>
77
			</exclusions>
78
        </dependency>
79
    	<dependency>
38 80
            <groupId>edu.ucsb.nceas.metacat.common</groupId>
39 81
            <artifactId>metacat-common</artifactId>
40 82
            <version>1.0-SNAPSHOT</version>
build.xml
953 953
			filtering="yes" />
954 954
		<copy file="lib/hazelcast.xml" todir="${war.webinf}"
955 955
			filtering="yes" />
956
		<copy file="lib/oa4mp_client.xml" todir="${war.webinf}"
957
			filtering="yes" />
956 958
		<copy todir="${war.context}" filtering="no">
957 959
			<fileset dir="lib">
958 960
				<include name="**/*.jpg" />

Also available in: Unified diff