You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@turbine.apache.org by gk...@apache.org on 2016/08/18 15:36:39 UTC
svn commit: r1756817 - in /turbine/core/trunk: conf/
src/java/org/apache/turbine/services/security/
src/test-cactus/testapp/WEB-INF/conf/ xdocs/howto/ xdocs/services/
Author: gk
Date: Thu Aug 18 15:36:39 2016
New Revision: 1756817
URL: http://svn.apache.org/viewvc?rev=1756817&view=rev
Log:
- add configurable wrapper e.g. for additional columns
Modified:
turbine/core/trunk/conf/TurbineResources.properties
turbine/core/trunk/src/java/org/apache/turbine/services/security/DefaultSecurityService.java
turbine/core/trunk/src/java/org/apache/turbine/services/security/DefaultUserManager.java
turbine/core/trunk/src/java/org/apache/turbine/services/security/SecurityService.java
turbine/core/trunk/src/test-cactus/testapp/WEB-INF/conf/TurbineComplete.properties
turbine/core/trunk/xdocs/howto/extend-user-howto.xml
turbine/core/trunk/xdocs/services/security-service.xml
Modified: turbine/core/trunk/conf/TurbineResources.properties
URL: http://svn.apache.org/viewvc/turbine/core/trunk/conf/TurbineResources.properties?rev=1756817&r1=1756816&r2=1756817&view=diff
==============================================================================
--- turbine/core/trunk/conf/TurbineResources.properties (original)
+++ turbine/core/trunk/conf/TurbineResources.properties Thu Aug 18 15:36:39 2016
@@ -637,6 +637,9 @@ services.SchedulerService.earlyInit=true
# Default: org.apache.turbine.services.security.passive.PassiveUserManager
services.SecurityService.user.manager = org.apache.turbine.services.security.DefaultUserManager
+# Default: org.apache.turbine.om.security.DefaultUserImpl
+#services.SecurityService.wrapper.class =
+
# -------------------------------------------------------------------
#
# A V A L O N C O M P O N E N T S E R V I C E
Modified: turbine/core/trunk/src/java/org/apache/turbine/services/security/DefaultSecurityService.java
URL: http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/services/security/DefaultSecurityService.java?rev=1756817&r1=1756816&r2=1756817&view=diff
==============================================================================
--- turbine/core/trunk/src/java/org/apache/turbine/services/security/DefaultSecurityService.java (original)
+++ turbine/core/trunk/src/java/org/apache/turbine/services/security/DefaultSecurityService.java Thu Aug 18 15:36:39 2016
@@ -125,7 +125,7 @@ public class DefaultSecurityService
{
this.userManager =
(UserManager) Class.forName(userManagerClassName).newInstance();
-
+
userManager.init(conf);
}
catch (Exception e)
Modified: turbine/core/trunk/src/java/org/apache/turbine/services/security/DefaultUserManager.java
URL: http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/services/security/DefaultUserManager.java?rev=1756817&r1=1756816&r2=1756817&view=diff
==============================================================================
--- turbine/core/trunk/src/java/org/apache/turbine/services/security/DefaultUserManager.java (original)
+++ turbine/core/trunk/src/java/org/apache/turbine/services/security/DefaultUserManager.java Thu Aug 18 15:36:39 2016
@@ -25,17 +25,22 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.commons.configuration.Configuration;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.fulcrum.factory.FactoryService;
import org.apache.fulcrum.security.acl.AccessControlList;
import org.apache.fulcrum.security.model.turbine.TurbineUserManager;
import org.apache.fulcrum.security.model.turbine.entity.TurbineUser;
+import org.apache.fulcrum.security.model.turbine.entity.impl.TurbineUserImpl;
import org.apache.fulcrum.security.util.DataBackendException;
import org.apache.fulcrum.security.util.EntityExistsException;
import org.apache.fulcrum.security.util.PasswordMismatchException;
import org.apache.fulcrum.security.util.UnknownEntityException;
import org.apache.fulcrum.security.util.UserSet;
import org.apache.turbine.om.security.DefaultUserImpl;
-import org.apache.turbine.om.security.User;
import org.apache.turbine.om.security.TurbineUserDelegate;
+import org.apache.turbine.om.security.User;
+import org.apache.turbine.services.InitializationException;
import org.apache.turbine.services.ServiceManager;
import org.apache.turbine.services.TurbineServices;
import org.apache.turbine.util.ObjectUtils;
@@ -53,6 +58,15 @@ public class DefaultUserManager implemen
{
/** Fulcrum user manager instance to delegate to */
private TurbineUserManager umDelegate = null;
+
+ private FactoryService factoryService = null;
+
+ /** The user class, which the UserManager uses as wrapper for Fulcrum {@link TurbineUser} */
+ private String userWrapperClass;
+
+
+ /** Logging */
+ private static Log log = LogFactory.getLog(DefaultUserManager.class);
/**
* Wrap a Fulcrum user object into a Turbine user object
@@ -63,24 +77,85 @@ public class DefaultUserManager implemen
*/
protected <U extends User> U wrap(TurbineUser user)
{
+ // U u = (U)new DefaultUserImpl(user);
@SuppressWarnings("unchecked")
- U u = (U)new DefaultUserImpl(user);
+ U u = (U) getUserWrapper(user);
return u;
}
-
+
/**
+ * Exception could be ignored, as it is tested before in {@link #init(Configuration)}.
+ *
+ * @return instance extending {@link User}
+ */
+ @SuppressWarnings("unchecked")
+ public <U extends User> U getUserWrapper(TurbineUser user) {
+ try {
+ Object params[] = new Object[1];
+ params[0] = user;
+ String signature[] = new String[1];
+ signature[0] = TurbineUser.class.getName();
+ return (U) factoryService.getInstance(getUserWrapperClass(), params, signature);
+ } catch (Exception e) {
+ log.error("after init/late instantiation exception", e);
+ return null; // (U)new DefaultUserImpl(user);
+ }
+ }
+
+ public String getUserWrapperClass() {
+ return userWrapperClass;
+ }
+
+ public void setUserWrapperClass(String userWrapperClass2) {
+ userWrapperClass = userWrapperClass2;
+ }
+
+ /**
* Initializes the UserManager
*
* @param conf A Configuration object to init this Manager
*/
@Override
- public void init(Configuration conf)
+ public void init(Configuration conf) throws InitializationException
{
ServiceManager manager = TurbineServices.getInstance();
this.umDelegate = (TurbineUserManager)manager.getService(TurbineUserManager.ROLE);
+
+ String userWrapperClass = conf.getString(
+ SecurityService.USER_WRAPPER_KEY,
+ SecurityService.USER_WRAPPER_DEFAULT);
+
+// String userClass = conf.getString(
+// SecurityService.USER_KEY,
+// SecurityService.USER_DEFAULT);
+
+
+ try {
+
+ factoryService = (FactoryService)manager.getService(FactoryService.ROLE);
+
+ // check instantiation
+
+ // should provide default constructor
+ TurbineUser turbineUser = umDelegate.getUserInstance();
+ //(TurbineUser) factoryService.getInstance(userClass);
+ Object params[] = new Object[1];
+ params[0] = turbineUser;
+ String signature[] = new String[1];
+ signature[0] = TurbineUser.class.getName();
+ User uc = (User) factoryService.getInstance(userWrapperClass, params, signature);
+
+ this.setUserWrapperClass(userWrapperClass);
+
+ } catch (Exception e)
+ {
+ throw new InitializationException("Failed to instantiate user wrapper class", e);
+ }
+
}
- /**
+
+ /**
* Check whether a specified user's account exists.
*
* The login name is used for looking up the account.
Modified: turbine/core/trunk/src/java/org/apache/turbine/services/security/SecurityService.java
URL: http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/services/security/SecurityService.java?rev=1756817&r1=1756816&r2=1756817&view=diff
==============================================================================
--- turbine/core/trunk/src/java/org/apache/turbine/services/security/SecurityService.java (original)
+++ turbine/core/trunk/src/java/org/apache/turbine/services/security/SecurityService.java Thu Aug 18 15:36:39 2016
@@ -25,6 +25,8 @@ import org.apache.fulcrum.security.acl.A
import org.apache.fulcrum.security.entity.Group;
import org.apache.fulcrum.security.entity.Permission;
import org.apache.fulcrum.security.entity.Role;
+import org.apache.fulcrum.security.model.turbine.entity.TurbineUser;
+import org.apache.fulcrum.security.model.turbine.entity.impl.TurbineUserImpl;
import org.apache.fulcrum.security.util.DataBackendException;
import org.apache.fulcrum.security.util.EntityExistsException;
import org.apache.fulcrum.security.util.GroupSet;
@@ -32,6 +34,7 @@ import org.apache.fulcrum.security.util.
import org.apache.fulcrum.security.util.PermissionSet;
import org.apache.fulcrum.security.util.RoleSet;
import org.apache.fulcrum.security.util.UnknownEntityException;
+import org.apache.turbine.om.security.DefaultUserImpl;
import org.apache.turbine.om.security.User;
import org.apache.turbine.services.Service;
import org.apache.turbine.services.security.passive.PassiveUserManager;
@@ -61,7 +64,7 @@ public interface SecurityService
String SERVICE_NAME = "SecurityService";
/**
- * the key within services's properties for user implementation
+ * the key within services's properties for user manager implementation
* classname (user.manager)
*/
String USER_MANAGER_KEY = "user.manager";
@@ -72,6 +75,32 @@ public interface SecurityService
*/
String USER_MANAGER_DEFAULT
= PassiveUserManager.class.getName();
+
+ /**
+ * the key within services's properties for user implementation
+ * classname (wrapper.class)
+ */
+ String USER_WRAPPER_KEY = "wrapper.class";
+
+ /**
+ * the default implementation of {@link User} interface
+ * (org.apache.turbine.om.security.DefaultUserImpl)
+ */
+ String USER_WRAPPER_DEFAULT
+ = DefaultUserImpl.class.getName();
+//
+// /**
+// * the key within services's properties for user implementation
+// * classname (user.class)
+// */
+// String USER_KEY = "user.class";
+//
+// /**
+// * the default implementation of {@link TurbineUser} interface
+// * (org.apache.turbine.om.security.DefaultUserImpl)
+// */
+// String USER_DEFAULT
+// = TurbineUserImpl.class.getName();
/*-----------------------------------------------------------------------
Management of User objects
Modified: turbine/core/trunk/src/test-cactus/testapp/WEB-INF/conf/TurbineComplete.properties
URL: http://svn.apache.org/viewvc/turbine/core/trunk/src/test-cactus/testapp/WEB-INF/conf/TurbineComplete.properties?rev=1756817&r1=1756816&r2=1756817&view=diff
==============================================================================
--- turbine/core/trunk/src/test-cactus/testapp/WEB-INF/conf/TurbineComplete.properties (original)
+++ turbine/core/trunk/src/test-cactus/testapp/WEB-INF/conf/TurbineComplete.properties Thu Aug 18 15:36:39 2016
@@ -660,7 +660,7 @@ services.SecurityService.user.manager =
# TurbinePermission objects.
#
# Class for User. Default: org.apache.turbine.om.security.TurbineUser
-services.SecurityService.user.class=org.apache.turbine.om.security.TurbineUser
+services.SecurityService.user.class=org.apache.turbine.om.security.TurbineUserImpl
# Class for Group. Default: org.apache.turbine.om.security.TurbineGroup
services.SecurityService.group.class=org.apache.turbine.om.security.TurbineGroup
# Class for Role. Default: org.apache.turbine.om.security.TurbineRole
Modified: turbine/core/trunk/xdocs/howto/extend-user-howto.xml
URL: http://svn.apache.org/viewvc/turbine/core/trunk/xdocs/howto/extend-user-howto.xml?rev=1756817&r1=1756816&r2=1756817&view=diff
==============================================================================
--- turbine/core/trunk/xdocs/howto/extend-user-howto.xml (original)
+++ turbine/core/trunk/xdocs/howto/extend-user-howto.xml Thu Aug 18 15:36:39 2016
@@ -29,7 +29,7 @@
<section name="Important note">
<p>
The information in this HOWTO pertains to Turbine 2.2. Please refer
- to the <a href="../services/torque-security-service.html">Torque
+ to the <a href="../services/security-service.html">Torque
Security Service</a> page for information on extending TurbineUser
in Turbine 2.3 and beyond.
</p>
@@ -118,7 +118,7 @@
</p>
<p>
Another interesting fact about TurbineUser is the way in which data stored in
- the database is accessed. Instaed of using using private attributes for storage
+ the database is accessed. Instead of using using private attributes for storage
within the object, all attibutes are stored in a hashtable (known herein as the
perm hashtable). Access to the perm hashtable is controlled through the
getPerm/setPerm methods.
@@ -194,12 +194,12 @@
</source>
<p>
Notice the attribute on the database tag for defaultJavaType. I used
- "object" as the value. The default is "primative". You do not have to
+ "object" as the value. The default is "primitive". You do not have to
use "object"!!!
</p>
<p>
- In the last version of Turbine (2.1), the only option was to use the
- primative types. However, this posed a small problem. It was not
+ Turbine Version 2.1 only: In this version of Turbine, the only option was to use the
+ primitive types. However, this posed a small problem. It was not
possible to have number or boolean types that contained null values.
If a null value was found in the database for columns of these types,
the value returned from the OM object was 0 or false, respectively.
Modified: turbine/core/trunk/xdocs/services/security-service.xml
URL: http://svn.apache.org/viewvc/turbine/core/trunk/xdocs/services/security-service.xml?rev=1756817&r1=1756816&r2=1756817&view=diff
==============================================================================
--- turbine/core/trunk/xdocs/services/security-service.xml (original)
+++ turbine/core/trunk/xdocs/services/security-service.xml Thu Aug 18 15:36:39 2016
@@ -82,6 +82,10 @@ services.SecurityService.classname=org.a
# Default: org.apache.turbine.services.security.passive.PassiveUserManager
services.SecurityService.user.manager = org.apache.turbine.services.security.DefaultUserManager
+
+# Default: org.apache.turbine.om.security.DefaultUserImpl
+#services.SecurityService.wrapper.class =
+
]]></source>
</section>
@@ -96,6 +100,15 @@ configured in TurbineResource.properties
allows access to various properties of an Turbine User object, can
change password, authenticate users to the Security service and
manages the Turbine user objects.
+
+If you have have additional columns in the User (e.g. TurbineUser) table, you get them handled properly (persisting and reading) this way:
+
+- create a non default wrapper.class. This class should extend DefaultUserImpl and override or add the required properties.
+
+- best practice would be to provide an interface to communicate on same standards between this wrapper.class and the backend ORM-class (e.g generated TurbineTorqueUser class). Otherwise you could use your ORM class.
+
+ The ORM class is e.g. fetched from the default implementation of the Fulcrum User Manager (org.apache.fulcrum.security.UserManager) (as configured in componentConfiguration.xml userManager->className) and the Turbine User Manager gets it by fetching it first from the Fulcrum User Manager (= umDelegate) and then setting this class as userDelegate in the wrapper class.
+
</p>
</section>