clearspace-integration.jspf 20.2 KB
Newer Older
1 2 3 4 5
<%@ page import="org.jivesoftware.util.LocaleUtils"%>
<%@ page import="org.jivesoftware.util.ParamUtils"%>
<%@ page import="java.util.*" %>
<%@ page import="org.jivesoftware.openfire.clearspace.ClearspaceManager" %>
<%@ page import="org.jivesoftware.util.JiveGlobals" %>
6
<%@ page import="org.jivesoftware.util.StringUtils" %>
7 8 9 10

<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
<%
11
    String uri;
12
    String sharedSecret;
13 14
    String existingHashSharedSecret = "";
    String plainSharedSecret = null;
15

16 17 18 19 20 21 22
    boolean verifyChain = JiveGlobals.getBooleanProperty("clearspace.certificate.verify.chain", true);
    boolean verifyRoot = JiveGlobals.getBooleanProperty("clearspace.certificate.verify.root", true);
    boolean selfSigned = JiveGlobals.getBooleanProperty("clearspace.certificate.accept-selfsigned", false);
    boolean verifyIdentity = JiveGlobals.getBooleanProperty("clearspace.certificate.verify.identity", false);
    boolean verifyValidity = JiveGlobals.getBooleanProperty("clearspace.certificate.verify.validity", true);


23 24 25
    // Get parameters
    boolean save = request.getParameter("save") != null;
    boolean test = request.getParameter("test") != null;
26 27
    @SuppressWarnings("unchecked")
    Map<String,String> xmppSettings = (Map<String,String>)session.getAttribute("xmppSettings");
28

29
    ClearspaceManager manager;
30 31 32 33 34 35 36
    if (ClearspaceManager.getInstance() != null) {
        // Use the existing manager. This will be the case after setup was completed
        manager = ClearspaceManager.getInstance();
    }
    else {
        manager = new ClearspaceManager();
    }
37 38
    Map<String, String> errors = new HashMap<String, String>();

39 40 41 42 43 44 45
    // If we came from a prelogin error, show it and remove it from the session
    String preloginError = (String) session.getAttribute("prelogin.setup.error");
    if (preloginError != null) {
        errors.put("prelogin", LocaleUtils.getLocalizedString(preloginError));
        session.removeAttribute("prelogin.setup.error");
    }

46
    if (save || test) {
47 48 49
        uri = ParamUtils.getParameter(request, "uri");
        if (uri == null) {
            errors.put("uri", LocaleUtils.getLocalizedString("setup.clearspace.service.uri_error"));
50
        }
51
        // this could be the new entered plain shared secret or the current hashed shared secret
52
        sharedSecret = ParamUtils.getParameter(request, "sharedSecret");
53 54 55

        // this will store new entered plain shared secret or the current plain shared secret
        //String plainSharedSecret = null;
56 57
        if (sharedSecret == null || sharedSecret.length() == 0) {
            errors.put("secret", LocaleUtils.getLocalizedString("setup.clearspace.service.secret_error"));
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
        } else {
            // set to the current plain shared secret
            plainSharedSecret = manager.getSharedSecret();

            // Hash the current shared secret
            if (plainSharedSecret != null) {
                existingHashSharedSecret = StringUtils.hash(plainSharedSecret);
            }
            // Check if the new shared secret was changed. If it wasn't changed, then it is the original hashed shared secret
            // NOTE: if the new PLAIN password equals the previous HASHED password this fails, but is unlikely.
            if (!existingHashSharedSecret.equals(sharedSecret)) {
                // Hash the new shared secret since it was changed
                String newHashSharedSecret = "";
                if (sharedSecret != null) {
                        newHashSharedSecret = StringUtils.hash(sharedSecret);
                }

                // Change password if their hash values are different
                if (!existingHashSharedSecret.equals(newHashSharedSecret)) {
                    plainSharedSecret = sharedSecret;
                }
            }
80
        }
81

82 83 84 85 86 87
        verifyChain = ParamUtils.getBooleanParameter(request, "verifyChain", verifyChain);
        verifyRoot = ParamUtils.getBooleanParameter(request, "verifyRoot", verifyRoot);
        selfSigned = ParamUtils.getBooleanParameter(request, "selfSigned", selfSigned);
        verifyIdentity = ParamUtils.getBooleanParameter(request, "verifyIdentity", verifyIdentity);
        verifyValidity = ParamUtils.getBooleanParameter(request, "verifyValidity", verifyValidity);

88 89
        Map<String, String> settings = new HashMap<String, String>();
        // If there are no errors check if there is a need to run a force test
90 91
        if (errors.isEmpty()) {
            // Store settings in a map and keep it in the session
92
            settings.put("clearspace.uri", uri);
93 94 95 96

            // Sets the current shared secret, it will be changed if the new shared secret is different
            settings.put("clearspace.sharedSecret", plainSharedSecret);

97 98 99 100 101
            settings.put("clearspace.certificate.verify.chain", Boolean.toString(verifyChain));
            settings.put("clearspace.certificate.verify.root", Boolean.toString(verifyRoot));
            settings.put("clearspace.certificate.accept-selfsigned", Boolean.toString(selfSigned));
            settings.put("clearspace.certificate.verify.identity", Boolean.toString(verifyIdentity));
            settings.put("clearspace.certificate.verify.validity", Boolean.toString(verifyValidity));
102 103 104 105 106 107 108 109 110 111 112 113

            if (save && forceTest) {
                ClearspaceManager managerTest = new ClearspaceManager(settings);
                if (managerTest.testConnection() != null) {
                    // if there is any problems don't save it
                    // add an error (this is the reason of why this check is in another "if errors.isEmpty()"
                    errors.put("connection", LocaleUtils.getLocalizedString("setup.clearspace.service.connection_error"));
                }
            }
        }

        if (errors.isEmpty()) {
114 115 116
            session.setAttribute("clearspaceSettings", settings);

            if (save) {
117

118
                // Save settings and redirect
119
                manager.setConnectionURI(uri);
120
                manager.setSharedSecret(plainSharedSecret);
121

122 123
                // Enable the Clearspace auth, user, group, vcard, lockout, security audit, and admin providers.
                JiveGlobals.setProperty("provider.auth.className",
124
                        "org.jivesoftware.openfire.clearspace.ClearspaceAuthProvider");
125 126 127
                JiveGlobals.setProperty("provider.user.className",
                        "org.jivesoftware.openfire.clearspace.ClearspaceUserProvider");
                JiveGlobals.setProperty("provider.group.className",
128
                        "org.jivesoftware.openfire.clearspace.ClearspaceGroupProvider");
129
                JiveGlobals.setProperty("provider.vcard.className",
130
                        "org.jivesoftware.openfire.clearspace.ClearspaceVCardProvider");
131
                JiveGlobals.setProperty("provider.lockout.className",
132
                        "org.jivesoftware.openfire.clearspace.ClearspaceLockOutProvider");
133
                JiveGlobals.setProperty("provider.securityAudit.className",
134
                        "org.jivesoftware.openfire.clearspace.ClearspaceSecurityAuditProvider");
135
                JiveGlobals.setProperty("provider.admin.className",
136
                        "org.jivesoftware.openfire.clearspace.ClearspaceAdminProvider");
137

138 139 140 141 142 143 144
                // Set configuration for certificate validation
                JiveGlobals.setProperty("clearspace.certificate.verify.chain", Boolean.toString(verifyChain));
                JiveGlobals.setProperty("clearspace.certificate.verify.root", Boolean.toString(verifyRoot));
                JiveGlobals.setProperty("clearspace.certificate.accept-selfsigned", Boolean.toString(selfSigned));
                JiveGlobals.setProperty("clearspace.certificate.verify.identity", Boolean.toString(verifyIdentity));
                JiveGlobals.setProperty("clearspace.certificate.verify.validity", Boolean.toString(verifyValidity));

145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
                // Save the settings for later, if we're in setup
                if (xmppSettings != null) {
                    xmppSettings.put("provider.auth.className",
                            "org.jivesoftware.openfire.clearspace.ClearspaceAuthProvider");
                    xmppSettings.put("provider.user.className",
                            "org.jivesoftware.openfire.clearspace.ClearspaceUserProvider");
                    xmppSettings.put("provider.group.className",
                            "org.jivesoftware.openfire.clearspace.ClearspaceGroupProvider");
                    xmppSettings.put("provider.vcard.className",
                            "org.jivesoftware.openfire.clearspace.ClearspaceVCardProvider");
                    xmppSettings.put("provider.lockout.className",
                            "org.jivesoftware.openfire.clearspace.ClearspaceLockOutProvider");
                    xmppSettings.put("provider.securityAudit.className",
                            "org.jivesoftware.openfire.clearspace.ClearspaceSecurityAuditProvider");
                    xmppSettings.put("provider.admin.className",
                            "org.jivesoftware.openfire.clearspace.ClearspaceAdminProvider");
                    xmppSettings.put("clearspace.uri", uri);
162
                    xmppSettings.put("clearspace.sharedSecret", plainSharedSecret);
163 164 165 166 167
                    xmppSettings.put("clearspace.certificate.verify.chain", Boolean.toString(verifyChain));
                    xmppSettings.put("clearspace.certificate.verify.root", Boolean.toString(verifyRoot));
                    xmppSettings.put("clearspace.certificate.accept-selfsigned", Boolean.toString(selfSigned));
                    xmppSettings.put("clearspace.certificate.verify.identity", Boolean.toString(verifyIdentity));
                    xmppSettings.put("clearspace.certificate.verify.validity", Boolean.toString(verifyValidity));
168 169 170 171

                    JiveGlobals.setPropertyEncrypted("clearspace.uri", true);
                    JiveGlobals.setPropertyEncrypted("clearspace.sharedSecret", true);

172 173
                    session.setAttribute("xmppSettings", xmppSettings);
                }
174 175 176 177
                if (initialSetup) {
                    // Set that the setup has been completed
                    JiveGlobals.setXMLProperty("setup","true");
                }
178 179 180 181 182 183 184
                // Redirect to next step.
                response.sendRedirect(nextPage);
                return;
            }
        }
    } else {
        // See if there are already values for the variables defined.
185
        uri = manager.getConnectionURI();
186
        sharedSecret = manager.getSharedSecret() == null || manager.getSharedSecret().trim().length() == 0 ? "" : StringUtils.hash(manager.getSharedSecret());
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
    }
%>
<html>
<head>
    <title><fmt:message key="setup.clearspace.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.clearspace.profile" />: <span><fmt:message key="setup.clearspace.service.integration" /></span></h1>
    <% } %>

    <div id="jive-contentBox_stepbar">
        <span class="jive-stepbar_step"><strong><fmt:message key="setup.clearspace.service.connection_settings" /></strong></span>
    </div>

    <div class="jive-contentBox jive-contentBox_for-stepbar">
    <h2><span><fmt:message key="setup.clearspace.service.connection_settings" /></span></h2>

    <p><fmt:message key="setup.clearspace.service.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" width="100%">
			<tr>
			    <td colspan="4"><strong><fmt:message key="setup.clearspace.service" /></strong></td>
			</tr>
            <tr>
241
			    <td align="right" width="1%" nowrap="nowrap"><fmt:message key="setup.clearspace.service.uri" />:</td>
242 243 244 245
                <td width="1%">
                    <table cellpadding="0" cellspacing="0" border="0" width="100%">
                    <tr>
                        <td width="1%" nowrap="nowrap">
246
                            <input type="text" name="uri" id="jiveCLEARSPACEuri" size="40" maxlength="255" value="<%= uri!=null?uri:"" %>">
247 248
                        </td>
                        <td width="99%">
249
                            <span class="jive-setup-helpicon" onmouseover="domTT_activate(this, event, 'content', '<fmt:message key="setup.clearspace.service.uri_help" />', 'styleClass', 'jiveTooltip', 'trail', true, 'delay', 300, 'lifetime', 8000);"></span>
250 251 252 253 254 255
                        </td>
                    </tr>
                    </table>
                </td>
			</tr>
			<tr>
256
                <td align="right" width="1%" nowrap="nowrap"><fmt:message key="setup.clearspace.service.secret" /> <%=plainSharedSecret%>:</td>
257 258 259 260
                <td colspan="3">
                    <table cellpadding="0" cellspacing="0" border="0" width="100%">
                    <tr>
                        <td width="1%" nowrap="nowrap">
261
                            <input type="password" name="sharedSecret" id="jiveCLEARSPACEsecret" size="22" maxlength="35" value="<%= (sharedSecret != null) ? sharedSecret : "" %>">
262 263 264 265 266 267 268 269 270
                        </td>
                        <td width="99%">
                            <span class="jive-setup-helpicon" onmouseover="domTT_activate(this, event, 'content', '<fmt:message key="setup.clearspace.service.secret_help" />', 'styleClass', 'jiveTooltip', 'trail', true, 'delay', 300, 'lifetime', -1);"></span>
                        </td>
                    </tr>
                    </table>
                </td>
			</tr>
			</table>
271
        </div>
272 273
		<!-- END jive-contentBox_bluebox -->

274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 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 368
        <!-- BEGIN jiveAdvancedButton -->
        <div class="jiveAdvancedButton">
            <a href="#" onclick="togglePanel(jiveAdvanced); return false;" id="jiveAdvancedLink"><fmt:message key="setup.clearspace.service.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.clearspace.service.certificate.verify.chain" />:
                    </td>
                    <td class="jive-advancedDesc jive-advancedBorderBottom jive-advancedBorderRight">
                        <fmt:message key="setup.clearspace.service.certificate.verify.chain_help" />
                    </td>
                    <td class="jive-advancedBorderBottom jive-advancedBorderRight" align="center">
                        <input type="radio" name="verifyChain" value="true" <% if (verifyChain) { %>checked <% } %>>
                    </td>
                    <td class="jive-advancedBorderBottom" align="center">
                        <input type="radio" name="verifyChain" value="false" <% if (!verifyChain) { %>checked <% } %>>
                    </td>
                </tr>
                <tr>
                    <td class="jive-advancedLabel" nowrap>
                        <fmt:message key="setup.clearspace.service.certificate.verify.root" />:
                    </td>
                    <td class="jive-advancedDesc jive-advancedBorderBottom jive-advancedBorderRight">
                        <fmt:message key="setup.clearspace.service.certificate.verify.root_help" />
                    </td>
                    <td class="jive-advancedBorderBottom jive-advancedBorderRight" align="center">
                        <input type="radio" name="verifyRoot" value="true" <% if (verifyRoot) { %>checked <% } %>>
                    </td>
                    <td class="jive-advancedBorderBottom" align="center">
                        <input type="radio" name="verifyRoot" value="false" <% if (!verifyRoot) { %>checked <% } %>>
                    </td>
                </tr>
                <tr>
                    <td class="jive-advancedLabel" nowrap>
                        <fmt:message key="setup.clearspace.service.certificate.accept-selfsigned" />:
                    </td>
                    <td class="jive-advancedDesc jive-advancedBorderBottom jive-advancedBorderRight">
                        <fmt:message key="setup.clearspace.service.certificate.accept-selfsigned_help" />
                    </td>
                    <td class="jive-advancedBorderBottom jive-advancedBorderRight" align="center">
                        <input type="radio" name="selfSigned" value="true" <% if (selfSigned) { %>checked <% } %>>
                    </td>
                    <td class="jive-advancedBorderBottom" align="center">
                        <input type="radio" name="selfSigned" value="false" <% if (!selfSigned) { %>checked <% } %>>
                    </td>
                </tr>
                <tr>
                    <td class="jive-advancedLabel" nowrap>
                        <fmt:message key="setup.clearspace.service.certificate.verify.identity" />:
                    </td>
                    <td class="jive-advancedDesc jive-advancedBorderBottom jive-advancedBorderRight">
                        <fmt:message key="setup.clearspace.service.certificate.verify.identity_help" />
                    </td>
                    <td class="jive-advancedBorderBottom jive-advancedBorderRight" align="center">
                        <input type="radio" name="verifyIdentity" value="true" <% if (verifyIdentity) { %>checked <% } %>>
                    </td>
                    <td class="jive-advancedBorderBottom" align="center">
                        <input type="radio" name="verifyIdentity" value="false" <% if (!verifyIdentity) { %>checked <% } %>>
                    </td>
                </tr>
                <tr>
                    <td class="jive-advancedLabel" nowrap>
                        <fmt:message key="setup.clearspace.service.certificate.verify.validity" />:
                    </td>
                    <td class="jive-advancedDesc jive-advancedBorderBottom jive-advancedBorderRight">
                        <fmt:message key="setup.clearspace.service.certificate.verify.validity_help" />
                    </td>
                    <td class="jive-advancedBorderBottom jive-advancedBorderRight" align="center">
                        <input type="radio" name="verifyValidity" value="true" <% if (verifyValidity) { %>checked <% } %>>
                    </td>
                    <td class="jive-advancedBorderBottom" align="center">
                        <input type="radio" name="verifyValidity" value="false" <% if (!verifyValidity) { %>checked <% } %>>
                    </td>
                </tr>
                </tbody>
                </table>
            </div>
        </div>
        <!-- END jiveAdvancedPanelcs (advanced connection settings) -->

369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
        <!-- BEGIN jive-buttons -->
		<div class="jive-buttons">

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

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

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

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

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

</body>
</html>