setup-ldap-group_test.jsp 4.13 KB
Newer Older
1 2 3
<%@ page import="org.jivesoftware.admin.LdapGroupTester" %>
<%@ page import="org.jivesoftware.util.LocaleUtils" %>
<%@ page import="org.jivesoftware.util.Log" %>
4
<%@ page import="org.jivesoftware.openfire.ldap.LdapManager" %>
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Collection" %>
<%@ 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" %>

<%
    String errorDetail = null;
    Collection<LdapGroupTester.Group> groups = new ArrayList<LdapGroupTester.Group>();

    Map<String, String> settings = (Map<String, String>) session.getAttribute("ldapSettings");
    Map<String, String> userSettings = (Map<String, String>) session.getAttribute("ldapUserSettings");
    Map<String, String> groupSettings = (Map<String, String>) session.getAttribute("ldapGroupSettings");
    if (settings != null && userSettings != null && groupSettings != null) {
        LdapManager manager = new LdapManager(settings);
        manager.setUsernameField(userSettings.get("ldap.usernameField"));
        manager.setSearchFilter(userSettings.get("ldap.searchFilter"));
        manager.setGroupNameField(groupSettings.get("ldap.groupNameField"));
        manager.setGroupDescriptionField(groupSettings.get("ldap.groupDescriptionField"));
        manager.setGroupMemberField(groupSettings.get("ldap.groupMemberField"));
        manager.setGroupSearchFilter(groupSettings.get("ldap.groupSearchFilter"));

        // Build the tester with the recreated LdapManager and vcard mapping information
        LdapGroupTester tester = new LdapGroupTester(manager);
        try {
            groups = tester.getGroups(10);
        }
        catch (Exception e) {
            // Inform user that an error occurred while trying to get users data
            errorDetail = LocaleUtils.getLocalizedString("setup.ldap.test.error-loading-sample");
            Log.error("Error occurred while trying to get users data from LDAP", e);
        }
        if (groups.isEmpty()) {
            // Inform user that no users were found
            errorDetail = LocaleUtils.getLocalizedString("setup.ldap.group.test.group-not-found");
        }
    } else {
        // Information was not found in the HTTP Session. Internal error?
        errorDetail = LocaleUtils.getLocalizedString("setup.ldap.test.internal-server-error");
    }
%>

48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
<html>
<head>
<meta name="decorator" content="none"/>
</head>
<body>


<!-- 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">Close</a>
		</div>


64
		<h2><fmt:message key="setup.ldap.server.test.title" />: <span><fmt:message key="setup.ldap.group_mapping" /></span></h2>
65

66
        <p><fmt:message key="setup.ldap.group.test.description" /></p>
67

68
        <% if (errorDetail == null) { %>
69

70 71 72 73
        <table border="0" cellpadding="0" cellspacing="1" class="jive-testTable-vcard" style="margin-right: 5px;">
            <tr>
                <td width="19%" class="jive-testpanel-vcard-header"><fmt:message key="group.summary.page_name" /></td>
                <td width="80%" class="jive-testpanel-vcard-header"><fmt:message key="setup.ldap.group.test.label-description" /></td>
74
                <td width="1%" class="jive-testpanel-vcard-header"><fmt:message key="setup.ldap.group.test.label-members" /></td>
75 76 77 78 79
            </tr>
            <% for (LdapGroupTester.Group group : groups) { %>
            <tr>
                <td valign="top" class="jive-testpanel-vcard-value"><%= group.getName()%></td>
                <td valign="top" class="jive-testpanel-vcard-value"><%= group.getDescription()%></td>
80
                <td valign="top" class="jive-testpanel-vcard-value"><%= group.getMembers()%></td>
81 82 83 84 85 86 87 88
            </tr>
            <% } %>
        </table>
        <% } else { %>
        <h4 class="jive-testError"><fmt:message key="setup.ldap.server.test.status-error" /></h4>
        <p><%= errorDetail %></p>
        <% }%>
    </div>
89 90 91 92 93
</div>


</body>
</html>