DirectoryServerVendor.java revision a82d04bc19fee9d5e34b41ccd7641da1f62ab634
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2008 Sun Microsystems Inc. All Rights Reserved
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The contents of this file are subject to the terms
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * of the Common Development and Distribution License
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (the License). You may not use this file except in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * compliance with the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * You can obtain a copy of the License at
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * permission and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Header Notice in each file and include the License file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * If applicable, add the following below the CDDL Header,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * with the fields enclosed by brackets [] replaced by
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * your own identifying information:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * $Id: DirectoryServerVendor.java,v 1.3 2009/01/28 05:35:03 ww203982 Exp $
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington * Portions Copyrighted 2010-2015 ForgeRock AS.
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport org.forgerock.opendj.ldap.ByteString;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport org.forgerock.opendj.ldap.Connection;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport org.forgerock.opendj.ldap.SearchResultReferenceIOException;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport org.forgerock.opendj.ldap.SearchScope;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport org.forgerock.opendj.ldap.responses.SearchResultEntry;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport org.forgerock.opendj.ldif.ConnectionEntryReader;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This singleton attempts to query vendor information of a Directory Server.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String VENDOR_OPENDJ = "OpenDJ ";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String VENDOR_OPENDS = "OpenDS Directory Server ";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String VENDOR_SUNDS_5 = "Sun-ONE-Directory/";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String VENDOR_SUNDS_6 = "Sun-Java(tm)-System-Directory/";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String VENDOR_SUNDS_7 = "Sun-Directory-Server/";
4709b991352c6de69ba02928ed6cbf373ca62ed5jeff.schenk private static String VENDOR_ODSEE_11 = "Oracle Directory Server Enterprise Edition";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static DirectoryServerVendor instance = new DirectoryServerVendor();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "vendorversion", "rootDomainNamingContext", "forestFunctionality"};
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private Vendor unknownVendor = new Vendor("unknown", "unknown");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns an instance of this class.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return an instance of this class.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static DirectoryServerVendor getInstance() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the vendor of Directory Server.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param conn LDAP connection to the server.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the vendor of Directory Server.
ce4d3fddc8fe2eddd68a20af9570b3cc63ece5abNeil Madden * @throws LdapException if unable to get the vendor information.
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington * @throws SearchResultReferenceIOException if unable to get the vendor information
ce4d3fddc8fe2eddd68a20af9570b3cc63ece5abNeil Madden public Vendor query(Connection conn) throws LdapException, SearchResultReferenceIOException {
a82d04bc19fee9d5e34b41ccd7641da1f62ab634Neil Madden ConnectionEntryReader res = conn.search(LDAPRequests.newSearchRequest("", SearchScope.BASE_OBJECT,
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington SearchResultEntry findEntry = res.readEntry();
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington /* Get the attributes of the root DSE. */
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington for (Attribute attribute : findEntry.getAllAttributes()) {
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington String attrName = attribute.getAttributeDescriptionAsString();
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington if ("vendorversion".equalsIgnoreCase(attrName)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String version = result.substring(VENDOR_OPENDJ.length());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String version = result.substring(VENDOR_OPENDS.length());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (result.startsWith(VENDOR_SUNDS_5)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String version = result.substring(VENDOR_SUNDS_5.length());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (result.startsWith(VENDOR_SUNDS_6)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String version = result.substring(VENDOR_SUNDS_6.length());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (result.startsWith(VENDOR_SUNDS_7)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String version = result.substring(VENDOR_SUNDS_7.length());
4709b991352c6de69ba02928ed6cbf373ca62ed5jeff.schenk } else if (result.startsWith(VENDOR_ODSEE_11)) {
4709b991352c6de69ba02928ed6cbf373ca62ed5jeff.schenk String version = result.substring(VENDOR_ODSEE_11.length());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public class Vendor {