req.setDerefAliases( AliasDerefMode.NEVER_DEREF_ALIASES );
// the ENTRY_DN_AT must be in the attribute list, otherwise sorting fails
req.addAttributes( SchemaConstants.ENTRY_DN_AT );
SortKey sk = new SortKey( SchemaConstants.ENTRY_DN_AT, "2.5.13.1" );
SortRequestControl ctrl = new SortRequestControlImpl();
ctrl.addSortKey( sk );
req.addControl( ctrl );
OperationManager operationManager = directoryService.getOperationManager();
Cursor<Entry> cursor = session.search( req );