r4591 - trunk/src/edu/ucsb/nceas/metacat/admin
daigle at ecoinformatics.org
daigle at ecoinformatics.org
Wed Nov 19 15:26:23 PST 2008
Author: daigle
Date: 2008-11-19 15:26:23 -0800 (Wed, 19 Nov 2008)
New Revision: 4591
Added:
trunk/src/edu/ucsb/nceas/metacat/admin/LoginAdmin.java
Log:
This handles the configuration login form
Copied: trunk/src/edu/ucsb/nceas/metacat/admin/LoginAdmin.java (from rev 4399, trunk/src/edu/ucsb/nceas/metacat/admin/AuthAdmin.java)
===================================================================
--- trunk/src/edu/ucsb/nceas/metacat/admin/LoginAdmin.java (rev 0)
+++ trunk/src/edu/ucsb/nceas/metacat/admin/LoginAdmin.java 2008-11-19 23:26:23 UTC (rev 4591)
@@ -0,0 +1,175 @@
+/**
+ * '$RCSfile$'
+ * Purpose: A Class that implements login methods
+ * Copyright: 2008 Regents of the University of California and the
+ * National Center for Ecological Analysis and Synthesis
+ * ors: Michael Daigle
+ *
+ * '$or: daigle $'
+ * '$Date$'
+ * '$Revision$'
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package edu.ucsb.nceas.metacat.admin;
+
+import java.io.IOException;
+import java.util.Vector;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.log4j.Logger;
+
+import edu.ucsb.nceas.metacat.util.AuthUtil;
+import edu.ucsb.nceas.metacat.util.RequestUtil;
+import edu.ucsb.nceas.metacat.util.UtilException;
+
+/**
+ * Control the display of the login page
+ */
+public class LoginAdmin extends MetaCatAdmin {
+
+ private static LoginAdmin Admin = null;
+ private static Logger logMetacat = Logger.getLogger(LoginAdmin.class);
+
+ /**
+ * private constructor since this is a singleton
+ */
+ private LoginAdmin() {}
+
+ /**
+ * Get the single instance of LoginAdmin.
+ *
+ * @return the single instance of LoginAdmin
+ */
+ public static LoginAdmin getInstance() {
+ if (Admin == null) {
+ Admin = new LoginAdmin();
+ }
+ return Admin;
+ }
+
+ /**
+ * Handle configuration of the Authentication properties
+ *
+ * @param request
+ * the http request information
+ * @param response
+ * the http response to be sent back to the client
+ */
+ public void authenticateUser(HttpServletRequest request,
+ HttpServletResponse response) throws AdminException {
+
+ String processForm = request.getParameter("processForm");
+ String formErrors = (String) request.getAttribute("formErrors");
+
+ if (processForm == null || !processForm.equals("true") || formErrors != null) {
+ // The servlet configuration parameters have not been set, or there
+ // were form errors on the last attempt to configure, so redirect to
+ // the web form for configuring metacat
+
+ try {
+ // Forward the request to the JSP page
+ RequestUtil.forwardRequest(request, response,
+ "/admin/admin-login.jsp");
+ } catch (IOException ioe) {
+ throw new AdminException("IO problem while initializing "
+ + "user login page:" + ioe.getMessage());
+ } catch (ServletException se) {
+ throw new AdminException("problem forwarding request while "
+ + "initializing user login page: " + se.getMessage());
+ }
+ } else {
+ // The configuration form is being submitted and needs to be
+ // processed.
+ Vector<String> processingSuccess = new Vector<String>();
+ Vector<String> processingErrors = new Vector<String>();
+ Vector<String> validationErrors = new Vector<String>();
+
+// String loginString = null;
+ Boolean isLoggedIn = false;
+ String userName = "";
+
+ try {
+ userName = request.getParameter("username");
+// String organization = request.getParameter("organization");
+ String password = request.getParameter("password");
+
+ // Validate that the options provided are legitimate. Note that
+ // we've allowed them to persist their entries. As of this point
+ // there is no other easy way to go back to the configure form
+ // and preserve their entries.
+ validationErrors.addAll(validateOptions(request));
+
+ if (validationErrors.size() == 0) {
+// Vector<String> dnList = OrganizationUtil.getOrgDNs(organization);
+ isLoggedIn = AuthUtil.logUserIn(request, userName, password);
+// loginString = LDAPUtil.createLDAPString(userName, organization, dnList);
+ }
+
+ if (!isLoggedIn) {
+ String errorMessage = "Could not log in as: " + userName
+ + " .Please try again";
+ processingErrors.add(errorMessage);
+ }
+ } catch (UtilException ue) {
+ String errorMessage = "Problem in utility while "
+ + "processing entication page: " + ue.getMessage();
+ processingErrors.add(errorMessage);
+ logMetacat.error(errorMessage);
+ }
+
+ try {
+ if (validationErrors.size() > 0 || processingErrors.size() > 0) {
+ RequestUtil.clearRequestMessages(request);
+ RequestUtil.setRequestFormErrors(request, validationErrors);
+ RequestUtil.setRequestErrors(request, processingErrors);
+ RequestUtil.forwardRequest(request, response, "/admin");
+ } else {
+ // Reload the main metacat configuration page
+ processingSuccess.add("User logged in as: " + userName);
+ RequestUtil.clearRequestMessages(request);
+ RequestUtil.setUserId(request, userName);
+ RequestUtil.setRequestSuccess(request, processingSuccess);
+ RequestUtil.forwardRequest(request, response,
+ "/admin?configureType=configure&processForm=false");
+ }
+ } catch (IOException ioe) {
+ throw new AdminException("IO problem while processing login page: "
+ + ioe.getMessage());
+ } catch (ServletException se) {
+ throw new AdminException("problem forwarding request while "
+ + "processoing login page: " + se.getMessage());
+ }
+ }
+ }
+
+ /**
+ * Validate the most important configuration options submitted by the user.
+ *
+ * @return a vector holding error message for any fields that fail
+ * validation.
+ */
+ protected Vector<String> validateOptions(HttpServletRequest request) {
+ Vector<String> errorVector = new Vector<String>();
+
+ //TODO MCD validate options.
+
+ return errorVector;
+ }
+}
\ No newline at end of file
Property changes on: trunk/src/edu/ucsb/nceas/metacat/admin/LoginAdmin.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
More information about the Metacat-cvs
mailing list