You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by Leandro Rodrigo Saad Cruz <le...@ibnetwork.com.br> on 2001/03/23 04:23:46 UTC

[PATCH] Changing User implementation

Hi all... I've changed my patches ( removed tabs and positioned the
Braces )
Sorry if I didn't make it right the first time.


I've created an interface called UserPeer which must be implemented by
your User impl (TurbineUserPeer)
so you must tell you impl of SesurityService what class impl UserPeer

 package org.apache.turbine.om.security.peer;

 public interface UserPeer {
  public static String USERNAME = "USERNAME";
  public static String USER_ID = "USER_ID";
  public String getFullColumnName(String name);
 }

add the following line to TR.properties
services.TurbineSecurityService.userPeer.class=org.apache.turbine.om.security.peer.TurbineUserPeer



===================================================================
RCS file:
/home/cvspublic/jakarta-turbine/src/java/org/apache/turbine/services/security/DBSecurityService.java,v

retrieving revision 1.17
diff -u -B -b -r1.17 DBSecurityService.java
--- services/security/DBSecurityService.java    2001/03/06 06:12:46
1.17
+++ services/security/DBSecurityService.java    2001/03/22 16:39:26
@@ -73,7 +73,6 @@
 import org.apache.turbine.om.security.peer.PermissionPeer;
 import org.apache.turbine.om.security.peer.UserGroupRolePeer;
 import org.apache.turbine.om.security.peer.RolePermissionPeer;
-import org.apache.turbine.om.security.peer.TurbineUserPeer;
 import org.apache.turbine.util.security.AccessControlList;
 import org.apache.turbine.util.security.GroupSet;
 import org.apache.turbine.util.security.RoleSet;
@@ -185,7 +184,7 @@
         try
         {
             lockExclusive();
-            userExists=TurbineUserPeer.checkExists(user);
+            userExists=TurbineSecurity.accountExists(user);
             groupExists=GroupPeer.checkExists(group);
             roleExists=RolePeer.checkExists(role);
             if(userExists && groupExists && roleExists)
@@ -239,7 +238,7 @@
         try
         {
             lockExclusive();
-            userExists=TurbineUserPeer.checkExists(user);
+            userExists=TurbineSecurity.accountExists(user);
             groupExists=GroupPeer.checkExists(group);
             roleExists=RolePeer.checkExists(role);
             if(userExists && groupExists && roleExists)
@@ -291,7 +290,7 @@
         try
         {
             lockExclusive();
-            userExists=TurbineUserPeer.checkExists(user);
+            userExists=TurbineSecurity.accountExists(user);
             if(userExists)
             {
                 // The following would not work, due to an annoying
misfeature of Village.

===================================================================
RCS file:
/home/cvspublic/jakarta-turbine/src/java/org/apache/turbine/services/security/SecurityService.java,v

retrieving revision 1.16
diff -u -B -b -r1.16 SecurityService.java
--- services/security/SecurityService.java      2001/03/06 06:12:47
1.16
+++ services/security/SecurityService.java      2001/03/22 16:46:26
@@ -60,6 +60,8 @@
 import org.apache.turbine.om.security.Group;
 import org.apache.turbine.om.security.Role;
 import org.apache.turbine.om.security.Permission;
+import org.apache.turbine.om.security.peer.UserPeer;
+
 import org.apache.turbine.util.security.GroupSet;
 import org.apache.turbine.util.security.RoleSet;
 import org.apache.turbine.util.security.PermissionSet;
@@ -97,7 +99,13 @@
     /** the key within services's properties for user implementation
classname (user.class) */
     public static final String USER_CLASS_KEY = "user.class";

+    /** the key within services's properties for user implementation
classname (user.class)  - Leandro */
+    public static final String USER_PEER_CLASS_KEY = "userPeer.class";
+
     /** the default implementation of User interface
(org.apache.turbine.om.security.DBUser) */
+    public static final String USER_PEER_CLASS_DEFAULT =
"org.apache.turbine.om.security.peer.TurbineUserPeer";
+
+    /** the default implementation of User interface
(org.apache.turbine.om.security.DBUser) */
     public static final String USER_CLASS_DEFAULT =
"org.apache.turbine.om.security.TurbineUser";

     /** the key within services's properties for user implementation
classname (user.manager) */
@@ -146,6 +154,30 @@
         throws UnknownEntityException;

     /**
+     * Returns the Class object for the implementation of UserPeer
interface
+     * used by the system (defined in TR.properties)
+     *
+     * @return the implementation of UserPeer interface used by the
system.
+     * @throws UnknownEntityException if the system's implementation of
UserPeer
+     *         interface could not be determined.
+     */
+    public Class getUserPeerClass()
+        throws UnknownEntityException;
+
+    /**
+     * Construct a UserPeer object.
+     *
+     * This method calls getUserPeerClass, and then creates a new
object using
+     * the default constructor.
+     *
+     * @return an object implementing UserPeer interface.
+     * @throws UnknownEntityException if the object could not be
instantiated.
+     */
+    public UserPeer getUserPeerInstance()
+        throws UnknownEntityException;
+
+
+    /**
      * Check whether a specified user's account exists.
      *
      * The login name is used for looking up the account.


===================================================================
RCS file:
/home/cvspublic/jakarta-turbine/src/java/org/apache/turbine/services/security/BaseSecurityService.java,v

retrieving revision 1.20
diff -u -B -b -r1.20 BaseSecurityService.java
--- services/security/BaseSecurityService.java  2001/03/06 06:12:46
1.20
+++ services/security/BaseSecurityService.java  2001/03/22 16:49:13
@@ -63,6 +63,8 @@
 import org.apache.turbine.om.security.Group;
 import org.apache.turbine.om.security.Role;
 import org.apache.turbine.om.security.Permission;
+import org.apache.turbine.om.security.peer.UserPeer;
+
 import org.apache.turbine.services.TurbineBaseService;
 import org.apache.turbine.services.InitializationException;
 import org.apache.turbine.services.resources.TurbineResources;
@@ -238,6 +243,35 @@
         return user;
     }

+    public Class getUserPeerClass() throws UnknownEntityException
+    {
+        String userPeerClassName = getProperties().getProperty(
+
SecurityService.USER_PEER_CLASS_KEY,
+
SecurityService.USER_PEER_CLASS_DEFAULT);
+        try
+        {
+            return Class.forName(userPeerClassName);
+        }
+        catch(Exception e)
+        {
+            throw new UnknownEntityException("Failed create a Class
object for UserPeer implementation", e);
+        }
+    }
+
+    public UserPeer getUserPeerInstance() throws UnknownEntityException

+    {
+        UserPeer up;
+        try
+        {
+            up = (UserPeer)getUserPeerClass().newInstance();
+        }
+        catch(Exception e)
+        {
+            throw new UnknownEntityException("Failed instantiate an
UserPeer implementation object", e);
+        }
+        return up;
+    }
+
     /**
      * Check whether a specified user's account exists.
      *


===================================================================
RCS file:
/home/cvspublic/jakarta-turbine/src/java/org/apache/turbine/services/security/TurbineSecurity.java,v

retrieving revision 1.14
diff -u -B -b -r1.14 TurbineSecurity.java
--- services/security/TurbineSecurity.java      2001/03/06 06:12:47
1.14
+++ services/security/TurbineSecurity.java      2001/03/22 16:55:05
@@ -61,6 +61,7 @@
 import org.apache.turbine.om.security.Group;
 import org.apache.turbine.om.security.Role;
 import org.apache.turbine.om.security.Permission;
+import org.apache.turbine.om.security.peer.UserPeer;
 import org.apache.turbine.util.security.GroupSet;
 import org.apache.turbine.util.security.RoleSet;
 import org.apache.turbine.util.security.PermissionSet;
@@ -145,6 +146,38 @@
         return getService().getUserInstance();
     }

+
+    /**
+     * Construct a UserPeer object.
+     *
+     * This method calls getUserPeerClass, and then creates a new
object using
+     * the default constructor.
+     *
+     * @return an object implementing UserPeer interface.
+     * @throws UnknownEntityException if the object could not be
instantiated.
+     */
+    public static UserPeer getUserPeerInstance()
+        throws UnknownEntityException
+    {
+        return getService().getUserPeerInstance();
+    }
+
+    /**
+     * Returns the Class object for the implementation of UserPeer
interface
+     * used by the system (defined in TR.properties)
+     *
+     * @return the implementation of UserPeer interface used by the
system.
+     * @throws UnknownEntityException if the system's implementation of
UserPeer
+     *         interface could not be determined.
+     */
+    public static Class getUserPeerClass()
+        throws UnknownEntityException
+    {
+        return getService().getUserPeerClass();
+    }
+
+
+
     /**
      * Check whether a specified user's account exists.
      *

===================================================================
RCS file:
/home/cvspublic/jakarta-turbine/src/java/org/apache/turbine/om/security/peer/RolePeer.java,v

retrieving revision 1.7
diff -u -B -b -r1.7 RolePeer.java
--- om/security/peer/RolePeer.java      2001/03/06 04:56:03     1.7
+++ om/security/peer/RolePeer.java      2001/03/22 16:57:08
@@ -58,6 +58,8 @@
 import org.apache.turbine.om.*;
 import org.apache.turbine.om.peer.*;
 import org.apache.turbine.om.security.*;
+import org.apache.turbine.om.security.peer.UserPeer;
+
 import org.apache.turbine.util.*;
 import org.apache.turbine.util.db.*;
 import org.apache.turbine.util.db.map.*;
@@ -66,6 +68,7 @@
 // Turbine Security Classes
 import org.apache.turbine.om.security.*;
 import org.apache.turbine.util.security.*;
+import org.apache.turbine.services.security.TurbineSecurity;

 // Village Database Classes
 import com.workingdogs.village.*;
@@ -128,9 +131,11 @@
         throws Exception
     {
         Criteria criteria = new Criteria();
-        criteria.add(TurbineUserPeer.USERNAME, user.getUserName());
+        UserPeer up = TurbineSecurity.getUserPeerInstance();
+        criteria.add(up.getFullColumnName(UserPeer.USERNAME),
user.getUserName());
         criteria.add(GroupPeer.NAME, group.getName());
-        criteria.addJoin(TurbineUserPeer.USER_ID,
UserGroupRolePeer.USER_ID);
+        criteria.addJoin(up.getFullColumnName(UserPeer.USER_ID),
UserGroupRolePeer.USER_ID);
+
         criteria.addJoin(GroupPeer.GROUP_ID,
UserGroupRolePeer.GROUP_ID);
         criteria.addJoin(UserGroupRolePeer.ROLE_ID, RolePeer.ROLE_ID);
         return retrieveSet(criteria);

===================================================================
RCS file:
/home/cvspublic/jakarta-turbine/src/java/org/apache/turbine/om/security/peer/TurbineUserPeer.java,v

retrieving revision 1.12
diff -u -B -b -r1.12 TurbineUserPeer.java
--- om/security/peer/TurbineUserPeer.java       2001/03/06 04:56:03
1.12
+++ om/security/peer/TurbineUserPeer.java       2001/03/22 17:00:54
@@ -82,7 +82,7 @@
  * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
  * @version $Id: TurbineUserPeer.java,v 1.12 2001/03/06 04:56:03 chrise
Exp $
  */
-public class TurbineUserPeer extends BasePeer
+public class TurbineUserPeer extends BasePeer implements UserPeer
 {
     /** The mapBuilder for this Peer. */
     private static final TurbineMapBuilder mapBuilder =
(TurbineMapBuilder) getMapBuilder();
@@ -199,6 +199,21 @@
     }

     /**
+     *
+     * Returns the full name of a column.
+     *
+     * @return A String with the full name of the column.
+     */
+    public String getFullColumnName (String name)
+    {
+        StringBuffer sb = new StringBuffer();
+        sb.append (TABLE_NAME);
+        sb.append (".");
+        sb.append (name);
+        return sb.toString();
+    }
+
+    /**
      * Builds a criteria object based upon an User object
      */
     public static Criteria buildCriteria(User user)

--
Leandro Rodrigo Saad Cruz

InterBusiness Tecnolgia e Servicos
http://www.ibnetwork.com.br
telefone 4191-3638
Sao Paulo - SP - Brasil




---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org


Re: [PATCH] Changing User implementation

Posted by Rafal Krzewski <Ra...@e-point.pl>.
Leandro Rodrigo Saad Cruz wrote:
> 
> Hi all... I've changed my patches ( removed tabs and positioned the
> Braces )
> Sorry if I didn't make it right the first time.

That's OK, you live and learn... 
 
> I've created an interface called UserPeer which must be implemented by
> your User impl (TurbineUserPeer)

In CVS now, thanks a lot!

Rafal

--
Rafal Krzewski
Senior Internet Developer
mailto:Rafal.Krzewski@e-point.pl
+48 22 8534830 http://e-point.pl

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org