DirContext dirContext;
try {
dirContext = this.connectionSource.getContext();
} catch (UserStoreException e) {
throw new DirectoryServerManagerException("Unable to retrieve directory connection.", e);
}
String searchBase = this.realmConfiguration.getUserStoreProperty(LDAPConstants.USER_SEARCH_BASE);
String userId = lookupUserId(serverName);
if (userId == null) {
throw new DirectoryServerManagerException("Could not find user id for given server principle " +
serverName);
}
try {
dirContext = (DirContext) dirContext.lookup(searchBase);
dirContext.unbind("uid=" + userId);
} catch (NamingException e) {
log.error("Could not remove service principle " + serverName, e);
throw new DirectoryServerManagerException("Could not remove service principle " + serverName, e);
} finally {
try {
JNDIUtil.closeContext(dirContext);
} catch (UserStoreException e) {
log.error("Unable to close directory context.", e);