Commits

Anonymous committed 6b0e9cf

Patch from USER-49

  • Participants
  • Parent commits f37135d

Comments (0)

Files changed (13)

example/manager/WEB-INF/classes/osuser.xml

 
     <!-- EJB providers -->
 	<provider class="com.opensymphony.user.provider.ejb.EJBCredentialsProvider">
-		<property name="location">ejb/osuser/User</property>
+		<property name="location.manage">ejb/osuser/Manager</property>
 	</provider>
 	<provider class="com.opensymphony.user.provider.ejb.EJBProfileProvider">
-		<property name="location.user">ejb/osuser/User</property>
-		<property name="location.group">ejb/osuser/Group</property>
+		<property name="location.manage">ejb/osuser/Manager</property>
 	</provider>
 	<provider class="com.opensymphony.user.provider.ejb.EJBAccessProvider">
-		<property name="location.user">ejb/osuser/User</property>
-		<property name="location.group">ejb/osuser/Group</property>
-		<property name="location.membership">ejb/osuser/Membership</property>
+		<property name="location.manage">ejb/osuser/Manager</property>
 	</provider>
 
     <!-- Hibernate Providers -->

src/java/com/opensymphony/user/provider/hibernate/HibernateAccessProvider.java

 import com.opensymphony.user.provider.AccessProvider;
 import com.opensymphony.user.provider.hibernate.entity.HibernateGroup;
 import com.opensymphony.user.provider.hibernate.entity.HibernateUser;
+import com.opensymphony.user.provider.hibernate.impl.HibernateGroupImpl;
 
 import java.util.ArrayList;
 import java.util.Collections;
     * @return Whether entity was successfully created.
     */
     public boolean create(String name) {
-        HibernateGroup group = new HibernateGroup();
+        HibernateGroup group = new HibernateGroupImpl();
         group.setName(name);
 
         return getGroupDAO().saveGroup(group);
     */
     public boolean removeFromGroup(String username, String groupname) {
         boolean result = false;
-        HibernateUser user = null;
-
-        user = getUserDAO().findUserByUsernameAndGroupname(username, groupname);
+        HibernateUser user = getUserDAO().findUserByUsernameAndGroupname(username, groupname);
 
         if (user != null) {
             Iterator groupsIter = user.getGroups().iterator();

src/java/com/opensymphony/user/provider/hibernate/HibernateCredentialsProvider.java

 
 import com.opensymphony.user.provider.CredentialsProvider;
 import com.opensymphony.user.provider.hibernate.entity.HibernateUser;
+import com.opensymphony.user.provider.hibernate.impl.HibernateUserImpl;
 
 import java.util.ArrayList;
 import java.util.Collections;
      * @return Whether entity was successfully created.
      */
     public boolean create(String name) {
-        HibernateUser user = new HibernateUser();
+        HibernateUser user = new HibernateUserImpl();
         user.setName(name);
 
         return getUserDAO().saveUser(user);

src/java/com/opensymphony/user/provider/hibernate/HibernateProfileProvider.java

     * Retrieve profile for User with given name.
     */
     public PropertySet getPropertySet(String name) {
-        PropertySet propertySet = null;
+        PropertySet propertySet;
 
         HashMap args = new HashMap();
 

src/java/com/opensymphony/user/provider/hibernate/dao/SessionManager.java

         }
     }
 
+    public SessionManager(SessionFactory sessionFactory) throws HibernateException {
+        this.sessionFactory = sessionFactory;
+    }
+
     //~ Methods ////////////////////////////////////////////////////////////////
 
     public Session getSession() throws HibernateException {

src/java/com/opensymphony/user/provider/hibernate/entity/HibernateGroup.hbm.xml

-<?xml version="1.0"?>
-<!DOCTYPE hibernate-mapping PUBLIC
-	"-//Hibernate/Hibernate Mapping DTD//EN"
-	"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
-
-<hibernate-mapping>
-    <class name="com.opensymphony.user.provider.hibernate.entity.HibernateGroup"
-           table="os_group" dynamic-update="true" >
-<!--        <jcs-cache usage="read-write"/>-->
-        <id name="id" type="long" column="id" unsaved-value="0">
-            <generator class="vm"/>
-        </id>
-
-        <property name="name" column="groupname" type="string" not-null="true" unique="true" />
-        <set name="users" table="os_user_group" inverse="true" cascade="none" lazy="false">
-<!--            <jcs-cache usage="read-write"/>-->
-            <key column="group_id"/>
-            <many-to-many column="user_id" class="com.opensymphony.user.provider.hibernate.entity.HibernateUser"/>
-        </set>
-
-    </class>
-</hibernate-mapping>

src/java/com/opensymphony/user/provider/hibernate/entity/HibernateGroup.java

  */
 package com.opensymphony.user.provider.hibernate.entity;
 
-import java.util.*;
+import java.util.List;
+import java.util.Set;
 
 
 /**
- * @author <a href="mailto:matthew@linjafoo.com">Matthew E. Porter</a>
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision: 1.2 $
  */
-public class HibernateGroup extends BaseHibernateEntity {
-    //~ Instance fields ////////////////////////////////////////////////////////
-
-    private Set users = null;
-
+public interface HibernateGroup {
     //~ Methods ////////////////////////////////////////////////////////////////
 
-    public List getUserList() {
-        ArrayList userList = new ArrayList();
+    public void setId(long id);
 
-        if (this.users != null) {
-            userList.addAll(this.users);
-        }
+    public long getId();
 
-        return userList;
-    }
+    public void setName(String name);
 
-    public List getUserNameList() {
-        ArrayList userNameList = new ArrayList();
+    public String getName();
 
-        if ((this.users != null) && (this.users.size() > 0)) {
-            Iterator userIter = this.users.iterator();
+    List getUserList();
 
-            while (userIter.hasNext()) {
-                HibernateUser user = (HibernateUser) userIter.next();
-                userNameList.add(user.getName());
-            }
-        }
+    List getUserNameList();
 
-        return userNameList;
-    }
+    void setUsers(Set users);
 
-    public void setUsers(Set users) {
-        this.users = users;
-    }
+    Set getUsers();
 
-    public Set getUsers() {
-        return users;
-    }
+    void addUser(HibernateUser user);
 
-    public void addUser(HibernateUser user) {
-        if (users == null) {
-            users = new HashSet(1);
-        }
+    boolean removeUser(HibernateUser user);
 
-        users.add(user);
-    }
-
-    public boolean removeUser(HibernateUser user) {
-        if (user != null) {
-            return users.remove(user);
-        } else {
-            return false;
-        }
-    }
-
-    public boolean removeUser(String username) {
-        if (users != null) {
-            Iterator userIter = users.iterator();
-
-            while (userIter.hasNext()) {
-                HibernateUser user = (HibernateUser) userIter.next();
-
-                if (user.getName().equals(username)) {
-                    return removeUser(user);
-                }
-            }
-        }
-
-        return false;
-    }
+    boolean removeUser(String username);
 }

src/java/com/opensymphony/user/provider/hibernate/entity/HibernateGroupImpl.hbm.xml

+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+	"-//Hibernate/Hibernate Mapping DTD//EN"
+	"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
+
+<hibernate-mapping>
+    <class name="com.opensymphony.user.provider.hibernate.entity.HibernateGroupImpl"
+           table="os_group" dynamic-update="true" >
+<!--        <jcs-cache usage="read-write"/>-->
+        <id name="id" type="long" column="id" unsaved-value="0">
+            <generator class="vm"/>
+        </id>
+
+        <property name="name" column="groupname" type="string" not-null="true" unique="true" />
+        <set name="users" table="os_user_group" inverse="true" cascade="none" lazy="false">
+<!--            <jcs-cache usage="read-write"/>-->
+            <key column="group_id"/>
+            <many-to-many column="user_id" class="com.opensymphony.user.provider.hibernate.entity.HibernateUserImpl"/>
+        </set>
+
+    </class>
+</hibernate-mapping>

src/java/com/opensymphony/user/provider/hibernate/entity/HibernateUser.hbm.xml

-<?xml version="1.0"?>
-<!DOCTYPE hibernate-mapping PUBLIC
-	"-//Hibernate/Hibernate Mapping DTD//EN"
-	"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
-
-<hibernate-mapping>
-    <class name="com.opensymphony.user.provider.hibernate.entity.HibernateUser" table="os_user" dynamic-update="true">
-<!--        <jcs-cache usage="read-write"/>-->
-        <id name="id" type="long" column="id" unsaved-value="0" >
-            <generator class="vm"/>
-        </id>
-
-        <property name="name" column="username" type="string" not-null="true" unique="true" />
-        <property name="passwordHash" column="passwd" type="string" not-null="false"/>
-
-        <set name="groups" table="os_user_group" inverse="false" cascade="none" lazy="false">
-<!--            <jcs-cache usage="read-write"/>-->
-            <key column="user_id"/>
-            <many-to-many column="group_id" class="com.opensymphony.user.provider.hibernate.entity.HibernateGroup"/>
-        </set>
-
-    </class>
-</hibernate-mapping>

src/java/com/opensymphony/user/provider/hibernate/entity/HibernateUser.java

  */
 package com.opensymphony.user.provider.hibernate.entity;
 
-import com.opensymphony.user.provider.ejb.util.Base64;
-import com.opensymphony.user.provider.ejb.util.PasswordDigester;
-
-import java.util.*;
+import java.util.List;
+import java.util.Set;
 
 
 /**
- * @author <a href="mailto:matthew@metissian.com">Matthew E. Porter</a>
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision: 1.3 $
  */
-public class HibernateUser extends BaseHibernateEntity {
-    //~ Instance fields ////////////////////////////////////////////////////////
-
-    private Set groups;
-    private String passwordHash;
-
+public interface HibernateUser {
     //~ Methods ////////////////////////////////////////////////////////////////
 
-    public List getGroupList() {
-        ArrayList groupList = new ArrayList();
+    public void setId(long id);
 
-        if ((this.groups != null) && (this.groups.size() > 0)) {
-            Iterator groupIter = this.groups.iterator();
+    public long getId();
 
-            while (groupIter.hasNext()) {
-                HibernateGroup group = (HibernateGroup) groupIter.next();
-                groupList.add(group);
-            }
-        }
+    public void setName(String name);
 
-        return groupList;
-    }
+    public String getName();
 
-    public List getGroupNameList() {
-        ArrayList groupNameList = new ArrayList();
+    List getGroupList();
 
-        if ((this.groups != null) && (this.groups.size() > 0)) {
-            Iterator groupIter = this.groups.iterator();
+    List getGroupNameList();
 
-            while (groupIter.hasNext()) {
-                HibernateGroup group = (HibernateGroup) groupIter.next();
-                groupNameList.add(group.getName());
-            }
-        }
+    void setGroups(Set groups);
 
-        return groupNameList;
-    }
+    Set getGroups();
 
-    public void setGroups(Set groups) {
-        this.groups = groups;
-    }
+    void setPassword(String password);
 
-    public Set getGroups() {
-        return groups;
-    }
+    void setPasswordHash(String passwordHash);
 
-    public void setPassword(String password) {
-        setPasswordHash(createHash(password));
-    }
+    String getPasswordHash();
 
-    public void setPasswordHash(String passwordHash) {
-        this.passwordHash = passwordHash;
-    }
+    void addGroup(HibernateGroup group);
 
-    public String getPasswordHash() {
-        return passwordHash;
-    }
+    boolean authenticate(String password);
 
-    public void addGroup(HibernateGroup group) {
-        if (this.groups == null) {
-            this.groups = new HashSet(1);
-        }
-
-        this.groups.add(group);
-    }
-
-    /**
-     * Verify that supplied password matches that of user.
-     *
-     */
-    public boolean authenticate(String password) {
-        if ((password == null) || (getPasswordHash() == null) || (password.length() == 0)) {
-            return false;
-        } else {
-            return compareHash(getPasswordHash(), password);
-        }
-    }
-
-    public void removeGroup(HibernateGroup group) {
-        if ((this.groups != null) && (this.groups.contains(group))) {
-            this.groups.remove(group);
-        }
-    }
-
-    private boolean compareHash(String hashedValue, String unhashedValue) {
-        return hashedValue.equals(createHash(unhashedValue));
-    }
-
-    private String createHash(String original) {
-        byte[] digested = PasswordDigester.digest(original.getBytes());
-        byte[] encoded = Base64.encode(digested);
-
-        return new String(encoded);
-    }
+    void removeGroup(HibernateGroup group);
 }

src/java/com/opensymphony/user/provider/hibernate/entity/HibernateUserImpl.hbm.xml

+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+	"-//Hibernate/Hibernate Mapping DTD//EN"
+	"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
+
+<hibernate-mapping>
+    <class name="com.opensymphony.user.provider.hibernate.entity.HibernateUserImpl" table="os_user" dynamic-update="true">
+<!--        <jcs-cache usage="read-write"/>-->
+        <id name="id" type="long" column="id" unsaved-value="0" >
+            <generator class="vm"/>
+        </id>
+
+        <property name="name" column="username" type="string" not-null="true" unique="true" />
+        <property name="passwordHash" column="passwd" type="string" not-null="false"/>
+
+        <set name="groups" table="os_user_group" inverse="false" cascade="none" lazy="false">
+<!--            <jcs-cache usage="read-write"/>-->
+            <key column="user_id"/>
+            <many-to-many column="group_id" class="com.opensymphony.user.provider.hibernate.entity.HibernateGroupImpl"/>
+        </set>
+
+    </class>
+</hibernate-mapping>

src/java/com/opensymphony/user/provider/hibernate/impl/HibernateGroupImpl.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.user.provider.hibernate.impl;
+
+import com.opensymphony.user.provider.hibernate.entity.BaseHibernateEntity;
+import com.opensymphony.user.provider.hibernate.entity.HibernateGroup;
+import com.opensymphony.user.provider.hibernate.entity.HibernateUser;
+
+import java.util.*;
+
+
+/**
+ * @author <a href="mailto:matthew@linjafoo.com">Matthew E. Porter</a>
+ */
+public class HibernateGroupImpl extends BaseHibernateEntity implements HibernateGroup {
+    //~ Instance fields ////////////////////////////////////////////////////////
+
+    private Set users = null;
+
+    //~ Methods ////////////////////////////////////////////////////////////////
+
+    public List getUserList() {
+        ArrayList userList = new ArrayList();
+
+        if (this.users != null) {
+            userList.addAll(this.users);
+        }
+
+        return userList;
+    }
+
+    public List getUserNameList() {
+        ArrayList userNameList = new ArrayList();
+
+        if ((this.users != null) && (this.users.size() > 0)) {
+            Iterator userIter = this.users.iterator();
+
+            while (userIter.hasNext()) {
+                HibernateUser user = (HibernateUser) userIter.next();
+                userNameList.add(user.getName());
+            }
+        }
+
+        return userNameList;
+    }
+
+    public void setUsers(Set users) {
+        this.users = users;
+    }
+
+    public Set getUsers() {
+        return users;
+    }
+
+    public void addUser(HibernateUser user) {
+        if (users == null) {
+            users = new HashSet(1);
+        }
+
+        users.add(user);
+    }
+
+    public boolean removeUser(HibernateUser user) {
+        if (user != null) {
+            return users.remove(user);
+        } else {
+            return false;
+        }
+    }
+
+    public boolean removeUser(String username) {
+        if (users != null) {
+            Iterator userIter = users.iterator();
+
+            while (userIter.hasNext()) {
+                HibernateUser user = (HibernateUser) userIter.next();
+
+                if (user.getName().equals(username)) {
+                    return removeUser(user);
+                }
+            }
+        }
+
+        return false;
+    }
+}

src/java/com/opensymphony/user/provider/hibernate/impl/HibernateUserImpl.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.user.provider.hibernate.impl;
+
+import com.opensymphony.user.provider.ejb.util.Base64;
+import com.opensymphony.user.provider.ejb.util.PasswordDigester;
+import com.opensymphony.user.provider.hibernate.entity.BaseHibernateEntity;
+import com.opensymphony.user.provider.hibernate.entity.HibernateGroup;
+import com.opensymphony.user.provider.hibernate.entity.HibernateUser;
+
+import java.util.*;
+
+
+/**
+ * @author <a href="mailto:matthew@metissian.com">Matthew E. Porter</a>
+ */
+public class HibernateUserImpl extends BaseHibernateEntity implements HibernateUser {
+    //~ Instance fields ////////////////////////////////////////////////////////
+
+    private Set groups;
+    private String passwordHash;
+
+    //~ Methods ////////////////////////////////////////////////////////////////
+
+    public List getGroupList() {
+        ArrayList groupList = new ArrayList();
+
+        if ((this.groups != null) && (this.groups.size() > 0)) {
+            Iterator groupIter = this.groups.iterator();
+
+            while (groupIter.hasNext()) {
+                HibernateGroup group = (HibernateGroup) groupIter.next();
+                groupList.add(group);
+            }
+        }
+
+        return groupList;
+    }
+
+    public List getGroupNameList() {
+        ArrayList groupNameList = new ArrayList();
+
+        if ((this.groups != null) && (this.groups.size() > 0)) {
+            Iterator groupIter = this.groups.iterator();
+
+            while (groupIter.hasNext()) {
+                HibernateGroup group = (HibernateGroup) groupIter.next();
+                groupNameList.add(group.getName());
+            }
+        }
+
+        return groupNameList;
+    }
+
+    public void setGroups(Set groups) {
+        this.groups = groups;
+    }
+
+    public Set getGroups() {
+        return groups;
+    }
+
+    public void setPassword(String password) {
+        setPasswordHash(createHash(password));
+    }
+
+    public void setPasswordHash(String passwordHash) {
+        this.passwordHash = passwordHash;
+    }
+
+    public String getPasswordHash() {
+        return passwordHash;
+    }
+
+    public void addGroup(HibernateGroup group) {
+        if (this.groups == null) {
+            this.groups = new HashSet(1);
+        }
+
+        this.groups.add(group);
+    }
+
+    /**
+     * Verify that supplied password matches that of user.
+     *
+     */
+    public boolean authenticate(String password) {
+        if ((password == null) || (getPasswordHash() == null) || (password.length() == 0)) {
+            return false;
+        } else {
+            return compareHash(getPasswordHash(), password);
+        }
+    }
+
+    public void removeGroup(HibernateGroup group) {
+        if ((this.groups != null) && (this.groups.contains(group))) {
+            this.groups.remove(group);
+        }
+    }
+
+    private boolean compareHash(String hashedValue, String unhashedValue) {
+        return hashedValue.equals(createHash(unhashedValue));
+    }
+
+    private String createHash(String original) {
+        byte[] digested = PasswordDigester.digest(original.getBytes());
+        byte[] encoded = Base64.encode(digested);
+
+        return new String(encoded);
+    }
+}