<%-- - - Copyright (C) 2006-2007 Jive Software, 2017-2022 Ignite Realtime Foundation. All rights reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. --%> <%@ page contentType="text/html; charset=UTF-8" %> <%@ page import="org.jivesoftware.admin.LdapUserProfile" %> <%@ page import="org.jivesoftware.admin.LdapUserTester" %> <%@ page import="org.jivesoftware.util.LocaleUtils" %> <%@ page import="org.jivesoftware.util.Log" %> <%@ page import="org.jivesoftware.util.ParamUtils" %> <%@ page import="org.jivesoftware.openfire.ldap.LdapManager" %> <%@ page import="java.util.ArrayList" %> <%@ page import="java.util.List" %> <%@ page import="java.util.Map" %> <%@ page import="org.slf4j.LoggerFactory" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> <%@ taglib uri="admin" prefix="admin" %> <% String errorDetail = null; Map attributes = null; Map settings = (Map) session.getAttribute("ldapSettings"); Map userSettings = (Map) session.getAttribute("ldapUserSettings"); LdapUserProfile vCardSettings = (LdapUserProfile) session.getAttribute("ldapVCardBean"); int userIndex = ParamUtils.getIntParameter(request, "userIndex", -1); if (settings != null && userSettings != null && vCardSettings != null) { settings.computeIfAbsent( "ldap.adminPassword", (key) -> LdapManager.getInstance().getAdminPassword() ); LdapManager manager = new LdapManager(settings); manager.setUsernameField(userSettings.get("ldap.usernameField")); manager.setSearchFilter(userSettings.get("ldap.searchFilter")); // Build the tester with the recreated LdapManager and vcard mapping information LdapUserTester tester = new LdapUserTester(manager, vCardSettings); List usernames = new ArrayList<>(); try { usernames = tester.getSample(40); } catch (Exception e) { // Inform user that an error occurred while trying to get users data errorDetail = LocaleUtils.getLocalizedString("setup.ldap.test.error-loading-sample"); LoggerFactory.getLogger("setup-ldap-user_user.jsp").error("Error occurred while trying to get a sample of user data from LDAP.", e); } if (usernames.isEmpty()) { // Inform user that no users were found errorDetail = LocaleUtils.getLocalizedString("setup.ldap.user.test.users-not-found"); } else { // Pick a user from the sample list of users userIndex = userIndex + 1; if (usernames.size() <= userIndex) { userIndex = 0; } // Get attributes for selected user final String username = usernames.get( userIndex ); attributes = tester.getAttributes( username ); if ( attributes == null || attributes.isEmpty() ) { errorDetail = "Unable to get attributes for: " + username; } else { // Postprocessing - remove all values that include the '{' character. for ( final Map.Entry entry : attributes.entrySet() ) { if ( entry.getValue().contains( "{" ) ){ entry.setValue( null ); } } } } } else { // Information was not found in the HTTP Session. Internal error? errorDetail = LocaleUtils.getLocalizedString("setup.invalid_session"); } pageContext.setAttribute( "attributes", attributes ); pageContext.setAttribute( "errorDetail", errorDetail ); pageContext.setAttribute( "currentPage", ParamUtils.getParameter(request, "currentPage") ); pageContext.setAttribute( "serverType", ParamUtils.getParameter(request, "serverType") ); pageContext.setAttribute( "userIndex", userIndex ); %>

:

:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
: