Project

General

Profile

1
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2005 University of New Mexico and the 
4
 *             Regents of the University of California and the
5
 *             National Center for Ecological Analysis and Synthesis
6
 *   '$Author: costa $'
7
 *     '$Date: 2005-11-16 09:57:33 -0800 (Wed, 16 Nov 2005) $'
8
 * '$Revision: 2741 $'
9
 *
10
 * This program is free software; you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation; either version 2 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program; if not, write to the Free Software
22
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
 */
24

    
25
package edu.ucsb.nceas.metacat.advancedsearch;
26

    
27
import edu.ucsb.nceas.metacat.client.*;
28

    
29

    
30
/**
31
 * @author dcosta
32
 * 
33
 * MetacatLogin class executes a Metacat login using the Metacat client.
34
 */
35
public class MetacatLogin  {
36

    
37
  /* Object variables */
38
  private LoginBean loginBean = null;
39

    
40
  
41
  /**
42
   * Constructor. Initializes the loginBean object variable.
43
   * 
44
   * @param loginBean  the LoginBean object, holds username and password
45
   */
46
  public MetacatLogin(final LoginBean loginBean) {
47
    this.loginBean = loginBean;
48
  }
49

    
50
  
51
  /**
52
   * Executes the Metacat login.
53
   * 
54
   * @param metacatURL      URL to the metacat servlet
55
   * @param metacat         a Metacat object, possibly null
56
   * 
57
   * @return loginSuccess   true if metacat login was successful, else false
58
   */
59
  public boolean executeLogin(final String metacatURL, final Metacat metacat) {
60
    final String DN;                            // LDAP distinguished name
61
    boolean loginSuccess = false;
62
    MetacatHelper metacatHelper = new MetacatHelper();
63
    String metacatResponse = "";
64
    final String organization = loginBean.getOrganization();
65
    final String password = loginBean.getPassword();
66
    final String username = loginBean.getUsername();
67
    
68
    if (
69
        username == null || 
70
        organization == null || 
71
        password == null || 
72
        username.equals("") || 
73
        organization.equals("") || 
74
        password.equals("")) 
75
    {
76
      return loginSuccess;
77
    }
78
    else {    
79
      System.err.println("Metacat URL: " + metacatURL);
80

    
81
      try {
82
        DN = metacatHelper.constructDN(username, organization);    
83
        metacatResponse = metacat.login(DN, password);
84
        System.err.println("metacatResponse:\n" + metacatResponse);
85
        
86
        if (metacatResponse.indexOf("Authentication successful") > -1) {
87
          loginSuccess = true;
88
        }
89
      } 
90
      catch (MetacatAuthException mae) {
91
        System.err.println("MetacatAuthException:\n" + mae.getMessage());
92
      } 
93
      catch (MetacatInaccessibleException mie) {
94
        System.err.println("Metacat Inaccessible:\n" + mie.getMessage());
95
      }
96
      catch (Exception e) {
97
        System.err.println("General exception:\n" + e.getMessage());
98
        e.printStackTrace();
99
      }
100
    }
101
    
102
    return loginSuccess;
103
  }
104

    
105
}
(12-12/14)