ldap-server.jspf 17.4 KB
Newer Older
Gaston Dombiak's avatar
Gaston Dombiak committed
1
<%@ page import="org.jivesoftware.util.LocaleUtils"%>
2
<%@ page import="org.jivesoftware.util.ParamUtils"%>
3
<%@ page import="org.jivesoftware.openfire.ldap.LdapManager"%>
4
<%@ page import="java.util.*" %>
Gaston Dombiak's avatar
Gaston Dombiak committed
5 6 7 8 9 10 11 12 13 14 15 16 17

<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
<%
    String host;
    int port = 389;
    String baseDN;
    String adminDN;
    String adminPassword;
    boolean connectionPoolEnabled = true;
    boolean sslEnabled = false;
    boolean debugEnabled = false;
    boolean referralsEnabled = false;
18
    boolean aliasReferralsEnabled = true;
Gaston Dombiak's avatar
Gaston Dombiak committed
19

20 21 22
    @SuppressWarnings("unchecked")
    Map<String,String> xmppSettings = (Map<String,String>)session.getAttribute("xmppSettings");

Gaston Dombiak's avatar
Gaston Dombiak committed
23 24 25 26
    // Get parameters
    boolean save = request.getParameter("save") != null;
    boolean test = request.getParameter("test") != null;

27
    LdapManager manager = LdapManager.getInstance();
Gaston Dombiak's avatar
Gaston Dombiak committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
    Map<String, String> errors = new HashMap<String, String>();

    if (save || test) {
        host = ParamUtils.getParameter(request, "host");
        if (host == null) {
            errors.put("host", LocaleUtils.getLocalizedString("setup.ldap.server.host_error"));
        }
        port = ParamUtils.getIntParameter(request, "port", port);
        if (port <= 0) {
            errors.put("port", LocaleUtils.getLocalizedString("setup.ldap.server.port_error"));
        }
        baseDN = ParamUtils.getParameter(request, "basedn");
        if (baseDN == null) {
            errors.put("baseDN", LocaleUtils.getLocalizedString("setup.ldap.server.basedn_error"));
        }
        adminDN = ParamUtils.getParameter(request, "admindn");
        adminPassword = ParamUtils.getParameter(request, "adminpwd");
        connectionPoolEnabled =
                ParamUtils.getBooleanParameter(request, "connectionpool", connectionPoolEnabled);
        sslEnabled = ParamUtils.getBooleanParameter(request, "ssl", sslEnabled);
        debugEnabled = ParamUtils.getBooleanParameter(request, "debug", debugEnabled);
        referralsEnabled = ParamUtils.getBooleanParameter(request, "referrals", referralsEnabled);
50
        aliasReferralsEnabled = ParamUtils.getBooleanParameter(request, "aliasreferrals", aliasReferralsEnabled);
Gaston Dombiak's avatar
Gaston Dombiak committed
51 52 53 54 55 56 57 58

        if (errors.isEmpty()) {
            // Store settings in a map and keep it in the session
            Map<String, String> settings = new HashMap<String, String>();
            settings.put("ldap.serverType", serverType);
            settings.put("ldap.host", host);
            settings.put("ldap.port", Integer.toString(port));
            settings.put("ldap.baseDN", baseDN);
59 60 61 62 63 64
            if (adminDN != null) {
                settings.put("ldap.adminDN", adminDN);
            }
            if (adminPassword != null) {
                settings.put("ldap.adminPassword", adminPassword);
            }
Gaston Dombiak's avatar
Gaston Dombiak committed
65 66 67 68 69
            settings.put("ldap.connectionPoolEnabled",
                    Boolean.toString(connectionPoolEnabled));
            settings.put("ldap.sslEnabled", Boolean.toString(sslEnabled));
            settings.put("ldap.debugEnabled", Boolean.toString(debugEnabled));
            settings.put("ldap.autoFollowReferrals", Boolean.toString(referralsEnabled));
70
            settings.put("ldap.autoFollowAliasReferrals", Boolean.toString(aliasReferralsEnabled));
Gaston Dombiak's avatar
Gaston Dombiak committed
71 72 73 74 75 76
            // Always disable connection pooling so that connections aren't left hanging open.
            settings.put("ldap.connectionPoolEnabled", "false");
            session.setAttribute("ldapSettings", settings);

            if (save) {
                // Save settings and redirect
77 78 79 80 81 82 83 84 85 86 87 88 89 90
                Collection<String> hosts = new ArrayList<String>();
                StringTokenizer st = new StringTokenizer(host, " ,\t\n\r\f");
                while (st.hasMoreTokens()) {
                    hosts.add(st.nextToken());
                }
                manager.setHosts(hosts);
                manager.setPort(port);
                manager.setBaseDN(baseDN);
                manager.setAdminDN(adminDN);
                manager.setAdminPassword(adminPassword);
                manager.setConnectionPoolEnabled(connectionPoolEnabled);
                manager.setSslEnabled(sslEnabled);
                manager.setDebugEnabled(debugEnabled);
                manager.setFollowReferralsEnabled(referralsEnabled);
91
                manager.setFollowAliasReferralsEnabled(aliasReferralsEnabled);
Gaston Dombiak's avatar
Gaston Dombiak committed
92

93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
                // Save the settings for later, if we're in setup
                if (xmppSettings != null) {
                    xmppSettings.put("ldap.host", host);
                    xmppSettings.put("ldap.port", Integer.toString(port));
                    xmppSettings.put("ldap.baseDN", baseDN);
                    xmppSettings.put("ldap.adminDN", adminDN);
                    xmppSettings.put("ldap.adminPassword", adminPassword);
                    xmppSettings.put("ldap.connectionPoolEnabled", Boolean.toString(connectionPoolEnabled));
                    xmppSettings.put("ldap.sslEnabled", Boolean.toString(sslEnabled));
                    xmppSettings.put("ldap.debugEnabled", Boolean.toString(debugEnabled));
                    xmppSettings.put("ldap.autoFollowReferrals", Boolean.toString(referralsEnabled));
                    xmppSettings.put("ldap.autoFollowAliasReferrals", Boolean.toString(aliasReferralsEnabled));
                    session.setAttribute("xmppSettings", xmppSettings);
                }

Gaston Dombiak's avatar
Gaston Dombiak committed
108 109 110 111 112
                // Redirect to next step.
                response.sendRedirect(nextPage);
                return;
            }
        }
113
    } else {
Gaston Dombiak's avatar
Gaston Dombiak committed
114
        // See if there are already values for the variables defined.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
        StringBuilder sb = new StringBuilder();
        for (String aHost : LdapManager.getInstance().getHosts()) {
            sb.append(aHost).append(", ");
        }
        host = sb.toString();
        if (host.trim().length() > 0) {
            host = host.substring(0, host.length() - 2);
        }
        port = manager.getPort();
        baseDN = manager.getBaseDN();
        adminDN = manager.getAdminDN();
        adminPassword = manager.getAdminPassword();
        connectionPoolEnabled = manager.isConnectionPoolEnabled();
        sslEnabled = manager.isSslEnabled();
        debugEnabled = manager.isDebugEnabled();
        referralsEnabled = manager.isFollowReferralsEnabled();
131
        aliasReferralsEnabled = manager.isFollowAliasReferralsEnabled();
Gaston Dombiak's avatar
Gaston Dombiak committed
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
    }
%>
<html>
<head>
    <title><fmt:message key="setup.ldap.title" /></title>
    <% for (Map.Entry<String, String> entry : meta.entrySet()) { %>
    <meta name="<%= entry.getKey()%>" content="<%= entry.getValue()%>"/>
    <% } %>
</head>
<body>

    <% if (test && errors.isEmpty()) { %>

        <a href="<%= testPage%>" id="lbmessage" title="<fmt:message key="global.test" />" style="display:none;"></a>
        <script type="text/javascript">
            function loadMsg() {
                var lb = new lightbox(document.getElementById('lbmessage'));
                lb.activate();
            }
            setTimeout('loadMsg()', 250);
        </script>

    <% } %>

    <% if (initialSetup) { %>
    <h1><fmt:message key="setup.ldap.profile" />: <span><fmt:message key="setup.ldap.connection_settings" /></span></h1>
    <% } %>

    <!-- BEGIN jive-contentBox_stepbar -->
	<div id="jive-contentBox_stepbar">
		<span class="jive-stepbar_step"><strong>1. <fmt:message key="setup.ldap.connection_settings" /></strong></span>
		<span class="jive-stepbar_step"><em>2. <fmt:message key="setup.ldap.user_mapping" /></em></span>
		<span class="jive-stepbar_step"><em>3. <fmt:message key="setup.ldap.group_mapping" /></em></span>
	</div>
	<!-- END jive-contentBox-stepbar -->

    <!-- BEGIN jive-contentBox -->
    <div class="jive-contentBox jive-contentBox_for-stepbar">

	<h2><fmt:message key="setup.ldap.step_one" />: <span><fmt:message key="setup.ldap.connection_settings" /></span></h2>
	<p><fmt:message key="setup.ldap.server.description" /></p>

    <%  if (errors.size() > 0) { %>

    <div class="error">
        <% for (String error:errors.values()) { %>
            <%= error%><br/>
        <% } %>
    </div>

    <%  } %>

    <form action="<%= currentPage%>" method="post">
		<!-- BEGIN jive-contentBox_bluebox -->
		<div class="jive-contentBox_bluebox">
			<table border="0" cellpadding="0" cellspacing="2">
			<tr>
			    <td colspan="4"><strong><fmt:message key="setup.ldap.server.ldap_server" /></strong></td>
			</tr>
            <% if (initialSetup) { %>
            <tr>
                <td align="right" width="1%" nowrap="nowrap"><fmt:message key="setup.ldap.server.type" />:</td>
                <td colspan="3" nowrap>
                    <select name="servertype" size="1" id="jiveLDAPserverType" style="width:90%;">
                        <option value="1" <%= serverType == null ? "selected" : "" %>><fmt:message key="setup.ldap.server.type_select" /></option>
                        <option value="2" <%= "activedirectory".equals(serverType) ? "selected" : "" %>>Active Directory</option>
                        <option value="3" <%= "openldap".equals(serverType) ? "selected" : "" %>>OpenLDAP</option>
                        <option value="4" <%= "other".equals(serverType) ? "selected" : "" %>><fmt:message key="setup.ldap.server.type_other" /></option>
                    </select><span class="jive-setup-helpicon" onmouseover="domTT_activate(this, event, 'content', '<fmt:message key="setup.ldap.server.type_help" />', 'styleClass', 'jiveTooltip', 'trail', true, 'delay', 300, 'lifetime', 8000);"></span>
                </td>
			</tr>
            <% } %>
            <tr>
			    <td align="right" width="1%" nowrap="nowrap"><fmt:message key="setup.ldap.server.host" />:</td>
                <td width="1%">
                    <table cellpadding="0" cellspacing="0" border="0" width="100%">
                    <tr>
                        <td width="1%" nowrap="nowrap">
                            <input type="text" name="host" id="jiveLDAPphost" size="22" maxlength="50" value="<%= host!=null?host:"" %>">
                        </td>
                        <td width="99%">
                            <span class="jive-setup-helpicon" onmouseover="domTT_activate(this, event, 'content', '<fmt:message key="setup.ldap.server.host_help" />', 'styleClass', 'jiveTooltip', 'trail', true, 'delay', 300, 'lifetime', 8000);"></span>
                        </td>
                    </tr>
                    </table>
                </td>
                <td align="right" width="1%" nowrap="nowrap">&nbsp;&nbsp; <fmt:message key="setup.ldap.server.port" />:</td>
                <td><input type="text" name="port" id="jiveLDAPport" size="5" maxlength="5" value="<%= port %>"><span class="jive-setup-helpicon" onmouseover="domTT_activate(this, event, 'content', '<fmt:message key="setup.ldap.server.port_help" />', 'styleClass', 'jiveTooltip', 'trail', true, 'delay', 300, 'lifetime', 8000);"></span></td>
			</tr>
			<tr>
                <td align="right"><fmt:message key="setup.ldap.server.basedn" />:</td>
                <td colspan="3">
                    <input type="text" name="basedn" id="jiveLDAPbasedn" size="40" maxlength="150" value="<%= baseDN!=null?baseDN:""%>" style="width:90%;">
                    <span class="jive-setup-helpicon" onmouseover="domTT_activate(this, event, 'content', '<fmt:message key="setup.ldap.server.basedn_help" />', 'styleClass', 'jiveTooltip', 'trail', true, 'delay', 300, 'lifetime', 16000);"></span>
                </td>
			</tr>
            <tr><td colspan="4">&nbsp;</td></tr>
            <tr>
			    <td colspan="4"><strong><fmt:message key="setup.ldap.server.auth" />:</strong></td>
			</tr>
			<tr>
                <td align="right" width="1%" nowrap="nowrap"><fmt:message key="setup.ldap.server.admindn" />:</td>
                <td colspan="3">
                    <input type="text" name="admindn" id="jiveLDAPadmindn" size="40" maxlength="150" value="<%= adminDN!=null?adminDN:""%>" style="width:90%;">
                    <span class="jive-setup-helpicon" onmouseover="domTT_activate(this, event, 'content', '<fmt:message key="setup.ldap.server.admindn_help" />', 'styleClass', 'jiveTooltip', 'trail', true, 'delay', 300, 'lifetime', -1);"></span>
                </td>
			</tr>
			<tr>
                <td align="right" width="1%" nowrap="nowrap"><fmt:message key="setup.ldap.server.password" />:</td>
                <td colspan="3"><input type="password" name="adminpwd" id="jiveLDAPadminpwd" size="22" maxlength="30" value="<%= adminPassword!=null?adminPassword:""%>"> <span class="jive-setup-helpicon" onmouseover="domTT_activate(this, event, 'content', '<fmt:message key="setup.ldap.server.password_help" />', 'styleClass', 'jiveTooltip', 'trail', true, 'delay', 300, 'lifetime', 8000);"></span></td>
			</tr>
			</table>
		</div>
		<!-- END jive-contentBox_bluebox -->


		<!-- BEGIN jiveAdvancedButton -->
		<div class="jiveAdvancedButton">
			<a href="#" onclick="togglePanel(jiveAdvanced); return false;" id="jiveAdvancedLink"><fmt:message key="setup.ldap.advanced" /></a>
		</div>
		<!-- END jiveAdvancedButton -->

		<!-- BEGIN jiveAdvancedPanelcs (advanced connection settings) -->
		<div class="jiveadvancedPanelcs" id="jiveAdvanced" style="display: none;">
			<div>
				<table border="0" cellpadding="0" cellspacing="1">
				<thead>
				<tr>
					<th width="10%"></th>
					<th></th>
					<th width="50"><fmt:message key="global.yes" /></th>
					<th width="50"><fmt:message key="global.no" /></th>
				</tr>
				</thead>
				<tbody>
				<tr>
					<td class="jive-advancedLabel" nowrap>
						<fmt:message key="setup.ldap.server.connection_pool" />:
					</td>
					<td class="jive-advancedDesc jive-advancedBorderBottom jive-advancedBorderRight">
					    <fmt:message key="setup.ldap.server.connection_pool_help" />
					</td>
					<td class="jive-advancedBorderBottom jive-advancedBorderRight" align="center">
275
						<input type="radio" name="connectionpool" value="true" <% if (connectionPoolEnabled) { %>checked <% } %>>
Gaston Dombiak's avatar
Gaston Dombiak committed
276 277
					</td>
					<td class="jive-advancedBorderBottom" align="center">
278
						<input type="radio" name="connectionpool" value="false" <% if (!connectionPoolEnabled) { %>checked <% } %>>
Gaston Dombiak's avatar
Gaston Dombiak committed
279 280 281 282 283 284 285 286 287 288
					</td>
				</tr>
				<tr>
					<td class="jive-advancedLabel" nowrap>
						<fmt:message key="setup.ldap.server.ssl" />:
					</td>
					<td class="jive-advancedDesc jive-advancedBorderBottom jive-advancedBorderRight">
						<fmt:message key="setup.ldap.server.ssl_help" />
					</td>
					<td class="jive-advancedBorderBottom jive-advancedBorderRight" align="center">
289
						<input type="radio" name="ssl" value="true" <% if (sslEnabled) { %>checked <% } %>>
Gaston Dombiak's avatar
Gaston Dombiak committed
290 291
					</td>
					<td class="jive-advancedBorderBottom" align="center">
292
						<input type="radio" name="ssl" value="false" <% if (!sslEnabled) { %>checked <% } %>>
Gaston Dombiak's avatar
Gaston Dombiak committed
293 294 295 296 297 298 299 300 301 302
					</td>
				</tr>
				<tr>
					<td class="jive-advancedLabel" nowrap>
						<fmt:message key="setup.ldap.server.debug" />:
					</td>
					<td class="jive-advancedDesc jive-advancedBorderBottom jive-advancedBorderRight">
						<fmt:message key="setup.ldap.server.debug_help" />
					</td>
					<td class="jive-advancedBorderBottom jive-advancedBorderRight" align="center">
303
						<input type="radio" name="debug" value="true" <% if (debugEnabled) { %>checked <% } %>>
Gaston Dombiak's avatar
Gaston Dombiak committed
304 305
					</td>
					<td class="jive-advancedBorderBottom" align="center">
306
						<input type="radio" name="debug" value="false" <% if (!debugEnabled) { %>checked <% } %>>
Gaston Dombiak's avatar
Gaston Dombiak committed
307 308 309 310 311 312 313 314 315 316
					</td>
				</tr>
				<tr>
					<td class="jive-advancedLabel" nowrap>
						<fmt:message key="setup.ldap.server.referral" />:
					</td>
					<td class="jive-advancedDesc jive-advancedBorderBottom jive-advancedBorderRight">
						<fmt:message key="setup.ldap.server.referral_help" />
					</td>
					<td class="jive-advancedBorderBottom jive-advancedBorderRight" align="center">
317
						<input type="radio" name="referrals" value="true" <% if (referralsEnabled) { %>checked <% } %>>
Gaston Dombiak's avatar
Gaston Dombiak committed
318 319
					</td>
					<td class="jive-advancedBorderBottom" align="center">
320
						<input type="radio" name="referrals" value="false" <% if (!referralsEnabled) { %>checked <% } %>>
Gaston Dombiak's avatar
Gaston Dombiak committed
321 322
					</td>
				</tr>
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
                <tr>
                    <td class="jive-advancedLabel" nowrap>
                        <fmt:message key="setup.ldap.server.alias_dereference" />:
                    </td>
                    <td class="jive-advancedDesc jive-advancedBorderBottom jive-advancedBorderRight">
                        <fmt:message key="setup.ldap.server.alias_dereference_help" />
                    </td>
                    <td class="jive-advancedBorderBottom jive-advancedBorderRight" align="center">
                        <input type="radio" name="aliasreferrals" value="true" <% if (aliasReferralsEnabled) { %>checked <% } %>>
                    </td>
                    <td class="jive-advancedBorderBottom" align="center">
                        <input type="radio" name="aliasreferrals" value="false" <% if (!aliasReferralsEnabled) { %>checked <% } %>>
                    </td>
                </tr>
                </tbody>
Gaston Dombiak's avatar
Gaston Dombiak committed
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
				</table>
			</div>
		</div>
		<!-- END jiveAdvancedPanelcs (advanced connection settings) -->


		<!-- BEGIN jive-buttons -->
		<div class="jive-buttons">

			<!-- BEGIN right-aligned buttons -->
			<div align="right">

                <input type="Submit" name="test" value="<fmt:message key="setup.ldap.test" />" id="jive-setup-test" border="0">

                <input type="Submit" name="save" value="<fmt:message key="setup.ldap.continue" />" id="jive-setup-save" border="0">
			</div>
			<!-- END right-aligned buttons -->

		</div>
		<!-- END jive-buttons -->

	</form>

	</div>
	<!-- END jive-contentBox -->



</body>
</html>