Project

General

Profile

« Previous | Next » 

Revision 4159

Added by daigle almost 16 years ago

Add support for separate LDAP and organization level configurations

View differences:

lib/admin/ldap-configuration.jsp
27 27
 */
28 28
%>
29 29

  
30
<%
31
	PropertiesMetaData propMetadata =
32
		(PropertiesMetaData)request.getAttribute("metadata");
33
 	Vector<String> ldapOrganizations = 
34
 		(Vector<String>)request.getAttribute("orgList"); 
35
	Map<Integer, MetaDataGroup> groupMap = 
36
		(Map<Integer, MetaDataGroup>)request.getAttribute("groupMap"); 
37
%>
38

  
39 30
<html>
40 31
<head>
41 32

  
......
57 48

  
58 49
<form method="POST" name="configuration_form" action="<%= request.getContextPath() %>/admin" 
59 50
                                        onsubmit="return submitForm(this);">
60
<%
61
	Map<Integer, MetaDataProperty> globalPropertiesMap = propMetadata.getPropertiesInGroup(1);
62
	MetaDataGroup globalGroup = groupMap.get(new Integer(1));
51
<% 
52
	// metadata holds all group and properties metadata
53
    PropertiesMetaData metadata = (PropertiesMetaData)request.getAttribute("metadata");
54
	if (metadata != null) {
55
		// each group describes a section of properties
56
		Map<Integer, MetaDataGroup> groupMap = metadata.getGroups();
57
		Set<Integer> groupIdSet = groupMap.keySet();
58
		for (Integer groupId : groupIdSet) {
59
			// for this group, display the header (group name)
60
			MetaDataGroup metaDataGroup = (MetaDataGroup)groupMap.get(groupId);
63 61
%>
64
  <h3><%=globalGroup.getName()%></h3> 
65
  <hr class="config-line">
62
		<h3><%= metaDataGroup.getName()  %></h3>
63
		<hr class="config-line">
64
		<table class="config-section">
66 65
<%
67
 	if (globalGroup.getComment() != null) {
68
%>
69
  <div class="heading-comment"><%=globalGroup.getComment()%></div><br>
66
			// get all the properties in this group
67
			Map<Integer, MetaDataProperty> propertyMap = 
68
				metadata.getPropertiesInGroup(metaDataGroup.getIndex());
69
			Set<Integer> propertyIndexes = propertyMap.keySet();
70
			// iterate through each property and display appropriately
71
			for (Integer propertyIndex : propertyIndexes) {
72
				MetaDataProperty metaDataProperty = propertyMap.get(propertyIndex);
73
    			String fieldType = metaDataProperty.getFieldType(); 
74
    			if (fieldType.equals("select")) {
75
%> 
76
			<tr>
77
				<td class="config-property-label">
78
     				<label for="<%= metaDataProperty.getKey() %>" title="<%= metaDataProperty.getDescription() %>"><%= metaDataProperty.getLabel() %></label>   
79
     			</td>	
80
     			<td class="config-property-input" >		
81
					<select name="<%= metaDataProperty.getKey() %>">
70 82
<%
71
	}
83
					Vector<String> fieldOptionValues = metaDataProperty.getFieldOptionValues();
84
					Vector<String> fieldOptionNames = metaDataProperty.getFieldOptionNames();
85
					for (int i = 0; i < fieldOptionNames.size(); i++) {
72 86
%>
73
<br>
74
<table class="config-section">
87
					<option value="<%= fieldOptionValues.elementAt(i) %>"> <%= fieldOptionNames.elementAt(i) %>
75 88
<%
76
	Set<Integer> globalIdSet = globalPropertiesMap.keySet();
77
	for (Integer globalId : globalIdSet) {
78
		MetaDataProperty globalProperty = globalPropertiesMap.get(globalId);
89
				}
79 90
%>
80
	<tr>
81
		<td class="config-property-label">
82
			<label for="<%= globalProperty.getKey() %>" title="<%= globalProperty.getDescription() %>"><%=globalProperty.getLabel()%></label>
83
		</td>	
84
		<td class="config-property-input" >	
85
			<input id="<%= globalProperty.getKey() %>" name="<%= globalProperty.getKey() %>" 
86
				value="<%= request.getAttribute(globalProperty.getKey()) %>"             		    	    	           		    	             			
87
				type="text"           			
88
				alt="LDAP server URL"/>	   
89
		</td>
90
		<td class="config-question-mark">        		    
91
			<img src="style/images/question-mark.gif" onClick="helpWindow('<%= request.getContextPath() %>', '<%= globalProperty.getHelpFile() %>')"/><br/>
92
		</td>
93
	</tr>
94
<%
95
	}
96
    Map<Integer, MetaDataProperty> orgPropertyMap = propMetadata.getPropertiesInGroup(2);
97
    MetaDataGroup orgGroup = groupMap.get(new Integer(2));
98
    Set<Integer> orgIdSet = orgPropertyMap.keySet();
91
					</select>
92
				</td>
93
				<td class="config-question-mark">
94
					<img src="style/images/question-mark.gif" 
95
	           		       alt="<%= metaDataProperty.getDescription() %>" 
96
	           		       title="<%= metaDataProperty.getDescription() %>"/>
97
				</td>
98
			</tr>
99

  
100
<%		
101
				} else if (fieldType.equals("password")) {
99 102
%>
100
	</table>
101
	<h3><%=orgGroup.getName()%></h3> 
102
    <hr class="config-line">
103
<%
104
 	if (orgGroup.getComment() != null) {
103
			<tr>
104
				<td class="config-property-label">
105
					<label for="<%= metaDataProperty.getKey() %>" title="<%= metaDataProperty.getDescription() %>"><%= metaDataProperty.getLabel() %></label>
106
     			</td>	
107
     			<td class="config-property-input" >	
108
					<input id="<%= metaDataProperty.getKey() %>" name="<%= metaDataProperty.getKey() %>" 	             		    	    	           		    	             			
109
	           		    	value="<%= request.getAttribute(metaDataProperty.getKey()) %>"
110
	           		    	type="<%= fieldType %>"
111
	           		    	alt="<%= metaDataProperty.getDescription() %>"/> 
112
				</td>
113
				<td class="config-question-mark">
114
					<img src="style/images/question-mark.gif" 
115
	           		       alt="<%= metaDataProperty.getDescription() %>" 
116
	           		       title="<%= metaDataProperty.getDescription() %>"/>
117
				</td>
118
			</tr>
119
<%		
120
				} else {
105 121
%>
106
  <div class="heading-comment"><%= orgGroup.getComment() %></div>
107
<%
108
 	}
122
			<tr>
123
				<td class="config-property-label">
124
					<label for="<%= metaDataProperty.getKey() %>" title="<%= metaDataProperty.getDescription() %>"><%= metaDataProperty.getLabel() %></label>
125
     			</td>	
126
     			<td class="config-property-input" >							
127
					<input id="<%= metaDataProperty.getKey() %>" name="<%= metaDataProperty.getKey() %>" 
128
	    			        value="<%= request.getAttribute(metaDataProperty.getKey()) %>"	             		    	    	           		    	             			
129
	           		    	type="<%= fieldType %>	"           			
130
	           		    	alt="<%= metaDataProperty.getDescription() %>"/>	
131
	           	</td>
132
				<td class="config-question-mark">           		    
133
					<img class=question-mark src="style/images/question-mark.gif" onClick="helpWindow('ldap_url_help.html')"/>
134
				</td>
135
 			</tr>
136
<%   			
137
				}
138
    			
139
    			if (metaDataProperty.getDescription() != null) {
109 140
%>
110
<br>
141
			<tr>
142
    	        <td></td>
143
    	        <td class="config-property-description" colspan="2" >
144
					<%= metaDataProperty.getDescription() %>
145
    	        </td>
146
			</tr>
111 147
<%
112
	for (String orgName : ldapOrganizations) {
148
    			}
149
			}
113 150
%>
114
<table class="config-section">
115
	<tr>
116
		<td class="config-checkbox">
117
	  		<input class="org" type="checkbox" name="<%= orgName %>.cb" onClick="toggleHiddenTable(this, 'hiding-section-<%= orgName %>')"/>
118
	  	</td>
119
	  	<td class="config-checkbox-label">	
120
			<label for="<%= orgName %>.cb"><%=orgName%></label>
121
		</td> 
122
		<td class="config-question-mark">
123
			<img src="style/images/question-mark.gif"
124
					alt="blah"
125
					title="blah"/>
126
		</td>
127
	</tr>
128
</table>
129
<table class="config-section-hiding" id="hiding-section-<%= orgName %>">  
151

  
152
			</table>
130 153
<%
131
	  	for (Integer orgId : orgIdSet) {
132
	  	MetaDataProperty orgProperty = orgPropertyMap.get(orgId);
133
	  	String orgKeyName = orgProperty.getKey() + "." + orgName;
134
%>		
135
	<tr>
136
		<td class="config-property-label" >	
137
	    	<label for="<%= orgKeyName %>" title="<%= orgProperty.getDescription() %>"><%= orgProperty.getLabel() %></label>
138
     	</td>	
139
     	<td class="config-property-input" >
140
			<input name="<%= orgKeyName %>" 
141
				value="<%= request.getAttribute(orgKeyName) %>"	  
142
<% 
143
			if (orgProperty.getFieldType().equals("password")) { 
144
%>           		    	    	           		    	             			
145
	           	type="password"       
146
<%
147
	  		}
148
%>    			
149
	           alt="List of administrators for this installation in LDAP DN syntax (colon separated)"/>	           		    
150
		</td>
151
		<td class="config-question-mark">
152
			<img src="style/images/question-mark.gif" onClick="helpWindow('<%= request.getContextPath() %>', '<%= orgProperty.getHelpFile() %>')"/>
153
		</td>
154
	</tr>	  
155
<%
156
	  	}
157
%>
158
      </table>
159
<%
154
		}
160 155
	}
161 156
%>
162 157

  
lib/admin/organization-configuration.jsp
1
<%@ page language="java"%>
2
<%@ page import="java.util.Set,java.util.Map,java.util.Vector,edu.ucsb.nceas.utilities.*" %>
3
<%
4
	/**
5
 *  '$RCSfile$'
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 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
%>
29

  
30
<%
31
	PropertiesMetaData metadata = (PropertiesMetaData)request.getAttribute("metadata");
32
 	Vector<String> ldapOrganizations = 
33
 		(Vector<String>)request.getAttribute("orgList"); 
34
%>
35

  
36
<html>
37
<head>
38

  
39
<title>Organization Configuration</title>
40
<link rel="stylesheet" type="text/css" 
41
        href="<%= request.getContextPath() %>/admin/admin.css"></link>
42
<script language="JavaScript" type="text/JavaScript" src="<%= request.getContextPath() %>/admin/admin.js"></script>
43
<script language="JavaScript" type="text/JavaScript" src="<%= request.getContextPath() %>/help/help.js"></script>
44

  
45
</head>
46
<body>
47
<img src="<%= request.getContextPath() %>/metacat-logo.png" width="100px" align="right"/> 
48
<h2>Organization Configuration</h2>
49
Enter organization specific properties here. 
50
<br class="ldap-header">
51

  
52
<%@ include file="./page-message-section.jsp"%>
53

  
54

  
55
<form method="POST" name="configuration_form" action="<%= request.getContextPath() %>/admin" 
56
                                        onsubmit="return submitForm(this);">
57
<%
58
	if (metadata != null) {
59
		// each group describes a section of properties
60
		Map<Integer, MetaDataGroup> groupMap = metadata.getGroups();
61
		Set<Integer> groupIdSet = groupMap.keySet();
62
		for (Integer groupId : groupIdSet) {
63
			// for this group, display the header (group name)
64
			MetaDataGroup metaDataGroup = (MetaDataGroup)groupMap.get(groupId);
65
%>
66
			<h3><%= metaDataGroup.getName()  %></h3>
67
			<hr class="config-line">
68
<%
69
 			if (metaDataGroup.getComment() != null) {
70
%>
71
  				<div class="heading-comment"><%= metaDataGroup.getComment() %></div>
72
<%
73
 			}
74
%>
75
			<br>
76
<%
77
			for (String orgName : ldapOrganizations) {
78
%>
79
			<table class="config-section">
80
				<tr>
81
				<td class="config-checkbox">
82
	  				<input class="org" type="checkbox" name="<%= orgName %>.cb" onClick="toggleHiddenTable(this, 'hiding-section-<%= orgName %>')"/>
83
	  			</td>
84
	  			<td class="config-checkbox-label">	
85
					<label for="<%= orgName %>.cb"><%=orgName%></label>
86
				</td> 
87
				<td class="config-question-mark">
88
					<img src="style/images/question-mark.gif"
89
							alt="blah"
90
							title="blah"/>
91
				</td>
92
				</tr>
93
			</table>
94
			<table class="config-section-hiding" id="hiding-section-<%= orgName %>">  
95
<%
96
				// get all the properties in this group
97
				Map<Integer, MetaDataProperty> propertyMap = 
98
					metadata.getPropertiesInGroup(metaDataGroup.getIndex());
99
				Set<Integer> orgIndexes = propertyMap.keySet();
100
	  			for (Integer orgIndex : orgIndexes) {
101
	  				MetaDataProperty orgProperty = propertyMap.get(orgIndex);
102
	  				String orgKeyName = orgProperty.getKey() + "." + orgName;
103
%>		
104
				<tr>
105
				<td class="config-property-label" >	
106
	    			<label for="<%= orgKeyName %>" title="<%= orgProperty.getDescription() %>"><%= orgProperty.getLabel() %></label>
107
     			</td>	
108
     			<td class="config-property-input" >
109
					<input name="<%= orgKeyName %>" 
110
						value="<%= request.getAttribute(orgKeyName) %>"	  
111
<% 
112
					if (orgProperty.getFieldType().equals("password")) { 
113
%>           		    	    	           		    	             			
114
	           			type="password"       
115
<%
116
	  				}
117
%>    			
118
	           			alt="List of administrators for this installation in LDAP DN syntax (colon separated)"/>	           		    
119
				</td>
120
				<td class="config-question-mark">
121
					<img src="style/images/question-mark.gif" onClick="helpWindow('<%= request.getContextPath() %>', '<%= orgProperty.getHelpFile() %>')"/>
122
				</td>
123
				</tr>	  
124
<%
125
				if (orgProperty.getDescription() != null) {
126
%>
127
	    	        <tr>
128
	    	        <td></td>
129
	    	        <td class="config-property-description" colspan="2" >
130
						<%= orgProperty.getDescription() %>
131
	    	        </td>
132
<%
133
	    			}
134
	  			}
135
%>
136
      		</table>
137
<%
138
			}
139
		}
140
	}
141
%>
142

  
143
  <input type="hidden" name="configureType" value="organization"/>
144
  <input type="hidden" name="processForm" value="true"/>
145
  <input class="left-button" type="submit" value="Save"/>
146
  <input class="button" type="button" value="Cancel" onClick="forward('./admin')"> 
147

  
148
</form>
149

  
150
</body>
151
</html>
0 152

  
lib/admin/admin-login.jsp
1 1
<%@ page language="java" %> 
2
<%@ page import="java.util.Vector,edu.ucsb.nceas.metacat.util.LDAPUtil,edu.ucsb.nceas.metacat.service.PropertyService" %>
2
<%@ page import="edu.ucsb.nceas.metacat.util.OrganizationUtil,edu.ucsb.nceas.metacat.service.PropertyService" %>
3 3
<% 
4 4
/**
5 5
 *  '$RCSfile$'
......
28 28
%>
29 29

  
30 30
<% 
31
	Vector<String> organizationList = LDAPUtil.getOrganizations();
31
	Vector<String> organizationList = OrganizationUtil.getOrganizations();
32 32
%>
33 33

  
34 34
<html>
......
85 85
%>
86 86
			<option value="<%= orgName %>"
87 87
<%
88
			if (PropertyService.getProperty("ldap.base." + orgName) == null || PropertyService.getProperty("ldap.base." + orgName).equals("")) {
88
			if (PropertyService.getProperty("organization.base." + orgName) == null || PropertyService.getProperty("organization.base." + orgName).equals("")) {
89 89
%>
90 90
			disabled="disabled"
91 91
<%
lib/admin/metacat-configuration.jsp
31 31
	MetaCatVersion metacatVersion = (MetaCatVersion)request.getAttribute("metaCatVersion"); 	
32 32
	DBVersion databaseVersion = (DBVersion)request.getAttribute("databaseVersion");		
33 33
    Boolean propsConfigured = (Boolean)request.getAttribute("propsConfigured");	
34
    Boolean orgsConfigured = (Boolean)request.getAttribute("orgsConfigured");	
34 35
    Boolean ldapConfigured = (Boolean)request.getAttribute("ldapConfigured");	
35 36
    Boolean skinsConfigured = (Boolean)request.getAttribute("skinsConfigured");	
36 37
    Boolean dbConfigured = (Boolean)request.getAttribute("dbConfigured");
......
76 77
%>
77 78

  
78 79
<%
80
	if (orgsConfigured != null && orgsConfigured) {
81
%>
82
        <tr>
83
        <td class="configured-tag">[configured] </td>
84
		<td class="property-title"> Organization Configuration </td> 
85
		<td class="configure-link"> <a href="<%= request.getContextPath() %>/admin?configureType=organization">Reconfigure Now</a> </td>
86
        </tr>
87
<%
88
	} else {
89
%>    		
90
        <tr>
91
 		<td class=unconfigured-tag>[unconfigured] </td>  
92
 		<td class=property-title> Organization Configuration </td>
93
		<td class=configure-link> <a href="<%= request.getContextPath() %>/admin?configureType=organization">Configure Now</a> </td>			
94
    	</tr>
95
<%
96
	}
97
%>
98

  
99
<%
79 100
	if (propsConfigured != null && propsConfigured) {
80 101
%>
81 102
        <tr>
lib/ldap.properties.metadata.xml
1
<?xml version="1.0"?>
2

  
3
<metadataConfig>
4
	<group>
5
		<index>1</index>
6
		<name>LDAP Configuration Values</name>
7
		<comment>
8
			LDAP Setup
9
		</comment>
10
		<description>LDAP Configuration Values.</description>
11
	</group>
12
	
13
	<config>
14
		<key>ldap.url</key>
15
		<label>LDAP URL</label>
16
		<group>1</group>
17
		<index>1</index>
18
		<description>LDAP Server URL.</description>
19
		<helpFile>properties.html#ldap.url</helpFile>
20
	</config>
21

  
22
	<config>
23
		<key>ldap.surl</key>
24
		<label>LDAP Secure URL</label>
25
		<group>1</group>
26
		<index>2</index>
27
		<description>LDAP Secure Server URL.</description>
28
		<helpFile>properties.html#ldap.surl</helpFile>
29
	</config>
30

  
31
	<config>
32
		<key>ldap.administrators</key>
33
		<label>MetaCat Administrators</label>
34
		<group>1</group>
35
		<index>3</index>
36
		<description>LDAP Administrators.</description>
37
		<helpFile>properties.html#ldap.admin</helpFile>
38
	</config>
39

  
40
</metadataConfig>
0 41

  
lib/org.properties.metadata.xml
3 3
<metadataConfig>
4 4
	<group>
5 5
		<index>1</index>
6
		<name>Global Values</name>
7
		<description>Database Configuration Values.</description>
8
	</group>
9
	<group>
10
		<index>2</index>
11 6
		<name>Organizational Level Values</name>
12 7
		<comment>
13 8
			Select the organizations for which you have admin rights, and update
......
17 12
	</group>
18 13

  
19 14
	<config>
20
		<key>ldap.url</key>
21
		<label>LDAP URL</label>
15
		<key>organization.name</key>
16
		<label>Organization Name</label>
22 17
		<group>1</group>
23 18
		<index>1</index>
24
		<description>LDAP Server URL.</description>
25
		<helpFile>properties.html#ldap.url</helpFile>
19
		<description>The display name of organization</description>
20
		<helpFile>properties.html#ldap.org</helpFile>
26 21
	</config>
27

  
22
	
28 23
	<config>
29
		<key>ldap.surl</key>
30
		<label>LDAP Secure URL</label>
24
		<key>organization.org</key>
25
		<label>LDAP Organization</label>
31 26
		<group>1</group>
32 27
		<index>2</index>
33
		<description>LDAP Secure Server URL.</description>
34
		<helpFile>properties.html#ldap.surl</helpFile>
35
	</config>
36

  
37
	<config>
38
		<key>ldap.administrators</key>
39
		<label>MetaCat Administrators</label>
40
		<group>1</group>
41
		<index>3</index>
42
		<description>LDAP Administrators.</description>
43
		<helpFile>properties.html#ldap.admin</helpFile>
44
	</config>
45
	
46
	<config>
47
		<key>ldap.allowedSubmitters</key>
48
		<label>Allowed Submitters</label>
49
		<group>1</group>
50
		<index>4</index>
51
		<description>Allowed Submitters</description>
52
		<helpFile>properties.html#ldap.allowed</helpFile>
53
	</config>
54

  
55
	<config>
56
		<key>ldap.deniedSubmitters</key>
57
		<label>Denied Submitters</label>
58
		<group>1</group>
59
		<index>5</index>
60
		<description>Denied Submitters</description>
61
		<helpFile>properties.html#ldap.denied</helpFile>
62
	</config>
63
	
64
	<config>
65
		<key>ldap.org</key>
66
		<label>LDAP Organization</label>
67
		<group>2</group>
68
		<index>1</index>
69 28
		<description>LDAP Organization</description>
70 29
		<helpFile>properties.html#ldap.org</helpFile>
71 30
	</config>
72 31
	
73 32
	<config>
74
		<key>ldap.base</key>
33
		<key>organization.base</key>
75 34
		<label>LDAP Base</label>
76
		<group>2</group>
77
		<index>2</index>
35
		<group>1</group>
36
		<index>3</index>
78 37
		<description>LDAP Base.</description>
79
		<helpFile>properties.html#ldap.base</helpFile>
38
		<helpFile>properties.html#organization.base</helpFile>
80 39
	</config>
81 40
	
82 41
	<config>
83
		<key>ldap.user</key>
42
		<key>organization.user</key>
84 43
		<label>LDAP User Name</label>
85
		<group>2</group>
86
		<index>3</index>
44
		<group>1</group>
45
		<index>4</index>
87 46
		<description>LDAP User Name</description>
88 47
		<helpFile>properties.html#ldap.user</helpFile>
89 48
	</config>
90 49

  
91 50
	<config>
92
		<key>ldap.password</key>
51
		<key>organization.password</key>
93 52
		<label>LDAP Password</label>
94
		<group>2</group>
53
		<group>1</group>
95 54
		<fieldType>password</fieldType>
96
		<index>4</index>
55
		<index>5</index>
97 56
		<description>LDAP Password</description>
98 57
		<helpFile>properties.html#ldap.passwd</helpFile>
99 58
	</config>
src/edu/ucsb/nceas/metacat/service/PropertyService.java
38 38

  
39 39
import org.apache.log4j.Logger;
40 40

  
41
import edu.ucsb.nceas.metacat.util.LDAPUtil;
41
import edu.ucsb.nceas.metacat.util.OrganizationUtil;
42 42
import edu.ucsb.nceas.metacat.util.UtilException;
43 43
import edu.ucsb.nceas.utilities.FileUtil;
44 44
import edu.ucsb.nceas.utilities.GeneralPropertyException;
......
62 62
	
63 63
	private static final String MAIN_CONFIG_NAME = "metacat.properties";
64 64
	private static final String ORG_CONFIG_NAME = "org.properties";
65
	private static final String LDAP_CONFIG_NAME = "ldap.properties";
65 66
	
66 67
	private static boolean bypassAlreadyChecked = false;
67 68
	
......
80 81
	private static String orgMetaDataFilePath = null;
81 82
	private static PropertiesMetaData orgMetaData = null;
82 83
	
84
	private static String ldapBackupPropertiesFilePath = null;
85
	private static SortedProperties ldapBackupProperties = null;
86
	
87
	private static String ldapMetaDataFilePath = null;
88
	private static PropertiesMetaData ldapMetaData = null;
89
	
90
	
83 91
	private static Logger logMetacat = Logger.getLogger(PropertyService.class);
84 92

  
85 93
	/**
......
139 147
			}
140 148

  
141 149
			// orgMetaData holds configuration information about organization level 
142
			// properties.  these are mostly ldap information relative to an 
143
			// organization. This is primarily used to display input fields on 
150
			// properties.  This is primarily used to display input fields on 
144 151
			// the organization configuration page. The information is retrieved 
145
			// from an xml metadata file dedication just to organization properties.
152
			// from an xml metadata file dedicated just to organization properties.
146 153
			orgMetaDataFilePath = configDir + FileUtil.getFS() + ORG_CONFIG_NAME + ".metadata.xml";
147 154
			if (orgMetaData == null) {
148 155
				orgMetaData = new PropertiesMetaData(orgMetaDataFilePath);
149 156
			}
157
			
158

  
159
			// ldapMetaData holds configuration information about organization level 
160
			// properties.  This is primarily used to display input fields on 
161
			// the ldap configuration page. The information is retrieved 
162
			// from an xml metadata file dedicated just to ldap properties.
163
			ldapMetaDataFilePath = configDir + FileUtil.getFS() + LDAP_CONFIG_NAME + ".metadata.xml";
164
			if (ldapMetaData == null) {
165
				ldapMetaData = new PropertiesMetaData(ldapMetaDataFilePath);
166
			}
150 167
		} catch (TransformerException te) {
151 168
			throw new GeneralPropertyException(te.getMessage());
152 169
		}
......
174 191
				new SortedProperties(orgBackupPropertiesFilePath);
175 192
			orgBackupProperties.load();
176 193
		}
194
		
195
		// The ldapBackupProperties hold properties that were backed up the 
196
		// last time the LDAP was configured.  On disk, the file will
197
		// look like a smaller version of metacat.properties.  It is stored 
198
		// in the data storage directory outside the application directories.
199
		ldapBackupPropertiesFilePath = backupDirPath + FileUtil.getFS() +  LDAP_CONFIG_NAME + ".backup";
200
		if (ldapBackupProperties == null) {
201
			ldapBackupProperties = 
202
				new SortedProperties(ldapBackupPropertiesFilePath);
203
			ldapBackupProperties.load();
204
		}
177 205
	
178 206
	}
179 207

  
......
284 312
	}
285 313
	
286 314
	/**
315
	 * Get the LDAP backup properties file. These are configurable 
316
	 * properties that are stored outside the metacat install directories so 
317
	 * the user does not need to re-enter all the configuration information 
318
	 * every time they do an upgrade.
319
	 * 
320
	 * @return a SortedProperties object with the backup properties
321
	 */
322
	public static SortedProperties getLDAPBackupProperties() {
323
		return ldapBackupProperties;
324
	}
325
	
326
	/**
287 327
	 * Get the main properties metadata. This is retrieved from an xml file that
288 328
	 * describes the attributes of configurable properties.
289 329
	 * 
......
305 345
	}
306 346
	
307 347
	/**
348
	 * Get the LDAP properties metadata. This is retrieved from an xml
349
	 * file that describes the attributes of configurable properties.
350
	 * 
351
	 * @return a PropertiesMetaData object with the organization properties
352
	 *         metadata
353
	 */
354
	public static PropertiesMetaData getLDAPMetaData() {
355
		return ldapMetaData;
356
	}
357
	
358
	/**
308 359
	 * Writes out backup configurable properties to a file.
309 360
	 */
310 361
	public static void persistMainBackupProperties(ServletContext servletContext)
......
351 402
			// the associated metadata file
352 403
			PropertiesMetaData orgMetadata = new PropertiesMetaData(orgMetaDataFilePath);
353 404
			
354
			// Here we get the group definition for group 1 from the org
355
			// metadata.  Group 1 should be global values across all 
356
			// organizations.  We then get all properties metadata associated 
357
			// with group 1, iterate through it and set it in the backup
358
			// properties.
359
			MetaDataGroup globalGroup = orgMetadata.getGroup(1);
360
			SortedMap<Integer, MetaDataProperty> globalPropertyMap = 
361
				orgMetadata.getPropertiesInGroup(globalGroup.getIndex());
362
			for (MetaDataProperty property : globalPropertyMap.values()) {
363
				String orgPropertyName = property.getKey();
364
				backupProperties.addProperty(orgPropertyName, getProperty(orgPropertyName));
365
			}
366
			
367 405
			// We do the same thing here for organization specific properies
368 406
			// with the addition that we need to iterate through all available 
369 407
			// organizations.  For instance, a metadata section that defines a 
370
			// property as "ldap.base" will be entered into the metacat.properties
371
			// file with a key of "ldap.base.NCEAS" for the NCEAS organization. 
408
			// property as "organization.base" will be entered into the metacat.properties
409
			// file with a key of "organization.base.NCEAS" for the NCEAS organization. 
372 410
			// This will be repeated for all available organizations.
373
			MetaDataGroup orgGroup = orgMetadata.getGroup(2);
374
			SortedMap<Integer, MetaDataProperty> orgPropertyMap = orgMetadata
375
					.getPropertiesInGroup(orgGroup.getIndex());
376
			for (String orgName : LDAPUtil.getOrganizations()) {
377
				for (MetaDataProperty property : orgPropertyMap.values()) {
378
					String orgPropertyName = property.getKey() + "." + orgName;
379
					backupProperties.addProperty(orgPropertyName, getProperty(orgPropertyName));
411
			Set<String> orgKeySet = orgMetadata.getKeys();
412
			for (String orgName : OrganizationUtil.getOrganizations()) {
413
				for (String propertyKey : orgKeySet) {
414
					String orgPropertyKey = propertyKey + "." + orgName;
415
					backupProperties.addProperty(orgPropertyKey, getProperty(orgPropertyKey));
380 416
				}
381 417
			}
382 418
			
......
393 429
			throw new GeneralPropertyException("Could not get organizations: " + ue.getMessage());
394 430
		}
395 431
	}
432
	
433
	/**
434
	 * Writes out backup configurable properties to a file.
435
	 */
436
	public static void persistLDAPBackupProperties(ServletContext servletContext)
437
			throws GeneralPropertyException {
396 438

  
439
		// Use the metadata to extract configurable properties from the 
440
		// overall properties list, and store those properties.
441
		try {
442
			SortedProperties backupProperties = 
443
				new SortedProperties(ldapBackupPropertiesFilePath);
444
			
445
			// Populate the backup properties for ldap properties using
446
			// the associated metadata file
447
			PropertiesMetaData ldapMetadata = new PropertiesMetaData(ldapMetaDataFilePath);
448

  
449
			Set<String> ldapKeySet = ldapMetadata.getKeys();
450
			for (String propertyKey : ldapKeySet) {
451
				backupProperties.addProperty(propertyKey, getProperty(propertyKey));
452
			}
453
			
454
			// store the properties to file
455
			backupProperties.store();
456

  
457
		} catch (TransformerException te) {
458
			throw new GeneralPropertyException("Could not transform backup properties xml: "
459
					+ te.getMessage());
460
		} catch (IOException ioe) {
461
			throw new GeneralPropertyException("Could not backup configurable properties: "
462
					+ ioe.getMessage());
463
		} 
464
	}
465

  
397 466
	/**
398 467
	 * Gets the backup properties directory
399 468
	 * 
......
473 542
				setPropertyNoPersist(orgBackupPropertyName, value);
474 543
			}
475 544
			
545
			SortedProperties ldapBackupProperties = getLDAPBackupProperties();
546
			Vector<String> ldapBackupPropertyNames = 
547
				ldapBackupProperties.getPropertyNames();
548
			for (String ldapBackupPropertyName : ldapBackupPropertyNames) {
549
				String value = ldapBackupProperties.getProperty(ldapBackupPropertyName);
550
				setPropertyNoPersist(ldapBackupPropertyName, value);
551
			}
552
			
476 553
			setPropertyNoPersist("configutil.propertiesConfigured", "true");
477 554
			setPropertyNoPersist("configutil.ldapConfigured", "true");
555
			setPropertyNoPersist("configutil.organizationsConfigured", "true");
478 556
			setPropertyNoPersist("configutil.skinsConfigured", "true");
479 557
			setPropertyNoPersist("configutil.databaseConfigured", "true");
480 558
				
src/edu/ucsb/nceas/metacat/util/OrganizationUtil.java
1
/**
2
 *  '$RCSfile$'
3
 *    Purpose: A Class that implements administrative methods 
4
 *  Copyright: 2008 Regents of the University of California and the
5
 *             National Center for Ecological Analysis and Synthesis
6
 *    Authors: Michael Daigle
7
 * 
8
 *   '$Author$'
9
 *     '$Date$'
10
 * '$Revision$'
11
 *
12
 * This program is free software; you can redistribute it and/or modify
13
 * it under the terms of the GNU General Public License as published by
14
 * the Free Software Foundation; either version 2 of the License, or
15
 * (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program; if not, write to the Free Software
24
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
 */
26

  
27
package edu.ucsb.nceas.metacat.util;
28

  
29
import java.util.Vector;
30

  
31
import edu.ucsb.nceas.metacat.service.PropertyService;
32
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
33
import edu.ucsb.nceas.utilities.StringUtil;
34

  
35
public class OrganizationUtil {
36

  
37
	/**
38
	 * private constructor - all methods are static so there is no no need to
39
	 * instantiate.
40
	 */
41
	private OrganizationUtil() {}
42

  
43
	/**
44
	 * gets a list of organization names from metacat.properties. Parses the csv
45
	 * string into a vector
46
	 * 
47
	 * @return a Vector of Strings that hold all available organizations
48
	 * 
49
	 * TODO MCD this should be retrieved from ldap instead of metacat.properties
50
	 */
51
	public static Vector<String> getOrganizations() throws UtilException {
52

  
53
		Vector<String> shortOrgNames = new Vector<String>();
54
		Vector<String> longOrgNames = null;
55
		
56
		longOrgNames = PropertyService.getPropertyNamesByGroup("organization.org");
57

  
58
		for (String longName : longOrgNames) {
59
			shortOrgNames.add(longName.substring(17));
60
		}
61
		return shortOrgNames;
62
	}
63
	
64
	/**
65
	 * gets a list of organization names from metacat.properties. Parses the csv
66
	 * string into a vector
67
	 * 
68
	 * @return a Vector of Strings that hold all available organizations
69
	 */
70
	public static Vector<String> getOrgDNs(String orgName) throws UtilException {
71

  
72
		String orgBaseList = null;
73
		try {
74
			orgBaseList = PropertyService.getProperty("organization.base." + orgName);
75
		} catch (PropertyNotFoundException pnfe) {
76
			throw new UtilException("Could not get metacat property: organization.base." 
77
					+ orgName + " : " + pnfe.getMessage());
78
		}
79
		// this will always return a vector (maybe an empty one)
80
		return StringUtil.toVector(orgBaseList, ',');
81
	}
82
	
83

  
84
	/**
85
	 * Reports whether LDAP is fully configured.
86
	 * 
87
	 * @return a boolean that is true if all sections are configured and false
88
	 *         otherwise
89
	 */
90
	public static boolean areOrganizationsConfigured() throws UtilException {
91
		String orgConfiguredString = PropertyService.UNCONFIGURED;
92
		try {
93
			orgConfiguredString = PropertyService.getProperty("configutil.organizationsConfigured");
94
		} catch (PropertyNotFoundException pnfe) {
95
			throw new UtilException("Could not determine if organizations are configured: "
96
					+ pnfe.getMessage());
97
		}
98
		return !orgConfiguredString.equals(PropertyService.UNCONFIGURED);
99
	}
100
}
0 101

  
src/edu/ucsb/nceas/metacat/util/MetaCatUtil.java
993 993
		boolean metacatConfigured = false;
994 994
		try {
995 995
			metacatConfigured = PropertyService.arePropertiesConfigured()
996
					&& LDAPUtil.isLDAPConfigured() && SkinUtil.areSkinsConfigured()
996
					&& OrganizationUtil.areOrganizationsConfigured() 
997
					&& LDAPUtil.isLDAPConfigured()
998
					&& SkinUtil.areSkinsConfigured()
997 999
					&& DatabaseUtil.isDatabaseConfigured();
998 1000
		} catch (UtilException ue) {
999 1001
			logMetacat.error("Could not determine if metacat is configured: "
src/edu/ucsb/nceas/metacat/util/LDAPUtil.java
343 343
	}
344 344

  
345 345
	/**
346
	 * gets a list of organization names from metacat.properties. Parses the csv
347
	 * string into a vector
348
	 * 
349
	 * @return a Vector of Strings that hold all available organizations
350
	 * 
351
	 * TODO MCD this should be retrieved from ldap instead of metacat.properties
352
	 */
353
	public static Vector<String> getOrganizations() throws UtilException {
354

  
355
		Vector<String> shortOrgNames = new Vector<String>();
356
		Vector<String> longOrgNames = null;
357
		
358
		longOrgNames = PropertyService.getPropertyNamesByGroup("ldap.org");
359

  
360
		for (String longName : longOrgNames) {
361
			shortOrgNames.add(longName.substring(9));
362
		}
363
		return shortOrgNames;
364
	}
365
	
366
	/**
367
	 * gets a list of organization names from metacat.properties. Parses the csv
368
	 * string into a vector
369
	 * 
370
	 * @return a Vector of Strings that hold all available organizations
371
	 */
372
	public static Vector<String> getOrgDNs(String orgName) throws UtilException {
373

  
374
		String orgBaseList = null;
375
		try {
376
			orgBaseList = PropertyService.getProperty("ldap.base." + orgName);
377
		} catch (PropertyNotFoundException pnfe) {
378
			throw new UtilException("Could not get metacat property: ldap.base." 
379
					+ orgName + " : " + pnfe.getMessage());
380
		}
381
		// this will always return a vector (maybe an empty one)
382
		return StringUtil.toVector(orgBaseList, ',');
383
	}
384

  
385
	/**
386 346
	 * Reports whether LDAP is fully configured.
387 347
	 * 
388 348
	 * @return a boolean that is true if all sections are configured and false
src/edu/ucsb/nceas/metacat/AuthLdap.java
96 96
			this.ldapsUrl = PropertyService.getProperty("ldap.surl");
97 97
			// use the NCEAS base as a fallback.  Normally, the base will be
98 98
			// parsed from the user during authentication
99
			this.ldapBase = PropertyService.getProperty("ldap.base.NCEAS");
99
			// TODO MCD this may need to remain always at NCEAS value
100
			this.ldapBase = PropertyService.getProperty("organization.base.NCEAS");
100 101
			this.referral = PropertyService.getProperty("ldap.referral");
101 102
			this.ldapConnectTimeLimit = PropertyService
102 103
					.getProperty("ldap.connectTimeLimit");
src/edu/ucsb/nceas/metacat/admin/LDAPAdmin.java
95 95
			
96 96
			try {
97 97
				// Load the properties metadata file so that the JSP page can
98
				// use
99
				// the metadata to construct the editing form
100
				PropertiesMetaData metadata = PropertyService.getOrgMetaData();
98
				// use the metadata to construct the editing form
99
				PropertiesMetaData metadata = PropertyService.getLDAPMetaData();
101 100
				request.setAttribute("metadata", metadata);
102 101
				request.setAttribute("groupMap", metadata.getGroups());
103
				
104
				request.setAttribute("orgList", LDAPUtil.getOrganizations());
105 102

  
106 103
				// add the list of ldap options and their values to the request
107 104
				Vector<String> propertyNames = PropertyService.getPropertyNamesByGroup("ldap");
......
114 111
				// the user from having to re-enter all values when upgrading.
115 112
				// If this is a first time install, getBackupProperties will return
116 113
				// null.
117
				SortedProperties backupProperties = PropertyService.getOrgBackupProperties();
114
				SortedProperties backupProperties = PropertyService.getLDAPBackupProperties();
118 115
				if (backupProperties != null) {
119 116
					Vector<String> backupKeys = backupProperties.getPropertyNames();
120 117
					for (String key : backupKeys) {
......
130 127
			} catch (PropertyNotFoundException pnfe) {
131 128
				throw new AdminException("Problem getting property while initializing "
132 129
						+ "LDAP properties page: " + pnfe.getMessage());
133
			} catch (UtilException ue) {
134
				throw new AdminException("Utility problem while " 
135
						+ "initializing LDAP properties page: " + ue.getMessage());
136 130
			} catch (IOException ioe) {
137 131
				throw new AdminException("IO problem while initializing "
138 132
						+ "LDAP properties page:" + ioe.getMessage());
......
149 143

  
150 144
			try {
151 145
				// For each property, check if it is changed and save it
152
				PropertiesMetaData orgMetaData = PropertyService
153
						.getOrgMetaData();
146
				PropertiesMetaData ldapMetaData = PropertyService
147
						.getLDAPMetaData();
154 148

  
155 149
				// process the fields for the global options (group 1)
156
				SortedMap<Integer, MetaDataProperty> globalPropertyMap = orgMetaData
150
				SortedMap<Integer, MetaDataProperty> globalPropertyMap = ldapMetaData
157 151
						.getPropertiesInGroup(1);
158 152
				Set<Integer> globalPropertyIndexes = globalPropertyMap.keySet();
159 153
				for (Integer globalPropertyIndex : globalPropertyIndexes) {
......
163 157
							globalPropertyKey);
164 158
				}
165 159

  
166
				// process the fields for the organization options (group 2)
167
				SortedMap<Integer, MetaDataProperty> orgPropertyMap = 
168
						orgMetaData.getPropertiesInGroup(2);
169
				Set<Integer> orgPropertyIndexes = orgPropertyMap.keySet();
170
				for (String orgName : LDAPUtil.getOrganizations()) {
171
					if (request.getParameter(orgName + ".cb") != null) {
172
						for (Integer orgPropertyIndex : orgPropertyIndexes) {
173
							String orgPropertyKey = orgPropertyMap.get(
174
									orgPropertyIndex).getKey() + "." + orgName;
175
							PropertyService.checkAndSetProperty(request, orgPropertyKey);
176
						}
177
						PropertyService.setPropertyNoPersist("ldap.configured." + orgName,
178
								"true");
179
					} else {
180
						PropertyService.setPropertyNoPersist("ldap.configured." + orgName,
181
								"false");
182
					}
183
				}
184

  
185 160
				// we need to write the options from memory to the properties
186 161
				// file
187 162
				PropertyService.persistProperties();
......
205 180
				// outside the install directory.  Note that we allow them to
206 181
				// do this even if they have validation errors.  They will
207 182
				// need to go back and fix the errors before they can run metacat.
208
				PropertyService.persistOrgBackupProperties(request.getSession()
183
				PropertyService.persistLDAPBackupProperties(request.getSession()
209 184
						.getServletContext());
210 185
			
211 186
			} catch (GeneralPropertyException gpe) {
......
218 193
						+ "properties page: " + ioe.getMessage();
219 194
				logMetacat.error(errorMessage);
220 195
				processingErrors.add(errorMessage);
221
			} catch (UtilException ue) {
222
				String errorMessage = "Error in utilities while: " 
223
						+ "processing LDAP properties page: " + ue.getMessage();
224
				logMetacat.error(errorMessage);
225
				processingErrors.add(errorMessage);
226
			}
196
			} 
227 197
			
228 198
			try {
229 199
				if (validationErrors.size() > 0 || processingErrors.size() > 0) {
......
269 239
		Vector<String> errorVector = new Vector<String>();
270 240

  
271 241
		//TODO MCD validate options.
272
		
273
//		// Test ldap connectivity
274
//		String ldapError = LDAPUtil.validateLDAPConnectivity(
275
//				request.getParameter("ldap.url"), request.getParameter("ldap.base"));
276
//		if (ldapError != null) {
277
//			errorVector.add(ldapError);
278
//		}
279 242

  
280 243
		return errorVector;
281 244
	}
src/edu/ucsb/nceas/metacat/admin/AuthAdmin.java
36 36
import org.apache.log4j.Logger;
37 37

  
38 38
import edu.ucsb.nceas.metacat.util.LDAPUtil;
39
import edu.ucsb.nceas.metacat.util.OrganizationUtil;
39 40
import edu.ucsb.nceas.metacat.util.RequestUtil;
40 41
import edu.ucsb.nceas.metacat.util.UtilException;
41 42

  
......
117 118
				validationErrors.addAll(validateOptions(request));
118 119
				
119 120
				if (validationErrors.size() == 0) {
120
					Vector<String> dnList = LDAPUtil.getOrgDNs(organization);
121
					Vector<String> dnList = OrganizationUtil.getOrgDNs(organization);
121 122
					isLoggedIn = LDAPUtil.logUserIn(request, userName, organization, dnList, password);
122 123
					loginString = LDAPUtil.createLDAPString(userName, organization, dnList);
123 124
				}
src/edu/ucsb/nceas/metacat/admin/MetaCatAdminServlet.java
42 42
import edu.ucsb.nceas.metacat.service.SessionService;
43 43
import edu.ucsb.nceas.metacat.util.LDAPUtil;
44 44
import edu.ucsb.nceas.metacat.util.MetaCatUtil;
45
import edu.ucsb.nceas.metacat.util.OrganizationUtil;
45 46
import edu.ucsb.nceas.metacat.util.RequestUtil;
46 47
import edu.ucsb.nceas.metacat.util.SkinUtil;
47 48
import edu.ucsb.nceas.metacat.util.SystemUtil;
......
133 134
							DBAdmin.getInstance().getDBVersion());
134 135
				}
135 136
			    request.setAttribute("ldapConfigured", new Boolean(LDAPUtil.isLDAPConfigured()));	
137
			    request.setAttribute("orgsConfigured", new Boolean(OrganizationUtil.areOrganizationsConfigured()));
136 138
			    request.setAttribute("skinsConfigured", new Boolean(SkinUtil.areSkinsConfigured()));
137 139
			    request.setAttribute("metacatConfigured", new Boolean(MetaCatUtil.isMetacatConfigured()));	
138 140
				RequestUtil.forwardRequest(request, response,
......
148 150
				SkinsAdmin.getInstance().configureSkins(request, response);
149 151
				return;
150 152
			} else if (action.equals("database")) {
151
				// process properties
153
				// process database
152 154
				DBAdmin.getInstance().configureDatabase(request, response);
153 155
				return;
154 156
			} else if (action.equals("ldap")) {
155
				// process properties
157
				// process ldap
156 158
				LDAPAdmin.getInstance().configureLDAP(request, response);
157 159
				return;
160
			} else if (action.equals("organization")) {
161
				// process organization
162
				OrganizationAdmin.getInstance().configureOrganization(request, response);
163
				return;
158 164
			} else if (action.equals("login")) {
159
				// process properties
165
				// process login
160 166
				AuthAdmin.getInstance().authenticateUser(request, response);
161 167
				return;
162 168
			} else {
src/edu/ucsb/nceas/metacat/admin/OrganizationAdmin.java
1
/**
2
 *  '$RCSfile$'
3
 *    Purpose: A Class that implements organization configuration methods
4
 *  Copyright: 2008 Regents of the University of California and the
5
 *             National Center for Ecological Analysis and Synthesis
6
 *    Authors: Michael Daigle
7
 *
8
 *   '$Author$'
9
 *     '$Date$'
10
 * '$Revision$'
11
 *
12
 * This program is free software; you can redistribute it and/or modify
13
 * it under the terms of the GNU General Public License as published by
14
 * the Free Software Foundation; either version 2 of the License, or
15
 * (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program; if not, write to the Free Software
24
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
 */
26

  
27
package edu.ucsb.nceas.metacat.admin;
28

  
29
import java.io.IOException;
30
import java.util.Set;
31
import java.util.SortedMap;
32
import java.util.Vector;
33

  
34
import javax.servlet.ServletException;
35
import javax.servlet.http.HttpServletRequest;
36
import javax.servlet.http.HttpServletResponse;
37

  
38
import org.apache.log4j.Logger;
39

  
40
import edu.ucsb.nceas.metacat.service.PropertyService;
41
import edu.ucsb.nceas.metacat.util.OrganizationUtil;
42
import edu.ucsb.nceas.metacat.util.RequestUtil;
43
import edu.ucsb.nceas.metacat.util.UtilException;
44
import edu.ucsb.nceas.utilities.FileUtil;
45
import edu.ucsb.nceas.utilities.GeneralPropertyException;
46
import edu.ucsb.nceas.utilities.MetaDataProperty;
47
import edu.ucsb.nceas.utilities.PropertiesMetaData;
48
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
49
import edu.ucsb.nceas.utilities.SortedProperties;
50

  
51
/**
52
 * Control the display of the organization configuration page and the processing
53
 * of the configuration values.
54
 */
55
public class OrganizationAdmin extends MetaCatAdmin {
56

  
57
	private static OrganizationAdmin organizationAdmin = null;
58
	private static Logger logMetacat = Logger.getLogger(OrganizationAdmin.class);
59

  
60
	/**
61
	 * private constructor since this is a singleton
62
	 */
63
	private OrganizationAdmin() {}
64

  
65
	/**
66
	 * Get the single instance of the MetaCatConfig.
67
	 * 
68
	 * @return the single instance of MetaCatConfig
69
	 */
70
	public static OrganizationAdmin getInstance() {
71
		if (organizationAdmin == null) {
72
			organizationAdmin = new OrganizationAdmin();
73
		}
74
		return organizationAdmin;
75
	}
76
	
77
	/**
78
	 * Handle configuration of the Organization properties
79
	 * 
80
	 * @param request
81
	 *            the http request information
82
	 * @param response
83
	 *            the http response to be sent back to the client
84
	 */
85
	public void configureOrganization(HttpServletRequest request,
86
			HttpServletResponse response) throws AdminException {
87

  
88
		String processForm = request.getParameter("processForm");
89
		String formErrors = (String) request.getAttribute("formErrors");
90

  
91
		if (processForm == null || !processForm.equals("true") || formErrors != null) {
92
			// The servlet configuration parameters have not been set, or there
93
			// were form errors on the last attempt to configure, so redirect to
94
			// the web form for configuring metacat
95
			
96
			try {
97
				// Load the properties metadata file so that the JSP page can
98
				// use
99
				// the metadata to construct the editing form
100
				PropertiesMetaData metadata = PropertyService.getOrgMetaData();
101
				request.setAttribute("metadata", metadata);
102
				request.setAttribute("groupMap", metadata.getGroups());
103
				
104
				request.setAttribute("orgList", OrganizationUtil.getOrganizations());
105

  
106
				// add the list of organization options and their values to the request
107
				Vector<String> propertyNames = 
108
					PropertyService.getPropertyNamesByGroup("organization");
109
				for (String name : propertyNames) {
110
					request.setAttribute(name, PropertyService.getProperty(name));
111
				} 
112

  
113
				// Check for any backup properties and apply them to the request.
114
				// These are properties from previous configurations. They keep
115
				// the user from having to re-enter all values when upgrading.
116
				// If this is a first time install, getBackupProperties will return
117
				// null.
118
				SortedProperties backupProperties = PropertyService.getOrgBackupProperties();
119
				if (backupProperties != null) {
120
					Vector<String> backupKeys = backupProperties.getPropertyNames();
121
					for (String key : backupKeys) {
122
						String value = backupProperties.getProperty(key);
123
						if (value != null) {
124
							request.setAttribute(key, value);
125
						}
126
					}
127
				}
128
				// Forward the request to the JSP page
129
				RequestUtil.forwardRequest(request, response,
130
						"/admin/organization-configuration.jsp");
131
			} catch (PropertyNotFoundException pnfe) {
132
				throw new AdminException("Problem getting property while initializing "
133
						+ "organization properties page: " + pnfe.getMessage());
134
			} catch (UtilException ue) {
135
				throw new AdminException("Utility problem while " 
136
						+ "initializing organization properties page: " + ue.getMessage());
137
			} catch (IOException ioe) {
138
				throw new AdminException("IO problem while initializing "
139
						+ "organization properties page:" + ioe.getMessage());
140
			} catch (ServletException se) {
141
				throw new AdminException("problem forwarding request while " 
142
						+ "initializing organization properties page: " + se.getMessage());
143
			}
144
		} else {
145
			// The configuration form is being submitted and needs to be
146
			// processed.
147
			Vector<String> processingSuccess = new Vector<String>();
148
			Vector<String> processingErrors = new Vector<String>();
149
			Vector<String> validationErrors = new Vector<String>();
150

  
151
			try {
152
				// For each property, check if it is changed and save it
153
				PropertiesMetaData orgMetaData = 
154
					PropertyService.getOrgMetaData();
155

  
156
				Set<String> orgKeys = orgMetaData.getKeys();
157
				for (String orgName : OrganizationUtil.getOrganizations()) {
158
					for (String key : orgKeys) {
159
						PropertyService.checkAndSetProperty(request, key + "." + orgName);
160
					}
161
				}
162

  
163
				// we need to write the options from memory to the properties
164
				// file
165
				PropertyService.persistProperties();
166

  
167
				// Validate that the options provided are legitimate. Note that
168
				// we've allowed them to persist their entries. As of this point
169
				// there is no other easy way to go back to the configure form
170
				// and preserve their entries.
171
				validationErrors.addAll(validateOptions(request));
172

  
173
				// Try to create data file and backup directories if
174
				// necessary.
175
				String backupDir = PropertyService.getBackupDir();
176
				if (!FileUtil.createDirectory(backupDir)) {
177
					String errorString = "Could not create directory: " + backupDir;
178
					logMetacat.error(errorString);
179
					validationErrors.add(errorString);
180
				}
181

  
182
				// Write out the configurable properties to a backup file
183
				// outside the install directory.  Note that we allow them to
184
				// do this even if they have validation errors.  They will
185
				// need to go back and fix the errors before they can run metacat.
186
				PropertyService.persistOrgBackupProperties(request.getSession()
187
						.getServletContext());
188
			
189
			} catch (GeneralPropertyException gpe) {
190
				String errorMessage = "Problem getting or setting property while "
191
					+ "processing organization properties page: " + gpe.getMessage();
192
				logMetacat.error(errorMessage);
193
				processingErrors.add(errorMessage);
194
			} catch (IOException ioe) {
195
				String errorMessage = "IO problem while processing organization "
196
						+ "properties page: " + ioe.getMessage();
197
				logMetacat.error(errorMessage);
198
				processingErrors.add(errorMessage);
199
			} catch (UtilException ue) {
200
				String errorMessage = "Error in utilities while: " 
201
						+ "processing organization properties page: " + ue.getMessage();
202
				logMetacat.error(errorMessage);
203
				processingErrors.add(errorMessage);
204
			}
205
			
206
			try {
207
				if (validationErrors.size() > 0 || processingErrors.size() > 0) {
208
					RequestUtil.clearRequestMessages(request);
209
					RequestUtil.setRequestFormErrors(request, validationErrors);
210
					RequestUtil.setRequestErrors(request, processingErrors);
211
					RequestUtil.forwardRequest(request, response, "/admin");
212
				} else {
213
					// Now that the options have been set, change the
214
					// 'organizationsConfigured' option to 'true'
215
					PropertyService.setProperty("configutil.organizationsConfigured",
216
							PropertyService.CONFIGURED);
217
					
218
					// Reload the main metacat configuration page
219
					processingSuccess.add("Organizations successfully configured");
220
					RequestUtil.clearRequestMessages(request);
221
					RequestUtil.setRequestSuccess(request, processingSuccess);
222
					RequestUtil.forwardRequest(request, response,
223
							"/admin?configureType=configure&processForm=false");
224
				}
225
			} catch (ServletException se) {
226
				throw new AdminException("problem forwarding request while "
227
						+ "processing organization properties page: " + se.getMessage());
228
			} catch (IOException ioe) {
229
				throw new AdminException("IO problem while processing organization "
230
						+ "properties page: " + ioe.getMessage());
231
			} catch (GeneralPropertyException gpe) {
232
				String errorMessage = "Problem getting or setting property while "
233
					+ "processing organization properties page: " + gpe.getMessage();
234
				logMetacat.error(errorMessage);
235
				processingErrors.add(errorMessage);
236
			}
237
		}
238
	}
239
	
240
	/**
241
	 * Validate the most important configuration options submitted by the user.
242
	 * 
243
	 * @return a vector holding error message for any fields that fail
244
	 *         validation.
245
	 */
246
	protected Vector<String> validateOptions(HttpServletRequest request) {
247
		Vector<String> errorVector = new Vector<String>();
248

  
249
		//TODO MCD validate options.
250

  
251
		return errorVector;
252
	}
253
}
0 254

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff