Author: akarasulu
Date: Sun May  1 08:40:43 2005
New Revision: 165518

URL: http://svn.apache.org/viewcvs?rev=165518&view=rev
Log:
changes ...

 o made the KerberosPrincipal final and private
 o added protected accessor for KerberosPrincipal
 o javadoc regarding the use of a relative name rather than a DN for search base
 o formatting


Modified:
    
directory/shared/kerberos/trunk/common/src/java/org/apache/kerberos/store/operations/GetPrincipal.java

Modified: 
directory/shared/kerberos/trunk/common/src/java/org/apache/kerberos/store/operations/GetPrincipal.java
URL: 
http://svn.apache.org/viewcvs/directory/shared/kerberos/trunk/common/src/java/org/apache/kerberos/store/operations/GetPrincipal.java?rev=165518&r1=165517&r2=165518&view=diff
==============================================================================
--- 
directory/shared/kerberos/trunk/common/src/java/org/apache/kerberos/store/operations/GetPrincipal.java
 (original)
+++ 
directory/shared/kerberos/trunk/common/src/java/org/apache/kerberos/store/operations/GetPrincipal.java
 Sun May  1 08:40:43 2005
@@ -42,8 +42,9 @@
 public class GetPrincipal implements ContextOperation
 {
     /** The name of the principal to get. */
-    protected KerberosPrincipal principal;
-    
+    private final KerberosPrincipal principal;
+
+
     /**
      * Creates the action to be used against the embedded ApacheDS DIT.
      */
@@ -51,31 +52,53 @@
     {
         this.principal = principal;
     }
-    
-    public Object execute( DirContext ctx, Name searchBaseDn )
+
+
+    /**
+     * Gets the KerberosPrincipal associated with this context operation.
+     * @return
+     */
+    protected KerberosPrincipal getPrincipal()
+    {
+        return principal;
+    }
+
+
+    /**
+     * Note that the base is a relative path from the exiting context.
+     * It is not a DN.
+     */
+    public Object execute( DirContext ctx, Name base )
        {
         if ( principal == null )
         {
             return null;
         }
         
-               String[] attrIDs = { KerberosAttribute.PRINCIPAL, 
KerberosAttribute.VERSION,
-                       KerberosAttribute.TYPE, KerberosAttribute.KEY };
+               String[] attrIDs = {
+
+            KerberosAttribute.PRINCIPAL,  KerberosAttribute.VERSION,
+
+            KerberosAttribute.TYPE,  KerberosAttribute.KEY
+        };
 
                Attributes matchAttrs = new BasicAttributes( false ); // 
case-sensitive
-               matchAttrs.put( new BasicAttribute( 
KerberosAttribute.PRINCIPAL, principal.getName() ) );
+
+        matchAttrs.put( new BasicAttribute( KerberosAttribute.PRINCIPAL, 
principal.getName() ) );
                
                PrincipalStoreEntry entry = null;
                
                try
                {
                    // Search for objects that have those matching attributes
-                   NamingEnumeration answer = ctx.search( searchBaseDn, 
matchAttrs, attrIDs );
+
+            NamingEnumeration answer = ctx.search( base, matchAttrs, attrIDs );
                    
                        if ( answer.hasMore() )
                        {
-                               SearchResult result = (SearchResult) 
answer.next();
-                   Attributes attrs = result.getAttributes();
+                               SearchResult result = ( SearchResult ) 
answer.next();
+
+                Attributes attrs = result.getAttributes();
                    
                    if ( attrs == null )
                    {
@@ -85,15 +108,17 @@
                    entry = getEntry( attrs );
                        }
                }
-               catch (NamingException e)
+               catch ( NamingException e )
                {
                        e.printStackTrace();
-                       return null;
+
+            return null;
                }
                
                return entry;
     }
-    
+
+
     /**
      * Marshals an a PrincipalStoreEntry from an Attributes object.
      *
@@ -106,7 +131,9 @@
         PrincipalStoreEntryModifier modifier = new 
PrincipalStoreEntryModifier();
 
         String principal = ( String ) attrs.get( KerberosAttribute.PRINCIPAL 
).get();
+
         String encryptionType = ( String ) attrs.get( KerberosAttribute.TYPE 
).get();
+
         String keyVersionNumber = ( String ) attrs.get( 
KerberosAttribute.VERSION ).get();
 
         if ( attrs.get( "apacheSamType" ) != null )
@@ -116,11 +143,14 @@
             modifier.setSamType( SamType.getTypeByOrdinal( Integer.parseInt( 
samType ) ) );
         }
 
-        byte[] keyBytes = (byte[]) attrs.get( KerberosAttribute.KEY ).get();
+        byte[] keyBytes = ( byte[] ) attrs.get( KerberosAttribute.KEY ).get();
 
         modifier.setPrincipal( new KerberosPrincipal( principal ) );
+
         modifier.setEncryptionType( Integer.parseInt( encryptionType ) );
+
         modifier.setKeyVersionNumber( Integer.parseInt( keyVersionNumber ) );
+
         modifier.setKey( keyBytes );
 
         return modifier.getEntry();


Reply via email to