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/20 23:50:00 UTC

[PATCH] Re: Problems Using another User Implementation

Jon Stevens wrote:

   on 3/20/01 8:11 AM, "Leandro Rodrigo Saad Cruz" <le...@ibnetwork.com.br>
   wrote:

   > Hi all, after carefull examination, we decided to replace TurbineUser as
   > our User implementation, but now we are facing some problems.
   > TurbineSecurity uses DBSecurityService, and DBSecuriryService(DBSS) in
   > tightly coupled with TurbineUserPeer.
   > Another issue : RolePeer uses TurbineUserPeer too.
   > So... implementing a UserManager and User is not sufficient to replace
   > TurbineUser.
   > A solution would be using and UserPeer obj wich holds a reference to the
   > correct UserPeer implementation...
   > any other ideas/comments ????

   Send a patch to do the decoupling. :-)

   -jon

Ok...

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

Ok now apply the patches bellow.
They modify all classes that were coupled with TurbineUserPeer (DBSecurityService and RolePeer)
and add the proper method calls for you to user UserPeer trough TurbineSecurity

===================================================================
RCS file: /home/cvspublic/jakarta-turbine/src/java/org/apache/turbine/services/security/DBSecurityService.java,v
retrieving revision 1.17
diff -u -r1.17 DBSecurityService.java
--- jakarta-turbine/src/java/org/apache/turbine/services/security/DBSecurityService.java        2001/03/06 06:12:46     1.17
+++ jakarta-turbine/src/java/org/apache/turbine/services/security/DBSecurityService.java        2001/03/20 21:30:54
@@ -73,7 +73,7 @@
 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;
@@ -154,7 +154,8 @@
         }
         catch(Exception e)
         {
-            throw new DataBackendException("Failed to build ACL for user '"+user.getUserName()+"'" ,e);
+            e.printStackTrace();
+           throw new DataBackendException("Failed to build ACL for user '"+user.getUserName()+"'" ,e);
         }
         finally
         {
@@ -185,8 +186,8 @@
         try
         {
             lockExclusive();
-            userExists=TurbineUserPeer.checkExists(user);
-            groupExists=GroupPeer.checkExists(group);
+           userExists=TurbineSecurity.accountExists(user);
+           groupExists=GroupPeer.checkExists(group);
             roleExists=RolePeer.checkExists(role);
             if(userExists && groupExists && roleExists)
             {
@@ -239,8 +240,8 @@
         try
         {
             lockExclusive();
-            userExists=TurbineUserPeer.checkExists(user);
-            groupExists=GroupPeer.checkExists(group);
+           userExists=TurbineSecurity.accountExists(user);
+           groupExists=GroupPeer.checkExists(group);
             roleExists=RolePeer.checkExists(role);
             if(userExists && groupExists && roleExists)
             {
@@ -291,7 +292,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 -r1.16 SecurityService.java
--- jakarta-turbine/src/java/org/apache/turbine/services/security/SecurityService.java  2001/03/06 06:12:47     1.16
+++ jakarta-turbine/src/java/org/apache/turbine/services/security/SecurityService.java  2001/03/20 21:32:49
@@ -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;
@@ -96,8 +98,14 @@

     /** 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) */
@@ -144,6 +152,10 @@
      */
     public User getUserInstance()
         throws UnknownEntityException;
+
+    public Class getUserPeerClass() throws UnknownEntityException;
+    public UserPeer getUserPeerInstance() throws UnknownEntityException;
+

     /**
      * Check whether a specified user's account exists.

===================================================================
RCS file: /home/cvspublic/jakarta-turbine/src/java/org/apache/turbine/services/security/BaseSecurityService.java,v
retrieving revision 1.20
diff -u -r1.20 BaseSecurityService.java
--- jakarta-turbine/src/java/org/apache/turbine/services/security/BaseSecurityService.java      2001/03/06 06:12:46     1.20
+++ jakarta-turbine/src/java/org/apache/turbine/services/security/BaseSecurityService.java      2001/03/20 21:34:01
@@ -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;
@@ -119,7 +121,7 @@

     /** The instance of UserManager the SecurityService uses */
     private UserManager userManager = null;
-
+
     /**
      * This method provides client-side encryption of passwords.
      *
@@ -178,15 +180,17 @@
         String userManagerClassName = getProperties().getProperty(
             SecurityService.USER_MANAGER_KEY,
             SecurityService.USER_MANAGER_DEFAULT);
-        try
+
+       try
         {
             userManager =  (UserManager)Class.
                 forName(userManagerClassName).newInstance();
-            setInit(true);
+           setInit(true);
         }
+
         catch(Exception e)
         {
-            throw new InitializationException("BaseSecurityService.init: Failed to instantiate UserManager" ,e);
+           throw new InitializationException("BaseSecurityService.init: Failed to instantiate UserManager" ,e);
         }
     }

@@ -213,7 +217,8 @@
             throw new UnknownEntityException("Failed create a Class object for User implementation", e);
         }
     }
-
+
+
     /**
      * Construct a blank User object.
      *
@@ -236,8 +241,37 @@
             throw new UnknownEntityException("Failed instantiate an User implementation object", e);
         }
         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 -r1.14 TurbineSecurity.java
--- jakarta-turbine/src/java/org/apache/turbine/services/security/TurbineSecurity.java  2001/03/06 06:12:47     1.14
+++ jakarta-turbine/src/java/org/apache/turbine/services/security/TurbineSecurity.java  2001/03/20 21:35:25
@@ -61,6 +61,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;
@@ -144,6 +146,20 @@
     {
         return getService().getUserInstance();
     }
+
+    public static UserPeer getUserPeerInstance()
+        throws UnknownEntityException
+    {
+        return getService().getUserPeerInstance();
+    }
+
+    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 -r1.7 RolePeer.java
--- jakarta-turbine/src/java/org/apache/turbine/om/security/peer/RolePeer.java  2001/03/06 04:56:03     1.7
+++ jakarta-turbine/src/java/org/apache/turbine/om/security/peer/RolePeer.java  2001/03/20 21:37:01
@@ -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());
-        criteria.add(GroupPeer.NAME, group.getName());
-        criteria.addJoin(TurbineUserPeer.USER_ID, UserGroupRolePeer.USER_ID);
+       UserPeer up = TurbineSecurity.getUserPeerInstance();
+       criteria.add(up.getFullColumnName(UserPeer.USERNAME), user.getUserName());
+       criteria.add(GroupPeer.NAME, group.getName());
+        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 -r1.12 TurbineUserPeer.java
--- jakarta-turbine/src/java/org/apache/turbine/om/security/peer/TurbineUserPeer.java   2001/03/06 04:56:03     1.12
+++ jakarta-turbine/src/java/org/apache/turbine/om/security/peer/TurbineUserPeer.java   2001/03/20 21:43:35
@@ -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();
@@ -190,6 +190,21 @@
      * @return A String with the full name of the column.
      */
     public static String getColumnName (String name)
+    {
+        StringBuffer sb = new StringBuffer();
+        sb.append (TABLE_NAME);
+        sb.append (".");
+        sb.append (name);
+        return sb.toString();
+    }
+
+    /**
+     *
+     * 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);

--
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] Re: Problems Using another User Implementation

Posted by Rafal Krzewski <Ra...@e-point.pl>.
Leandro Rodrigo Saad Cruz wrote:

> 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
> 
> Ok now apply the patches bellow.
> They modify all classes that were coupled with TurbineUserPeer (DBSecurityService and RolePeer)
> and add the proper method calls for you to user UserPeer trough TurbineSecurity

I'll take care of your patch, since SecurityService is my area of
responsibility.
I'd appreciate if you fixed the indentation, and used -N flag on the
diff to include
files added by you in the patch also.
Please send the patch directly to me as an attachment.

Thanks,
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


Re: [PATCH] Re: Problems Using another User Implementation

Posted by Daniel Rall <dl...@collab.net>.
Jon Stevens <jo...@latchkey.com> writes:

> on 3/21/01 10:05 AM, "Daniel Rall" <dl...@collab.net> wrote:
> 
> > Here's what I use to provide nice indentation:
> 
> updated the website...

Thanks Jon, my apologies for never getting to that as I said I would
(ages ago).

Daniel

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


Re: [PATCH] Re: Problems Using another User Implementation

Posted by Jon Stevens <jo...@latchkey.com>.
on 3/21/01 10:05 AM, "Daniel Rall" <dl...@collab.net> wrote:

> Here's what I use to provide nice indentation:

updated the website...

-jon

-- 
If you come from a Perl or PHP background, JSP is a way to take
your pain to new levels. --Anonymous
<http://jakarta.apache.org/velocity/ymtd/ymtd.html>


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


Re: [PATCH] Re: Problems Using another User Implementation

Posted by Daniel Rall <dl...@collab.net>.
Dave Bryson <da...@miceda-data.com> writes:

> > > Could you please re-submit the patches without tabs in them and following
> > > the proper bracing guidelines? :-)
> > >
> > > example:
> > >
> > > +        try
> > > +           {
> > > +               return Class.forName(userPeerClassName);
> > > +           }
> > >
> > > -            setInit(true);
> > > +           setInit(true);
> > >
> > > -jon
> > >
> > 
> > Sorry man.. that's emacs
> 
> It's not emacs, it's your setting.
> Add this to your .emacs file:
> (setq-default tab-width 4 indent-tabs-mode nil)

Here's what I use to provide nice indentation:

  ;; Persuade indention to insert tabs only in Makefile or Outline mode, and to
  ;; use a reasonable width.
  (setq indent-tabs-mode nil
        tab-width 4)

  ;; Set the amount of offset used by the '+' and '-' symbols in 
  ;; c-offsets-alist.
  (setq c-basic-offset 4)

  ;; Convince Emacs to indent properly (braces flush with start of block).
  (c-set-offset 'substatement-open 0 nil)

  ;; Turn on syntax highlighting when X is running.
  (if (boundp 'window-system) (font-lock-mode-on))


Daniel Rall

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


Re: [PATCH] Re: Problems Using another User Implementation

Posted by Dave Bryson <da...@miceda-data.com>.
> > Could you please re-submit the patches without tabs in them and following
> > the proper bracing guidelines? :-)
> >
> > example:
> >
> > +        try
> > +           {
> > +               return Class.forName(userPeerClassName);
> > +           }
> >
> > -            setInit(true);
> > +           setInit(true);
> >
> > -jon
> >
> 
> Sorry man.. that's emacs

It's not emacs, it's your setting.
Add this to your .emacs file:
(setq-default tab-width 4 indent-tabs-mode nil)

-- 
Dave Bryson
daveb@miceda-data.com
----------------------


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


Re: [PATCH] Re: Problems Using another User Implementation

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Leandro Rodrigo Saad Cruz wrote:
> 
> Jon Stevens wrote:
> 
> > Could you please re-submit the patches without tabs in them and following
> > the proper bracing guidelines? :-)
> > [SNIP]
> > -jon
> >
> 
> Sorry man.. that's emacs

Anyone care to place bets on what's about to happen?

:D

geir


-- 
Geir Magnusson Jr.                               geirm@optonline.net
Developing for the web?  See http://jakarta.apache.org/velocity/

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


Re: [PATCH] Re: Problems Using another User Implementation

Posted by Jon Stevens <jo...@latchkey.com>.
on 3/21/01 4:50 AM, "Leandro Rodrigo Saad Cruz" <le...@ibnetwork.com.br>
wrote:

> Sorry man.. that's emacs

Sorry man.. your code's not getting checked in until it follows the
guidelines or someone else decides to clean it up...

I know that emacs can be configured to properly format code...dlr?

-jon


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


Re: [PATCH] Re: Problems Using another User Implementation

Posted by Leandro Rodrigo Saad Cruz <le...@ibnetwork.com.br>.
Jon Stevens wrote:

> Could you please re-submit the patches without tabs in them and following
> the proper bracing guidelines? :-)
>
> example:
>
> +        try
> +           {
> +               return Class.forName(userPeerClassName);
> +           }
>
> -            setInit(true);
> +           setInit(true);
>
> -jon
>

Sorry man.. that's emacs

--
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] Re: Problems Using another User Implementation

Posted by Jon Stevens <jo...@latchkey.com>.
on 3/20/01 2:50 PM, "Leandro Rodrigo Saad Cruz" <le...@ibnetwork.com.br>
wrote:

> Ok now apply the patches bellow.

Could you please re-submit the patches without tabs in them and following
the proper bracing guidelines? :-)

example:

+        try
+           {
+               return Class.forName(userPeerClassName);
+           }

-            setInit(true);
+           setInit(true);

-jon

-- 
If you come from a Perl or PHP background, JSP is a way to take
your pain to new levels. --Anonymous
<http://jakarta.apache.org/velocity/ymtd/ymtd.html>


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