8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2005 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: SMSFlatFileObject.java,v 1.9 2008/06/25 05:44:09 qcheng Exp $
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Portions Copyrighted [2011] [ForgeRock AS]
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.SMSEntry; // for the sunserviceID hack.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.ServiceAlreadyExistsException;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.ServiceNotFoundException;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.common.CaseInsensitiveHashMap;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.common.CaseInsensitiveHashSet;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.common.CaseInsensitiveProperties;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.common.CaseInsensitiveTreeSet;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This class represents a configuration object stored in a file.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Each file lives in a file system under a directory of configuration
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * objects organized in a hierarchy. Each level in the hierarchy
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * is represented by a directory. The naming convention of
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * a configuration object is hierarchy levels separated by a comma,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * for example "ou=serviceName,ou=services,dc=sun,dc=com".
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This object would live in the directory
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <config-dir>/dc=com/dc=sun/ou=services/ou=serviceName
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The directory has a file with the object's attributes in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * java.util.Properties format. The file name is Attributes.properties.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Attributes with multi-values are seperated by a comma.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * A comma within a value is encoded as %2C, and a % within a value
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * is encoded with %25.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic class SMSFlatFileObject extends SMSFlatFileObjectBase {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static final String DEFAULT_NAMEMAP_FILENAME = "NameMap.properties";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static final String DEFAULT_ATTRIBUTE_FILENAME = "Attributes.properties";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Simple class that looks for subentries with name matching the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * filter. Only wildcard '*' character is supported in the filter.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private class FilenameFilter implements FileFilter {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Pattern to match
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Default constructor
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Replace "*" with ".*"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster pattern = Pattern.compile(filter.toLowerCase());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Check for all files
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return (true);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return (pattern.matcher(filename.toLowerCase()).matches());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Loads the name mapper, create it if it doesn't exist.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster StringBuffer nameMapFilename = new StringBuffer(mRootDir);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster nameMapFilename.append(DEFAULT_NAMEMAP_FILENAME);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mNameMapHandle = new File(nameMapFilename.toString());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "SMSFlatFileObject.initialize: cannot read file "+
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mNameMap = loadProperties(mNameMapHandle, null);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String errmsg = "SMSFlatFileObject.initialize: " +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String errmsg = "SMSFlatFileObject.initialize: " +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // create root dn if this is a new directory.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mDebug.message("SMSFlatFileObject.initialize: " +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // not possible
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mDebug.message("SMSFlatFileObject.initialize: " +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // also create ou=services this is a new directory.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster create(null, "ou=services,"+mRootDN, new HashMap());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mDebug.message("SMSFlatFileObject.initialize: " +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "created SMS object for ou=services,"+
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // not possible
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mDebug.message("SMSFlatFileObject.initialize: "+
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns a path to object's attributes file.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Check if the name is present in NameMap.properties
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((attrFile = mNameMap.getProperty(objKey)) != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Check immidiate parent
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((attrFile = mNameMap.getProperty(objKey)) != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String dirName = objName.substring(0, index).trim();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster StringBuilder sb = new StringBuilder(attrFile.length() +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster sb.append(attrFile.substring(0, attrFile.length() -
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Construct the file name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster new StringBuilder(mRootDir.length()+objName.length()+20);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // objName is assumed to be a dn so construct the filepath
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // backwards from the top of directory tree.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (i == j) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String rdn = new String(objchars, i+1, j-i).trim();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // encode file name in case there are characters
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // unsupported in the FS such as '/' or '\' and '*'
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // on windows.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String encodedRdn = FileNameEncoder.encode(rdn);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (i != j) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String encodedLastRdn = FileNameEncoder.encode(lastRdn);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Creates lookup/search files with the given values under the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * given directory.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster StringBuilder sb = new StringBuilder(dirHandle.getPath());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for (Iterator i = sunserviceids.iterator(); i.hasNext(); ) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String errmsg = "SMSFlatFileObject.createLookupIdFiles: " +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster " File, "+ idFile.getPath() + ". Exception: " +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mDebug.error("SMSFlatFileObject.createLookupIdFiles",e);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Real routine to get sub entries, used by subEntries() and
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * schemaSubEntries().
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws ServiceNotFoundException if the configuration object is
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * not found.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws SchemaException if a sub directory name is not in the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * expected "ou=..." format.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mRWLock.readRequest(); // wait indefinitely for the read lock.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Check if object exists.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String filepath = mNameMap.getProperty(objKey);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String errmsg = "SMSFlatFileObjectBase.getSubEntries: " +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String errmsg = "SMSFlatFileObject.getSubEntries: "+
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster " does not exist or is not a directory.";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Create file filter for filter and sid filter.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster FilenameFilter subentFileFilter = new FilenameFilter(filter);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (sidFilter != null && sidFilter.length() > 0) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // filter also needs to be encoded since the file names
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // are encoded.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Create set for return, use sorted set if sortResults is true.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster subentries = new CaseInsensitiveTreeSet(ascendingOrder);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Set all entries that match filter, and that match
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // sunserviceid/sunxmlkeyvalye if sidFilter was not null.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster File[] subentriesFound = parentDir.listFiles(subentFileFilter);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean done = false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for (int i = 0; (i < subentriesFound.length) && !done; i++) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (sidFileFilter == null || ((sunserviceidFiles =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster subentriesFound[i].listFiles(sidFileFilter)) != null &&
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String filename = subentriesFound[i].getName();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (equalSign < 0 || equalSign == (filename.length()-1)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String errmsg = "SMSFlatFileObject.getSubEntries: "+
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster FileNameDecoder.decode(filename.substring(equalSign+1));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // stop if number of entries requested has been reached.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // if sort results, need to get the whole list first.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // remove extra entries from the bottom.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Object l = ((CaseInsensitiveTreeSet) subentries).last();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Delete sunxmlkeyvalue files under the given directory.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected void deleteSunXmlKeyValFiles(File dirHandle) throws SMSException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Construct the file filter and get the files
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster StringBuilder sb = new StringBuilder(SMSEntry.ATTR_XML_KEYVAL);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster FilenameFilter filter = new FilenameFilter(sb.toString());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster File[] deleteFiles = dirHandle.listFiles(filter);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for (int i = 0; deleteFiles != null && i < deleteFiles.length; i++) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Constructor for SMSFlatFileObject.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Reads in attributes of a configuration object.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return A Map with the coniguration object's attributes or null if the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * configuration object does not exist or no attributes are found.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param token Ignored argument. Access check is assumed to have
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * occurred before reaching this method.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param objName Name of the configuration object, expected to be a dn.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws SMSException if an IO error occurred during the read.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws SchemaException if a format error occurred while reading the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * attributes properties file.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws IllegalArgumentException if objName argument is null or empty.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public Map read(SSOToken token, String objName)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // check args
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (objName == null || objName.length() == 0) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "SMSFlatFileObject.read: object name is null or empty.");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // check if object exists.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String filepath = mNameMap.getProperty(objKey);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mDebug.message("SMSFlatFileObject.read: object " +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Read in file as properties.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // props will be null if object does not exist and
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // this func subsequently returns null
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // convert each value string to a Set.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Creates the configuration object. Creates the directory for the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * object and the attributes properties file with the given attributes.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param token Ignored argument. Access check is assumed to have
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * occurred before reaching this method.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param objName Name of the configuration object to create. Name is
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * expected to be a dn.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param attrs Map of attributes for the object.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws IllegalArgumentException if the objName or attrs argument is
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * null or empty.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws ServiceAlreadyExistsException if the configuration object
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * already exists.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws SMSException if an IO error occurred while creating the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * configuration object.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void create(SSOToken token, String objName, Map attrs)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (objName == null || objName.length() == 0 || attrs == null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "SMSFlatFileObject.create: "+
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "One or more arguments is null or empty");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Check if object already exists.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String errmsg = "SMSFlatFileObject.create: object " + objName +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ServiceAlreadyExistsException(errmsg);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Now Create the object.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster filepath = mNameMap.getProperty(objKey); // recheck
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String errmsg = "SMSFlatFileObject.create: object " + objName +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ServiceAlreadyExistsException(errmsg);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String errmsg = "SMSFlatFileObject.create: object " + objName +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster " exists before create!";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ServiceAlreadyExistsException(errmsg);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Put attrs into in properties format,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // replacing any percent's with %25 and commas with %2C
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // in the values.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // there's no need for case insensitive properties here since
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // we are not reading from it.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for (Iterator i = keys.iterator(); i.hasNext(); ) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (key.equalsIgnoreCase(SMSEntry.ATTR_SERVICE_ID)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (key.equalsIgnoreCase(SMSEntry.ATTR_XML_KEYVAL)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Create directory, property file, etc.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // create directory
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String errmsg = "SMSFlatFileObject.create: object " +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // create the attributes properties file.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String errmsg = "SMSFlatFileObject.create: object " +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster objName + ": Could not create file " + filepath;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String errmsg = "SMSFlatFileObject.create: object " +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster objName + " IOException encountered when creating file "
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // write the attributes properties file.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // create sunserviceid files for faster return in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // schemaSubEntries method.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (sunserviceids != null && !sunserviceids.isEmpty()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster createSunServiceIdFiles(parentDir, sunserviceids);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // create sunxmlkeyvalue files for faster search
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (sunxmlkeyvals != null && !sunxmlkeyvals.isEmpty()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster createSunXmlKeyValFiles(parentDir, sunxmlkeyvals);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // add the name in the name map and save.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster saveProperties(mNameMap, mNameMapHandle, null);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // If any error occurred, clean up - remove the directory
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // and files created.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Modify the attributes for the given configuration object.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param token Ignored argument. Access check is assumed to have
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * occurred before reaching this method.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param objName Name of the configuration object to modify. Name is
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * expected to be a dn.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param mods Array of attributes to modify.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws IllegalArgumentException if objName or mods argument is null or
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * empty, or if an error was encountered getting attributes from the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * mods argument.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws ServiceNotFoundException if the attributes properties file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * for the configuration object is not found.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws SchemaException if a format error occurred while reading in the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * existing attributes properties file.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws SMSException if an IO error occurred while reading or writing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * to the attributes properties file.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void modify(SSOToken token, String objName, ModificationItem[] mods)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((objName == null) || (objName.length() == 0) ||
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "SMSFlatFileObject.modify: "+
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "One or more arguments is null or empty");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Check if object exists.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String errmsg = "SMSFlatFileObject.modify: object " +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Now do the modification.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster filepath = mNameMap.getProperty(objKey); // recheck
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String errmsg = "SMSFlatFileObject.modify: object " +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "SMSFlatFileObject.modify: Attributes file for object "
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Read in attributes in existing file first.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Properties props = loadProperties(filehandle, objName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean hasSunXmlKeyValue = (props.getProperty(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SMSEntry.ATTR_XML_KEYVAL) == null) ? false: true;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Replace modification items in attributes properties
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * save attributes properties file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * sunserviceid's are never modified so don't worry about
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * renaming them in modify().
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Check for sunxmlkeyvalues
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SMSEntry.ATTR_XML_KEYVAL) == null) ? false: true;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Delete the lookup files and recreate them
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster deleteSunXmlKeyValFiles(filehandle.getParentFile());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set xmlKeyVals = toValSet(SMSEntry.ATTR_XML_KEYVAL,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster createSunXmlKeyValFiles(filehandle.getParentFile(), xmlKeyVals);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Deletes the configuration object and all objects below it.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param token Ignored argument. Access check is assumed to have
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * occurred before reaching this method.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param objName Name of the configuration object to delete. Name is
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * expected to be a dn.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws IllegalArgumentException if objName argument is null or empty.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws SMSException if any files for or under the configuration object
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * could not be removed.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void delete(SSOToken token, String objName)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((objName == null) || (objName.length() == 0)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "SMSFlatFileObject.delete: object name is null or empty.");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Check if object exists
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((filepath == null) && mDebug.messageEnabled()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mDebug.message("SMSFlatFileObject.delete: " + objName +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ": object not found.");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster filepath = mNameMap.getProperty(objKey); // recheck.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mDebug.message("SMSFlatFileObject.delete: " + objName +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ": object not found.");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // delete everything from the file dir on.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // remove all names from name map under the objname.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster saveProperties(mNameMap, mNameMapHandle, null);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns <code>ture</code> if the configuration object exists.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param token Ignored argument. Access check is assumed to have
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * occurred before reaching this method.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param objName Name of the configuration object to check.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return <code>true>/code> if the configuration object exists.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws IllegalArgumentException if objName is null or empty.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public boolean entryExists(SSOToken token, String objName) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean exists = false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (objName == null || objName.length() == 0) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "SMSFlatFileObject.entryExists: "+
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "One or more arguments is null or empty.");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String filepath = mNameMap.getProperty(objName.toLowerCase());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return a String representing the name of this class.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return ("SMSFlatFileObject");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Recursively deletes the given directory and all
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * files and directories underneath.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // remove all files in each sub-dir
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String errmsg = "SMSFlatFileObject.delete: File "+
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster " could not be removed!";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Creates sunxmlkeyvalue files with the given values under the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * given directory. sunxmlkeyvalue files are created so searching
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * for realms does not have to read in every attribute properrties
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * file and look for the sunxmlkeyvalue attribute. we just need to look
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * for sub directories with the sunxmlkeyvalue file.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private void createSunXmlKeyValFiles(File dirHandle, Set sunxmlkeyvals)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster createLookupFiles(dirHandle, SMSEntry.ATTR_XML_KEYVAL,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Creates sunserviceid files with the given values under the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * given directory. sunserviceid files are created so getting
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * schemasubentries does not have to read in every attribute properrties
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * file and look for the serviceid attribute. we just need to look
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * for sub directories with the sunserviceid file.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private void createSunServiceIdFiles(File dirHandle, Set sunserviceids)