* @throws Exception if there are problems while searching the directory
*/
public static ServerEntry findPrincipalEntry( CoreSession session, DN searchBaseDn, String principal )
throws Exception
{
EntryFilteringCursor cursor = null;
try
{
SchemaManager schemaManager = session.getDirectoryService().getSchemaManager();
cursor = session.search( searchBaseDn, SearchScope.SUBTREE,
getFilter( schemaManager, principal ), AliasDerefMode.DEREF_ALWAYS, null );
cursor.beforeFirst();
if ( cursor.next() )
{
ServerEntry entry = cursor.get();
LOG.debug( "Found entry {} for kerberos principal name {}", entry, principal );
while ( cursor.next() )
{
LOG.error( I18n.err( I18n.ERR_149, principal, cursor.next() ) );
}
return entry;
}
else
{
LOG.warn( "No server entry found for kerberos principal name {}", principal );
return null;
}
}
finally
{
if ( cursor != null )
{
cursor.close();
}
}
}