directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 56805 - in incubator/directory/kerberos/trunk/eve-kerberos/src: java/org java/org/apache java/org/apache/kerberos java/org/apache/kerberos/kdc test/org test/org/apache test/org/apache/kerberos test/org/apache/kerberos/kdc
Date Sun, 07 Nov 2004 04:35:55 GMT
Author: akarasulu
Date: Sat Nov  6 20:35:55 2004
New Revision: 56805

Added:
   incubator/directory/kerberos/trunk/eve-kerberos/src/java/org/
   incubator/directory/kerberos/trunk/eve-kerberos/src/java/org/apache/
   incubator/directory/kerberos/trunk/eve-kerberos/src/java/org/apache/kerberos/
   incubator/directory/kerberos/trunk/eve-kerberos/src/java/org/apache/kerberos/kdc/
   incubator/directory/kerberos/trunk/eve-kerberos/src/java/org/apache/kerberos/kdc/EmbeddedEveStore.java
   incubator/directory/kerberos/trunk/eve-kerberos/src/test/org/
   incubator/directory/kerberos/trunk/eve-kerberos/src/test/org/apache/
   incubator/directory/kerberos/trunk/eve-kerberos/src/test/org/apache/kerberos/
   incubator/directory/kerberos/trunk/eve-kerberos/src/test/org/apache/kerberos/kdc/
   incubator/directory/kerberos/trunk/eve-kerberos/src/test/org/apache/kerberos/kdc/EmbeddedEveStoreTest.java
Log:
Added a few stuff a while back to start playing.  This may change now.


Added: incubator/directory/kerberos/trunk/eve-kerberos/src/java/org/apache/kerberos/kdc/EmbeddedEveStore.java
==============================================================================
--- (empty file)
+++ incubator/directory/kerberos/trunk/eve-kerberos/src/java/org/apache/kerberos/kdc/EmbeddedEveStore.java
Sat Nov  6 20:35:55 2004
@@ -0,0 +1,142 @@
+/*
+ *   Copyright 2004 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.kdc;
+
+
+import java.util.Hashtable;
+import javax.security.auth.kerberos.KerberosPrincipal;
+import javax.naming.NamingException;
+import javax.naming.NamingEnumeration;
+import javax.naming.directory.*;
+
+import org.apache.kerberos.kdc.store.PrincipalStore;
+import org.apache.kerberos.kdc.store.PrincipalStoreEntry;
+import org.apache.kerberos.kdc.store.LdapStore;
+import org.apache.kerberos.kdc.store.PrincipalStoreEntryModifier;
+
+
+/**
+ * Document this class.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class EmbeddedEveStore implements PrincipalStore
+{
+
+    // ------------------------------------------------------------------------
+    // Krb5 Schema Attributes
+    // ------------------------------------------------------------------------
+
+    private static final String PRINCIPAL_NAME     = "krb5PrincipalName";
+    private static final String KEY_VERSION_NUMBER = "krb5KeyVersionNumber";
+    private static final String ENCRYPTION_TYPE    = "krb5EncryptionType";
+    private static final String KEY                = "krb5Key";
+
+    /** JNDI environment properties and more */
+    private final Hashtable env;
+
+
+    /**
+     * Creates the embedded eve principal store.
+     *
+     * @param env the environement properties used to initialize the Eve
+     * Kerberos environment
+     */
+    public EmbeddedEveStore( Hashtable env )
+    {
+        this.env = ( Hashtable ) env.clone();
+    }
+
+
+    /**
+     * Does nothing really.
+     */
+    public void init()
+    {
+    }
+
+
+    public PrincipalStoreEntry getEntry( KerberosPrincipal principal ) throws KerberosException
+    {
+        InitialDirContext ctx = null;
+
+        if ( principal == null )
+        {
+            return null;
+        }
+
+        try
+        {
+            ctx = new InitialDirContext( env );
+        }
+        catch ( NamingException e )
+        {
+            e.printStackTrace();
+            return null;
+        }
+
+        StringBuffer filter = new StringBuffer();
+        filter.append( "(& (" );
+        filter.append( PRINCIPAL_NAME );
+        filter.append( '=' );
+        filter.append( principal.getName() );
+        filter.append( ") ( objectClass = krb5Principal ) )" );
+        SearchControls ctrls = new SearchControls();
+
+        try
+        {
+            Attributes attrs = null;
+            NamingEnumeration list = ctx.search( "", filter.toString(), ctrls );
+            if ( list.hasMore() )
+            {
+                SearchResult result = ( SearchResult ) list.next();
+                attrs = result.getAttributes();
+            }
+            list.close();
+            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( PRINCIPAL_NAME ).get();
+        String encryptionType = (String) attrs.get( ENCRYPTION_TYPE ).get();
+        String keyVersionNumber = (String) attrs.get( 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 );
+        return modifier.getEntry();
+    }
+}

Added: incubator/directory/kerberos/trunk/eve-kerberos/src/test/org/apache/kerberos/kdc/EmbeddedEveStoreTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/kerberos/trunk/eve-kerberos/src/test/org/apache/kerberos/kdc/EmbeddedEveStoreTest.java
Sat Nov  6 20:35:55 2004
@@ -0,0 +1,90 @@
+/*
+ *   Copyright 2004 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.kdc;
+
+
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.directory.*;
+import javax.security.auth.kerberos.KerberosPrincipal;
+
+import junit.framework.TestCase;
+import org.apache.eve.jndi.EveContextFactory;
+
+
+/**
+ * Document this class.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class EmbeddedEveStoreTest extends TestCase
+{
+    public void testEveStore() throws Exception
+    {
+        Hashtable env = new Hashtable();
+        env.put( Context.PROVIDER_URL, "dc=example,dc=com" );
+        env.put( Context.INITIAL_CONTEXT_FACTORY, "org.apache.eve.jndi.EveContextFactory"
);
+
+        BasicAttributes attrs = new BasicAttributes( true );
+        BasicAttribute attr = new BasicAttribute( "objectClass" );
+        attr.add( "top" );
+        attr.add( "organizationalUnit" );
+        attr.add( "extensibleObject" );
+        attrs.put( attr );
+        attr = new BasicAttribute( "ou" );
+        attr.add( "testing" );
+        attrs.put( attr );
+
+        env.put( EveContextFactory.PARTITIONS_ENV, "example" );
+        env.put( EveContextFactory.SUFFIX_BASE_ENV + "example", "dc=example,dc=com" );
+        env.put( EveContextFactory.INDICES_BASE_ENV + "example", "ou objectClass" );
+        env.put( EveContextFactory.ATTRIBUTES_BASE_ENV + "example", attrs );
+
+        EmbeddedEveStore store = new EmbeddedEveStore( env );
+        store.init();
+        assertNull( store.getEntry( null ) );
+    }
+
+
+    public void testEveStoreGetEntry() throws Exception
+    {
+        Hashtable env = new Hashtable();
+        env.put( Context.PROVIDER_URL, "dc=example,dc=com" );
+        env.put( Context.INITIAL_CONTEXT_FACTORY, "org.apache.eve.jndi.EveContextFactory"
);
+
+        BasicAttributes attrs = new BasicAttributes( true );
+        BasicAttribute attr = new BasicAttribute( "objectClass" );
+        attr.add( "top" );
+        attr.add( "organizationalUnit" );
+        attr.add( "extensibleObject" );
+        attrs.put( attr );
+        attr = new BasicAttribute( "ou" );
+        attr.add( "testing" );
+        attrs.put( attr );
+
+        env.put( EveContextFactory.PARTITIONS_ENV, "example" );
+        env.put( EveContextFactory.SUFFIX_BASE_ENV + "example", "dc=example,dc=com" );
+        env.put( EveContextFactory.INDICES_BASE_ENV + "example", "ou objectClass" );
+        env.put( EveContextFactory.ATTRIBUTES_BASE_ENV + "example", attrs );
+
+        EmbeddedEveStore store = new EmbeddedEveStore( env );
+        KerberosPrincipal principal = new KerberosPrincipal( "krbtgt/EXAMPLE.COM@EXAMPLE.COM"
);
+        store.getEntry( principal );
+    }
+}

Mime
View raw message