Author: erodriguez Date: Mon Nov 8 15:30:42 2004 New Revision: 56979 Added: incubator/directory/kerberos/trunk/eve-kerberos-seda/ incubator/directory/kerberos/trunk/eve-kerberos-seda/src/ incubator/directory/kerberos/trunk/eve-kerberos-seda/src/java/ incubator/directory/kerberos/trunk/eve-kerberos-seda/src/java/org/ incubator/directory/kerberos/trunk/eve-kerberos-seda/src/java/org/apache/ incubator/directory/kerberos/trunk/eve-kerberos-seda/src/java/org/apache/kerberos/ incubator/directory/kerberos/trunk/eve-kerberos-seda/src/java/org/apache/kerberos/kdc/ incubator/directory/kerberos/trunk/eve-kerberos-seda/src/java/org/apache/kerberos/kdc/server/ incubator/directory/kerberos/trunk/eve-kerberos-seda/src/java/org/apache/kerberos/kdc/server/seda/ incubator/directory/kerberos/trunk/eve-kerberos-seda/src/java/org/apache/kerberos/kdc/server/seda/EveKerberosSedaMain.java incubator/directory/kerberos/trunk/eve-kerberos-seda/src/java/org/apache/kerberos/kdc/server/seda/KerberosDecoder.java incubator/directory/kerberos/trunk/eve-kerberos-seda/src/java/org/apache/kerberos/kdc/server/seda/KerberosEncoder.java incubator/directory/kerberos/trunk/eve-kerberos-seda/src/java/org/apache/kerberos/kdc/server/seda/KerberosHandler.java incubator/directory/kerberos/trunk/eve-kerberos-seda/src/java/org/apache/kerberos/kdc/server/seda/KerberosProtocolProvider.java Log: First pass at Eve, Kerberos, and SEDA integration.
Added: incubator/directory/kerberos/trunk/eve-kerberos-seda/src/java/org/apache/kerberos/kdc/server/seda/EveKerberosSedaMain.java ============================================================================== --- (empty file) +++ incubator/directory/kerberos/trunk/eve-kerberos-seda/src/java/org/apache/kerberos/kdc/server/seda/EveKerberosSedaMain.java Mon Nov 8 15:30:42 2004 @@ -0,0 +1,149 @@ +/* + * 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.server.seda; + + +import org.apache.eve.jndi.EveContextFactory; +import org.apache.kerberos.kdc.EmbeddedEveStore; +import org.apache.kerberos.kdc.KdcConfiguration; +import org.apache.kerberos.kdc.KdcDispatcher; +import org.apache.kerberos.kdc.store.BootstrapStore; +import org.apache.kerberos.kdc.store.PrincipalStore; +import org.apache.seda.DefaultFrontend; +import org.apache.seda.DefaultFrontendFactory; +import org.apache.seda.listener.ListenerConfig; +import org.apache.seda.listener.TCPListenerConfig; +import org.apache.seda.listener.UDPListenerConfig; +import org.apache.seda.protocol.DefaultInetServicesDatabase; +import org.apache.seda.protocol.InetServiceEntry; +import org.apache.seda.protocol.ProtocolProvider; +import org.apache.seda.protocol.TransportTypeEnum; + +import javax.naming.Context; +import javax.naming.directory.BasicAttribute; +import javax.naming.directory.BasicAttributes; +import java.io.File; +import java.net.InetAddress; +import java.util.Hashtable; + + +public class EveKerberosSedaMain +{ + private final KdcConfiguration config = new KdcConfiguration(); + private final BootstrapStore bootstrap = new BootstrapStore( config ); + private PrincipalStore ldap; + private KdcDispatcher kdc; + + /** the frontend used to contain the protocols */ + protected DefaultFrontend fe = null; + + /** the protocol provider */ + protected ProtocolProvider proto = null; + + /** the listener configuration for the protocol */ + protected ListenerConfig tcpConfig; + protected ListenerConfig udpConfig; + + /** the server port number for the protocol */ + protected int port; + + public static void main( String[] args ) + { + EveKerberosSedaMain m = new EveKerberosSedaMain(); + m.go(); + } + + private void go() + { + Hashtable env = new Hashtable(); + env.put( Context.PROVIDER_URL, "dc=example,dc=com" ); + env.put( Context.INITIAL_CONTEXT_FACTORY, "org.apache.eve.jndi.EveContextFactory" ); + env.put( EveContextFactory.WKDIR_ENV, "target" + File.separator + "eve" ); + + 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 ); + + env.put( EmbeddedEveStore.KDC_ENTRY_LDIF_FILE, "./src/ldif/example.com" ); + env.put( EmbeddedEveStore.KDC_ENTRY_BASEDN_KEY, "ou=Users,dc=example,dc=com" ); + + ldap = new EmbeddedEveStore( env ); + + init(); + + try + { + proto = new KerberosProtocolProvider(); + setup(); + kdc = new KdcDispatcher( config, bootstrap, ldap ); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + /** + * Instantiates the factory then gets a handle on the Frontend. + * + * @throws Exception due to create() + */ + protected void setup() throws Exception + { + port = config.getDefaultPort(); + + fe = (DefaultFrontend) new DefaultFrontendFactory().create(); + + InetServiceEntry srvEntry; + + srvEntry = new InetServiceEntry(proto.getName(), port, proto, TransportTypeEnum.TCP); + ((DefaultInetServicesDatabase) fe.getInetServicesDatabase()).addEntry(srvEntry); + tcpConfig = new TCPListenerConfig(InetAddress.getLocalHost(), srvEntry); + fe.getTCPListenerManager().bind(tcpConfig); + + srvEntry = new InetServiceEntry(proto.getName(), port, proto, TransportTypeEnum.UDP); + ((DefaultInetServicesDatabase) fe.getInetServicesDatabase()).addEntry(srvEntry); + udpConfig = new UDPListenerConfig(InetAddress.getLocalHost(), srvEntry); + fe.getUDPListenerManager().bind(udpConfig); + } + + private void init() + { + Runnable runnable = new Runnable() + { + public void run() + { + bootstrap.init(); + ldap.init(); + } + }; + Thread storeInit = new Thread( runnable ); + storeInit.start(); + } +} + Added: incubator/directory/kerberos/trunk/eve-kerberos-seda/src/java/org/apache/kerberos/kdc/server/seda/KerberosDecoder.java ============================================================================== --- (empty file) +++ incubator/directory/kerberos/trunk/eve-kerberos-seda/src/java/org/apache/kerberos/kdc/server/seda/KerberosDecoder.java Mon Nov 8 15:30:42 2004 @@ -0,0 +1,43 @@ +/* + * 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.server.seda; + +import org.apache.commons.codec.stateful.AbstractStatefulDecoder; + + +/** + * A decoder for Kerberos requests. + * + * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a> + * @version $Rev: 56478 $ + */ +public class KerberosDecoder extends AbstractStatefulDecoder +{ + /** + * Returns a decoded Kerberos PDU. The codec is an identity + * operation. Each decode call triggers a callback since we're presuming + * each chunk to be a valid PDU while streaming the request back. + * + * @param encoded the object to return which is a buffer + */ + public void decode(Object encoded) + { + super.decodeOccurred(encoded); + } +} + Added: incubator/directory/kerberos/trunk/eve-kerberos-seda/src/java/org/apache/kerberos/kdc/server/seda/KerberosEncoder.java ============================================================================== --- (empty file) +++ incubator/directory/kerberos/trunk/eve-kerberos-seda/src/java/org/apache/kerberos/kdc/server/seda/KerberosEncoder.java Mon Nov 8 15:30:42 2004 @@ -0,0 +1,44 @@ +/* + * 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.server.seda; + +import org.apache.commons.codec.stateful.AbstractStatefulEncoder; + + +/** + * An encoder for Kerberos replies. + * + * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a> + * @version $Rev: 56478 $ + */ +public class KerberosEncoder extends AbstractStatefulEncoder +{ + /** + * Returns an encoded Kerberos PDU. The codec is an identity + * operation. Each encode call triggers a callback since we're presuming + * each chunk to be a valid PDU while streaming the request back as the + * response. + * + * @param substrate the object to return which is a buffer + */ + public void encode(Object substrate) + { + super.encodeOccurred(substrate); + } +} + Added: incubator/directory/kerberos/trunk/eve-kerberos-seda/src/java/org/apache/kerberos/kdc/server/seda/KerberosHandler.java ============================================================================== --- (empty file) +++ incubator/directory/kerberos/trunk/eve-kerberos-seda/src/java/org/apache/kerberos/kdc/server/seda/KerberosHandler.java Mon Nov 8 15:30:42 2004 @@ -0,0 +1,43 @@ +/* + * 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.server.seda; + + +import org.apache.seda.listener.ClientKey; +import org.apache.seda.protocol.AbstractSingleReplyHandler; + + +/** + * A handler for Kerberos requests that returns Kerberos replies. + * + * @author <a href="mailto:[EMAIL PROTECTED]"> Apache Directory Project</a> + * @version $Rev: 56478 $ + */ +public class KerberosHandler extends AbstractSingleReplyHandler +{ + /** + * Processes Kerberos requests and returns Kerberos replies. + * + * @param request the buffer of data to be processed. + * @return the response to the request. + */ + public Object handle(ClientKey key, Object request) + { + return request; + } +} + Added: incubator/directory/kerberos/trunk/eve-kerberos-seda/src/java/org/apache/kerberos/kdc/server/seda/KerberosProtocolProvider.java ============================================================================== --- (empty file) +++ incubator/directory/kerberos/trunk/eve-kerberos-seda/src/java/org/apache/kerberos/kdc/server/seda/KerberosProtocolProvider.java Mon Nov 8 15:30:42 2004 @@ -0,0 +1,122 @@ +/* + * 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.server.seda; + +import org.apache.commons.codec.stateful.DecoderFactory; +import org.apache.commons.codec.stateful.EncoderFactory; +import org.apache.commons.codec.stateful.StatefulDecoder; +import org.apache.commons.codec.stateful.StatefulEncoder; +import org.apache.seda.listener.ClientKey; +import org.apache.seda.protocol.ProtocolProvider; +import org.apache.seda.protocol.RequestHandler; +import org.apache.seda.protocol.SingleReplyHandler; + + +/** + * An kerberos protocol service provider for the SEDA framework. The provider along + * with the SEDA framework implements an RFC 1510 compliant server. + * + * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a> + * @version $Rev: 56478 $ + */ +public final class KerberosProtocolProvider implements ProtocolProvider +{ + /** the authoritative service name of this internet protocol: 'kerberos' */ + public static final String NAME = "kerberos"; + + /** a null decoder that triggers a callback returning the substrate as is */ + public static final StatefulDecoder KERBEROS_DECODER = + new KerberosDecoder(); + + /** a null encoder that triggers a callback returning the substrate as is */ + public static final StatefulEncoder KERBEROS_ENCODER = + new KerberosEncoder(); + + /** kerberos handler where request is return back as a response */ + public static final SingleReplyHandler KERBEROS_HANDLER = + new KerberosHandler(); + + /** + * Gets the authoritative name for the service of this provider. + * + * @return the authoritative service name + */ + public final String getName() + { + return NAME; + } + + /** + * Gets a factory used to create a new StatefulDecoder for this service's + * protocol. + * + * @return a new StatefulDecoder for this service's protocol + */ + public final DecoderFactory getDecoderFactory() + { + return new DecoderFactory() + { + /** + * Creates a really simple factory for decoders that return back + * thir request in the same decode call; 1:1 decode to callback. + * The same decoder will be returned evertime since no state is + * ever stored by these decoders. + * + * @return a chunking state based decoder + */ + public StatefulDecoder createDecoder() + { + return KERBEROS_DECODER; + } + }; + } + + /** + * Gets a factory used to create a new StatefulEncoder for this service's + * protocol. + * + * @return a new StatefulEncoder for this service's protocol + */ + public EncoderFactory getEncoderFactory() + { + return new EncoderFactory() + { + /** + * Creates a factory that always returns the same encoder which + * never really maintains any state. This encoder simply returns + * the object to encode as is without affecting it in any way. + * + * @return a new chunking state based encoder + */ + public StatefulEncoder createEncoder() + { + return KERBEROS_ENCODER; + } + }; + } + + /** + * @param request the ByteBuffer containing the data to process + * @return the same ByteBuffer without any changes + */ + public RequestHandler getHandler(ClientKey key, Object request) + { + return KERBEROS_HANDLER; + } +} +
