|
1 |
<%@ page import="edu.ucsb.nceas.metacat.client.*" %>
|
|
2 |
<%
|
|
3 |
/**
|
|
4 |
* '$RCSfile$'
|
|
5 |
* Authors: Matt Jones, Chad Berkley
|
|
6 |
* Copyright: 2000 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 program is free software; you can redistribute it and/or modify
|
|
15 |
* it under the terms of the GNU General Public License as published by
|
|
16 |
* the Free Software Foundation; either version 2 of the License, or
|
|
17 |
* (at your option) any later version.
|
|
18 |
*
|
|
19 |
* This program is distributed in the hope that it will be useful,
|
|
20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
22 |
* GNU General Public License for more details.
|
|
23 |
*
|
|
24 |
* You should have received a copy of the GNU General Public License
|
|
25 |
* along with this program; if not, write to the Free Software
|
|
26 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
27 |
*
|
|
28 |
* This is an XSLT (http://www.w3.org/TR/xslt) stylesheet designed to
|
|
29 |
* convert an XML file showing the resultset of a query
|
|
30 |
* into an HTML format suitable for rendering with modern web browsers.
|
|
31 |
*/
|
|
32 |
|
|
33 |
//////////////////////////////////////////////////////////////////////////////
|
|
34 |
//
|
|
35 |
// NOTE:
|
|
36 |
//
|
|
37 |
// GLOBAL CONSTANTS (SETTINGS SUCH AS METACAT URL, LDAP DOMAIN AND DEBUG
|
|
38 |
// SWITCH) ARE ALL IN THE INCLUDE FILE "PORTAL_SETTINGS.jsp"
|
|
39 |
//
|
|
40 |
//////////////////////////////////////////////////////////////////////////////
|
|
41 |
|
|
42 |
// GLOBAL VARIABLES //////////////////////////////////////////////////////////
|
|
43 |
String loginStatus = null;
|
|
44 |
String sess_sessionId = null;
|
|
45 |
String sessionidField = null;
|
|
46 |
String metacatResponse = null;
|
|
47 |
String posted_ldapUserName = null;
|
|
48 |
String typedUserName = null;
|
|
49 |
String posted_organization = null;
|
|
50 |
String posted_password = null;
|
|
51 |
String loginAction = null;
|
|
52 |
String loginButtonLabel = null;
|
|
53 |
String loginEnabledDisabled = null;
|
|
54 |
Metacat metacat = null;
|
|
55 |
HttpSession rfSession = null;
|
|
56 |
boolean isLoggedIn = false;
|
|
57 |
//String relativeRoot = "@style-skins-path@/pisco";
|
|
58 |
//String knbSiteUrl = "@knb-site-url@";
|
|
59 |
//String include_portalhead_title = null;
|
|
60 |
|
|
61 |
//////////////////////////////////////////////////////////////////////////////
|
|
62 |
|
|
63 |
try {
|
|
64 |
rfSession = request.getSession(true);
|
|
65 |
|
|
66 |
} catch(Exception e) {
|
|
67 |
|
|
68 |
throw new ServletException("trying to get session: "+e);
|
|
69 |
}
|
|
70 |
|
|
71 |
Object sess_sessionIdObj = rfSession.getAttribute("sess_sessionIdObj");
|
|
72 |
|
|
73 |
if (sess_sessionIdObj!=null) {
|
|
74 |
sess_sessionId = (String)sess_sessionIdObj;
|
|
75 |
|
|
76 |
// if sess_sessionIdObj is empty string, that means user has logged out
|
|
77 |
// (had problems if I set it to null, so used empty string instead)
|
|
78 |
if (sess_sessionId.length() < 1) sess_sessionId = null;
|
|
79 |
else isLoggedIn = true;
|
|
80 |
|
|
81 |
} else {
|
|
82 |
|
|
83 |
sess_sessionId = null;
|
|
84 |
}
|
|
85 |
|
|
86 |
typedUserName = request.getParameter("username");
|
|
87 |
typedUserName = (typedUserName!=null)? typedUserName.trim() : "";
|
|
88 |
|
|
89 |
posted_organization = request.getParameter("organization");
|
|
90 |
posted_organization = (posted_organization!=null)? posted_organization.trim() : "";
|
|
91 |
|
|
92 |
posted_ldapUserName = "uid=" + typedUserName
|
|
93 |
+ ",o=" + posted_organization + LDAP_DOMAIN;
|
|
94 |
|
|
95 |
posted_password = request.getParameter("password");
|
|
96 |
posted_password = (posted_password!=null)? posted_password.trim() : "";
|
|
97 |
|
|
98 |
loginAction = request.getParameter("loginAction");
|
|
99 |
loginAction = (loginAction!=null)? loginAction.trim() : "";
|
|
100 |
|
|
101 |
//////////////////////////////////////////////////////////////////////////////
|
|
102 |
|
|
103 |
if (loginAction.equals(LOGOUT_LABEL)) {
|
|
104 |
// DO LOGOUT //////////////////////////////////////////////////////////////
|
|
105 |
|
|
106 |
if (sess_sessionId!=null && rfSession.getAttribute("sess_metacatObj")!=null) {
|
|
107 |
metacat = (Metacat)(rfSession.getAttribute("sess_metacatObj"));
|
|
108 |
metacat.logout();
|
|
109 |
}
|
|
110 |
sess_sessionId = null;
|
|
111 |
rfSession.setAttribute("sess_sessionIdObj", "");
|
|
112 |
isLoggedIn = false;
|
|
113 |
|
|
114 |
} else if (loginAction.equals(LOGIN_LABEL)) {
|
|
115 |
// DO LOGIN ////////////////////////////////////////////////////////////////
|
|
116 |
|
|
117 |
if (sess_sessionId!=null) isLoggedIn = true;
|
|
118 |
else {
|
|
119 |
|
|
120 |
// get metacat object - either cached from session...
|
|
121 |
if (rfSession.getAttribute("sess_metacatObj")!=null) {
|
|
122 |
|
|
123 |
metacat = (Metacat)(rfSession.getAttribute("sess_metacatObj"));
|
|
124 |
|
|
125 |
} else { // ...or create it if it doesn't already exist
|
|
126 |
try {
|
|
127 |
metacat = MetacatFactory.createMetacatConnection(METACAT_URL);
|
|
128 |
} catch (MetacatInaccessibleException mie) {
|
|
129 |
throw new ServletException("Metacat connection to "+METACAT_URL
|
|
130 |
+" failed." + mie.getMessage());
|
|
131 |
}
|
|
132 |
if (metacat==null) {
|
|
133 |
throw new ServletException("Metacat connection to "+METACAT_URL
|
|
134 |
+" failed - Metacat object is NULL!");
|
|
135 |
}
|
|
136 |
rfSession.setAttribute("sess_metacatObj", metacat);
|
|
137 |
}
|
|
138 |
// now do login...
|
|
139 |
try {
|
|
140 |
metacatResponse = metacat.login(posted_ldapUserName, posted_password);
|
|
141 |
|
|
142 |
if (metacatResponse!=null && metacatResponse.indexOf("<login>") >= 0) {
|
|
143 |
sess_sessionId = metacat.getSessionId();
|
|
144 |
rfSession.setAttribute("sess_sessionIdObj",
|
|
145 |
((sess_sessionId!=null)? sess_sessionId: "") );
|
|
146 |
isLoggedIn = true;
|
|
147 |
} else {
|
|
148 |
loginStatus = "<em class=\"italic\">Incorrect username or password - please try again</em>";
|
|
149 |
isLoggedIn = false;
|
|
150 |
}
|
|
151 |
} catch (MetacatAuthException mae) {
|
|
152 |
loginStatus = "<em class=\"italic\">Incorrect username or password! - please try again</em>";
|
|
153 |
isLoggedIn = false;
|
|
154 |
} catch (MetacatInaccessibleException mie) {
|
|
155 |
isLoggedIn = false;
|
|
156 |
loginStatus = "<em class=\"italic\">ERROR logging in - problems connecting - please try later</em>";
|
|
157 |
}
|
|
158 |
}
|
|
159 |
}
|
|
160 |
|
|
161 |
//////////////////////////////////////////////////////////////////////////////
|
|
162 |
|
|
163 |
if (isLoggedIn) {
|
|
164 |
loginButtonLabel = LOGOUT_LABEL;
|
|
165 |
loginEnabledDisabled = "disabled";
|
|
166 |
if (sess_sessionId!=null && sess_sessionId.length()>0) {
|
|
167 |
sessionidField = "<input type=\"hidden\" name=\"sessionid\" value=\""
|
|
168 |
+sess_sessionId+"\">";
|
|
169 |
} else {
|
|
170 |
sessionidField = "";
|
|
171 |
}
|
|
172 |
// if loginStatus has already been set above, don't overwrite it...
|
|
173 |
if (loginStatus==null) loginStatus
|
|
174 |
= "<em class=\"italic\">logged in as: " +posted_ldapUserName+"</em>";
|
|
175 |
} else {
|
|
176 |
loginButtonLabel = LOGIN_LABEL;
|
|
177 |
loginEnabledDisabled = "";
|
|
178 |
sessionidField = "";
|
|
179 |
// if loginStatus has already been set above, don't overwrite it...
|
|
180 |
if (loginStatus==null) loginStatus
|
|
181 |
= "<em class=\"italic\">Not logged in: </em>";
|
|
182 |
}
|
|
183 |
|
|
184 |
if (DEBUG_TO_BROWSER) {
|
|
185 |
%>
|
|
186 |
<div id="debug">
|
|
187 |
<ul>
|
|
188 |
<li>METACAT_URL: <%=METACAT_URL%></li>
|
|
189 |
<li>rfSession: <%=rfSession%></li>
|
|
190 |
<li>metacatResponse: <%=metacatResponse%></li>
|
|
191 |
<li>posted_ldapUserName: <%=posted_ldapUserName%></li>
|
|
192 |
<li>posted_password: <%=posted_password%></li>
|
|
193 |
<li>isLoggedIn: <%=isLoggedIn%></li>
|
|
194 |
<li>sess_sessionId LOCAL: <%=sess_sessionId%></li>
|
|
195 |
<li>sess_sessionIdObj FROM SESSION: <%=rfSession.getAttribute("sess_sessionIdObj")%></li>
|
|
196 |
</ul>
|
|
197 |
</div>
|
|
198 |
<%
|
|
199 |
}
|
|
200 |
%>
|
0 |
201 |
|
I'm adding the two jsp files that originated in the KNB skin developed
by Matthew Brooke, modified for the PISCO skin.