You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rave.apache.org by zh...@apache.org on 2011/04/01 02:29:38 UTC

svn commit: r1087520 [10/35] - in /incubator/rave/donations/ogce-gadget-container: ./ config/ config/shindig-1.1-BETA5/ config/shindig-2.0.0/ db-cleaner/ examples/ examples/src/ examples/src/main/ examples/src/main/java/ examples/src/main/java/cgl/ exa...

Added: incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/OSGUserManager.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/OSGUserManager.java?rev=1087520&view=auto
==============================================================================
--- incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/OSGUserManager.java (added)
+++ incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/OSGUserManager.java Fri Apr  1 00:29:22 2011
@@ -0,0 +1,106 @@
+package cgl.shindig.usermanage;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ *
+ */
+
+
+import java.security.Principal;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+// @Singleton
+public class OSGUserManager implements UserManager {
+    private Logger log = LoggerFactory.getLogger(OSGUserManager.class.getName());
+
+    private Connection conn = null;
+
+    /**
+     * Related OSG tables:
+     * dn
+     */
+
+
+    public OSGUserManager (String adminID, Properties configProps) {
+    }
+
+    /**
+     * read user from table dn.
+     */
+    public CredUser getUser (String dn) throws Exception {
+        try {
+            if (conn == null || conn.isClosed())
+                conn = DriverManager.getConnection("jdbc:mysql://localhost/oim?" +
+                        "user=root&password=");
+
+            Statement stmt = conn.createStatement();
+            ResultSet rs = stmt.executeQuery("SELECT * FROM dn where dn_string = '" +
+                    dn.trim() + "'");
+            if (rs.first()) {
+                CredUser user = new CredUser();
+                user.setScreenname(dn.trim());
+                user.setPassword("");
+                user.setSubSystem("osg");
+                return user;
+            } else { //no results returned
+                return null;
+            }
+        } catch (SQLException ex) {
+            log.error("SQLException was thrown:\n" +
+                "SQLException: " + ex.getMessage() +
+                "SQLState: " + ex.getSQLState() +
+                "VendorError: " + ex.getErrorCode());
+            throw ex;
+        }
+    }
+
+    /**
+     * read user from table dn.
+     */
+    public CredUser getUserByEmail (String email) throws Exception {
+        throw new Exception("In OSG mode, getUserByEmail is not supported.");
+    }
+
+    public CredUser getUser (Principal principal) throws Exception {
+        return getUser(principal.getName());
+    }
+
+    public List<User> getAllUsers() throws Exception {
+        return new ArrayList<User>();
+    }
+    
+    public User createUser (String userId, String passwd) throws Exception {
+        throw new Exception("In OSG mode, you cannot create new user through OGCE portal");
+    }
+
+    public void insertUser(User user) throws Exception {
+        throw new Exception("In OSG mode, you cannot insert new user through OGCE portal");
+    }
+}
+

Added: incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/UILayout.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/UILayout.java?rev=1087520&view=auto
==============================================================================
--- incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/UILayout.java (added)
+++ incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/UILayout.java Fri Apr  1 00:29:22 2011
@@ -0,0 +1,70 @@
+package cgl.shindig.usermanage;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ *
+ */
+
+import java.util.Arrays;
+
+/** Bean which represents layout information of a user.
+  * The actual layout data is stored as a string. Which format is used by the layout data is up to
+  * the programmers.
+  * Currently, I am using JSON.
+  */
+public class UILayout{
+    private int     id;
+    private String screenname;
+    private String layout;
+
+    public int      getId( ){ return id; }
+    public void     setId( int id ){ this.id = id; }
+    public void setScreenname(String sn){ this.screenname = sn; }
+    public String getScreenname(){ return this.screenname; }
+    public void setLayout(String layout){ this.layout = layout; }
+    public String getLayout(){ return this.layout; }
+    public UILayout(String sn, String layout){
+        this.setScreenname( sn );
+        this.setLayout( layout );
+    }
+    public UILayout(){}
+
+    private boolean equalsString(String str1, String str2) {
+        if (str1 == null)
+            return str2 == null;
+        else
+            return str1.equals(str2);
+    }
+
+    public boolean equals(Object obj) {
+        if (this == obj) return true;
+        if (obj instanceof UILayout) {
+            UILayout uilayout2 = (UILayout)obj;
+            return equalsString(this.getScreenname(), uilayout2.getScreenname())
+                && equalsString(this.getLayout(), uilayout2.getLayout());
+        } else {
+            return false;
+        }
+    }
+
+    public int hashCode() {
+        return Arrays.hashCode(new Object[]{
+            this.getScreenname(), this.getLayout()
+        });
+    }
+}

Added: incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/User.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/User.java?rev=1087520&view=auto
==============================================================================
--- incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/User.java (added)
+++ incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/User.java Fri Apr  1 00:29:22 2011
@@ -0,0 +1,207 @@
+package cgl.shindig.usermanage;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ *
+ */
+
+
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Date;
+
+/*
+enum Gender{
+    MALE ('M'), 
+    FEMALE ('F')
+
+    private String value;
+
+    Gender(String gender){
+        if( gender.compareToIgnoreCase("m") || gender.compareToIgnoreCase("male") ){
+            this.value = 'M';
+        }else if( gender.compareToIgnoreCase('F') || gender.compareToIgnoreCase("female") ){
+        }else{
+        }
+    }
+}
+
+*/
+
+/** Bean which represents a user.
+  * Fields of the user structure are based on OpenID Simple Registration Extension.
+  */
+public class User{
+    private int     id;
+    private String  firstname;
+    private String  lastname;
+    //private String    gender;
+    //private int       age;
+    private Date    dob;
+    private String  language;
+    private String  timezone;
+    private String  email;
+    private String  gender;
+    private String  postcode;
+    private String  openid;
+    private String  nickname;
+    private String  country;
+
+    private String  screenname;
+    private String  password;
+
+    public int      getId( ){ return id; }
+    public void     setId( int id ){ this.id = id; }
+    public String   getScreenname( ){ return this.screenname; }
+    public void     setScreenname( String sn ){ this.screenname = sn; }
+    public String   getPassword(){ return this.password; }
+    public void     setPassword( String password ){ this.password = password; }
+    public String   getFirstname( ){return this.firstname;}
+    public void     setFirstname( String fn ) { this.firstname = fn; }
+    public String   getLastname( ){ return this.lastname; }
+    public void     setLastname( String ln ){ this.lastname = ln; }
+    public Date     getDob() {return this.dob;}
+    public void     setDob(Date dob){ this.dob = dob; }
+    public String   getLanguage() {return this.language;}
+    public void     setLanguage(String language){ this.language = language; }
+    public String   getTimezone(){ return this.timezone;}
+    public void     setTimezone(String timezone){ this.timezone = timezone; }
+    public String   getEmail(){ return this.email; }
+    public void     setEmail(String email){ this.email=email; }
+    public String   getGender(){ return this.gender; }
+    public void     setGender(String gender){ this.gender = gender; }
+    public String   getPostcode(){ return this.postcode; }
+    public void     setPostcode(String postcode){ this.postcode=postcode; }
+    public String   getOpenid(){ return this.openid; }
+    public void     setOpenid(String openid){ this.openid = openid; }
+    public String   getNickname(){ return this.nickname; }
+    public void     setNickname(String nickname){ this.nickname = nickname; }
+    public String   getCountry(){ return this.country; }
+    public void     setCountry(String country){ this.country = country; }
+
+    //public int        getAge( ){ return this.age; }
+    //public void       setAge( int age ){ this.age = age; }
+    //public String getGender( ){ this.getGender; }
+
+    public User(){}
+    public User( String sn, String fn, String ln, Date dob, String language,
+                 String timezone, String email, String gender, String postcode,
+                 String openid, String pwd, String country ){
+        this.setScreenname( sn );
+        this.setFirstname( fn );
+        this.setLastname( ln );
+        this.setDob( dob );
+        this.setLanguage( language );
+        this.setTimezone( timezone );
+        this.setEmail( email );
+        this.setGender( gender );
+        this.setPostcode( postcode );
+        this.setOpenid( openid );
+        this.setPassword( pwd );
+        //this.setAge( age );
+        this.setCountry( country );
+    }
+    public void     display(){
+        String output = "";
+        output += "id:"+this.id;
+        output += "\nfirst name:"+this.firstname;
+        output += "\nlast name:"+this.lastname;
+        //output += "\nage:"+this.age;
+        System.out.println( output );
+    }
+
+    private boolean equalsString(String str1, String str2) {
+        if (str1 == null)
+            return str2 == null;
+        else
+            return str1.equals(str2);
+    }
+    private boolean equalsDate(Date date1, Date date2) {
+        if (date1 == null)
+            return date2 == null;
+        else
+            return date1.equals(date2);
+    }
+
+    private boolean equalsScreenName(User user2) {
+        return equalsString(this.getScreenname(), user2.getScreenname());
+    }
+    private boolean equalsPassword(User user2) {
+        return equalsString(this.getPassword(), user2.getPassword());
+    }
+    private boolean equalsFirstname(User user2) {
+        return equalsString(this.getFirstname(), user2.getFirstname());
+    }
+    private boolean equalsLastname(User user2) {
+        return equalsString(this.getLastname(), user2.getLastname());
+    }
+    private boolean equalsLanguage(User user2) {
+        return equalsString(this.getLanguage(), user2.getLanguage());
+    }
+    private boolean equalsTimezone(User user2) {
+        return equalsString(this.getTimezone(), user2.getTimezone());
+    }
+    private boolean equalsEmail(User user2) {
+        return equalsString(this.getEmail(), user2.getEmail());
+    }
+    private boolean equalsGender(User user2) {
+        return equalsString(this.getGender(), user2.getGender());
+    }
+    private boolean equalsPostcode(User user2) {
+        return equalsString(this.getPostcode(), user2.getPostcode());
+    }
+    private boolean equalsOpenid(User user2) {
+        return equalsString(this.getOpenid(), user2.getOpenid());
+    }
+    private boolean equalsNickname(User user2) {
+        return equalsString(this.getNickname(), user2.getNickname());
+    }
+    private boolean equalsCountry(User user2) {
+        return equalsString(this.getCountry(), user2.getCountry());
+    }
+    private boolean equalsDob(User user2) {
+        return equalsDate(this.getDob(), user2.getDob());
+    }
+
+    public boolean equals(Object obj) {
+        if (this == obj) return true;
+        if (obj instanceof User) {
+            User user2 = (User)obj;
+            return equalsScreenName(user2) && equalsPassword(user2)
+                && equalsFirstname(user2) && equalsLastname(user2)
+                && equalsLanguage(user2) && equalsTimezone(user2)
+                && equalsEmail(user2) && equalsGender(user2)
+                && equalsPostcode(user2) && equalsOpenid(user2)
+                && equalsNickname(user2) && equalsCountry(user2)
+                && equalsDob(user2);
+        } else {
+            return false;
+        }
+    }
+
+    public int hashCode() {
+        return Arrays.hashCode(new Object[]{
+            this.getScreenname(), this.getPassword(), this.getFirstname(),
+            this.getLastname(), this.getLanguage(), this.getTimezone(),
+            this.getEmail(), this.getGender(), this.getPostcode(),
+            this.getOpenid(), this.getNickname(), this.getCountry(),
+            this.getDob()
+        });
+    }
+}
+

Added: incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/UserDBMgr.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/UserDBMgr.java?rev=1087520&view=auto
==============================================================================
--- incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/UserDBMgr.java (added)
+++ incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/UserDBMgr.java Fri Apr  1 00:29:22 2011
@@ -0,0 +1,440 @@
+package cgl.shindig.usermanage;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ *
+ */
+
+
+import java.io.UnsupportedEncodingException;
+import java.security.NoSuchAlgorithmException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Logger;
+
+import org.hibernate.Criteria;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.criterion.Restrictions;
+
+import cgl.shindig.common.Util;
+import cgl.shindig.security.CryptedSimpleCredentials;
+import cgl.shindig.security.SimpleCredentials;
+
+/**
+ * This class manages the database tables.
+ *
+ */
+public class UserDBMgr{
+    private static Logger logger =
+        Logger.getLogger(UserDBMgr.class.getName());
+
+    // ***********************************************************************
+    // **       user database
+    // ***********************************************************************
+    /**
+     * Insert a user into the database.
+     *
+     * @param   user A User object which represents the user to be inserted.
+     * @return  A boolean value which indicates whether the insertion succeeded.
+     */
+    public static boolean insertUser( User user ) {
+    	return insertUser(user, false);
+    }
+    
+	 //Note the boolean pwdCrypted means "Is the password encrypted?"  If false (unencrypted), then
+	 //encrypt it.
+    public static boolean insertUser( User user, boolean pwdCrypted ){
+        String plainTextPwd = user.getPassword();
+        String cryptedPwd;
+		  //If the password is NOT encrypted, then encrypt it.
+        if (!pwdCrypted) {
+			try {
+				cryptedPwd = new CryptedSimpleCredentials(new SimpleCredentials(user.getScreenname(), plainTextPwd.toCharArray())).getPassword();
+			} catch (NoSuchAlgorithmException e) {
+				e.printStackTrace();
+				return false;
+			} catch (UnsupportedEncodingException e) {
+				e.printStackTrace();
+				return false;
+			}
+        } else {
+        	cryptedPwd = plainTextPwd;
+        }
+        user.setPassword(cryptedPwd);
+        
+        try{
+				//Make sure no such user (identified by the screen name) already exists in the DB.
+				//If so, return false.
+            if( getUserBySN( user.getScreenname() ) != null ){
+                return false;
+            }
+            Session session = SessionFac.getSessionFac().getCurrentSession();
+            session.beginTransaction();
+            session.save(user);
+            session.getTransaction().commit();
+            return true;
+        }catch(Exception e){
+            logger.warning(e.toString());
+            return false;
+        }finally{
+				//Not sure why this is here, since it is unreachable, I think.  Maybe just for sanity.
+        	user.setPassword(plainTextPwd);
+        }
+    }
+
+    /**
+     * Delete a user from the database.
+     *
+     * @param id
+     */
+    public static boolean removeUserBySN( String sn ){
+        User user = getUserBySN( sn );
+        if( user != null ){
+            Session session = SessionFac.getSessionFac().getCurrentSession();
+            session.beginTransaction();
+            session.delete( user );
+            session.getTransaction().commit();
+            return true;
+        }else
+            return false;
+    }
+
+    public static boolean updateUser( User user ){
+        String sn = user.getScreenname();
+        User existinguser = getUserBySN( sn );
+        if( existinguser == null ){
+            return false;
+        }else{
+            removeUserBySN( sn );
+            if (Util.isEmpty(user.getPassword())) {
+            	user.setPassword(existinguser.getPassword());
+            	insertUser(user, true);
+            } else {
+            	insertUser(user, false);
+            }
+            return true;
+        }
+    }
+
+    /**
+     * Retrieve information of a user based on his/her openid.
+     * @param sn Screen name
+     */
+    public static User getUserByOpenID( String openid ){
+        try {
+            Session session = SessionFac.getSessionFac().getCurrentSession();
+            session.beginTransaction();
+            Criteria criteria = session.createCriteria(User.class).add(
+                    Restrictions.eq("openid", openid));
+            List list = criteria.list();
+            session.getTransaction().commit();
+            if( list.size() == 0 ){
+                logger.warning("No person with OpenID "+openid+" is found");
+                return null;
+            }else{
+                if ( list.size() > 1 )
+                    logger.warning("Returned list should just contain one object! So the data may have been corrupted.");
+                return (User)list.get(0);
+            }
+        } catch(Exception ex) {
+            logger.warning(ex.toString());
+            return null;
+        }
+    }
+
+    /** update user's information */
+    public static boolean setUserBySN( User user ){
+        String sn = user.getScreenname();
+        User existinguser = getUserBySN( sn );
+        if( existinguser == null ){
+            insertUser( user );
+        }else{
+            removeUserBySN( sn );
+            insertUser( user );
+        }
+        return true;
+    }
+
+    public static boolean getUserByname( String screenname ){
+        return true;
+    }
+
+    /**
+     * Retrieve information of a user based on his/her screen name.
+     *
+     * @param sn Screen name
+     */
+    public static User getUserBySN( String sn ){
+        try {
+            Session session = SessionFac.getSessionFac().getCurrentSession();
+            session.beginTransaction();
+            Criteria criteria = session.createCriteria(User.class).add( Restrictions.eq("screenname", sn));
+            List list = criteria.list();
+            session.getTransaction().commit();
+            if( list.size() == 0 ){
+                logger.warning("No person with screen name "+sn+" is found");
+                return null;
+            }else{
+                if ( list.size() > 1 )
+                    logger.warning("Returned list should just contain one object! So the data may have been corrupted.");
+                return (User)list.get(0);
+            }
+        } catch(Exception ex) {
+            logger.warning(ex.toString());
+            return null;
+        }
+    }
+
+    /**
+     * Retrieve information of a user based on his/her email.
+     *
+     * @param email Email address
+     */
+    public static User getUserByEmail(String email) {
+        try {
+            Session session = SessionFac.getSessionFac().getCurrentSession();
+            session.beginTransaction();
+            Criteria criteria =
+                session.createCriteria(User.class).add(Restrictions.eq("email", email));
+            List list = criteria.list();
+            session.getTransaction().commit();
+            if( list.size() == 0 ){
+                logger.warning("No person with email " + email + " is found");
+                return null;
+            } else {
+                if ( list.size() > 1 )
+                    logger.warning("Returned list should just contain one object! So the data may have been corrupted.");
+                return (User)list.get(0);
+            }
+        } catch(Exception ex) {
+            logger.warning(ex.toString());
+            return null;
+        }
+    }
+
+    /** Get all users in the system. */
+    public static List<User> getAllUsers(){
+        try {
+            Session session = SessionFac.getSessionFac().getCurrentSession();
+            session.beginTransaction();
+            Criteria criteria = session.createCriteria(User.class);
+            List list = criteria.list();
+            session.getTransaction().commit();
+            return (List<User>)list;
+        } catch(Exception ex) {
+            logger.warning(ex.toString());
+            return new ArrayList<User>();
+        }
+    }
+
+    // ***********************************************************************
+    // **       user layout
+    // ***********************************************************************
+    /** Get all layout data in the system. */
+    public static List<UILayout> getAllLayout(){
+        try {
+            Session session = SessionFac.getSessionFac().getCurrentSession();
+            session.beginTransaction();
+            Criteria criteria = session.createCriteria(UILayout.class);
+            List list = criteria.list();
+            session.getTransaction().commit();
+            return (List<UILayout>)list;
+        } catch(Exception ex) {
+            logger.warning(ex.toString());
+            return new ArrayList<UILayout>();
+        }
+    }
+
+    /** retrieve layout information according to user's screen name */
+    public static UILayout getUILayoutBySN( String sn ){
+        try {
+            Session session = SessionFac.getSessionFac().getCurrentSession();
+            if( session == null ) return null;
+            session.beginTransaction();
+            Criteria criteria = session.createCriteria(UILayout.class).add( Restrictions.eq("screenname", sn));
+            List list = criteria.list();
+            session.getTransaction().commit();
+            if( list.size() == 0 ){
+                logger.warning("No person with screen name "+sn+" is found");
+                return null;
+            }else{
+                if ( list.size() > 1 )
+                    logger.warning("Returned list should just contain one object! So the data may have been corrupted.");
+                return (UILayout)list.get(0);
+            }
+        } catch(Exception ex) {
+            logger.warning(ex.toString());
+            return null;
+        }
+    }
+
+    /** update a layout object stored in the database.
+     * If the object does not exist, create a new one. */
+    public static void setUILayoutBySN( UILayout layout ){
+        String sn = layout.getScreenname();
+        UILayout existinglayout = getUILayoutBySN( sn );
+        Session session = SessionFac.getSessionFac().getCurrentSession();
+        if( session == null ) return;
+        session.beginTransaction();
+        if( existinglayout == null ){
+            session.save(layout);
+        }else{
+            existinglayout.setLayout( layout.getLayout() );
+            session.update(existinglayout);
+        }
+        session.getTransaction().commit();
+    }
+
+    /** insert a layout object into the database */
+    public static boolean insertUILayout( UILayout layout ){
+        try{
+				//If a layout already is associated with the supplied screen name,
+				//don't insert.  Return false.
+            if( getUILayoutBySN(layout.getScreenname()) != null ){
+                return false;
+            }
+            Session session = SessionFac.getSessionFac().getCurrentSession();
+            if( session == null ) return false;
+            session.beginTransaction();
+            session.save(layout);
+            session.getTransaction().commit();
+            return true;
+        }catch(Exception e){
+            logger.warning(e.toString());
+            return false;
+        }
+    }
+
+    /** delete layout info of a user. */
+    public static boolean delUILayoutBySN(String sn){
+        UILayout existinglayout = getUILayoutBySN( sn );
+        Session session = SessionFac.getSessionFac().getCurrentSession();
+        if( session == null ) return false;
+        if( existinglayout != null ){
+            session.beginTransaction();
+            session.delete(existinglayout);
+            session.getTransaction().commit();
+            return true;
+        }else{
+            return true;
+        }
+    }
+
+    // ***********************************************************************
+    // **       admin
+    // ***********************************************************************
+    /** retrieve adminuser information according to user's screen name */
+    public static AdminUser getAdminUserBySN(String sn) {
+        try {
+            Session session = SessionFac.getSessionFac().getCurrentSession();
+            if( session == null ) return null;
+            session.beginTransaction();
+            Criteria criteria = session.createCriteria(AdminUser.class).add(
+                    Restrictions.eq("screenname", sn));
+            List list = criteria.list();
+            session.getTransaction().commit();
+            if( list.size() == 0 ){
+                logger.warning("No admin user with screen name "+sn+" is found");
+                return null;
+            }else{
+                if ( list.size() > 1 )
+                    logger.warning("Returned list should just contain " +
+                            "one object! So the data may have been corrupted.");
+                return (AdminUser)list.get(0);
+            }
+        } catch(Exception ex) {
+            logger.warning(ex.toString());
+            return null;
+        }
+    }
+
+    /**
+     * update a adminuser object stored in the database.
+     * If the object does not exist, create a new one.
+     */
+    public static void setAdminUserBySN(AdminUser adminUser){
+        String sn = adminUser.getScreenname();
+        AdminUser existingadmin = getAdminUserBySN(sn);
+        Session session = SessionFac.getSessionFac().getCurrentSession();
+        if (session == null) return;
+        session.beginTransaction();
+        if (existingadmin == null){
+            session.save(adminUser);
+        }else{
+            existingadmin.setPassword(adminUser.getPassword());
+            session.update(existingadmin);
+        }
+        session.getTransaction().commit();
+    }
+
+    /**
+     * insert a adminuser object into the database
+     */
+    public static boolean insertAdminUser( AdminUser adminUser ){
+        try{
+            if( getAdminUserBySN(adminUser.getScreenname()) != null ){
+                return false;
+            }
+            Session session = SessionFac.getSessionFac().getCurrentSession();
+            if( session == null ) return false;
+            session.beginTransaction();
+            session.save(adminUser);
+            session.getTransaction().commit();
+            return true;
+        }catch(Exception e){
+            logger.warning(e.toString());
+            return false;
+        }
+    }
+
+    /**
+     * delete info of a adminuser.
+     */
+    public static boolean delAdminUserBySN(String sn){
+        AdminUser existingadmin = getAdminUserBySN(sn);
+        Session session = SessionFac.getSessionFac().getCurrentSession();
+        if( session == null ) return false;
+        if( existingadmin != null ){
+            session.beginTransaction();
+            session.delete(existingadmin);
+            session.getTransaction().commit();
+            return true;
+        }else{
+            return true;
+        }
+    }
+}
+
+/** This class get session factory of hibernate */
+class SessionFac{
+    private static SessionFactory sessionFac = null;
+    private static Logger logger =
+        Logger.getLogger(SessionFactory.class.getName());
+    static{
+        try{
+            sessionFac = new Configuration().configure().buildSessionFactory();
+        }catch(Throwable ex){
+            logger.severe("Initial SessionFactory creation failed\n" + ex);
+        }
+    }
+    public static SessionFactory getSessionFac(){
+        return sessionFac;
+    }
+}

Added: incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/UserJSONFormatter.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/UserJSONFormatter.java?rev=1087520&view=auto
==============================================================================
--- incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/UserJSONFormatter.java (added)
+++ incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/UserJSONFormatter.java Fri Apr  1 00:29:22 2011
@@ -0,0 +1,104 @@
+package cgl.shindig.usermanage;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ *
+ */
+
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+public class UserJSONFormatter{
+    public static String format(User user) {
+    	JSONObject jsonObj = new JSONObject();
+    	try {
+    		jsonObj = format2JSONObject(user);
+    		return jsonObj.toString();
+    	} catch (JSONException e) { // TODO: more elegant error handling
+    		e.printStackTrace();
+    		return null;
+    	}
+    }
+    
+    private static UILayout findLayoutForUser(User user, List<UILayout> allLayout){
+        for (Iterator<UILayout> it = allLayout.iterator(); it.hasNext();) {
+            UILayout layout = it.next();
+            if (layout.getScreenname().equals(user.getScreenname()))
+                return layout;
+        }
+        return null;
+    }
+
+    public static String format(User user, List<UILayout> allLayout){
+        UILayout layout = findLayoutForUser(user, allLayout);
+
+      	JSONObject jsonObj = new JSONObject();
+    	try {
+    		jsonObj = format2JSONObject(user);
+    		jsonObj.put("layoutdata", (layout == null?"":layout.getLayout()));
+    		return jsonObj.toString();
+    	} catch (JSONException e) { // TODO: more elegant error handling
+    		e.printStackTrace();
+    		return null;
+    	}
+    }
+
+
+    private static JSONObject format2JSONObject (User user) throws JSONException {
+    	JSONObject jsonObj = new JSONObject();
+    	jsonObj.put("screenname", user.getScreenname());
+    	jsonObj.put("password", "");
+    	jsonObj.put("firstname", user.getFirstname());
+    	jsonObj.put("lastname", user.getLastname());
+    	jsonObj.put("country", user.getCountry());
+    	
+        Date dob = user.getDob();
+        Calendar calendar = Calendar.getInstance();
+        if (dob != null) {
+            // TODO: dob should not be null!!
+            // However, I found when h2 is used with hibernate, date cannot be
+            // retrieved into object field!!
+            calendar.setTime(dob);
+        }
+        jsonObj.put("dobday", calendar.get(Calendar.DAY_OF_WEEK));
+        jsonObj.put("dobmonth", calendar.get(Calendar.MONTH));
+        jsonObj.put("dobyear", calendar.get(Calendar.YEAR));
+
+        jsonObj.put("language", user.getLanguage());
+        jsonObj.put("timezone", user.getTimezone());
+        jsonObj.put("email", user.getEmail());
+        jsonObj.put("gender", user.getGender());
+        jsonObj.put("openid", user.getOpenid());
+        jsonObj.put("zipcode", user.getPostcode());
+        jsonObj.put("nickname", user.getNickname());
+        return jsonObj;
+    }
+    
+    private static String escapeDoubleQuotation(String str) {
+        if (str == null)
+            return "";
+        return str.replaceAll("\"", "\\\\\"");
+    }
+}
+

Added: incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/UserManager.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/UserManager.java?rev=1087520&view=auto
==============================================================================
--- incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/UserManager.java (added)
+++ incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/UserManager.java Fri Apr  1 00:29:22 2011
@@ -0,0 +1,44 @@
+package cgl.shindig.usermanage;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ *
+ */
+
+
+import java.security.Principal;
+import java.util.List;
+
+// @Singleton
+public interface UserManager {
+
+    // public UserManager (String adminID, Properties configProps);
+
+    public CredUser getUser (String userid) throws Exception;
+
+    public CredUser getUserByEmail (String email) throws Exception;
+
+    public CredUser getUser (Principal principal) throws Exception;
+    
+    public List<User> getAllUsers() throws Exception;
+
+    public User createUser (String userId, String passwd) throws Exception;
+    
+    public void insertUser (User user) throws Exception;
+}
+

Added: incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/UserPrefEntry.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/UserPrefEntry.java?rev=1087520&view=auto
==============================================================================
--- incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/UserPrefEntry.java (added)
+++ incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/UserPrefEntry.java Fri Apr  1 00:29:22 2011
@@ -0,0 +1,57 @@
+package cgl.shindig.usermanage;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ *
+ */
+
+
+class UserPrefEntry {
+    private String prefName;
+    private String prefValue;
+
+	/**
+	 * get the value of prefName
+	 * @return the value of prefName
+	 */
+	public String getPrefName(){
+		return this.prefName;
+	}
+	/**
+	 * set a new value to prefName
+	 * @param prefName the new value to be used
+	 */
+	public void setPrefName(String prefName) {
+		this.prefName=prefName;
+	}
+	/**
+	 * get the value of prefValue
+	 * @return the value of prefValue
+	 */
+	public String getPrefValue(){
+		return this.prefValue;
+	}
+	/**
+	 * set a new value to prefValue
+	 * @param prefValue the new value to be used
+	 */
+	public void setPrefValue(String prefValue) {
+		this.prefValue=prefValue;
+	}
+}
+

Added: incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/UserValidator.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/UserValidator.java?rev=1087520&view=auto
==============================================================================
--- incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/UserValidator.java (added)
+++ incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/UserValidator.java Fri Apr  1 00:29:22 2011
@@ -0,0 +1,244 @@
+package cgl.shindig.usermanage;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ *
+ */
+
+
+
+/** Validator for user information. 
+  * Currently, not all fields are checked. I will refine it later.
+  *
+  * The validation shoulde be compatible with the data type specification of 
+  * underlying tables.
+  * This is the statement which creates table 'user'.
+    CREATE TABLE IF NOT EXISTS user (
+         id         INTEGER  NOT NULL AUTO_INCREMENT PRIMARY KEY,
+         firstname  VARCHAR(50) NOT NULL,
+         lastname   VARCHAR(50) NOT NULL,
+         screenname VARCHAR(32) NOT NULL UNIQUE, 
+         nickname   VARCHAR(32),
+         openid     VARCHAR(128),
+         password   VARCHAR(50) NOT NULL,
+         dateofbirth DATE,
+         language   VARCHAR(10),
+         timezone   VARCHAR(10),
+         email      VARCHAR(64),
+         gender     CHAR(1),
+         zipcode    VARCHAR(16)
+    );
+  */
+public class UserValidator{
+	/* length restriction of first name */
+	private int		minlengthFN;
+	private int		maxlengthFN;
+	/* length restriction of last name */
+	private int		minlengthLN;
+	private int		maxlengthLN;
+	/* length restriction of screen name */
+	private int		minlengthSN;
+	private int		maxlengthSN;
+	/* length restriction of password */
+	private int		minlengthPWD;
+	private int		maxlengthPWD;
+    /* length of openid field */
+    private int     minlengthOpenId;
+    private int     maxlengthOpenId;
+    /* length of language field */
+    private int     minlengthLang;
+    private int     maxlengthLang;
+    /* length of timezone field */
+    private int     minlengthTimezone;
+    private int     maxlengthTimezone;
+    /* length of email field */
+    private int     minlengthEmail;
+    private int     maxlengthEmail;
+    /* length of gender field */
+    private int     minlengthGender;
+    private int     maxlengthGender;
+    /* length of zipcode field */
+    private int     minlengthZipcode;
+    private int     maxlengthZipcode;
+
+	/* numeric restriction of age */
+	private int		minAge;
+	private int 	maxAge;
+
+	 //Probably many of these need additional formatting validation besides just the length. 
+	public UserValidator(){
+		this.minAge = 18;
+		this.maxAge = 150;
+		this.minlengthPWD = 5;
+		this.maxlengthPWD = 20;
+		this.minlengthFN = 1;
+		this.maxlengthFN = 20;
+		this.minlengthLN = 1;
+		this.maxlengthLN = 20;
+		this.minlengthSN = 5;
+		this.maxlengthSN = 20;
+
+        this.minlengthOpenId    = 0;
+        this.maxlengthOpenId    = 128;
+        this.minlengthLang      = 0;
+        this.maxlengthLang      = 10;
+        this.minlengthTimezone  = 0;
+        this.maxlengthTimezone  = 10;
+        this.minlengthEmail     = 0;
+        this.maxlengthEmail     = 64;
+        this.minlengthGender    = 0;
+        this.maxlengthGender    = 1;
+        this.minlengthZipcode   = 0;
+        this.maxlengthZipcode   = 16;
+	}
+
+/*
+	private boolean validateAge(User user){
+		return numericRangeValidate(user.getAge(), this.minAge, this.maxAge);
+	}
+    */
+	private boolean validateZipcode(User user){
+        if( user.getPostcode() == null ){
+            if( this.minlengthZipcode == 0 )
+                return true;
+            else
+                return false;
+        }else{
+            int len = user.getPostcode().length();
+            return numericRangeValidate(len, this.minlengthZipcode, this.maxlengthZipcode);
+        }
+	}
+	private boolean validateGender(User user){
+        if( user.getGender() == null ){
+            if( this.minlengthGender == 0 )
+                return true;
+            else
+                return false;
+        }else{
+            int len = user.getGender().length();
+            return numericRangeValidate(len, this.minlengthGender, this.maxlengthGender);
+        }
+	}
+	private boolean validateEmail(User user){
+        if( user.getEmail() == null ){
+            if( this.minlengthEmail == 0 )
+                return true;
+            else
+                return false;
+        }else{
+            int len = user.getEmail().length();
+            return numericRangeValidate(len, this.minlengthEmail, this.maxlengthEmail);
+        }
+	}
+	private boolean validateTimeZone(User user){
+        if( user.getTimezone() == null ){
+            if( this.minlengthTimezone == 0 )
+                return true;
+            else
+                return false;
+        }else{
+            int len = user.getTimezone().length();
+            return numericRangeValidate(len, this.minlengthTimezone, this.maxlengthTimezone);
+        }
+	}
+	private boolean validateLanguage(User user){
+        if( user.getLanguage() == null ){
+            if( this.minlengthLang == 0 )
+                return true;
+            else
+                return false;
+        }else{
+            int len = user.getLanguage().length();
+            return numericRangeValidate(len, this.minlengthLang, this.maxlengthLang);
+        }
+	}
+	private boolean validateOpenId(User user){
+        if( user.getOpenid() == null ){
+            if( this.minlengthOpenId == 0 )
+                return true;
+            else
+                return false;
+        }else{
+            int len = user.getOpenid().length();
+            return numericRangeValidate(len, this.minlengthOpenId, this.maxlengthOpenId);
+        }
+	}
+	private boolean validateFirstname(User user){
+        if( user.getFirstname() == null ){
+            if( this.minlengthFN == 0 )
+                return true;
+            else
+                return false;
+        }else{
+            int len = user.getFirstname().length();
+            return numericRangeValidate(len, this.minlengthFN, this.maxlengthFN);
+        }
+	}
+	private boolean validateLastname(User user){
+        if( user.getLastname() == null ){
+            if( this.minlengthLN == 0 )
+                return true;
+            else
+                return false;
+        }else{
+            int len = user.getLastname().length();
+            return numericRangeValidate(len, this.minlengthLN, this.maxlengthLN);
+        }
+	}
+	private boolean validateScreenname(User user){
+        if( user.getScreenname() == null ){
+            if( this.minlengthSN == 0 )
+                return true;
+            else
+                return false;
+        }else{
+            int len = user.getScreenname().length();
+            return numericRangeValidate(len, this.minlengthSN, this.maxlengthSN);
+        }
+	}
+	private boolean validatePassword(User user){
+        if( user.getPassword() == null ){
+            if( this.minlengthPWD == 0 )
+                return true;
+            else
+                return false;
+        }else{
+            int len = user.getPassword().length();
+            return numericRangeValidate(len, this.minlengthPWD, this.maxlengthPWD);
+        }
+	}
+
+	public boolean validate( User user ){
+		return validate(user, "__invalid__");
+	}
+	
+	public boolean validate( User user, String method ){
+		return validateScreenname(user) && 
+			  (method.equalsIgnoreCase("put") || validatePassword(user)) &&
+			   validateFirstname(user)  && validateLastname(user) &&
+               validateZipcode(user)    && validateGender(user)   &&
+               validateEmail(user)      && validateTimeZone(user) &&
+               validateLanguage(user)   && validateOpenId(user);
+	}
+
+	private boolean numericRangeValidate( int value, int min, int max ){
+		if( value >= min && value <= max )
+			return true;
+		return false;
+	}
+}

Added: incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/servlet/AdminUserListener.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/servlet/AdminUserListener.java?rev=1087520&view=auto
==============================================================================
--- incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/servlet/AdminUserListener.java (added)
+++ incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/servlet/AdminUserListener.java Fri Apr  1 00:29:22 2011
@@ -0,0 +1,57 @@
+package cgl.shindig.usermanage.servlet;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ *
+ */
+
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+import org.h2.tools.Server;
+import org.h2.util.StringUtils;
+
+import cgl.shindig.usermanage.AdminUser;
+import cgl.shindig.usermanage.UserDBMgr;
+
+/**
+ * This class can be used to initialize AdminUser database.
+ */
+public class AdminUserListener implements ServletContextListener {
+
+    public void contextInitialized(ServletContextEvent servletContextEvent) {
+        try {
+            String screenname = "admin", password = "admin";
+            AdminUser adminUser = new AdminUser(screenname, password);
+            UserDBMgr.setAdminUserBySN(adminUser);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    public void contextDestroyed(ServletContextEvent servletContextEvent) {
+    }
+}
+

Added: incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/servlet/AuthenzResult.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/servlet/AuthenzResult.java?rev=1087520&view=auto
==============================================================================
--- incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/servlet/AuthenzResult.java (added)
+++ incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/servlet/AuthenzResult.java Fri Apr  1 00:29:22 2011
@@ -0,0 +1,35 @@
+package cgl.shindig.usermanage.servlet;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ *
+ */
+
+
+import cgl.shindig.usermanage.User;
+
+public class AuthenzResult {
+    // result code
+    public int authenzRC = -1;
+    // user
+    public User user = null;
+
+    public boolean isSuccessful () {
+        return authenzRC == 0;
+    }
+}

Added: incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/servlet/CertProtectedUserAdmin.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/servlet/CertProtectedUserAdmin.java?rev=1087520&view=auto
==============================================================================
--- incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/servlet/CertProtectedUserAdmin.java (added)
+++ incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/servlet/CertProtectedUserAdmin.java Fri Apr  1 00:29:22 2011
@@ -0,0 +1,33 @@
+package cgl.shindig.usermanage.servlet;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ *
+ */
+
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+
+public class CertProtectedUserAdmin extends UserAdmin {
+	@Override
+	public void init(ServletConfig config) throws ServletException {
+    	super.init(config);
+    	this.securityChecker = UserAdmin.DummySecurityChecker;
+    }
+}

Added: incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/servlet/OpenIDAXStore.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/servlet/OpenIDAXStore.java?rev=1087520&view=auto
==============================================================================
--- incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/servlet/OpenIDAXStore.java (added)
+++ incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/servlet/OpenIDAXStore.java Fri Apr  1 00:29:22 2011
@@ -0,0 +1,67 @@
+package cgl.shindig.usermanage.servlet;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ *
+ */
+
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.Properties;
+import java.util.Enumeration;
+import java.util.Map;
+import java.util.HashMap;
+
+/** This class retrieves OpenID Attribute Exchange types from a file.
+  * The file specifies those attributes that will be exchanged. 
+  */
+public class OpenIDAXStore{
+    private Map<String, String> sremap = new HashMap<String, String>();
+
+    /*
+     *  @param filename
+     *          name of the property file which contains information about
+     *          Attribute Exchange Extension.
+     *          Every line in the file should look like:
+     *          label = Type-URI
+     */
+    public OpenIDAXStore(String filename){
+        File propfile = new File(filename);
+        if( !propfile.exists() ){
+            System.err.println("Property file "+ filename + "does not exist.");
+        }else{
+            Properties props = new Properties();
+            try{
+                FileInputStream fis = new FileInputStream( propfile );
+                props.load(fis);
+                Enumeration e = props.propertyNames();
+                while( e.hasMoreElements() ){
+                    String key = (String)e.nextElement();
+                    sremap.put( key, props.getProperty(key) );
+                }
+                fis.close();
+            }catch(Exception e){
+                System.err.println("error:"+e);
+            }
+        }
+    }
+    public Map<String, String> getMap(){
+        return this.sremap;
+    }
+}

Added: incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/servlet/OpenIDSREStore.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/servlet/OpenIDSREStore.java?rev=1087520&view=auto
==============================================================================
--- incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/servlet/OpenIDSREStore.java (added)
+++ incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/servlet/OpenIDSREStore.java Fri Apr  1 00:29:22 2011
@@ -0,0 +1,67 @@
+package cgl.shindig.usermanage.servlet;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ *
+ */
+
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.Properties;
+import java.util.Enumeration;
+import java.util.Map;
+import java.util.HashMap;
+
+/** This class retrieves OpenID Simple Registration Extension types from a file.
+  * The file specifies those fields (e.g. email, nickname) that will be retrieved from OpenId provider. 
+  */
+public class OpenIDSREStore{
+    private Map<String, String> sremap = new HashMap<String, String>();
+
+    /*
+     *  @param filename
+     *          name of the property file which contains information about
+     *          Simple Registration Extension.
+     *          Every line in the file should look like:
+     *          openid.sreg.type = URI
+     */
+    public OpenIDSREStore(String filename){
+        File propfile = new File(filename);
+        if( !propfile.exists() ){
+            System.err.println("Property file "+ filename + "does not exist.");
+        }else{
+            Properties props = new Properties();
+            try{
+                FileInputStream fis = new FileInputStream( propfile );
+                props.load(fis);
+                Enumeration e = props.propertyNames();
+                while( e.hasMoreElements() ){
+                    String key = (String)e.nextElement();
+                    sremap.put( key, props.getProperty(key) );
+                }
+                fis.close();
+            }catch(Exception e){
+                System.err.println("error:"+e);
+            }
+        }
+    }
+    public Map<String, String> getMap(){
+        return this.sremap;
+    }
+}

Added: incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/servlet/OpenIdAuth.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/servlet/OpenIdAuth.java?rev=1087520&view=auto
==============================================================================
--- incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/servlet/OpenIdAuth.java (added)
+++ incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/servlet/OpenIdAuth.java Fri Apr  1 00:29:22 2011
@@ -0,0 +1,411 @@
+package cgl.shindig.usermanage.servlet;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ *
+ */
+
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.logging.Logger;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import org.openid4java.consumer.ConsumerException;
+import org.openid4java.consumer.ConsumerManager;
+import org.openid4java.consumer.VerificationResult;
+import org.openid4java.discovery.DiscoveryInformation;
+import org.openid4java.discovery.Identifier;
+import org.openid4java.message.AuthRequest;
+import org.openid4java.message.AuthSuccess;
+import org.openid4java.message.MessageExtension;
+import org.openid4java.message.ParameterList;
+import org.openid4java.message.ax.AxMessage;
+import org.openid4java.message.ax.FetchRequest;
+import org.openid4java.message.ax.FetchResponse;
+import org.openid4java.message.sreg.SRegMessage;
+import org.openid4java.message.sreg.SRegRequest;
+import org.openid4java.message.sreg.SRegResponse;
+import org.openid4java.server.RealmVerifier;
+
+import cgl.shindig.common.BaseHttpServlet;
+import cgl.shindig.common.ServletUtil;
+import cgl.shindig.common.Util;
+import cgl.shindig.usermanage.User;
+import cgl.shindig.usermanage.UserDBMgr;
+
+public class OpenIdAuth extends BaseHttpServlet {
+
+    /* following several variables are set in init and myinit functions */
+    private static String contextPath = null;
+    private static String hostAddr = null;
+    private static String baseURL = null;
+
+    //OpenId provider will send request to following address after it authenticates the openid.
+    //example: http://gf1.ucs.indiana.edu:8088/ajax-shindig/openidsignin
+    private static String returnTo = null;
+
+    //if openid is authenticated successfully, and the user has NOT created an account in our
+    //system, redirect to following page.
+    //example: http://gf1.ucs.indiana.edu:8088/ajax-shindig/index.jsp?state=0
+    private static String mainSuccPage = null;
+
+    private static String mainSuccPageBase = null;
+
+    //if openid authentication failed, redirect to following page.
+    //example: http://gf1.ucs.indiana.edu:8088/ajax-shindig/index.jsp?state=1
+    private static String mainFailPage = null;
+
+    //if openid is authenticated successfully, and the user has created an account in our
+    //system, redirect to following page.
+    //example: http://gf1.ucs.indiana.edu:8088/ajax-shindig/www/ishindig.html
+    protected static String mainSuccUserPage = null;
+
+
+    private static final String OPENID_IDENTITY = "openid.identity";
+    private static final String OPENID_MODE = "openid.mode";
+    private static final String OPENID_CLAIMED_ID = "openid.claimed_id";
+    public static final String axmapAttrName = "axmap";
+    public static final String sregmapAttrName = "sregmap";
+    public static final String OPENID_CLAIMED_ID_SESSION = "claimed";
+    public static final String OPENID_ID_SESSION = "openid";
+
+    private String openidVersion = "";
+    private String identity = "";
+
+    /********************************************************************************
+     ***        Note: this variable can not be static!!!                        *****
+     ***        Openid4java does not handle it correctly if ConsumerManager     *****
+     ***        is a static variable.                                           *****
+     ********************************************************************************/
+    private ConsumerManager manager;
+
+    private static final String SREFilenameprop = "sre_prop_file";
+    private static final String AXFilenameprop = "ax_prop_file";
+    private static String SREFilename;
+    private static String AXFilename;
+    private static OpenIDSREStore srestore;
+    private static OpenIDAXStore axstore;
+
+
+    //whether SRC and AX will be tested
+    private static boolean bypassSRE = false;
+    private static boolean bypassAX = true;
+
+    @Override
+    public void init(ServletConfig config) throws ServletException {
+        super.init(config);
+
+        if( baseURL == null || baseURL.length() == 0 ){
+        	contextPath = ServletUtil.getContextPath(config);
+        	if( contextPath != null )
+    	        contextPath += "/";
+        }
+
+        try {
+            ServletContext context = getServletContext();
+            SREFilename = context.getInitParameter(SREFilenameprop);
+            AXFilename = context.getInitParameter(AXFilenameprop);
+            SREFilename = context.getRealPath(SREFilename);
+            AXFilename = context.getRealPath(AXFilename);
+            srestore = new OpenIDSREStore(SREFilename);
+            axstore = new OpenIDAXStore(AXFilename);
+
+            this.manager = new ConsumerManager();
+            DummyRealmVerifier rv = new DummyRealmVerifier();
+            rv.setEnforceRpId(false);
+            this.manager.setRealmVerifier(rv);
+        } catch (ConsumerException e) {
+            throw new ServletException(e);
+        }
+    }
+
+
+    @Override
+    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+            throws ServletException, IOException {
+        processInit(req);
+        AuthProcedure(req, resp);
+    }
+
+    @Override
+    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
+            throws ServletException, IOException {
+        processInit(req);
+        AuthProcedure(req, resp);
+    }
+
+    /* get host address and set some addresses */
+    private void processInit(HttpServletRequest request){
+    	if(Util.isEmpty(hostAddr)){
+    		hostAddr = ServletUtil.getBaseURL(request);;
+    		baseURL = hostAddr + contextPath;
+    		returnTo = baseURL + "www/openidsignin";
+    		mainSuccPage = baseURL + "index.jsp?state=0";
+    		mainSuccPageBase = "/index.jsp?state=0";
+    		mainFailPage = baseURL + "index.jsp?state=1";
+    		mainSuccUserPage = baseURL + "www/ishindig.html";
+    	}
+    }
+    
+    private void AuthProcedure(HttpServletRequest req, HttpServletResponse resp)
+            throws ServletException, IOException {
+        if( (req.getParameter(OPENID_IDENTITY) != null) ) {
+            //get response from OpenID provider
+            parseAuthResponse(req, resp);
+        }else if(req.getParameter(OPENID_MODE)!=null){
+            if(req.getParameter(OPENID_MODE).equals("cancel")){//authentication failed
+                resp.sendRedirect(mainFailPage);
+            }else if(req.getParameter(OPENID_MODE).equals("setup_needed")){//immediate request is not appropriate.
+                resp.sendRedirect(mainFailPage);
+            }
+        }else{ //get request from end user
+            handleReqFromClient(req, resp);
+        }
+    }
+
+    /** 
+     * After getting request from end user, this function sends authentication request
+     *  to the OpenID provider
+     */
+    public void handleReqFromClient(HttpServletRequest request, HttpServletResponse response){
+        /* first, get the claimed openid submitted by end user */
+        String openid = request.getParameter(OPENID_CLAIMED_ID);
+        logger.info(openid);
+        
+        if(Util.isEmpty(openid)){
+            try{
+                response.sendRedirect(mainFailPage);
+            } catch (Exception e) {
+                logger.severe(e.toString());
+            }
+            return;
+        }
+
+        boolean succ = true;
+
+        try{
+            /* Simple Registration Extension */
+            SRegRequest sreg = null;
+            if( bypassSRE == false ){
+                sreg = SRegRequest.createFetchRequest();
+                Map<String, String> map = srestore.getMap();
+                Set entries = map.entrySet();
+                Iterator it = entries.iterator();
+                while( it.hasNext() ){
+                    Map.Entry<String, String> entry = (Map.Entry<String,String>)it.next();
+                    String key = (String)entry.getKey();
+                    sreg.addAttribute(key.substring("openid.sreg.".length()), true); // required
+                }
+            }
+
+            /* Attribute Exchange */
+            FetchRequest fetch = null;
+            if( bypassAX == false ){
+                fetch = FetchRequest.createFetchRequest();
+                Map<String, String> axmap = axstore.getMap();
+                Set axentries = axmap.entrySet();
+                Iterator axit = axentries.iterator();
+                while( axit.hasNext() ){
+                    Map.Entry<String, String> entry = (Map.Entry<String,String>)axit.next();
+                    String key = (String)entry.getKey(); //Label
+                    String value = (String)entry.getValue(); //Type URI
+                    if( request.getParameter(key) != null ){
+                        logger.info( key + ":" + request.getParameter(key) );
+                        if( "on".compareTo( request.getParameter(key) ) == 0)
+                            // .,:\n are not allowed in the alias
+                            fetch.addAttribute(key.replaceAll("[.,:\n]","-"), value, false); // required
+                    }
+                }
+            }
+
+            /* Do the actual work */
+            logger.info("Starting OpenID provider discovery.");
+            List discoveries = manager.discover(openid);
+            logger.info("Discovered OpenID provider");
+            DiscoveryInformation discovered = manager.associate(discoveries);
+            logger.info("Associate a URL.");
+            HttpSession session = request.getSession(true);
+            session.setAttribute("discovered", discovered);
+            openidVersion = discovered.getVersion();
+            logger.info("OpenId version " + openidVersion);
+
+            String nextURL      = request.getParameter(SignIn.keyNextURL);
+            String fullReturnTo = returnTo;
+            try {
+                /**
+                 * For OpenID authentication, parameter "next" is lost.
+                 * The reason is that for some OpenID providers (e.g. Blogspot)
+                 * there is limitation on length of the request URL.
+                 */
+                // fullReturnTo += "?" + SignIn.keyNextURL + "=" +
+                //     URLEncoder.encode(nextURL, "utf-8");
+            } catch(Exception ex) {
+                System.err.println("parameter next cannot be url encoded.");
+            }
+            AuthRequest authReq = manager.authenticate(discovered, fullReturnTo);
+
+            session.setAttribute(OPENID_CLAIMED_ID_SESSION, openid);
+
+            /* add those extensions you want to test */
+            if( bypassSRE == false )
+                authReq.addExtension(sreg);
+            if( bypassAX == false )
+                authReq.addExtension(fetch);
+
+            logger.info("Redirects to URL:" + authReq.getDestinationUrl(true));
+            response.sendRedirect(authReq.getDestinationUrl(true));
+        } catch (Exception e) {
+            logger.severe(e.toString());
+            succ = false;
+        }
+
+        /* Redirection failed */
+        if( succ == false ){
+            try{
+                response.sendRedirect(mainFailPage);
+            }catch (Exception e) {
+                logger.severe(e.toString());
+            }
+        }
+    }
+
+    /**
+     * get authentication response from OpenID Provider
+     */
+    public void parseAuthResponse(HttpServletRequest request, HttpServletResponse response){
+        try {
+            HttpSession session = request.getSession();
+            ParameterList openidResp = new ParameterList(request.getParameterMap());
+            
+            DiscoveryInformation discovered = (DiscoveryInformation)session.getAttribute("discovered");
+            session.removeAttribute("discovered");
+
+            StringBuffer receivingURL = request.getRequestURL();
+            String queryString = request.getQueryString();
+            if( queryString != null && queryString.length() > 0 )
+                receivingURL.append("?").append(queryString);
+            VerificationResult verification = manager.verify(receivingURL.toString(), openidResp, discovered);
+
+            Identifier verified = verification.getVerifiedId();
+            String openid = null;
+            
+            if( verified != null ){
+                AuthSuccess authSuccess = (AuthSuccess)verification.getAuthResponse();
+                /*
+                 * This piece of code does not work with blogspot.com while it works well
+                 * with myopenid.com.
+                request.setAttribute("opendpoint", authSuccess.getOpEndpoint());
+                request.setAttribute("claimed", authSuccess.getClaimed());
+                session.setAttribute("openid", authSuccess.getClaimed());
+                 */
+                openid = (String)session.getAttribute(OPENID_CLAIMED_ID_SESSION);
+                session.removeAttribute(OPENID_CLAIMED_ID_SESSION);
+                
+                if (authSuccess.hasExtension(SRegMessage.OPENID_NS_SREG)) {
+                    logger.info("resp contains SREG extension");
+                    MessageExtension ext = authSuccess.getExtension(SRegMessage.OPENID_NS_SREG);
+                    if (ext instanceof SRegResponse) {
+                        logger.info("got a sreg response");
+                        SRegResponse sregResp = (SRegResponse) ext;
+                        Map sregmap = sregResp.getAttributes();
+                        request.setAttribute(sregmapAttrName,  sregmap);
+                    }
+                }
+
+                if (authSuccess.hasExtension(AxMessage.OPENID_NS_AX)) {
+                    FetchResponse fetchResp = (FetchResponse) authSuccess.getExtension(AxMessage.OPENID_NS_AX);
+                    logger.info("resp contains AX extension");
+
+                    request.setAttribute(axmapAttrName, fetchResp.getAttributes());
+                    List aliases = fetchResp.getAttributeAliases();
+                    for (Iterator iter = aliases.iterator(); iter.hasNext();) {
+                            String alias = (String) iter.next();
+                            List values = fetchResp.getAttributeValues(alias);
+                            if (values.size() > 0) {
+                                logger.info(alias+":"+values.get(0));
+                            }
+                    }
+                }
+
+
+                //session.setAttribute("user.openid", verified.getIdentifier() );
+                //response.sendRedirect(this.mainSuccPage);
+                //getServletContext().getRequestDispatcher(this.mainSuccPageBase).forward(request, response);
+                authPostProcess(this, request, response, openid);
+            }else{
+                System.err.println("Authentication failed");
+                response.sendRedirect(this.mainFailPage);
+            }
+        } catch(Exception e) {
+            e.printStackTrace();
+        }
+    }
+    
+    
+	/**
+	 * Post(not POST request, but post processing which is contrary to pre)
+	 * processing of openid authentication.
+	 */
+    public static void authPostProcess(HttpServlet servlet,
+            HttpServletRequest request, HttpServletResponse response, String openid)
+            throws ServletException, IOException {
+    	Logger logger = Logger.getLogger(OpenIdAuth.class.getSimpleName());
+        logger.info("OpenID authentication post processing :" + openid );
+        BaseHttpServlet.markOpenID(request, openid);
+        try{
+            User user = null;
+            if( (user = UserDBMgr.getUserByOpenID(openid)) == null ){//the user is new
+            	BaseHttpServlet.markSignupState(request, -1);
+                RedirectionHub.forward2SignPage(servlet, request, response, false);
+            }else{//the user has created account before.
+                ServletSessionMgr.putAuthenUserInSession(request, user.getScreenname());
+                logger.info("old user openid");
+                RedirectionHub.forward2Home(servlet, request, response);
+            }
+        }catch(Exception e){
+            RedirectionHub.forward2SignPage(servlet, request, response, true);
+            logger.severe(e.toString());
+        }
+    }
+}
+
+/* Relying party realm verification is mandatory in new OpenID specification.
+ * This class makes verification process trivial by returning 0 (0 means success)
+ * in any case.
+ */
+class DummyRealmVerifier extends RealmVerifier{
+    public int validate(java.lang.String realm, java.lang.String returnTo){
+        return 0;
+    }
+
+    public int validate(java.lang.String realm, java.lang.String returnTo, boolean enforceRpId) {
+        return 0;
+    }
+}
+

Added: incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/servlet/OpenIdSignIn.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/servlet/OpenIdSignIn.java?rev=1087520&view=auto
==============================================================================
--- incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/servlet/OpenIdSignIn.java (added)
+++ incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/usermanage/servlet/OpenIdSignIn.java Fri Apr  1 00:29:22 2011
@@ -0,0 +1,77 @@
+package cgl.shindig.usermanage.servlet;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ *
+ */
+
+
+import java.io.*;
+import java.util.*;
+import javax.servlet.*;
+import javax.servlet.http.*;
+
+import cgl.shindig.usermanage.*;
+
+import org.openid4java.consumer.*;
+import org.openid4java.discovery.*;
+import org.openid4java.message.*;
+import org.openid4java.message.sreg.*;
+import org.openid4java.message.ax.*;
+import org.openid4java.server.*;
+
+/** This class handles signin of openid users. */
+public class OpenIdSignIn extends HttpServlet{
+
+    /* This is name of the input field in the HTML. */
+    private static final String keyOpenid   = "openid.claimed_id";
+
+
+    public void doPost(HttpServletRequest request, HttpServletResponse response)
+            throws javax.servlet.ServletException, java.io.IOException{
+        String openid   = request.getParameter(keyOpenid);
+
+        int state = 0; //state of this operation
+        User user = null;
+        if( openid == null ){
+            //input is invalid
+            state = 1;
+        } else {
+            //search for it in the database.
+            user = UserDBMgr.getUserByOpenID( openid );
+            if( user == null ){
+                //no corresponding user is found in database.
+                state = 2;
+            }
+        }
+        OpenIdAuth.markSigninState(request, state);
+        
+        if( state != 0 ){//sign in failed
+            RedirectionHub.forward2SignPage(this, request, response, false);
+        }else{
+            request.setAttribute("user", user);
+            ServletSessionMgr.putAuthenUserInSession(request, user.getScreenname());
+            RedirectionHub.forward2Home(this, request, response);
+        }
+    }
+
+    public void doGet(HttpServletRequest request, HttpServletResponse response)
+    	throws javax.servlet.ServletException, java.io.IOException{
+        RedirectionHub.forward2SignPage(this, request, response, true);
+    }
+}