ADSContextHelper.java revision 91fc158da838138e9f51e169f550e3c9e4c52ede
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at
* trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
* add the following below this CDDL HEADER, with the fields enclosed
* by brackets "[]" replaced with your own identifying information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Portions Copyright 2007 Sun Microsystems, Inc.
*/
/**
* This is the only class in the org.opends.admin.ads package that uses the
* classes from OpenDS.jar (in particular the administration client framework
* API). Before calling this class OpenDS.jar must be
* loaded. The goal is basically to centralize in one single place the
* dependencies of this package on OpenDS.jar. This is done in order the
* QuickSetup code to be able to use some of the functionalities provided
* by the ADSContext classes before OpenDS.jar is downloaded.
*/
public class ADSContextHelper
{
/**
* Default constructor.
*/
public ADSContextHelper()
{
}
/**
* Removes the administration suffix.
* @param ctx the DirContext to be used.
* @param backendName the name of the backend where the administration
* suffix is stored.
* @throws ADSContextException if the administration suffix could not be
* removed.
*/
{
try
{
try
{
}
catch (ManagedObjectNotFoundException monfe)
{
// It does not exist.
}
{
{
{
{
}
else
{
}
}
}
}
}
catch (Throwable t)
{
throw new ADSContextException(
}
}
/**
* Creates the Administration Suffix.
* @param ctx the DirContext to be used.
* @param backendName the name of the backend where the administration
* suffix is stored.
* @throws ADSContextException if the administration suffix could not be
* created.
*/
throws ADSContextException
{
try
{
try
{
}
catch (ManagedObjectNotFoundException e)
{
}
catch (ClassCastException cce)
{
throw new ADSContextException(
}
{
backend.setEnabled(true);
backend.setIsPrivateBackend(true);
}
{
}
{
}
}
catch (Throwable t)
{
throw new ADSContextException(
}
}
/**
Register instance key-pair public-key certificate provided in
serverProperties: generate a key-id attribute if one is not provided (as
expected); add an instance key public-key certificate entry for the key
certificate; and associate the certificate entry with the server entry via
the key ID attribute.
@param ctx the InitialLdapContext on the server we want to update.
@param serverProperties Properties of the server being registered to which
the instance key entry belongs.
@param serverEntryDn The server's ADS entry DN.
@throws ADSContextException In case some JNDI operation fails or there is a
problem getting the instance public key certificate ID.
*/
public void registerInstanceKeyCertificate(
throws ADSContextException {
assert serverProperties.containsKey(
if (! serverProperties.containsKey(
return;
}
/* the key ID might be supplied in serverProperties (although, I am unaware
of any such case). */
/* these attributes are used both to search for an existing certificate
entry and, if one does not exist, add a new certificate entry */
}
+ ";binary",
/* search for public-key certificate entry in ADS DIT */
try
{
/* attribute ds-cfg-key-id is the entry is a MUST in the schema */
}
}
/* TODO: It is possible (but unexpected) that the caller specifies a
ds-cfg-key-id value for which there is a certificate entry in ADS, but
the certificate value does not match that supplied by the caller. The
above search would not return the entry, but the below attempt to add
an new entry with the supplied ds-cfg-key-id will fail (throw a
NameAlreadyBoundException) */
else {
/* create key ID, if it was not supplied in serverProperties */
(byte[])serverProperties.get(
}
/* add public-key certificate entry */
}
/* associate server entry with certificate entry via key ID attribute */
(new BasicAttributes(
}
catch (NamingException ne)
{
throw new ADSContextException(
}
catch (CryptoManagerException cme)
{
throw new ADSContextException(
}
}
/**
* Returns the crypto instance key objectclass name as defined in
* ConfigConstants.
* @return the crypto instance key objectclass name as defined in
* ConfigConstants.
*/
public String getOcCryptoInstanceKey()
{
}
/**
* Returns the crypto key compromised time attribute name as defined in
* ConfigConstants.
* @return the crypto key compromised time attribute name as defined in
* ConfigConstants.
*/
public String getAttrCryptoKeyCompromisedTime()
{
}
}