setup-admin-settings_test.jsp 7.94 KB
Newer Older
Gaston Dombiak's avatar
Gaston Dombiak committed
1
<%@ page import="org.jivesoftware.util.LocaleUtils" %>
2
<%@ page import="org.jivesoftware.util.ParamUtils, org.jivesoftware.openfire.ldap.LdapManager, org.jivesoftware.openfire.user.UserNotFoundException, org.xmpp.packet.JID" %>
Gaston Dombiak's avatar
Gaston Dombiak committed
3 4
<%@ page import="java.net.URLEncoder" %>
<%@ page import="java.util.Map" %>
5
<%@ page import="org.jivesoftware.openfire.clearspace.ClearspaceManager" %>
Gaston Dombiak's avatar
Gaston Dombiak committed
6 7 8 9 10 11 12

<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>

<%
    String username = ParamUtils.getParameter(request, "username");
    String password = ParamUtils.getParameter(request, "password");
13 14
    boolean ldap = "true".equals(request.getParameter("ldap"));
    boolean clearspace = "true".equals(request.getParameter("clearspace"));
Gaston Dombiak's avatar
Gaston Dombiak committed
15

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
    if (ldap) {
        boolean success = false;
        String errorDetail = "";
        Map<String, String> settings = (Map<String, String>) session.getAttribute("ldapSettings");
        Map<String, String> userSettings =
                (Map<String, String>) session.getAttribute("ldapUserSettings");
        // Run the test if password was provided and we have the ldap information
        if (settings != null && password != null) {
            LdapManager manager = new LdapManager(settings);
            manager.setUsernameField(userSettings.get("ldap.usernameField"));
            manager.setSearchFilter(userSettings.get("ldap.searchFilter"));
            try {
                String userDN = manager.findUserDN(JID.unescapeNode(username));
                // See if the user authenticates.
                if (manager.checkAuthentication(userDN, password)) {
                    // User was able to authenticate with provided password
                    success = true;
                }
                else {
                    errorDetail = LocaleUtils.getLocalizedString("setup.admin.settings.test.error-password");
                }
Gaston Dombiak's avatar
Gaston Dombiak committed
37
            }
38 39 40 41 42 43
            catch (UserNotFoundException e) {
                errorDetail = LocaleUtils.getLocalizedString("setup.admin.settings.test.error-user");
            }
            catch (Exception e) {
                errorDetail = e.getMessage();
                e.printStackTrace();
Gaston Dombiak's avatar
Gaston Dombiak committed
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
            }
        }
%>
    <!-- BEGIN connection settings test panel -->
	<div class="jive-testPanel">
		<div class="jive-testPanel-content">

			<div align="right" class="jive-testPanel-close">
				<a href="#" class="lbAction" rel="deactivate"><fmt:message key="setup.ldap.server.test.close" /></a>
			</div>

            <h2><fmt:message key="global.test" />: <span><fmt:message key="setup.admin.settings.test.title-desc" /></span></h2>
            <% if (password != null) { %>
                <% if (success) { %>
                <h4 class="jive-testSuccess"><fmt:message key="setup.admin.settings.test.status-success" /></h4>

		    	<p><fmt:message key="setup.admin.settings.test.status-success.detail" /></p>
                <% } else { %>
                <h4 class="jive-testError"><fmt:message key="setup.admin.settings.test.status-error" /></h4>
                <p><%= errorDetail %></p>
                <% }
                }
                if (!success) {
             %>
            <form action="setup-admin-settings.jsp" name="testform" method="post">
                <input type="hidden" name="ldap" value="true">
                <input type="hidden" name="test" value="true">
                <input type="hidden" name="username" value="<%= URLEncoder.encode(username, "UTF-8")%>">
                <table cellpadding="3" cellspacing="2" border="0">
                    <tr valign="top">
                        <td class="jive-label">
                            <fmt:message key="setup.admin.settings.administrator" />:
                        </td>
                         <td>
                        <%= JID.unescapeNode(username) %>
                        </td>
                        <td>
                            &nbsp;
                        </td>
                    </tr>
                    <tr valign="top">
                        <td class="jive-label">
                            <fmt:message key="setup.ldap.server.password" />:
                        </td>
                         <td>
                        <input type="password" name="password" size="20" maxlength="50"/>
                        </td>
                        <td>
                            <input type="submit" name="addAdministrator" value="<fmt:message key="global.test" />"/>
                        </td>
                    </tr>
                </table>
            </form>
            <% } %>
        </div>
	</div>
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 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
	<!-- END connection settings test panel -->
<%  } else if (clearspace) {
    boolean success = false;
    String errorDetail = "";
    Map<String, String> settings = (Map<String, String>) session.getAttribute("clearspaceSettings");
    // Run the test if password was provided and we have the clearspace information
    if (settings != null && password != null) {
        ClearspaceManager manager = new ClearspaceManager(settings);
        try {
            // See if the user authenticates.
            if (manager.checkAuthentication(username, password)) {
                // User was able to authenticate with provided password
                success = true;
            }
            else {
                errorDetail = LocaleUtils.getLocalizedString("setup.admin.settings.test.error-password");
            }
        }
//        catch (UserNotFoundException e) {
//            errorDetail = LocaleUtils.getLocalizedString("setup.admin.settings.test.error-user");
//        }
        catch (Exception e) {
            errorDetail = e.getMessage();
            e.printStackTrace();
        }
    }
%>
<!-- BEGIN connection settings test panel -->
<div class="jive-testPanel">
    <div class="jive-testPanel-content">

        <div align="right" class="jive-testPanel-close">
            <a href="#" class="lbAction" rel="deactivate"><fmt:message key="setup.clearspace.service.test.close" /></a>
        </div>

        <h2><fmt:message key="global.test" />: <span><fmt:message key="setup.admin.settings.test.title-desc" /></span></h2>
        <% if (password != null) { %>
            <% if (success) { %>
            <h4 class="jive-testSuccess"><fmt:message key="setup.admin.settings.test.status-success" /></h4>

            <p><fmt:message key="setup.admin.settings.test.status-success.detail" /></p>
            <% } else { %>
            <h4 class="jive-testError"><fmt:message key="setup.admin.settings.test.status-error" /></h4>
            <p><%= errorDetail %></p>
            <% }
            }
            if (!success) {
         %>
        <form action="setup-admin-settings.jsp" name="testform" method="post">
            <input type="hidden" name="clearspace" value="true">
            <input type="hidden" name="test" value="true">
            <input type="hidden" name="username" value="<%= URLEncoder.encode(username, "UTF-8")%>">
            <table cellpadding="3" cellspacing="2" border="0">
                <tr valign="top">
                    <td class="jive-label">
                        <fmt:message key="setup.admin.settings.administrator" />:
                    </td>
                     <td>
                    <%= JID.unescapeNode(username) %>
                    </td>
                    <td>
                        &nbsp;
                    </td>
                </tr>
                <tr valign="top">
                    <td class="jive-label">
                        <fmt:message key="setup.clearspace.service.password" />:
                    </td>
                     <td>
                    <input type="password" name="password" size="20" maxlength="50"/>
                    </td>
                    <td>
                        <input type="submit" name="addAdministrator" value="<fmt:message key="global.test" />"/>
                    </td>
                </tr>
            </table>
        </form>
        <% } %>
    </div>
</div>
<!-- END connection settings test panel -->
<%  } %>