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 2005/03/14 01:00:17 UTC

svn commit: r157358 - in directory/protocols/kerberos/trunk/store/src/java/org/apache/kerberos/store: KerberosAttribute.java LookupPrincipalActionImpl.java

Author: erodriguez
Date: Sun Mar 13 16:00:16 2005
New Revision: 157358

URL: http://svn.apache.org/viewcvs?view=rev&rev=157358
Log:
Consolidating store classes to store component.

Added:
    directory/protocols/kerberos/trunk/store/src/java/org/apache/kerberos/store/KerberosAttribute.java
    directory/protocols/kerberos/trunk/store/src/java/org/apache/kerberos/store/LookupPrincipalActionImpl.java

Added: directory/protocols/kerberos/trunk/store/src/java/org/apache/kerberos/store/KerberosAttribute.java
URL: http://svn.apache.org/viewcvs/directory/protocols/kerberos/trunk/store/src/java/org/apache/kerberos/store/KerberosAttribute.java?view=auto&rev=157358
==============================================================================
--- directory/protocols/kerberos/trunk/store/src/java/org/apache/kerberos/store/KerberosAttribute.java (added)
+++ directory/protocols/kerberos/trunk/store/src/java/org/apache/kerberos/store/KerberosAttribute.java Sun Mar 13 16:00:16 2005
@@ -0,0 +1,36 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+
+package org.apache.kerberos.store;
+
+
+public class KerberosAttribute
+{
+    // ------------------------------------------------------------------------
+    // Krb5 Schema Attributes
+    // ------------------------------------------------------------------------
+    
+    /** the krb5kdc schema key for a krb5KDCEntry */
+    public static final String KEY       = "krb5Key";
+    /** the krb5kdc schema key encryption type for a krb5KDCEntry */
+    public static final String TYPE      = "krb5EncryptionType";
+    /** the krb5kdc schema principal name for a krb5KDCEntry */
+    public static final String PRINCIPAL = "krb5PrincipalName";
+    /** the krb5kdc schema key version identifier for a krb5KDCEntry */
+    public static final String VERSION   = "krb5KeyVersionNumber";
+}
+

Added: directory/protocols/kerberos/trunk/store/src/java/org/apache/kerberos/store/LookupPrincipalActionImpl.java
URL: http://svn.apache.org/viewcvs/directory/protocols/kerberos/trunk/store/src/java/org/apache/kerberos/store/LookupPrincipalActionImpl.java?view=auto&rev=157358
==============================================================================
--- directory/protocols/kerberos/trunk/store/src/java/org/apache/kerberos/store/LookupPrincipalActionImpl.java (added)
+++ directory/protocols/kerberos/trunk/store/src/java/org/apache/kerberos/store/LookupPrincipalActionImpl.java Sun Mar 13 16:00:16 2005
@@ -0,0 +1,139 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+
+package org.apache.kerberos.store;
+
+import javax.naming.Name;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.SearchResult;
+import javax.naming.ldap.LdapContext;
+import javax.security.auth.kerberos.KerberosPrincipal;
+
+import org.apache.kerberos.kdc.KerberosException;
+import org.apache.kerberos.sam.SamType;
+import org.apache.ldap.common.message.LockableAttributesImpl;
+
+/**
+ * Encapsulates the action of looking up a principal in an embedded ApacheDS DIT.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class LookupPrincipalActionImpl implements PrincipalStore
+{
+    /** a handle on the top initial context: get new context from this */
+    protected LdapContext ctx;
+    /** the search base relative to provider URL to use for reading entries */
+    protected Name searchBaseDn;
+    
+    /**
+     * Creates the action to be used against the embedded ApacheDS DIT.
+     */
+    public LookupPrincipalActionImpl( LdapContext ctx, Name searchBaseDn )
+    {
+        this.ctx = ctx;
+        this.searchBaseDn = searchBaseDn;
+    }
+    
+    public void init()
+    {
+        // TODO - Remove me.
+    }
+    
+    
+    public PrincipalStoreEntry getEntry( KerberosPrincipal principal ) throws KerberosException
+    {
+        if ( principal == null )
+        {
+            return null;
+        }
+
+        Attributes attributes = new LockableAttributesImpl();
+
+        attributes.put( KerberosAttribute.PRINCIPAL, principal.getName() );
+
+        try
+        {
+            Attributes attrs = null;
+
+            NamingEnumeration list = ctx.search( searchBaseDn, attributes );
+
+            if ( list.hasMore() )
+            {
+                SearchResult result = ( SearchResult ) list.next();
+
+                attrs = result.getAttributes();
+            }
+
+            list.close();
+
+            if ( attrs == null )
+            {
+                return null;
+            }
+
+            return getEntry( attrs );
+        }
+        catch ( NamingException e )
+        {
+            e.printStackTrace();
+
+            return null;
+        }
+    }
+
+
+    /**
+     * Marshals an a PrincipalStoreEntry from an Attributes object.
+     *
+     * @param attrs the attributes of the Kerberos principal
+     * @return the entry for the principal
+     * @throws NamingException if there are any access problems
+     */
+    private PrincipalStoreEntry getEntry( Attributes attrs ) throws NamingException
+    {
+        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 )
+        {
+            String samType = ( String ) attrs.get( "apacheSamType" ).get();
+
+            modifier.setSamType( SamType.getTypeByOrdinal( Integer.parseInt( samType ) ) );
+        }
+
+        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();
+    }
+}
+