setup-ldap-server_test.jsp 3.18 KB
Newer Older
1
<%@ page import="org.jivesoftware.util.LocaleUtils" %>
2
<%@ page import="org.jivesoftware.openfire.ldap.LdapManager, javax.naming.*, javax.naming.ldap.LdapContext, java.net.UnknownHostException" %>
3 4 5 6 7
<%@ page import="java.util.Map" %>

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

8 9 10 11 12 13
<%
    boolean success = false;
    String errorDetail = "";
    Map<String, String> settings = (Map<String, String>) session.getAttribute("ldapSettings");
    if (settings != null) {
        LdapManager manager = new LdapManager(settings);
Matt Tucker's avatar
Matt Tucker committed
14
        LdapContext context = null;
15
        try {
Matt Tucker's avatar
Matt Tucker committed
16 17 18
            context = manager.getContext();
            NamingEnumeration list = context.list("");
            list.close();
19 20 21 22 23
            // We were able to successfully connect to the LDAP server
            success = true;
        }
        catch (NamingException e) {
            if (e instanceof AuthenticationException) {
24
                errorDetail = LocaleUtils.getLocalizedString("setup.ldap.server.test.error-auth");
25 26
            }
            else if (e instanceof CommunicationException) {
27
                errorDetail = LocaleUtils.getLocalizedString("setup.ldap.server.test.error-connection");
Matt Tucker's avatar
Matt Tucker committed
28 29 30
                Throwable cause = e.getCause();
                if (cause != null) {
                    if (cause instanceof UnknownHostException) {
31
                        errorDetail = LocaleUtils.getLocalizedString("setup.ldap.server.test.error-unknownhost");
Matt Tucker's avatar
Matt Tucker committed
32 33
                    }
                }
34 35
            }
            else if (e instanceof InvalidNameException) {
36
                errorDetail = LocaleUtils.getLocalizedString("setup.ldap.server.test.invalid-name");
Matt Tucker's avatar
Matt Tucker committed
37 38
            }
            else if (e instanceof NameNotFoundException) {
39
                errorDetail = LocaleUtils.getLocalizedString("setup.ldap.server.test.name-not-found");
40 41 42 43 44 45
            }
            else {
                errorDetail = e.getExplanation();
            }
            e.printStackTrace();
        }
Matt Tucker's avatar
Matt Tucker committed
46 47 48 49 50 51 52 53 54
        finally {
            if (context != null) {
                try {
                    context.close();
                }
                catch (Exception e) {
                }
            }
        }
55 56 57
    }
%>
    <!-- BEGIN connection settings test panel -->
58 59 60 61
	<div class="jive-testPanel">
		<div class="jive-testPanel-content">
		
			<div align="right" class="jive-testPanel-close">
62
				<a href="#" class="lbAction" rel="deactivate"><fmt:message key="setup.ldap.server.test.close" /></a>
63 64 65
			</div>
			
			
66
			<h2><fmt:message key="setup.ldap.server.test.title" />: <span><fmt:message key="setup.ldap.server.test.title-desc" /></span></h2>
67
            <% if (success) { %>
68
            <h4 class="jive-testSuccess"><fmt:message key="setup.ldap.server.test.status-success" /></h4>
69

70
			<p><fmt:message key="setup.ldap.server.test.status-success.detail" /></p>
71
            <% } else { %>
72
            <h4 class="jive-testError"><fmt:message key="setup.ldap.server.test.status-error" /></h4>
Matt Tucker's avatar
Matt Tucker committed
73
            <p><%= errorDetail %></p>
74 75 76
            <% } %>
            
        </div>
77 78
	</div>
	<!-- END connection settings test panel -->