You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@lucene.apache.org by ho...@apache.org on 2006/06/27 21:31:23 UTC

svn commit: r417565 [2/4] - in /lucene/java/trunk/contrib/gdata-server: src/java/org/apache/lucene/gdata/data/ src/java/org/apache/lucene/gdata/server/administration/ src/java/org/apache/lucene/gdata/server/authentication/ src/java/org/apache/lucene/gd...

Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/authentication/BlowfishAuthenticationController.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/authentication/BlowfishAuthenticationController.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/authentication/BlowfishAuthenticationController.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/authentication/BlowfishAuthenticationController.java Tue Jun 27 12:31:20 2006
@@ -0,0 +1,274 @@
+/**
+ * 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.lucene.gdata.server.authentication;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.security.Provider;
+import java.security.Security;
+import java.util.StringTokenizer;
+import java.util.concurrent.locks.ReentrantLock;
+
+import javax.crypto.BadPaddingException;
+import javax.crypto.Cipher;
+import javax.crypto.IllegalBlockSizeException;
+import javax.crypto.KeyGenerator;
+import javax.crypto.spec.SecretKeySpec;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.gdata.data.GDataAccount;
+import org.apache.lucene.gdata.data.GDataAccount.AccountRole;
+import org.apache.lucene.gdata.server.registry.Component;
+import org.apache.lucene.gdata.server.registry.ComponentType;
+
+import sun.misc.BASE64Decoder;
+import sun.misc.BASE64Encoder;
+
+/**
+ * A
+ * {@link org.apache.lucene.gdata.server.authentication.AuthenticationController}
+ * implmentation using a <i>Blowfish</i> algorithmn to en/decrpyt the
+ * authentification token. The <i>Blowfish</i> algorithmn enables a stateless
+ * authetication of the client. The token contains all information to
+ * authenticate the client on possible other hosts.
+ * <p>
+ * The token contains the first 32 bit of the client ip (e.g. 192.168.0),
+ * account name, {@link org.apache.lucene.gdata.data.GDataAccount.AccountRole}
+ * and the cration time as a timestamp. The timestamp will be checked on every
+ * subsequent request. If the timestamp plus the configured timeout is less
+ * than the current time the client has to reauthenticate again.
+ * </p>
+ * <p>
+ * The auth token returned by the
+ * {@link BlowfishAuthenticationController#authenticatAccount(GDataAccount, String)}
+ * method is a BASE64 encoded string.
+ * </p>
+ * 
+ * @see javax.crypto.Cipher
+ * @see sun.misc.BASE64Encoder
+ * @see sun.misc.BASE64Decoder
+ * @author Simon Willnauer
+ * 
+ */
+@Component(componentType = ComponentType.AUTHENTICATIONCONTROLLER)
+public class BlowfishAuthenticationController implements
+        AuthenticationController {
+    private static final Log LOG = LogFactory
+            .getLog(BlowfishAuthenticationController.class);
+
+    private static final String ALG = "Blowfish";
+
+    private static final String TOKEN_LIMITER = "#";
+
+    private static final String ENCODING = "UTF-8";
+
+    private Cipher deCrypt;
+
+    private Cipher enCrypt;
+
+    // TODO make this configurable
+    private int minuteOffset = 30;
+
+    private long milisecondOffset;
+
+    private BASE64Encoder encoder = new BASE64Encoder();
+
+    private BASE64Decoder decoder = new BASE64Decoder();
+
+    private ReentrantLock lock = new ReentrantLock();
+
+    // TODO make this configurable
+    private String key = "myTestKey";
+
+    /**
+     * @see org.apache.lucene.gdata.server.authentication.AuthenticationController#initialize()
+     */
+    public void initialize() {
+        if (this.key == null)
+            throw new IllegalArgumentException("Auth key must not be null");
+        if (this.key.length() < 5 || this.key.length() > 16)
+            throw new IllegalArgumentException(
+                    "Auth key length must be greater than 4 and less than 17");
+
+        try {
+            Provider sunJce = new com.sun.crypto.provider.SunJCE();
+            Security.addProvider(sunJce);
+            KeyGenerator kgen = KeyGenerator.getInstance(ALG);
+            kgen.init(448); // 448 Bit^M
+            byte[] raw = this.key.getBytes();
+            SecretKeySpec skeySpec = new SecretKeySpec(raw, ALG);
+            this.deCrypt = Cipher.getInstance(ALG);
+            this.enCrypt = Cipher.getInstance(ALG);
+            this.deCrypt.init(Cipher.DECRYPT_MODE, skeySpec);
+            this.enCrypt.init(Cipher.ENCRYPT_MODE, skeySpec);
+        } catch (Exception e) {
+            throw new AuthenticatorException(
+                    "Can't initialize BlowfishAuthenticationController -- "
+                            + e.getMessage(), e);
+
+        }
+        calculateTimeOffset();
+    }
+
+    /**
+     * @see org.apache.lucene.gdata.server.authentication.AuthenticationController#authenticatAccount(org.apache.lucene.gdata.data.GDataAccount,
+     *      java.lang.String)
+     */
+    public String authenticatAccount(GDataAccount account, String requestIp) {
+        try {
+            String passIp = requestIp.substring(0, requestIp.lastIndexOf('.'));
+            String role = Integer.toString(account.getRolesAsInt());
+
+            return calculateAuthToken(passIp, role, account.getName());
+        } catch (Exception e) {
+            throw new AuthenticatorException("Can not authenticat account -- "
+                    + e.getMessage(), e);
+
+        }
+    }
+
+    /**
+     * @see org.apache.lucene.gdata.server.authentication.AuthenticationController#authenticateToken(java.lang.String,
+     *      java.lang.String,
+     *      org.apache.lucene.gdata.data.GDataAccount.AccountRole,
+     *      java.lang.String)
+     */
+    public boolean authenticateToken(final String token,
+            final String requestIp, AccountRole role, String accountName) {
+        if (LOG.isInfoEnabled())
+            LOG.info("authenticate Token " + token + " for requestIp: "
+                    + requestIp);
+        if (token == null || requestIp == null)
+            return false;
+        String passIp = requestIp.substring(0, requestIp.lastIndexOf('.'));
+        String authString = null;
+        try {
+            authString = deCryptAuthToken(token);
+        } catch (Exception e) {
+            throw new AuthenticatorException("Can not decrypt token -- "
+                    + e.getMessage(), e);
+        }
+        if (authString == null)
+            return false;
+        try {
+            StringTokenizer tokenizer = new StringTokenizer(authString,
+                    TOKEN_LIMITER);
+            if (!tokenizer.nextToken().equals(passIp))
+                return false;
+            String tempAccountName = tokenizer.nextToken();
+            int intRole = Integer.parseInt(tokenizer.nextToken());
+            /*
+             * Authentication goes either for a account role or a account. For
+             * entry manipulation the account name will be retrieved by the
+             * feedId otherwise it will be null If it is null the authentication
+             * goes against the account role
+             */
+            if (tempAccountName == null
+                    || (!tempAccountName.equals(accountName) && !GDataAccount
+                            .isInRole(intRole, role)))
+                return false;
+            long timeout = Long.parseLong(tokenizer.nextToken());
+
+            return (timeout + this.milisecondOffset) > System
+                    .currentTimeMillis();
+        } catch (Exception e) {
+            LOG.error("Error occured while encrypting token " + e.getMessage(),
+                    e);
+            return false;
+        }
+
+    }
+
+    private void calculateTimeOffset() {
+        this.milisecondOffset = this.minuteOffset * 60 * 1000;
+    }
+
+    protected String calculateAuthToken(final String ipAddress,
+            final String role, String accountName)
+            throws IllegalBlockSizeException, BadPaddingException,
+            UnsupportedEncodingException {
+        StringBuilder builder = new StringBuilder();
+        builder.append(ipAddress).append(TOKEN_LIMITER);
+        builder.append(accountName).append(TOKEN_LIMITER);
+        builder.append(role).append(TOKEN_LIMITER);
+        builder.append(System.currentTimeMillis());
+
+        this.lock.lock();
+        try {
+            byte[] toencode = builder.toString().getBytes(ENCODING);
+            byte[] result = this.enCrypt.doFinal(toencode);
+            return this.encoder.encode(result);
+        } finally {
+            this.lock.unlock();
+
+        }
+
+    }
+
+    protected String deCryptAuthToken(final String authToken)
+            throws IOException, IllegalBlockSizeException, BadPaddingException {
+        this.lock.lock();
+        try {
+            byte[] input = this.decoder.decodeBuffer(authToken);
+            byte[] result = this.deCrypt.doFinal(input);
+            return new String(result, ENCODING);
+        } finally {
+            this.lock.unlock();
+        }
+
+    }
+
+    /**
+     * @return Returns the minuteOffset.
+     */
+    public int getMinuteOffset() {
+        return this.minuteOffset;
+    }
+
+    /**
+     * @param minuteOffset
+     *            The minuteOffset to set.
+     */
+    public void setMinuteOffset(int minuteOffset) {
+        this.minuteOffset = minuteOffset;
+        calculateTimeOffset();
+    }
+
+    /**
+     * @return Returns the key.
+     */
+    public String getKey() {
+        return this.key;
+    }
+
+    /**
+     * @param key
+     *            The key to set.
+     */
+    public void setKey(String key) {
+        this.key = key;
+    }
+
+    /**
+     * @see org.apache.lucene.gdata.server.registry.ServerComponent#destroy()
+     */
+    public void destroy() {
+        //
+    }
+
+}

Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/authentication/GDataHttpAuthenticator.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/authentication/GDataHttpAuthenticator.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/authentication/GDataHttpAuthenticator.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/authentication/GDataHttpAuthenticator.java Tue Jun 27 12:31:20 2006
@@ -0,0 +1,59 @@
+/**
+ * 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.lucene.gdata.server.authentication;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.lucene.gdata.data.GDataAccount.AccountRole;
+import org.apache.lucene.gdata.server.GDataRequest;
+
+/**
+ * The GData protocol is based on the widly know REST approach and therefor
+ * client authentication will mostly be provided via a REST interface.
+ * <p>
+ * This interface describes internally used authentication methods to be
+ * implemented by http based authenticator implementations. The GData Server
+ * basically has 2 different REST interfaces need authentication. One is for
+ * altering feed entries and the other for administration actions.
+ * </p>
+ * <p>The interface altering entries work with {@link com.google.gdata.client.Service.GDataRequest} object created by the handler and passed to the {@link org.apache.lucene.gdata.server.Service} instance.
+ * Administration interfaces use the plain {@link javax.servlet.http.HttpServletRequest} inside the handler.
+ * For each type of interface a authentication type a method has to be provided by implementing classes.</p> 
+ * 
+ * @author Simon Willnauer
+ * 
+ */
+public interface GDataHttpAuthenticator {
+
+    /**
+     * Authenticates the client request based on the given GdataRequst and required account role
+     * @param request - the gdata request
+     * @param role - the required role for passing the authentication
+     * 
+     * @return <code>true</code> if the request successfully authenticates, otherwise <code>false</code>
+     */
+    public boolean authenticateAccount(final GDataRequest request,
+            AccountRole role);
+
+    /**
+     * Authenticates the client request based on the given requst and required account role
+     * @param request - the client request
+     * @param role - the required role for passing the authentication
+     * @return <code>true</code> if the request successfully authenticates, otherwise <code>false</code>
+     */
+    public boolean authenticateAccount(final HttpServletRequest request,
+            AccountRole role);
+}

Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/authentication/package.html
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/authentication/package.html?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/authentication/package.html (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/authentication/package.html Tue Jun 27 12:31:20 2006
@@ -0,0 +1,10 @@
+<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> 
+<html> 
+<head> 
+   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
+   <meta name="Author" content="Simon Willnauer"> 
+</head> 
+<body> 
+Classes and Exceptions used for client authentification.
+</body> 
+</html> 
\ No newline at end of file

Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/Component.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/Component.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/Component.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/Component.java Tue Jun 27 12:31:20 2006
@@ -0,0 +1,74 @@
+/**
+ * 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.lucene.gdata.server.registry;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * The {@link Component} annotation is used to annotate a class as a
+ * server-component of the GDATA-Server. Annotated class can be configured via
+ * the gdata-config.xml file to be looked up by aribaty classes at runtime via
+ * the
+ * {@link org.apache.lucene.gdata.server.registry.GDataServerRegistry#lookup(Class, ComponentType)}
+ * method.
+ * <p>
+ * Classes annotated with the Component annotation need to provide a default
+ * constructor to be instanciated via reflection. Components of the GData-Server
+ * are definded in the
+ * {@link org.apache.lucene.gdata.server.registry.ComponentType} enumeration.
+ * Each of the enum types are annotated with a
+ * {@link org.apache.lucene.gdata.server.registry.SuperType} annotation. This
+ * annotation specifies the super class or interface of the component. A class
+ * annotated with the Component annotation must implement or extends this
+ * defined super-type. This enables developers to use custom implemetations of
+ * the component like a custom {@link org.apache.lucene.gdata.storage.Storage}.
+ * </p>
+ * <p>
+ * Each ComponentType can only registerd once as the
+ * {@link org.apache.lucene.gdata.server.registry.GDataServerRegistry} does not
+ * provide multipe instances of a ComponentType.
+ * </p>
+ * <p>
+ * This annotation can only annotate types and can be accessed at runtime.
+ * {@link java.lang.annotation.Target} ==
+ * {@link java.lang.annotation.ElementType#TYPE} and
+ * {@link java.lang.annotation.Retention} ==
+ * {@link java.lang.annotation.RetentionPolicy#RUNTIME}.
+ * 
+ * @see org.apache.lucene.gdata.server.registry.GDataServerRegistry
+ * @see org.apache.lucene.gdata.server.registry.ComponentType
+ * @see org.apache.lucene.gdata.server.registry.SuperType
+ * 
+ * 
+ * @author Simon Willnauer
+ * 
+ */
+@Target( { TYPE })
+@Retention(value = RUNTIME)
+public @interface Component {
+
+    /**
+     * @see ComponentType
+     * @return - the component type
+     */
+    ComponentType componentType();
+
+}

Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/ComponentType.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/ComponentType.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/ComponentType.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/ComponentType.java Tue Jun 27 12:31:20 2006
@@ -0,0 +1,53 @@
+package org.apache.lucene.gdata.server.registry;
+
+import org.apache.lucene.gdata.server.ServiceFactory;
+import org.apache.lucene.gdata.server.authentication.AuthenticationController;
+import org.apache.lucene.gdata.servlet.handler.RequestHandlerFactory;
+import org.apache.lucene.gdata.storage.StorageController;
+
+/**
+ * The enmueration {@link ComponentType} defines the GDATA-Server Components 
+ * available via {@link org.apache.lucene.gdata.server.registry.GDataServerRegistry#lookup(Class, ComponentType)} 
+ * method.
+ * @see org.apache.lucene.gdata.server.registry.Component
+ * @see org.apache.lucene.gdata.server.registry.GDataServerRegistry 
+ * @author Simon Willnauer
+ *
+ */
+public enum ComponentType {
+    /**
+     * StorageController Type
+     * 
+     * @see StorageController
+     */
+    @SuperType(superType = StorageController.class)
+    STORAGECONTROLLER,
+    /**
+     * RequestHandlerFactory Type
+     * 
+     * @see RequestHandlerFactory
+     */
+    @SuperType(superType = RequestHandlerFactory.class)
+    REQUESTHANDLERFACTORY,
+    /**
+     * INDEXER TYPE
+     * 
+     */
+    // TODO not available yet
+    @SuperType(superType = Object.class)
+    INDEXER,
+    /**
+     * ServiceFactory Type
+     * 
+     * @see ServiceFactory
+     */
+    @SuperType(superType = ServiceFactory.class)
+    SERVICEFACTORY,
+    /**
+     * Supertype for AuthenticationController implementations
+     * @see AuthenticationController
+     */
+    @SuperType(superType = AuthenticationController.class)
+    AUTHENTICATIONCONTROLLER
+
+}

Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/ProvidedService.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/ProvidedService.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/ProvidedService.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/ProvidedService.java Tue Jun 27 12:31:20 2006
@@ -0,0 +1,48 @@
+/** 
+ * 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.lucene.gdata.server.registry;
+
+import com.google.gdata.data.ExtensionProfile;
+
+/**
+ * This interface describes a service provided by the GData-Server.
+ * @see org.apache.lucene.gdata.server.registry.GDataServerRegistry 
+ * @author Simon Willnauer
+ *
+ */
+public interface ProvidedService {
+
+    /** 
+     * @return Returns the feedType. 
+     */
+    public abstract Class getFeedType();
+
+    /** 
+     * @return - the extension profile for this feed 
+     */
+    public abstract ExtensionProfile getExtensionProfile();
+
+    /**
+     * @return the entry Type configured for this Service
+     */
+    public abstract Class getEntryType();
+
+    /**
+     * @return - the servicename
+     */
+    public abstract String getName();
+
+}
\ No newline at end of file

Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/ProvidedServiceConfig.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/ProvidedServiceConfig.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/ProvidedServiceConfig.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/ProvidedServiceConfig.java Tue Jun 27 12:31:20 2006
@@ -0,0 +1,131 @@
+/** 
+ * 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.lucene.gdata.server.registry;
+
+import com.google.gdata.data.ExtensionProfile;
+
+/**
+ * Standart implementation of
+ * {@link org.apache.lucene.gdata.server.registry.ProvidedService} to be used
+ * inside the
+ * {@link org.apache.lucene.gdata.server.registry.GDataServerRegistry}
+ * 
+ * @author Simon Willnauer
+ * 
+ */
+public class ProvidedServiceConfig implements ProvidedService {
+    private String serviceName;
+
+    private Class entryType;
+
+    private Class feedType;
+
+    private ExtensionProfile extensionProfile;
+
+   
+    ProvidedServiceConfig(ExtensionProfile profile, Class feedType,
+            Class entryType, String serviceName) {
+        this.extensionProfile = profile;
+        this.feedType = feedType;
+        this.entryType = entryType;
+        this.serviceName = serviceName;
+
+    }
+
+    /**
+     * Default constructor to instanciate via reflection 
+     */
+    public ProvidedServiceConfig() {
+        //
+    }
+
+    /**
+     * @see org.apache.lucene.gdata.server.registry.ProvidedService#getFeedType()
+     */
+    public Class getFeedType() {
+        return this.feedType;
+    }
+
+    /**
+     * @param feedType
+     *            The feedType to set.
+     */
+    public void setFeedType(Class feedType) {
+        this.feedType = feedType;
+    }
+
+    /**
+     * @see org.apache.lucene.gdata.server.registry.ProvidedService#getExtensionProfile()
+     */
+    public ExtensionProfile getExtensionProfile() {
+        return this.extensionProfile;
+    }
+
+    /**
+     * @param extensionProfil -
+     *            the extensionprofile for this feed configuration
+     */
+    public void setExtensionProfile(ExtensionProfile extensionProfil) {
+        this.extensionProfile = extensionProfil;
+    }
+
+    
+    /**
+     *TODO add comment
+     * @param <E>
+     * @param extensionProfileClass
+     * @throws InstantiationException
+     * @throws IllegalAccessException
+     */
+    public <E extends ExtensionProfile> void setExtensionProfileClass(
+            Class<E> extensionProfileClass) throws InstantiationException,
+            IllegalAccessException {
+        if (extensionProfileClass == null)
+            throw new IllegalArgumentException(
+                    "ExtensionProfile class must not be null");
+
+        this.extensionProfile = extensionProfileClass.newInstance();
+    }
+
+    /**
+     * @see org.apache.lucene.gdata.server.registry.ProvidedService#getEntryType()
+     */
+    public Class getEntryType() {
+        return this.entryType;
+    }
+    
+    /**
+     * @param entryType
+     */
+    public void setEntryType(Class entryType) {
+        this.entryType = entryType;
+    }
+
+    /**
+     * @see org.apache.lucene.gdata.server.registry.ProvidedService#getName()
+     */
+    public String getName() {
+        return this.serviceName;
+    }
+
+    /**
+     * @param serviceName
+     */
+    public void setName(String serviceName) {
+        this.serviceName = serviceName;
+    }
+
+}

Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/RegistryException.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/RegistryException.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/RegistryException.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/RegistryException.java Tue Jun 27 12:31:20 2006
@@ -0,0 +1,51 @@
+package org.apache.lucene.gdata.server.registry;
+
+/**
+ * This exception is thrown by the
+ * {@link org.apache.lucene.gdata.server.registry.GDataServerRegistry} if
+ * registering a service or a component fails.
+ * 
+ * @author Simon Willnauer
+ * 
+ */
+public class RegistryException extends Exception {
+
+ 
+    private static final long serialVersionUID = -3563720639871194466L;
+
+    /**
+     * Constructs a new Registry Exception.
+     */
+    public RegistryException() {
+        super();
+        
+    }
+
+    /**
+     * Constructs a new Registry Exception with the specified detail message.
+     * @param arg0 - detail message
+     */
+    public RegistryException(String arg0) {
+        super(arg0);
+        
+    }
+
+    /**
+     * Constructs a new Registry Exception with the specified detail message and nested exception.
+     * @param arg0 - detail message
+     * @param arg1 - nested exception
+     */
+    public RegistryException(String arg0, Throwable arg1) {
+        super(arg0, arg1);
+        
+    }
+
+    /** Constructs a new Registry Exception with a nested exception.
+     * @param arg0 - nested exception
+     */
+    public RegistryException(Throwable arg0) {
+        super(arg0);
+        
+    }
+
+}

Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/ServerComponent.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/ServerComponent.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/ServerComponent.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/ServerComponent.java Tue Jun 27 12:31:20 2006
@@ -0,0 +1,42 @@
+/**
+ * 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.lucene.gdata.server.registry;
+
+/**
+ * To Register a class as a component in the
+ * {@link org.apache.lucene.gdata.server.registry.GDataServerRegistry} the class
+ * or a super class must implements this interface.
+ * <p>
+ * <tt>ServerComponent</tt> defines a method <tt>initialize</tt> and
+ * <tt>destroy</tt>. <tt>initialize</tt> will be called when the component
+ * is registered and <tt>destroy</tt> when the registry is destroyed (usually
+ * at server shut down).</p>
+ * @see org.apache.lucene.gdata.server.registry.GDataServerRegistry
+ * @author Simon Willnauer
+ * 
+ */
+public interface ServerComponent {
+    /**
+     * will be call when the component is registered.
+     */
+    public abstract void initialize();
+
+    /**
+     * will be called when the registry is going down e.g. when the  {@link GDataServerRegistry#destroy()} method is called.
+     */
+    public abstract void destroy();
+}

Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/SuperType.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/SuperType.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/SuperType.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/SuperType.java Tue Jun 27 12:31:20 2006
@@ -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.lucene.gdata.server.registry;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * This Annotation is use to annotate
+ * {@link org.apache.lucene.gdata.server.registry.ComponentType} elements to
+ * specify an interface e.g. super type of a defined component.
+ * <p>This annotation will be visible at runtime</p>
+ * @see org.apache.lucene.gdata.server.registry.Component
+ * @see org.apache.lucene.gdata.server.registry.GDataServerRegistry
+ * 
+ * @author Simon Willnauer
+ * 
+ */
+@Target( { FIELD })
+@Retention(value = RUNTIME)
+public @interface SuperType {
+    /**
+     * 
+     * @return the specified super type
+     */
+    Class superType();
+}

Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/AccountAdministrationServlet.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/AccountAdministrationServlet.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/AccountAdministrationServlet.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/AccountAdministrationServlet.java Tue Jun 27 12:31:20 2006
@@ -0,0 +1,73 @@
+/**
+ * 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.lucene.gdata.servlet;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.gdata.servlet.handler.GDataRequestHandler;
+
+/**
+ * This Servlet provides an REST interface to create / update and delete user instances.
+ * @author Simon Willnauer
+ *
+ */
+public class AccountAdministrationServlet extends AbstractGdataServlet {
+   
+    private static final Log LOGGER = LogFactory.getLog(AccountAdministrationServlet.class);
+
+    /**
+     * 
+     */
+    private static final long serialVersionUID = 8215863212137543185L;
+
+    @Override
+    protected void doDelete(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException {
+        GDataRequestHandler handler = HANDLER_FACTORY.getDeleteAccountHandler();
+        if(LOGGER.isInfoEnabled())
+            LOGGER.info("Process delete Account request");
+        handler.processRequest(arg0,arg1);
+       
+    }
+
+    @Override
+    protected void doPost(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException {
+        GDataRequestHandler handler = HANDLER_FACTORY.getInsertAccountHandler();
+        if(LOGGER.isInfoEnabled())
+            LOGGER.info("Process insert Account request");
+        handler.processRequest(arg0,arg1);        
+       
+    }
+
+    @Override
+    protected void doPut(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException {
+        
+        GDataRequestHandler handler = HANDLER_FACTORY.getUpdateAccountHandler();
+        if(LOGGER.isInfoEnabled())
+            LOGGER.info("Process update Account request");
+        handler.processRequest(arg0,arg1);  
+    }
+    
+   
+   
+
+}

Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/AuthenticationServlet.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/AuthenticationServlet.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/AuthenticationServlet.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/AuthenticationServlet.java Tue Jun 27 12:31:20 2006
@@ -0,0 +1,50 @@
+/**
+ * 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.lucene.gdata.servlet;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.lucene.gdata.servlet.handler.AuthenticationHandler;
+
+/**
+ * REST interface for handling authentification requests from clients to get a
+ * auth token either as a cookie or as a plain auth token. This Servlet uses a
+ * single {@link org.apache.lucene.gdata.servlet.handler.AuthenticationHandler}
+ * instance to handle the incoming requests.
+ * 
+ * @author Simon Willnauer
+ * 
+ */
+public class AuthenticationServlet extends HttpServlet {
+
+    private final AuthenticationHandler handler = new AuthenticationHandler();
+
+    private static final long serialVersionUID = 7132478125868917848L;
+
+    @SuppressWarnings("unused")
+    @Override
+    protected void doPost(HttpServletRequest request,
+            HttpServletResponse response) throws ServletException, IOException {
+        this.handler.processRequest(request, response);
+    }
+
+}

Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/FeedAdministrationServlet.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/FeedAdministrationServlet.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/FeedAdministrationServlet.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/FeedAdministrationServlet.java Tue Jun 27 12:31:20 2006
@@ -0,0 +1,71 @@
+/**
+ * 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.lucene.gdata.servlet;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.gdata.servlet.handler.GDataRequestHandler;
+
+/**
+ * This Servlet provides an REST interface to create / update and delete Feed instances.
+ *  
+ * @author Simon Willnauer
+ *
+ */
+public class FeedAdministrationServlet extends AbstractGdataServlet {
+    private static final Log LOGGER = LogFactory.getLog(FeedAdministrationServlet.class);
+    /**
+     * 
+     */
+    private static final long serialVersionUID = -905586350743277032L;
+
+    @Override
+    protected void doDelete(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException {
+        GDataRequestHandler handler = HANDLER_FACTORY.getDeleteFeedHandler();
+        if(LOGGER.isInfoEnabled())
+            LOGGER.info("Process delete feed request");
+        handler.processRequest(arg0,arg1);
+     
+    }
+
+    @Override
+    protected void doPost(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException {
+        GDataRequestHandler handler = HANDLER_FACTORY.getInsertFeedHandler();
+        if(LOGGER.isInfoEnabled())
+            LOGGER.info("Process insert feed request");
+        handler.processRequest(arg0,arg1);
+     
+    }
+
+    @Override
+    protected void doPut(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException {
+        GDataRequestHandler handler = HANDLER_FACTORY.getUpdateFeedHandler();
+        if(LOGGER.isInfoEnabled())
+            LOGGER.info("Process update feed request");
+        handler.processRequest(arg0,arg1);
+     
+    }
+
+  
+
+}

Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/AbstractAccountHandler.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/AbstractAccountHandler.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/AbstractAccountHandler.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/AbstractAccountHandler.java Tue Jun 27 12:31:20 2006
@@ -0,0 +1,186 @@
+/**
+ * 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.lucene.gdata.servlet.handler;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.gdata.data.GDataAccount;
+import org.apache.lucene.gdata.data.GDataAccount.AccountRole;
+import org.apache.lucene.gdata.server.ServiceException;
+import org.apache.lucene.gdata.server.ServiceFactory;
+import org.apache.lucene.gdata.server.administration.AccountBuilder;
+import org.apache.lucene.gdata.server.administration.AdminService;
+import org.apache.lucene.gdata.server.registry.ComponentType;
+import org.apache.lucene.gdata.server.registry.GDataServerRegistry;
+import org.xml.sax.SAXException;
+
+/**
+ * @author Simon Willnauer
+ * 
+ */
+public abstract class AbstractAccountHandler extends RequestAuthenticator
+        implements GDataRequestHandler {
+    private static final Log LOG = LogFactory
+            .getLog(AbstractAccountHandler.class);
+
+    private boolean authenticated = false;
+
+    private int error;
+
+    private String errorMessage = "";
+
+    private boolean isError = false;
+
+    protected AdminService service;
+
+    /**
+     * @see org.apache.lucene.gdata.servlet.handler.GDataRequestHandler#processRequest(javax.servlet.http.HttpServletRequest,
+     *      javax.servlet.http.HttpServletResponse)
+     */
+    @SuppressWarnings("unused")
+    public void processRequest(HttpServletRequest request,
+            HttpServletResponse response) throws ServletException, IOException {
+        
+            this.authenticated = authenticateAccount(request,
+                AccountRole.USERADMINISTRATOR);
+        
+        if (this.authenticated) {
+            GDataServerRegistry registry = GDataServerRegistry.getRegistry();
+            ServiceFactory factory = registry.lookup(ServiceFactory.class,
+                    ComponentType.SERVICEFACTORY);
+            try {
+
+                GDataAccount account = getAccountFromRequest(request);
+                if (!account.requiredValuesSet()) {
+                    setError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+                            "requiered server component not available");
+                    throw new AccountHandlerException(
+                            "requiered values are not set -- account can not be saved -- "
+                                    + account);
+                }
+                this.service = factory.getAdminService();
+                processServiceAction(account);
+            } catch (ServiceException e) {
+                LOG.error("Can't process account action -- " + e.getMessage(),
+                        e);
+                setError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "");
+            } catch (Exception e) {
+                LOG.error("Can't process account action -- " + e.getMessage(),
+                        e);
+            }
+        }else{
+            setError(HttpServletResponse.SC_UNAUTHORIZED,"Authorization failed");
+        }
+        sendResponse(response);
+
+    }
+    
+    
+    
+
+    protected GDataAccount getAccountFromRequest(
+            final HttpServletRequest request) throws AccountHandlerException {
+        try {
+            GDataAccount account = AccountBuilder.buildAccount(request
+                    .getReader());
+            if (account == null) {
+                setError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "");
+                throw new AccountHandlerException(
+                        "unexpected value -- parsed account is null");
+            }
+            return account;
+        } catch (IOException e) {
+            setError(HttpServletResponse.SC_BAD_REQUEST, "can not read input");
+            throw new AccountHandlerException("Can't read from request reader",
+                    e);
+        } catch (SAXException e) {
+            setError(HttpServletResponse.SC_BAD_REQUEST,
+                    "can not parse gdata account");
+            throw new AccountHandlerException(
+                    "Can not parse incoming gdata account", e);
+        }
+    }
+
+    protected void sendResponse(HttpServletResponse response) {
+
+        if (!this.isError)
+            return;
+        try {
+            response.sendError(this.error, this.errorMessage);
+        } catch (IOException e) {
+            LOG.warn("can send error in RequestHandler ", e);
+        }
+    }
+
+    protected void setError(int error, String message) {
+        this.error = error;
+        this.errorMessage = message;
+        this.isError = true;
+    }
+
+    protected int getErrorCode() {
+        return this.error;
+    }
+
+    protected String getErrorMessage() {
+        return this.errorMessage;
+    }
+
+    protected abstract void processServiceAction(final GDataAccount account)
+            throws ServiceException;
+
+    static class AccountHandlerException extends Exception {
+
+        /**
+         * 
+         */
+        private static final long serialVersionUID = 3140463271122190694L;
+
+        /**
+         * Constructs a new <tt>AccountHandlerException</tt> with an exception
+         * message and the exception caused this exception.
+         * 
+         * @param arg0 -
+         *            the exception message
+         * @param arg1 -
+         *            the exception cause
+         */
+        public AccountHandlerException(String arg0, Throwable arg1) {
+            super(arg0, arg1);
+
+        }
+
+        /**
+         * Constructs a new <tt>AccountHandlerException</tt> with an exception
+         * message.
+         * 
+         * @param arg0 -
+         *            the exception message
+         */
+        public AccountHandlerException(String arg0) {
+            super(arg0);
+
+        }
+
+    }
+}

Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/AbstractFeedHandler.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/AbstractFeedHandler.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/AbstractFeedHandler.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/AbstractFeedHandler.java Tue Jun 27 12:31:20 2006
@@ -0,0 +1,173 @@
+/**
+ * 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.lucene.gdata.servlet.handler;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.gdata.data.GDataAccount;
+import org.apache.lucene.gdata.data.ServerBaseFeed;
+import org.apache.lucene.gdata.data.GDataAccount.AccountRole;
+import org.apache.lucene.gdata.server.GDataEntityBuilder;
+import org.apache.lucene.gdata.server.ServiceException;
+import org.apache.lucene.gdata.server.ServiceFactory;
+import org.apache.lucene.gdata.server.administration.AdminService;
+import org.apache.lucene.gdata.server.registry.ComponentType;
+import org.apache.lucene.gdata.server.registry.GDataServerRegistry;
+import org.apache.lucene.gdata.server.registry.ProvidedService;
+
+import com.google.gdata.util.ParseException;
+
+/**
+ * 
+ * @author Simon Willnauer
+ *
+ */
+public abstract class AbstractFeedHandler extends RequestAuthenticator implements GDataRequestHandler {
+    private static final Log LOG = LogFactory.getLog(AbstractFeedHandler.class);
+
+    protected static final String PARAMETER_ACCOUNT = "account";
+
+    protected static final String PARAMETER_SERVICE = "service";
+    private int error;
+    protected boolean authenticated = false;
+    
+      private String errorMessage = "";
+      private boolean isError = false;
+      
+    /**
+     * @see org.apache.lucene.gdata.servlet.handler.GDataRequestHandler#processRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
+     */
+    @SuppressWarnings("unused")
+    public void processRequest(HttpServletRequest request,
+            HttpServletResponse response) throws ServletException, IOException {
+            this.authenticated = authenticateAccount(request,AccountRole.FEEDAMINISTRATOR);
+            if(!this.authenticated)
+                setError(HttpServletResponse.SC_UNAUTHORIZED,"Authorization failed");
+        
+    }
+    
+    protected ServerBaseFeed createFeedFromRequest(HttpServletRequest request) throws ParseException, IOException, FeedHandlerException{
+        GDataServerRegistry registry = GDataServerRegistry.getRegistry();
+        String providedService = request.getParameter(PARAMETER_SERVICE);
+        if(!registry.isServiceRegistered(providedService)){
+            setError(HttpServletResponse.SC_NOT_FOUND,"no such service");
+            throw new FeedHandlerException("ProvicdedService is not registered -- Name: "+providedService);
+         }
+        ProvidedService provServiceInstance = registry.getProvidedService(providedService);  
+        if(providedService == null){
+            setError(HttpServletResponse.SC_BAD_REQUEST,"no such service");
+            throw new FeedHandlerException("no such service registered -- "+providedService);
+        }
+        try{
+            ServerBaseFeed retVal = new ServerBaseFeed(GDataEntityBuilder.buildFeed(request.getReader(),provServiceInstance));
+            retVal.setServiceConfig(provServiceInstance);
+        return retVal;
+        }catch (IOException e) {
+            if(LOG.isInfoEnabled())
+                LOG.info("Can not read from input stream - ",e);
+            setError(HttpServletResponse.SC_BAD_REQUEST,"Can not read from input stream");
+            throw e;
+        }catch (ParseException e) {
+            if(LOG.isInfoEnabled())
+                LOG.info("feed can not be parsed - ",e);
+            setError(HttpServletResponse.SC_BAD_REQUEST,"incoming feed can not be parsed");
+            throw e;
+        }
+        
+    }
+    
+    
+    protected GDataAccount createRequestedAccount(HttpServletRequest request) throws FeedHandlerException{
+        GDataServerRegistry registry = GDataServerRegistry.getRegistry();
+           ServiceFactory serviceFactory = registry.lookup(ServiceFactory.class,ComponentType.SERVICEFACTORY);
+        
+        if(serviceFactory == null){
+            setError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Required server component not available");
+            throw new FeedHandlerException("Required server component not available -- "+ServiceFactory.class.getName());
+        }
+        AdminService service = serviceFactory.getAdminService();
+        String account = request.getParameter(PARAMETER_ACCOUNT);
+        try{
+        return service.getAccount(account);
+        }catch (ServiceException e) {
+            if(LOG.isInfoEnabled())
+                LOG.info("no account for requested account - "+account,e);
+            setError(HttpServletResponse.SC_BAD_REQUEST,"no such account");
+            throw new FeedHandlerException(e.getMessage(),e);
+        }
+    }
+    
+    protected void sendResponse(HttpServletResponse response){
+        
+        if(!this.isError)
+            return;
+        try{
+        response.sendError(this.error,this.errorMessage);
+        }catch (IOException e) {
+            LOG.warn("can send error in RequestHandler ",e);
+        }
+    }
+    
+    protected void setError(int error, String message){
+        this.error = error;
+        this.errorMessage = message;
+        this.isError = true;
+    }
+    protected int getErrorCode(){
+        return this.error;
+    }
+    
+    protected String getErrorMessage(){
+        return this.errorMessage;
+    }
+    
+    class FeedHandlerException extends Exception{
+
+        /**
+         * 
+         */
+        private static final long serialVersionUID = 1L;
+
+        /**
+         * Creates a new FeedHandlerException with a exception message and the exception cause this ex.
+         * @param arg0 - the message
+         * @param arg1 - the cause
+         */
+        public FeedHandlerException(String arg0, Throwable arg1) {
+            super(arg0, arg1);
+       
+        }
+
+        /**
+         * Creates a new FeedHandlerException with a exception message.
+         * @param arg0 - message
+         */
+        public FeedHandlerException(String arg0) {
+            super(arg0 );
+            
+        }
+        
+    }
+    
+
+}

Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/AuthenticationHandler.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/AuthenticationHandler.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/AuthenticationHandler.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/AuthenticationHandler.java Tue Jun 27 12:31:20 2006
@@ -0,0 +1,124 @@
+/**
+ * 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.lucene.gdata.servlet.handler;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.gdata.data.GDataAccount;
+import org.apache.lucene.gdata.server.ServiceException;
+import org.apache.lucene.gdata.server.ServiceFactory;
+import org.apache.lucene.gdata.server.administration.AdminService;
+import org.apache.lucene.gdata.server.authentication.AuthenticationController;
+import org.apache.lucene.gdata.server.authentication.AuthenticationException;
+import org.apache.lucene.gdata.server.registry.ComponentType;
+import org.apache.lucene.gdata.server.registry.GDataServerRegistry;
+
+
+
+/**
+ * @author Simon Willnauer
+ *
+ */
+public class AuthenticationHandler implements GDataRequestHandler {
+    private static final Log LOG = LogFactory.getLog(AuthenticationHandler.class);
+    private final AuthenticationController controller;
+    private final static String errorKey = "Error";
+    private final static char seperatory = '=';
+    private final ServiceFactory serviceFactory;
+    private final GDataServerRegistry registry;
+    /**
+     * 
+     */
+    public AuthenticationHandler() {
+        this.registry = GDataServerRegistry.getRegistry();
+        this.controller = this.registry.lookup(AuthenticationController.class, ComponentType.AUTHENTICATIONCONTROLLER);
+        this.serviceFactory = this.registry.lookup(ServiceFactory.class, ComponentType.SERVICEFACTORY);
+    }
+
+    /**
+     * @see org.apache.lucene.gdata.servlet.handler.GDataRequestHandler#processRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
+     */
+    @SuppressWarnings("unused")
+    public void processRequest(HttpServletRequest request,
+            HttpServletResponse response) throws ServletException, IOException {
+        
+        try {
+        String serviceName = request.getParameter(AuthenticationController.SERVICE_PARAMETER);
+        if(LOG.isInfoEnabled()){
+            String application = request.getParameter(AuthenticationController.APPLICATION_PARAMETER);
+            LOG.info("Authentication request for service: "+serviceName+"; Application name: "+application);
+        }
+        
+        if(!this.registry.isServiceRegistered(serviceName))
+            throw new AuthenticationException("requested Service "+serviceName+"is not registered");
+        String password = request.getParameter(AuthenticationController.PASSWORD_PARAMETER);
+        String accountName = request.getParameter(AuthenticationController.ACCOUNT_PARAMETER);
+        String clientIp = request.getRemoteHost();
+        
+       
+        
+        GDataAccount  account = getAccount(accountName);
+        if(account == null || !account.getPassword().equals(password))
+            throw new AuthenticationException("Account is null or password does not match");
+        
+        String token = this.controller.authenticatAccount(account,clientIp);
+        sendToken(response,token);
+        if(LOG.isInfoEnabled()){
+            
+            LOG.info("Account authenticated -- "+account);
+        }
+        } catch (AuthenticationException e){
+            LOG.error("BadAuthentication -- "+e.getMessage(),e);
+            sendError(response, HttpServletResponse.SC_FORBIDDEN,"BadAuthentication");
+        }catch (Exception e) {
+            LOG.error("Unexpected Exception -- SERVERERROR -- "+e.getMessage(),e);
+            sendError(response,HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Service not available");
+        }
+    }
+    
+    
+   private GDataAccount getAccount(String accountName) throws ServiceException{
+       AdminService service = this.serviceFactory.getAdminService();
+       return service.getAccount(accountName);
+        
+    }
+   private void sendError(HttpServletResponse response, int code, String message)throws IOException{
+       Writer writer = response.getWriter();
+       writer.write(errorKey);
+       writer.write(seperatory);
+       writer.write(message);
+       response.sendError(code);
+   }
+   
+   private void sendToken(HttpServletResponse response, String token) throws IOException{
+       Writer responseWriter = response.getWriter();
+       Cookie cookie = new Cookie(AuthenticationController.TOKEN_KEY,token);
+       response.addCookie(cookie);
+       responseWriter.write(AuthenticationController.TOKEN_KEY);
+       responseWriter.write(seperatory);
+       responseWriter.write(token);
+       responseWriter.close();
+   }
+}

Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/DeleteAccountStrategy.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/DeleteAccountStrategy.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/DeleteAccountStrategy.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/DeleteAccountStrategy.java Tue Jun 27 12:31:20 2006
@@ -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.lucene.gdata.servlet.handler;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.gdata.data.GDataAccount;
+import org.apache.lucene.gdata.server.ServiceException;
+
+/**
+ * @author Simon Willnauer
+ *
+ */
+public class DeleteAccountStrategy extends AbstractAccountHandler {
+
+    private static final Log LOG = LogFactory.getLog(DefaultDeleteHandler.class);
+
+    
+
+    @Override
+    protected void processServiceAction(GDataAccount account) throws ServiceException {
+        try{
+        this.service.deleteAccount(account);
+        }catch (ServiceException e) {
+            LOG.error("Can't delete account -- "+e.getMessage(),e);
+            throw e;
+        }
+        
+    }
+}

Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/DeleteFeedHandler.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/DeleteFeedHandler.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/DeleteFeedHandler.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/DeleteFeedHandler.java Tue Jun 27 12:31:20 2006
@@ -0,0 +1,81 @@
+/**
+ * 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.lucene.gdata.servlet.handler;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.gdata.data.ServerBaseFeed;
+import org.apache.lucene.gdata.server.ServiceFactory;
+import org.apache.lucene.gdata.server.registry.ComponentType;
+import org.apache.lucene.gdata.server.registry.GDataServerRegistry;
+
+/**
+ * @author Simon Willnauer
+ *
+ */
+public class DeleteFeedHandler extends AbstractFeedHandler{
+    private static final Log LOG = LogFactory.getLog(DeleteFeedHandler.class);
+
+    /**
+     * @throws IOException 
+     * @see org.apache.lucene.gdata.servlet.handler.GDataRequestHandler#processRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
+     */
+    @Override
+    public void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+            super.processRequest(request,response);
+            if(this.authenticated){
+            try {
+                ServerBaseFeed feed = createDeleteFeed(request);
+                
+                GDataServerRegistry registry = GDataServerRegistry.getRegistry();
+                ServiceFactory serviceFactory = registry.lookup(ServiceFactory.class,ComponentType.SERVICEFACTORY);
+                if(serviceFactory == null){
+                    setError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,"required component is not available");
+                    throw new FeedHandlerException("Can't save feed - ServiceFactory is null");
+                }
+                serviceFactory.getAdminService().deleteFeed(feed);
+            } catch (FeedHandlerException e) {
+                LOG.error("Can not delete feed -- "+e.getMessage(),e);
+            }catch (Exception e) {
+                LOG.error("Can not delete feed -- "+e.getMessage(),e);
+                setError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,"can not create feed");
+            } 
+            }
+            sendResponse(response);
+           
+        
+        
+    }
+
+    private ServerBaseFeed createDeleteFeed(final HttpServletRequest request) throws FeedHandlerException {
+        String feedId = request.getParameter("feedid");
+        if(feedId == null){
+            setError(HttpServletResponse.SC_BAD_REQUEST,"No feed id specified");
+            throw new FeedHandlerException("no feed Id specified");
+        }
+        ServerBaseFeed retVal = new ServerBaseFeed();
+        retVal.setId(feedId);
+        return retVal;
+    }
+
+}

Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/InsertAccountStrategy.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/InsertAccountStrategy.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/InsertAccountStrategy.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/InsertAccountStrategy.java Tue Jun 27 12:31:20 2006
@@ -0,0 +1,48 @@
+/**
+ * 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.lucene.gdata.servlet.handler;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.gdata.data.GDataAccount;
+import org.apache.lucene.gdata.server.ServiceException;
+
+/**
+ * @author Simon Willnauer
+ * 
+ */
+public class InsertAccountStrategy extends AbstractAccountHandler {
+    private static final Log LOG = LogFactory.getLog(InsertAccountStrategy.class);
+   
+  
+
+    @Override
+    protected void processServiceAction(GDataAccount account) throws ServiceException {
+        try{
+        this.service.createAccount(account);
+        }catch (ServiceException e) {
+            LOG.error("Can't create account -- "+e.getMessage(),e);
+            throw e;
+        }
+        
+    }
+
+
+
+    
+
+}

Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/InsertFeedHandler.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/InsertFeedHandler.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/InsertFeedHandler.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/InsertFeedHandler.java Tue Jun 27 12:31:20 2006
@@ -0,0 +1,78 @@
+/**
+ * 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.lucene.gdata.servlet.handler;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.gdata.data.GDataAccount;
+import org.apache.lucene.gdata.data.ServerBaseFeed;
+import org.apache.lucene.gdata.server.ServiceException;
+import org.apache.lucene.gdata.server.ServiceFactory;
+import org.apache.lucene.gdata.server.registry.ComponentType;
+import org.apache.lucene.gdata.server.registry.GDataServerRegistry;
+
+/**
+ * @author Simon Willnauer
+ * 
+ */
+public class InsertFeedHandler extends AbstractFeedHandler {
+    private static final Log LOG = LogFactory.getLog(InsertFeedHandler.class);
+
+    /**
+     * @see org.apache.lucene.gdata.servlet.handler.GDataRequestHandler#processRequest(javax.servlet.http.HttpServletRequest,
+     *      javax.servlet.http.HttpServletResponse)
+     */
+    @SuppressWarnings("unused")
+    public void processRequest(HttpServletRequest request,
+            HttpServletResponse response) throws ServletException, IOException {
+        super.processRequest(request, response);
+        if (this.authenticated) {
+            try {
+                ServerBaseFeed feed = createFeedFromRequest(request);
+                GDataAccount account = createRequestedAccount(request);
+
+                GDataServerRegistry registry = GDataServerRegistry
+                        .getRegistry();
+                ServiceFactory serviceFactory = registry.lookup(
+                        ServiceFactory.class, ComponentType.SERVICEFACTORY);
+                if (serviceFactory == null) {
+                    setError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+                            "required component is not available");
+                    throw new FeedHandlerException(
+                            "Can't save feed - ServiceFactory is null");
+                }
+                serviceFactory.getAdminService().createFeed(feed, account);
+            } catch (ServiceException e) {
+                setError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+                        "can not create feed");
+                LOG.error("Can not create feed -- " + e.getMessage(), e);
+            } catch (Exception e) {
+                LOG.error("Can not create feed -- " + e.getMessage(), e);
+
+            }
+
+        }
+        sendResponse(response);
+    }
+
+}

Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/RequestAuthenticator.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/RequestAuthenticator.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/RequestAuthenticator.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/RequestAuthenticator.java Tue Jun 27 12:31:20 2006
@@ -0,0 +1,145 @@
+/**
+ * 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.lucene.gdata.servlet.handler;
+
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.gdata.data.GDataAccount;
+import org.apache.lucene.gdata.data.GDataAccount.AccountRole;
+import org.apache.lucene.gdata.server.GDataRequest;
+import org.apache.lucene.gdata.server.ServiceException;
+import org.apache.lucene.gdata.server.ServiceFactory;
+import org.apache.lucene.gdata.server.administration.AdminService;
+import org.apache.lucene.gdata.server.authentication.AuthenticationController;
+import org.apache.lucene.gdata.server.authentication.AuthenticatorException;
+import org.apache.lucene.gdata.server.authentication.GDataHttpAuthenticator;
+import org.apache.lucene.gdata.server.registry.ComponentType;
+import org.apache.lucene.gdata.server.registry.GDataServerRegistry;
+
+/**
+ * The RequestAuthenticator provides access to the registered
+ * {@link org.apache.lucene.gdata.server.authentication.AuthenticationController}
+ * as a super class for all request handler requiereing authentication for
+ * access. This class implements the
+ * {@link org.apache.lucene.gdata.server.authentication.GDataHttpAuthenticator}
+ * to get the auth token from the given request and call the needed Components
+ * to authenticat the client.
+ * <p>
+ * For request handler handling common requests like entry insert or update the
+ * authentication will be based on the account name verified as the owner of the
+ * feed to alter. If the accountname in the token does not match the name of the
+ * account which belongs to the feed the given role will be used for
+ * autentication. Authentication using the
+ * {@link RequestAuthenticator#authenticateAccount(HttpServletRequest, AccountRole)}
+ * method, the account name will be ignored, authentication will be based on the
+ * given <tt>AccountRole</tt>
+ * </p>
+ * 
+ * @author Simon Willnauer
+ * 
+ */
+public class RequestAuthenticator implements GDataHttpAuthenticator {
+    private static final Log LOG = LogFactory
+            .getLog(RequestAuthenticator.class);
+
+    /**
+     * @see org.apache.lucene.gdata.server.authentication.GDataHttpAuthenticator#authenticateAccount(org.apache.lucene.gdata.server.GDataRequest,
+     *      org.apache.lucene.gdata.data.GDataAccount.AccountRole)
+     */
+    public boolean authenticateAccount(GDataRequest request, AccountRole role) {
+        String clientIp = request.getRemoteAddress();
+        if (LOG.isDebugEnabled())
+            LOG
+                    .debug("Authenticating Account for GDataRequest -- modifying entries -- Role: "
+                            + role + "; ClientIp: " + clientIp);
+
+        AuthenticationController controller = GDataServerRegistry.getRegistry()
+                .lookup(AuthenticationController.class,
+                        ComponentType.AUTHENTICATIONCONTROLLER);
+        ServiceFactory factory = GDataServerRegistry.getRegistry().lookup(
+                ServiceFactory.class, ComponentType.SERVICEFACTORY);
+        AdminService adminService = factory.getAdminService();
+        GDataAccount account;
+        try {
+            account = adminService.getFeedOwningAccount(request.getFeedId());
+            String token = getTokenFromRequest(request.getHttpServletRequest());
+            if (LOG.isDebugEnabled())
+                LOG.debug("Got Token: " + token + "; for requesting account: "
+                        + account);
+            if (account != null && token != null)
+                return controller.authenticateToken(token, clientIp,
+                        AccountRole.ENTRYAMINISTRATOR, account.getName());
+
+        } catch (ServiceException e) {
+            LOG.error("can get GDataAccount for feedID -- "
+                    + request.getFeedId(), e);
+            throw new AuthenticatorException(" Service exception occured", e);
+
+        }
+
+        return false;
+    }
+
+    /**
+     * @see org.apache.lucene.gdata.server.authentication.GDataHttpAuthenticator#authenticateAccount(javax.servlet.http.HttpServletRequest,
+     *      org.apache.lucene.gdata.data.GDataAccount.AccountRole)
+     */
+    public boolean authenticateAccount(HttpServletRequest request,
+            AccountRole role) {
+        String clientIp = request.getRemoteAddr();
+        if (LOG.isDebugEnabled())
+            LOG
+                    .debug("Authenticating Account for GDataRequest -- modifying entries -- Role: "
+                            + role + "; ClientIp: " + clientIp);
+        AuthenticationController controller = GDataServerRegistry.getRegistry()
+                .lookup(AuthenticationController.class,
+                        ComponentType.AUTHENTICATIONCONTROLLER);
+        String token = getTokenFromRequest(request);
+        if (LOG.isDebugEnabled())
+            LOG.debug("Got Token: " + token + ";");
+        if (token == null)
+            return false;
+        return controller.authenticateToken(token, clientIp, role, null);
+
+    }
+
+    protected String getTokenFromRequest(HttpServletRequest request) {
+        String token = request
+                .getHeader(AuthenticationController.AUTHORIZATION_HEADER);
+        if (token == null || !token.startsWith("GoogleLogin")) {
+            Cookie[] cookies = request.getCookies();
+            if (cookies == null) {
+                return null;
+            }
+            for (int i = 0; i < cookies.length; i++) {
+                if (cookies[i].getName().equals(
+                        AuthenticationController.TOKEN_KEY)) {
+                    token = cookies[i].getValue();
+                    break;
+                }
+
+            }
+        }
+        if (token != null)
+            token = token.substring(token.indexOf("=") + 1);
+        return token;
+    }
+
+}

Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/UpdataAccountStrategy.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/UpdataAccountStrategy.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/UpdataAccountStrategy.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/UpdataAccountStrategy.java Tue Jun 27 12:31:20 2006
@@ -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.lucene.gdata.servlet.handler;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.gdata.data.GDataAccount;
+import org.apache.lucene.gdata.server.ServiceException;
+
+/**
+ * @author Simon Willnauer
+ *
+ */
+public class UpdataAccountStrategy extends AbstractAccountHandler {
+
+    private static final Log LOG = LogFactory.getLog(UpdataAccountStrategy.class);
+
+    
+
+    @Override
+    protected void processServiceAction(GDataAccount account) throws ServiceException {
+        try{
+        this.service.updateAccount(account);
+        }catch (ServiceException e) {
+            LOG.error("Can't update account -- "+e.getMessage(),e);
+            throw e;
+        }
+        
+    }
+}

Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/UpdateFeedHandler.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/UpdateFeedHandler.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/UpdateFeedHandler.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/UpdateFeedHandler.java Tue Jun 27 12:31:20 2006
@@ -0,0 +1,80 @@
+/**
+ * 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.lucene.gdata.servlet.handler;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.gdata.data.GDataAccount;
+import org.apache.lucene.gdata.data.ServerBaseFeed;
+import org.apache.lucene.gdata.server.ServiceException;
+import org.apache.lucene.gdata.server.ServiceFactory;
+import org.apache.lucene.gdata.server.registry.ComponentType;
+import org.apache.lucene.gdata.server.registry.GDataServerRegistry;
+
+/**
+ * @author Simon Willnauer
+ * 
+ */
+public class UpdateFeedHandler extends AbstractFeedHandler {
+    private static final Log LOG = LogFactory.getLog(UpdateFeedHandler.class);
+
+    /**
+     * @see org.apache.lucene.gdata.servlet.handler.AbstractFeedHandler#processRequest(javax.servlet.http.HttpServletRequest,
+     *      javax.servlet.http.HttpServletResponse)
+     */
+    @SuppressWarnings("unused")
+    @Override
+    public void processRequest(HttpServletRequest request,
+            HttpServletResponse response) throws ServletException, IOException {
+        super.processRequest(request, response);
+        if (this.authenticated) {
+            try {
+                ServerBaseFeed feed = createFeedFromRequest(request);
+                GDataAccount account = createRequestedAccount(request);
+
+                GDataServerRegistry registry = GDataServerRegistry
+                        .getRegistry();
+                ServiceFactory serviceFactory = registry.lookup(
+                        ServiceFactory.class, ComponentType.SERVICEFACTORY);
+                if (serviceFactory == null) {
+                    setError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+                            "required component is not available");
+                    throw new FeedHandlerException(
+                            "Can't update feed - ServiceFactory is null");
+                }
+                serviceFactory.getAdminService().updateFeed(feed, account);
+            } catch (ServiceException e) {
+                setError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+                        "can not update feed");
+                LOG.error("Can not update feed -- " + e.getMessage(), e);
+            } catch (Exception e) {
+
+                LOG.error("Can not update feed -- " + e.getMessage(), e);
+
+            }
+        }
+        sendResponse(response);
+
+    }
+
+}