1 |
6543
|
leinfelder
|
<%@ page language="java"%>
|
2 |
|
|
<%
|
3 |
|
|
/**
|
4 |
|
|
* '$RCSfile$'
|
5 |
|
|
* Authors: Matt Jones
|
6 |
|
|
* Copyright: 2008 Regents of the University of California and the
|
7 |
|
|
* National Center for Ecological Analysis and Synthesis
|
8 |
|
|
* For Details: http://www.nceas.ucsb.edu/
|
9 |
|
|
*
|
10 |
|
|
* '$Author$'
|
11 |
|
|
* '$Date$'
|
12 |
|
|
* '$Revision$'
|
13 |
|
|
*
|
14 |
|
|
* This is an HTML document for loading an xml document into Oracle
|
15 |
|
|
*
|
16 |
|
|
* This program is free software; you can redistribute it and/or modify
|
17 |
|
|
* it under the terms of the GNU General Public License as published by
|
18 |
|
|
* the Free Software Foundation; either version 2 of the License, or
|
19 |
|
|
* (at your option) any later version.
|
20 |
|
|
*
|
21 |
|
|
* This program is distributed in the hope that it will be useful,
|
22 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
23 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
24 |
|
|
* GNU General Public License for more details.
|
25 |
|
|
*
|
26 |
|
|
* You should have received a copy of the GNU General Public License
|
27 |
|
|
* along with this program; if not, write to the Free Software
|
28 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
29 |
|
|
*/
|
30 |
|
|
%>
|
31 |
|
|
<%@page import="edu.ucsb.nceas.metacat.service.SessionService"%>
|
32 |
|
|
<%@page import="org.dataone.client.D1Client"%>
|
33 |
|
|
<%@page import="java.net.URL"%>
|
34 |
|
|
<%@page import="java.io.InputStream"%>
|
35 |
|
|
<%@page import="org.apache.commons.io.IOUtils"%>
|
36 |
|
|
<%@page import="org.dataone.service.types.v1.Subject"%>
|
37 |
|
|
<%@page import="org.dataone.service.types.v1.Session"%>
|
38 |
|
|
<%@page import="edu.ucsb.nceas.metacat.dataone.MNodeService"%>
|
39 |
|
|
<%
|
40 |
|
|
|
41 |
|
|
boolean success = false;
|
42 |
|
|
|
43 |
|
|
//gather the input
|
44 |
|
|
String primarySubject = null; // retrieved from portal service
|
45 |
|
|
String secondarySubject = request.getParameter("secondarySubject");
|
46 |
|
|
String token = request.getParameter("token");
|
47 |
|
|
|
48 |
|
|
// check the metacat session
|
49 |
|
|
String sessionId = request.getParameter("sessionid");
|
50 |
|
|
if (sessionId == null) {
|
51 |
|
|
sessionId = request.getSession().getId();
|
52 |
|
|
}
|
53 |
|
|
boolean isMetacatSessionValid = SessionService.getInstance().validateSession(sessionId);
|
54 |
|
|
|
55 |
7389
|
leinfelder
|
// get the CN environment, dynamically
|
56 |
|
|
String cnURL = D1Client.getCN().getNodeBaseServiceUrl();
|
57 |
7390
|
leinfelder
|
String portalURL = cnURL.substring(0, cnURL.lastIndexOf(new URL(cnURL).getPath())) + "/portal";
|
58 |
|
|
//String portalURL = "https://cn-dev.dataone.org/portal";
|
59 |
6543
|
leinfelder
|
|
60 |
|
|
//check the DataONE token
|
61 |
7390
|
leinfelder
|
String tokenURL = portalURL + "/identity?action=isAuthenticated&token=" + token;
|
62 |
6543
|
leinfelder
|
InputStream tokenInputStream = new URL(tokenURL).openStream();
|
63 |
|
|
String tokenContent = IOUtils.toString(tokenInputStream, "UTF-8");
|
64 |
6544
|
leinfelder
|
tokenContent = tokenContent.trim();
|
65 |
6543
|
leinfelder
|
boolean isD1SessionValid = Boolean.parseBoolean(tokenContent);
|
66 |
|
|
|
67 |
|
|
// look up the D1 subject
|
68 |
7390
|
leinfelder
|
String subjectURL = portalURL + "/identity?action=getSubject&token=" + token;
|
69 |
6543
|
leinfelder
|
InputStream subjectStream = new URL(subjectURL).openStream();
|
70 |
|
|
primarySubject = IOUtils.toString(subjectStream, "UTF-8");
|
71 |
6544
|
leinfelder
|
primarySubject = primarySubject.trim();
|
72 |
6543
|
leinfelder
|
|
73 |
|
|
// call the mapping method as the MN
|
74 |
|
|
if (isMetacatSessionValid && isD1SessionValid) {
|
75 |
|
|
Session mnSession = new Session();
|
76 |
|
|
mnSession.setSubject(MNodeService.getInstance(request).getCapabilities().getSubject(0));
|
77 |
|
|
// TODO: set up the certificate for this node
|
78 |
6544
|
leinfelder
|
mnSession = null;
|
79 |
6543
|
leinfelder
|
Subject s1 = new Subject();
|
80 |
|
|
s1.setValue(primarySubject);
|
81 |
|
|
Subject s2 = new Subject();
|
82 |
|
|
s2.setValue(secondarySubject);
|
83 |
|
|
|
84 |
|
|
success = D1Client.getCN().mapIdentity(mnSession, s1, s2);
|
85 |
|
|
}
|
86 |
|
|
|
87 |
|
|
if (success) {
|
88 |
|
|
%>
|
89 |
|
|
Mapping set from <%=primarySubject %> to <%=secondarySubject %>
|
90 |
|
|
<%
|
91 |
6544
|
leinfelder
|
} else {
|
92 |
|
|
%>
|
93 |
|
|
Could not set mapping set from <%=primarySubject %> to <%=secondarySubject %>
|
94 |
|
|
<%
|
95 |
6543
|
leinfelder
|
}
|
96 |
|
|
%>
|