Project

General

Profile

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: daigle $'
11
  *     '$Date: 2008-04-02 16:28:31 -0700 (Wed, 02 Apr 2008) $'
12
  * '$Revision: 3780 $'
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
  <!--  %@ include file="../../common/common-settings.jsp"% -->
35

    
36
  <% 
37

    
38
  //////////////////////////////////////////////////////////////////////////////
39
  //
40
  // NOTE:
41
  //
42
  //  GLOBAL CONSTANTS (SETTINGS SUCH AS METACAT URL, LDAP DOMAIN	AND DEBUG 
43
  //  SWITCH) ARE ALL IN THE INCLUDE FILE "PORTAL_SETTINGS.jsp"
44
  //
45
  //////////////////////////////////////////////////////////////////////////////
46

    
47
  // GLOBAL VARIABLES //////////////////////////////////////////////////////////
48
	String      loginStatus           = null;
49
	String    	sess_sessionId        = null;
50
	String      sessionidField        = null;
51
	String      metacatResponse       = null;
52
	String      posted_ldapUserName   = null;
53
	String      typedUserName         = null;
54
	String      posted_organization   = null;
55
	String      posted_password       = null;
56
	String      loginAction           = null;
57
	String      loginButtonLabel      = null;
58
	String      loginEnabledDisabled  = null;
59
	Metacat     metacat               = null;
60
	HttpSession rfSession             = null;
61
	boolean     isLoggedIn            = false;
62
    String      relativeRoot          = SERVLET_URL + "/style/skins/knb2";
63
    String      knbSiteUrl            = KNB_SITE_URL;
64
    String      include_portalhead_title = null;
65
	
66
  //////////////////////////////////////////////////////////////////////////////	
67
	
68
  try {
69
		rfSession = request.getSession(true);
70
		
71
	} catch(Exception e) {
72
	
73
		throw new ServletException("trying to get session: "+e);
74
	}
75
	
76
	Object sess_sessionIdObj = rfSession.getAttribute("sess_sessionIdObj");
77
	
78
	if (sess_sessionIdObj!=null) {
79
	  sess_sessionId = (String)sess_sessionIdObj;
80
    
81
		// if sess_sessionIdObj is empty string, that means user has logged out
82
		// (had problems if I set it to null, so used empty string instead)
83
		if (sess_sessionId.length() < 1) sess_sessionId = null;
84
	  else isLoggedIn = true;
85
    
86
  } else {
87
		
88
    sess_sessionId = null;
89
	}
90
	
91
	typedUserName   = request.getParameter("username");
92
	typedUserName   = (typedUserName!=null)? typedUserName.trim() : "";
93
	
94
	posted_organization = request.getParameter("organization");
95
	posted_organization = (posted_organization!=null)? posted_organization.trim() : "";
96

    
97
	posted_ldapUserName = "uid=" + typedUserName 
98
                                    + ",o=" + posted_organization + LDAP_DOMAIN;
99
	
100
	posted_password = request.getParameter("password");
101
	posted_password = (posted_password!=null)? posted_password.trim() : "";
102
	
103
	loginAction     = request.getParameter("loginAction");
104
	loginAction     = (loginAction!=null)? loginAction.trim() : "";
105
	
106
  //////////////////////////////////////////////////////////////////////////////	
107
	
108
	if (loginAction.equals(LOGOUT_LABEL)) { 
109
	// DO LOGOUT //////////////////////////////////////////////////////////////		
110
	
111
	  if (sess_sessionId!=null && rfSession.getAttribute("sess_metacatObj")!=null) {
112
		  metacat = (Metacat)(rfSession.getAttribute("sess_metacatObj"));
113
			metacat.logout();			
114
		}
115
		sess_sessionId = null;
116
		rfSession.setAttribute("sess_sessionIdObj", "");
117
		isLoggedIn = false;
118
		
119
	} else if (loginAction.equals(LOGIN_LABEL)) {  
120
	// DO LOGIN ////////////////////////////////////////////////////////////////	
121
	
122
		if (sess_sessionId!=null) isLoggedIn = true;		
123
		else {
124
		
125
		  // get metacat object - either cached from session...
126
			if (rfSession.getAttribute("sess_metacatObj")!=null) {
127
				
128
				metacat = (Metacat)(rfSession.getAttribute("sess_metacatObj"));
129
			
130
			} else {   // ...or create it if it doesn't already exist
131
				try {
132
					metacat = MetacatFactory.createMetacatConnection(SERVLET_URL);
133
				} catch (MetacatInaccessibleException mie) {
134
					throw new ServletException("Metacat connection to "+SERVLET_URL
135
                                                +" failed." + mie.getMessage());
136
				}
137
				if (metacat==null) {
138
					throw new ServletException("Metacat connection to "+SERVLET_URL
139
                                          +" failed - Metacat object is NULL!");
140
				}
141
				rfSession.setAttribute("sess_metacatObj", metacat);
142
			}
143
			// now do login...
144
			try {
145
					metacatResponse = metacat.login(posted_ldapUserName, posted_password);
146
					
147
					if (metacatResponse!=null && metacatResponse.indexOf("<login>") >= 0) {
148
						sess_sessionId = metacat.getSessionId();
149
						rfSession.setAttribute("sess_sessionIdObj", 
150
                                  ((sess_sessionId!=null)? sess_sessionId: "") );
151
						isLoggedIn = true;
152
					} else {
153
						loginStatus = "<em class=\"loginStatus\">Incorrect username or password - please try again</em>";
154
						isLoggedIn = false;
155
					}
156
			} catch (MetacatAuthException mae) {
157
					loginStatus = "<em class=\"loginStatus\">Incorrect username or password! - please try again</em>";
158
					isLoggedIn = false;
159
			} catch (MetacatInaccessibleException mie) {
160
					isLoggedIn = false;
161
					loginStatus = "<em class=\"loginStatus\">ERROR logging in - problems connecting - please try later</em>";
162
			}
163
		}
164
  }
165
	
166
  //////////////////////////////////////////////////////////////////////////////	
167

    
168
  if (isLoggedIn) {
169
		loginButtonLabel     = LOGOUT_LABEL;
170
		loginEnabledDisabled = "disabled";
171
		if (sess_sessionId!=null && sess_sessionId.length()>0) {
172
  	  sessionidField = "<input type=\"hidden\" name=\"sessionid\"     value=\""
173
                                                          +sess_sessionId+"\">";
174
	  } else {
175
	    sessionidField = "";
176
		}
177
		// if loginStatus has already been set above, don't overwrite it...
178
	  if (loginStatus==null) loginStatus 
179
                          = "<em class=\"loginStatus\">You ARE logged in</em>";
180
  } else {
181
		loginButtonLabel     = LOGIN_LABEL;
182
		loginEnabledDisabled = "";
183
	  sessionidField = "";
184
	  // if loginStatus has already been set above, don't overwrite it...
185
	  if (loginStatus==null) loginStatus 
186
                      = "<em class=\"loginStatus\">You are NOT logged in</em>";
187
	}
188

    
189
  if (DEBUG_TO_BROWSER) {
190
%>	
191
<table>							
192
	<tr> 
193
		<td colspan="4" align="left" valign="top" class="text_plain" bgcolor="#ffff00">
194
			<ul>
195
				<li>SERVLET_URL:&nbsp;<%=SERVLET_URL%></li>
196
				<li>rfSession:&nbsp;<%=rfSession%></li>
197
				<li>metacatResponse:&nbsp;<%=metacatResponse%></li>
198
				<li>posted_ldapUserName:&nbsp;<%=posted_ldapUserName%></li>
199
				<li>posted_password:&nbsp;<%=posted_password%></li>
200
				<li>isLoggedIn:&nbsp;<%=isLoggedIn%></li>
201
				<li>sess_sessionId LOCAL:&nbsp;<%=sess_sessionId%></li>
202
				<li>sess_sessionIdObj FROM SESSION:&nbsp;<%=rfSession.getAttribute("sess_sessionIdObj")%></li>
203
			</ul></td>
204
  </tr>
205
</table>
206
<%
207
  }
208
%>
(9-9/18)