rences 斤?。萩指?匯和 賠汽 1 嶄贋刈壓 ApacheDS 嶄議 MessagingPreferences 斤?。
FetchAliceMessagingPreferences 哘喘殻會頁 賠汽 7 嶄心欺議 SearchForAliceByCN 哘喘殻會議奐 膿井。糞縞貧?賠汽 8 嚥 賠汽 7 壓化帶 8 岻念脅?揖?壓化帶 8 嶄?繍戻函 Alice 方象訳朕議 RDN 。貫賠汽 8 嶄議化帶 8 嶄?繍蝕兵臥孀 Alice 議 Preferences 斤??
賠汽 8. FetchAliceMessagingPreferences
public class FetchAliceMessagingPreferences {
public FetchAliceMessagingPreferences() {
try
{
//------------------------------------------
//Step1: Setting up JNDI properties for ApacheDS
//------------------------------------------
InputStream inputStream = new FileInputStream ( "ApacheDS.properties");
Properties properties = new Properties();
properties.load(inputStream);
properties.setProperty("java.naming.security.credentials", "secret");
//------------------------------------------
// Step2: Fetching a DirContext object
//------------------------------------------
DirContext ctx = new InitialDirContext(properties);
//---------------------------------------------
//Step3: Setting search context
//---------------------------------------------
String searchContext = "ou=users";
//--------------------------------------------
//Step4: Creating search attributes for Alice
//--------------------------------------------
Attribute cn = new BasicAttribute("cn");
Attribute objclass = new BasicAttribute("objectClass");
//putting attribute values
cn.add("Alice");
objclass.add("person");
//Instantiate an Attributes object and put search attributes in it
Attributes attrs = new BasicAttributes(true);
attrs.put(cn);
attrs.put(objclass);
//------------------------------------------
//Step5: Executing search
//------------------------------------------
NamingEnumeration ne = ctx.search(searchContext, attrs);
if (ne != null)
{
//Step 6: Iterating through SearchResults
while (ne.hasMore()) {
//Step 7: Getting individual SearchResult object
SearchResult sr = (SearchResult) ne.next();
//Step 8:
String entryRDN = sr.getName();
//---------------------------------------------
//Step9: Setting a new search context
//---------------------------------------------
searchContext = entryRDN
|