You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by er...@apache.org on 2004/11/02 03:43:33 UTC

svn commit: rev 56328 - incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/kdc/store

Author: erodriguez
Date: Mon Nov  1 18:43:32 2004
New Revision: 56328

Modified:
   incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/kdc/store/LdapStore.java
Log:
LdapStore now handles NamingExceptions interally and simply returns a null principal to calling services.

Modified: incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/kdc/store/LdapStore.java
==============================================================================
--- incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/kdc/store/LdapStore.java	(original)
+++ incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/kdc/store/LdapStore.java	Mon Nov  1 18:43:32 2004
@@ -106,54 +106,48 @@
 
 			ctx.close();
 		} catch (NamingException e) {
-			e.printStackTrace();
+			_entry = null;
 		}
 	}
 
-	private void search(DirContext ctx) {
+	private void search(DirContext ctx) throws NamingException {
 		
-		try {
-			String[] attrIDs = {LdapStore.PRINCIPAL_NAME, LdapStore.KEY_VERSION_NUMBER,
-								LdapStore.ENCRYPTION_TYPE, LdapStore.KEY};
+		String[] attrIDs = {LdapStore.PRINCIPAL_NAME, LdapStore.KEY_VERSION_NUMBER,
+							LdapStore.ENCRYPTION_TYPE, LdapStore.KEY};
 
-			Attributes matchAttrs = new BasicAttributes(false); // case-sensitive
-			matchAttrs.put(new BasicAttribute(LdapStore.PRINCIPAL_NAME, _principal));
-			matchAttrs.put(new BasicAttribute(LdapStore.KEY));
-			matchAttrs.put(new BasicAttribute(LdapStore.ENCRYPTION_TYPE));
-			matchAttrs.put(new BasicAttribute(LdapStore.KEY_VERSION_NUMBER));
+		Attributes matchAttrs = new BasicAttributes(false); // case-sensitive
+		matchAttrs.put(new BasicAttribute(LdapStore.PRINCIPAL_NAME, _principal));
+		matchAttrs.put(new BasicAttribute(LdapStore.KEY));
+		matchAttrs.put(new BasicAttribute(LdapStore.ENCRYPTION_TYPE));
+		matchAttrs.put(new BasicAttribute(LdapStore.KEY_VERSION_NUMBER));
 
-			// Search for objects that have those matching attributes
-			NamingEnumeration answer = ctx.search("", matchAttrs, attrIDs);
-			
+		// Search for objects that have those matching attributes
+		NamingEnumeration answer = ctx.search("", matchAttrs, attrIDs);
+		
+		if (answer.hasMore()) {
 			getFirstEntry(answer);
-			
-		} catch (NamingException e) {
-			System.err.println("Problem getting attribute: " + e);
 		}
 	}
 
-	private void getFirstEntry(NamingEnumeration enum) {
+	private void getFirstEntry(NamingEnumeration enum) throws NamingException {
 		
 		PrincipalStoreEntryModifier modifier = new PrincipalStoreEntryModifier();
 		
-		try {
-			SearchResult sr = (SearchResult) enum.next();
-			if (sr != null) {
-				Attributes attrs = sr.getAttributes();
-				
-				String principal        = (String) attrs.get(LdapStore.PRINCIPAL_NAME).get();
-				String encryptionType   = (String) attrs.get(LdapStore.ENCRYPTION_TYPE).get();
-				String keyVersionNumber = (String) attrs.get(LdapStore.KEY_VERSION_NUMBER).get();
-				byte[] keyBytes         = (byte[]) attrs.get(LdapStore.KEY).get();
-				
-				modifier.setPrincipal(new KerberosPrincipal(principal));
-				modifier.setEncryptionType(Integer.parseInt(encryptionType));
-				modifier.setKeyVersionNumber(Integer.parseInt(keyVersionNumber));
-				modifier.setKey(keyBytes);
-			}
-		} catch (NamingException e) {
-			e.printStackTrace();
+		SearchResult sr = (SearchResult) enum.next();
+		if (sr != null) {
+			Attributes attrs = sr.getAttributes();
+			
+			String principal        = (String) attrs.get(LdapStore.PRINCIPAL_NAME).get();
+			String encryptionType   = (String) attrs.get(LdapStore.ENCRYPTION_TYPE).get();
+			String keyVersionNumber = (String) attrs.get(LdapStore.KEY_VERSION_NUMBER).get();
+			byte[] keyBytes         = (byte[]) attrs.get(LdapStore.KEY).get();
+			
+			modifier.setPrincipal(new KerberosPrincipal(principal));
+			modifier.setEncryptionType(Integer.parseInt(encryptionType));
+			modifier.setKeyVersionNumber(Integer.parseInt(keyVersionNumber));
+			modifier.setKey(keyBytes);
 		}
+		
 		_entry = modifier.getEntry();
 	}
 }