CTSDataUtils.java revision 6781df49de38f222bbedc6bcc5340dab857b3865
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2012-2013 ForgeRock Inc. All Rights Reserved
*
* The contents of this file are subject to the terms of the Common Development and
* Distribution License (the License). You may not use this file except in compliance with the
* License.
*
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
* specific language governing permission and limitations under the License.
*
* When distributing Covered Software, include this CDDL Header Notice in each file and include
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information:
*
* "Portions copyright [year] [name of copyright owner]".
*
*/
/**
* Public class to provide Additional Data Utilities for the CTS Directory Store
* Implementation. Such as verification of DIT for CTS storage.
*
* @author jeff.schenk@forgerock.com
*/
class CTSDataUtils {
/**
* Debug Logging
*/
/**
* Define all our DIT entries which need to be verified and potentially
* created for Validation of the CTS Service Component.
* <p/>
* This DIT hierarchy must exist for CTS component to operate
* correctly.
* <p/>
* The Sequence of these should be in DIT order.
*/
private final String[] CONTAINERS_TO_BE_VALIDATED;
/**
* Reference to Internally Shared SM Data Layer.
*/
private final CTSPersistentStore ctsPersistentStore;
/**
* Default Constructor, provide CTSPersistent Store to use this utility.
*
* @param ctsPersistentStore - CTSPersistentStore Instance.
*/
this.ctsPersistentStore = ctsPersistentStore;
}
/**
* Define any necessary LDIF Files which can be used for the upgrade.
*/
private static final String[] UPGRADE_LDIF_SCHEMA_FILENAMES = {
// CTS Version 1 LDAP Schemata
// CTS Version 1 LDAP Indices
};
/**
* Define any Template Files which require Tag Swapping prior to performing
* the LDIF File.
*/
private static final String[] UPGRADE_LDIF_DIT_FILENAMES = {
// CTS Version 1 LDAP Container suffixes
};
/**
* Provides an Indication if the DIT must be upgraded to provide a new
* <p/>
* Performs Validation of our LDAP Connection and
* the existence of our DIT hierarchy which this component requires.
*
* @return boolean - indicates if validation was successful or not.
* @throws StoreException - Exception thrown if Error condition exists.
*/
public boolean isDITValid() throws StoreException {
// Iterate over our Token DIT Structure to Verify.
Map<String, Boolean> validationResultMap = new HashMap<String, Boolean>(CONTAINERS_TO_BE_VALIDATED.length);
}
// Now Iterate over the Validation Result Map to supply information, especially if we have
// detected something missing...
int validatedSuccessfully = 0;
} else {
}
} // End of KeySet for each loop...
// Determine if we are good to go or not....
}
/**
* Provides method to perform the upgrade process of the DIT.
*
* @return
* @throws StoreException
*/
public boolean upgradeDIT() throws StoreException {
// *************************************************
// Obtain our Directory Connection
try {
if (ldapConnection == null) {
DEBUG.error("Unable to obtain a Directory Connection to perform Upgrade of DIT for CTS Persistent Store.");
return false;
}
// *************************************************
// For upgrading DIT from a pre-10.1.0-Xpress State.
// Perform LDIF processing
DEBUG.error("Unable to perform Load of LDIF Schema Filename:[" + AMSetupServlet.getRealPath(ldifFilename) + "]");
} else {
DEBUG.message("Load of LDIF Schema Filename:[" + AMSetupServlet.getRealPath(ldifFilename) + "], was successful.");
}
} // end of for each iteration over LDIF File to be run against our current CTS Backend.
// *************************************************
// For upgrading DIT from a pre-10.1.0-Xpress State.
// Perform LDIF processing for any Files which require Tag Swapping
try {
// Feed our LDIF to Tag Swapped Data as Input to update DIT.
// Right now only one element needs to be Tagged Swapped.
String fileContents = sb.toString().replace("@"+SetupConstants.SM_CONFIG_ROOT_SUFFIX+"@", CTSPersistentStore.getBASE_ROOT_DN());
DataInputStream dataInputStream = new DataInputStream(new ByteArrayInputStream(fileContents.getBytes()));
// Load the LDIF.
} catch (LDAPException ldapException) {
DEBUG.error("Unable to perform processing of LDIF Filename:[" + ldifFilename + "], LDAP Exception: "+
} catch (IOException ioe) {
DEBUG.error("Unable to perform processing of LDIF Filename:[" + ldifFilename + "], "+ioe.getMessage());
}
} // end of for each iteration over LDIF File to be run against our current CTS Backend.
// *************************************************
// Return re-validation check of upgraded DIT.
return isDITValid();
} finally {
if (ldapConnection != null) {
}
}
}
/**
* Loads the LDIF changes to the directory server.
*
* @param ldifFilename the name of the LDIF filename.
* @return boolean - indicator if LDIF File was processed successfully.
*/
private boolean loadLDIF(final LDAPConnection ldapConnection, final String ldifFilename) throws StoreException {
try {
return true;
} catch (IOException ioe) {
} catch (LDAPException le) {
}
// LDIF File was not successfully processed.
return false;
}
/**
* Private Helper method, Does DN Exist?
*
* @param dn - To be Check for Existence.
* @return boolean - indicator, "True" if DN has been Found, otherwise "False".
*/
try {
// Obtain a Connection.
// Perform the Search.
LDAPv2.SCOPE_BASE, CTSPersistentStore.getAnyObjectclassFilter(), CTSPersistentStore.getReturnAttrs_DN_ONLY_ARRAY(), false, new LDAPSearchConstraints());
return false;
}
return true;
} catch (LDAPException ldapException) {
return false;
}
return false;
} finally {
if (ldapConnection != null) {
// Release the Connection.
}
}
}
}