portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dlest...@apache.org
Subject svn commit: r331065 [2/2] - in /portals/jetspeed-2/trunk: commons/src/java/org/apache/jetspeed/util/ commons/src/test/org/apache/jetspeed/util/ components/page-manager/src/java/org/apache/jetspeed/om/page/psml/ components/portal/src/java/org/apache/jet...
Date Sun, 06 Nov 2005 03:40:54 GMT
Modified: portals/jetspeed-2/trunk/components/security/src/java/org/apache/jetspeed/security/spi/impl/ldap/LdapPrincipalDaoImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/security/src/java/org/apache/jetspeed/security/spi/impl/ldap/LdapPrincipalDaoImpl.java?rev=331065&r1=331064&r2=331065&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/security/src/java/org/apache/jetspeed/security/spi/impl/ldap/LdapPrincipalDaoImpl.java
(original)
+++ portals/jetspeed-2/trunk/components/security/src/java/org/apache/jetspeed/security/spi/impl/ldap/LdapPrincipalDaoImpl.java
Sat Nov  5 19:40:32 2005
@@ -29,52 +29,48 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.jetspeed.security.GroupPrincipal;
 import org.apache.jetspeed.security.SecurityException;
+import org.apache.jetspeed.security.UserPrincipal;
+import org.apache.jetspeed.security.impl.GroupPrincipalImpl;
+import org.apache.jetspeed.security.impl.UserPrincipalImpl;
 
 /**
  * @see org.apache.jetspeed.security.spi.impl.ldap.LdapPrincipalDao
- * 
- * @author <a href="mailto:mike.long@dataline.com">Mike Long </a>
+ * @author <a href="mailto:mike.long@dataline.com">Mike Long </a>, <a
+ *         href="mailto:dlestrat@apache.org">David Le Strat</a>
  */
 public abstract class LdapPrincipalDaoImpl extends AbstractLdapDao implements LdapPrincipalDao
 {
     /** The logger. */
-    private static final Log LOG = LogFactory.getLog(LdapPrincipalDaoImpl.class);
+    private static final Log logger = LogFactory.getLog(LdapPrincipalDaoImpl.class);
 
     /** The uid attribute name. */
     protected static final String UID_ATTR_NAME = "uid";
-    
+
     /**
      * <p>
      * Default constructor.
      * </p>
      * 
-     * @throws NamingException A {@link NamingException}.
      * @throws SecurityException A {@link SecurityException}.
      */
-    public LdapPrincipalDaoImpl() throws NamingException, SecurityException
+    public LdapPrincipalDaoImpl() throws SecurityException
     {
         super();
     }
-    
+
     /**
      * <p>
      * Initializes the dao.
      * </p>
      * 
-     * @param ldapServerName The server name.
-     * @param rootDn The root domain.
-     * @param rootPassword The root password.
-     * @param rootContext The root context.
-     * @param defaultDnSuffix The default suffix.
-     * 
-     * @throws NamingException A {@link NamingException}.
+     * @param ldapConfig Holds the ldap binding configuration.
      * @throws SecurityException A {@link SecurityException}.
      */
-    public LdapPrincipalDaoImpl(String ldapServerName, String rootDn, String rootPassword,
String rootContext,
-            String defaultDnSuffix) throws NamingException, SecurityException
+    public LdapPrincipalDaoImpl(LdapBindingConfig ldapConfig) throws SecurityException
     {
-        super(ldapServerName, rootDn, rootPassword, rootContext, defaultDnSuffix);
+        super(ldapConfig);
     }
 
     /**
@@ -89,8 +85,7 @@
 
     /**
      * <p>
-     * A template method for defining the attributes for a particular LDAP
-     * class.
+     * A template method for defining the attributes for a particular LDAP class.
      * </p>
      * 
      * @param principalUid The principal uid.
@@ -104,10 +99,14 @@
     public void create(final String principalUid) throws SecurityException
     {
         Attributes attrs = defineLdapAttributes(principalUid);
-
         try
         {
-            ctx.createSubcontext("uid=" + principalUid + super.defaultDnSuffix, attrs);
+            String userDn = "uid=" + principalUid + getDnSuffix();
+            ctx.createSubcontext(userDn, attrs);
+            if (logger.isDebugEnabled())
+            {
+                logger.debug("Creating user dn: " + userDn);
+            }
         }
         catch (NamingException e)
         {
@@ -116,6 +115,15 @@
     }
 
     /**
+     * <p>
+     * Builds the dn suffix.
+     * </p>
+     * 
+     * @return The dn suffix.
+     */
+    protected abstract String getDnSuffix();
+
+    /**
      * @see org.apache.jetspeed.security.spi.impl.ldap.LdapPrincipalDao#delete(java.lang.String)
      */
     public void delete(final String principalUid) throws SecurityException
@@ -140,35 +148,54 @@
     }
 
     /**
-     * <p>
-     * Converts the uid to an ldap acceptable name.
-     * </p>
-     * 
-     * @param uid The uid.
-     * @return The converted name.
+     * @see org.apache.jetspeed.security.spi.impl.ldap.LdapPrincipalDao#convertUidToLdapAcceptableName(java.lang.String)
      */
-    protected String convertUidToLdapAcceptableName(String uid)
+    public String convertUidToLdapAcceptableName(String fullPath)
     {
-        return uid.replaceAll("/", "&");
+        if (logger.isErrorEnabled())
+        {
+            logger.debug("Principal fullPath:" + fullPath);
+        }
+        String ldapAcceptableName = fullPath;
+        if (null == fullPath)
+        {
+            return ldapAcceptableName;
+        }
+        else if (fullPath.indexOf(UserPrincipal.PREFS_USER_ROOT) >= 0)
+        {
+            ldapAcceptableName = convertUidWithoutSlashes(UserPrincipalImpl.getPrincipalNameFromFullPath(fullPath));
+        }
+        else if (fullPath.indexOf(GroupPrincipal.PREFS_GROUP_ROOT) >= 0)
+        {
+            ldapAcceptableName = convertUidWithoutSlashes(GroupPrincipalImpl.getPrincipalNameFromFullPath(fullPath));
+        }
+        if (logger.isErrorEnabled())
+        {
+            logger.debug("Ldap acceptable name:" + ldapAcceptableName);
+        }
+
+        return ldapAcceptableName;
     }
 
     /**
      * <p>
-     * Convert the uid back from the ldap acceptable name.
+     * Returns a well formed uid for LDAP.
      * </p>
      * 
      * @param uid The uid.
-     * @return The converted back name.
+     * @return The well formed uid.
      */
-    protected String convertUidFromLdapAcceptableName(String uid)
+    private String convertUidWithoutSlashes(String uid)
     {
-        return uid.replaceAll("&", "/");
+        String uidWithSlashed = uid.replaceAll("/", "&");
+        return uidWithSlashed;
     }
 
     /**
-     * @see org.apache.jetspeed.security.spi.impl.ldap.LdapPrincipalDao#find(java.lang.String)
+     * @see org.apache.jetspeed.security.spi.impl.ldap.LdapPrincipalDao#find(java.lang.String,
+     *      java.lang.String)
      */
-    public Principal[] find(final String principalUid) throws SecurityException
+    public Principal[] find(final String principalUid, String principalType) throws SecurityException
     {
         try
         {
@@ -214,7 +241,6 @@
         while (searchResults.hasMore())
         {
             SearchResult searchResult = (SearchResult) searchResults.next();
-
             buildPrincipal(principals, searchResult);
         }
     }

Modified: portals/jetspeed-2/trunk/components/security/src/java/org/apache/jetspeed/security/spi/impl/ldap/LdapUserCredentialDao.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/security/src/java/org/apache/jetspeed/security/spi/impl/ldap/LdapUserCredentialDao.java?rev=331065&r1=331064&r2=331065&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/security/src/java/org/apache/jetspeed/security/spi/impl/ldap/LdapUserCredentialDao.java
(original)
+++ portals/jetspeed-2/trunk/components/security/src/java/org/apache/jetspeed/security/spi/impl/ldap/LdapUserCredentialDao.java
Sat Nov  5 19:40:32 2005
@@ -34,7 +34,7 @@
      * @param password The password.
      * @throws SecurityException A {@link SecurityException}.
      */
-    public abstract void changePassword(final String uid, final String password) throws SecurityException;
+    abstract void changePassword(final String uid, final String password) throws SecurityException;
 
     /**
      * <p>
@@ -48,12 +48,12 @@
      * @param password The password.
      * @throws SecurityException A {@link SecurityException}.
      */
-    public abstract boolean authenticate(final String uid, final String password) throws
SecurityException;
+    abstract boolean authenticate(final String uid, final String password) throws SecurityException;
 
     /**
      * @param uid The uid.
      * @return The password.
      *@throws SecurityException A {@link SecurityException}.@throws SecurityException
      */
-    public abstract char[] getPassword(final String uid) throws SecurityException;
+    abstract char[] getPassword(final String uid) throws SecurityException;
 }

Modified: portals/jetspeed-2/trunk/components/security/src/java/org/apache/jetspeed/security/spi/impl/ldap/LdapUserCredentialDaoImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/security/src/java/org/apache/jetspeed/security/spi/impl/ldap/LdapUserCredentialDaoImpl.java?rev=331065&r1=331064&r2=331065&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/security/src/java/org/apache/jetspeed/security/spi/impl/ldap/LdapUserCredentialDaoImpl.java
(original)
+++ portals/jetspeed-2/trunk/components/security/src/java/org/apache/jetspeed/security/spi/impl/ldap/LdapUserCredentialDaoImpl.java
Sat Nov  5 19:40:32 2005
@@ -30,12 +30,12 @@
 
 /**
  * @see org.apache.jetspeed.security.spi.impl.ldap.LdapUserCredentialDao
- * @author <a href="mailto:mike.long@dataline.com">Mike Long </a>
+ * @author <a href="mailto:mike.long@dataline.com">Mike Long </a>, <a href="mailto:dlestrat@apache.org">David
Le Strat</a>
  */
 public class LdapUserCredentialDaoImpl extends AbstractLdapDao implements LdapUserCredentialDao
 {
     /** The logger. */
-    private static final Log LOG = LogFactory.getLog(LdapUserCredentialDaoImpl.class);
+    private static final Log logger = LogFactory.getLog(LdapUserCredentialDaoImpl.class);
 
     /** The password attribute. */ 
     private static final String PASSWORD_ATTR_NAME = "userPassword";
@@ -45,10 +45,9 @@
      * Default constructor.
      * </p>
      *
-     * @throws NamingException A {@link NamingException}.
      * @throws SecurityException A {@link SecurityException}.
      */
-    public LdapUserCredentialDaoImpl() throws NamingException, SecurityException
+    public LdapUserCredentialDaoImpl() throws SecurityException
     {
         super();
     }
@@ -58,19 +57,13 @@
      * Initializes the dao.
      * </p>
      * 
-     * @param ldapServerName The server name.
-     * @param rootDn The root domain.
-     * @param rootPassword The root password.
-     * @param rootContext The root context.
-     * @param defaultDnSuffix The default suffix.
+     * @param ldapConfig Holds the ldap binding configuration.
      * 
-     * @throws NamingException A {@link NamingException}.
      * @throws SecurityException A {@link SecurityException}.
      */
-    public LdapUserCredentialDaoImpl(String ldapServerName, String rootDn, String rootPassword,
String rootContext,
-            String defaultDnSuffix) throws NamingException, SecurityException
+    public LdapUserCredentialDaoImpl(LdapBindingConfig ldapConfig) throws SecurityException
     {
-        super(ldapServerName, rootDn, rootPassword, rootContext, defaultDnSuffix);
+        super(ldapConfig);
     }
     
     /**
@@ -193,9 +186,7 @@
                 return attr;
             }
         }
-
         return null;
-
     }
 
     /**
@@ -213,18 +204,21 @@
 
         for (int i = 0; i < rawPass.length; i++)
         {
-            LOG.debug(new String("password byte[" + i + "]:" + rawPass[i]));
+            if (logger.isDebugEnabled())
+            {
+                logger.debug(new String("password byte[" + i + "]:" + rawPass[i]));
+            }
 
             Byte passByte = new Byte(rawPass[i]);
 
-            LOG.debug("password byte[" + i + "] short value:" + passByte.shortValue());
-            charPass[i] = (char) rawPass[i]; //I know I lose the
-
-            // sign and this is only
-            // good for ascii text.
-            LOG.debug("passchar char[" + i + "]:" + charPass[i]);
+            logger.debug("password byte[" + i + "] short value:" + passByte.shortValue());
+            // I know I lose the sign and this is only good for ascii text.
+            charPass[i] = (char) rawPass[i];           
+            if (logger.isDebugEnabled())
+            {
+                logger.debug("passchar char[" + i + "]:" + charPass[i]);
+            }
         }
-
         return charPass;
     }
 

Modified: portals/jetspeed-2/trunk/components/security/src/java/org/apache/jetspeed/security/spi/impl/ldap/LdapUserPrincipalDao.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/security/src/java/org/apache/jetspeed/security/spi/impl/ldap/LdapUserPrincipalDao.java?rev=331065&r1=331064&r2=331065&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/security/src/java/org/apache/jetspeed/security/spi/impl/ldap/LdapUserPrincipalDao.java
(original)
+++ portals/jetspeed-2/trunk/components/security/src/java/org/apache/jetspeed/security/spi/impl/ldap/LdapUserPrincipalDao.java
Sat Nov  5 19:40:32 2005
@@ -22,7 +22,8 @@
  * The ldap user principal DAO.
  * </p>
  * 
- * @author <a href="mailto:mike.long@dataline.com">Mike Long </a>
+ * @author <a href="mailto:mike.long@dataline.com">Mike Long </a>, <a
+ *         href="mailto:dlestrat@apache.org">David Le Strat</a>
  */
 public interface LdapUserPrincipalDao extends LdapPrincipalDao
 {
@@ -50,8 +51,7 @@
 
     /**
      * <p>
-     * Return an array of the group principal UIDS that belong to a specific
-     * user.
+     * Return an array of the group principal UIDS that belong to a specific user.
      * </p>
      * 
      * @param userPrincipalUid The user principal uid.

Modified: portals/jetspeed-2/trunk/components/security/src/java/org/apache/jetspeed/security/spi/impl/ldap/LdapUserPrincipalDaoImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/security/src/java/org/apache/jetspeed/security/spi/impl/ldap/LdapUserPrincipalDaoImpl.java?rev=331065&r1=331064&r2=331065&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/security/src/java/org/apache/jetspeed/security/spi/impl/ldap/LdapUserPrincipalDaoImpl.java
(original)
+++ portals/jetspeed-2/trunk/components/security/src/java/org/apache/jetspeed/security/spi/impl/ldap/LdapUserPrincipalDaoImpl.java
Sat Nov  5 19:40:32 2005
@@ -30,57 +30,52 @@
 import javax.naming.directory.SearchControls;
 import javax.naming.directory.SearchResult;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.jetspeed.security.SecurityException;
 import org.apache.jetspeed.security.impl.UserPrincipalImpl;
 
 /**
- * @author <a href="mailto:mike.long@dataline.com">Mike Long </a>
+ * @author <a href="mailto:mike.long@dataline.com">Mike Long </a>, <a
+ *         href="mailto:dlestrat@apache.org">David Le Strat</a>
  */
 public class LdapUserPrincipalDaoImpl extends LdapPrincipalDaoImpl implements LdapUserPrincipalDao
 {
     /** The logger. */
-    private static final Log LOG = LogFactory.getLog(LdapUserPrincipalDaoImpl.class);
+    private static final Log logger = LogFactory.getLog(LdapUserPrincipalDaoImpl.class);
 
     /** The group attribute name. */
     private static final String GROUP_ATTR_NAME = "j2-group";
-   
+
     /**
      * <p>
      * Default constructor.
      * </p>
      * 
-     * @throws NamingException A {@link NamingException}.
      * @throws SecurityException A {@link SecurityException}.
      */
-    public LdapUserPrincipalDaoImpl() throws NamingException, SecurityException
+    public LdapUserPrincipalDaoImpl() throws SecurityException
     {
         super();
     }
-    
+
     /**
      * <p>
      * Initializes the dao.
      * </p>
      * 
-     * @param ldapServerName The server name.
-     * @param rootDn The root domain.
-     * @param rootPassword The root password.
-     * @param rootContext The root context.
-     * @param defaultDnSuffix The default suffix.
-     * 
-     * @throws NamingException A {@link NamingException}.
+     * @param ldapConfig Holds the ldap binding configuration.
      * @throws SecurityException A {@link SecurityException}.
      */
-    public LdapUserPrincipalDaoImpl(String ldapServerName, String rootDn, String rootPassword,
String rootContext,
-            String defaultDnSuffix) throws NamingException, SecurityException
+    public LdapUserPrincipalDaoImpl(LdapBindingConfig ldapConfig) throws SecurityException
     {
-        super(ldapServerName, rootDn, rootPassword, rootContext, defaultDnSuffix);
+        super(ldapConfig);
     }
 
     /**
-     * @see org.apache.jetspeed.security.spi.impl.ldap.LdapUserPrincipalDao#addGroup(java.lang.String,
java.lang.String)
+     * @see org.apache.jetspeed.security.spi.impl.ldap.LdapUserPrincipalDao#addGroup(java.lang.String,
+     *      java.lang.String)
      */
     public void addGroup(String userPrincipalUid, String groupPrincipalUid) throws SecurityException
     {
@@ -94,8 +89,7 @@
      * 
      * @param userPrincipalUid
      * @param groupPrincipalUid
-     * @param operationType whether to replace or remove the specified user
-     *            group from the user
+     * @param operationType whether to replace or remove the specified user group from the
user
      * @throws SecurityException A {@link SecurityException}.
      */
     private void modifyUserGroup(String userPrincipalUid, String groupPrincipalUid, int operationType)
@@ -119,7 +113,8 @@
     }
 
     /**
-     * @see org.apache.jetspeed.security.spi.impl.ldap.LdapUserPrincipalDao#removeGroup(java.lang.String,
java.lang.String)
+     * @see org.apache.jetspeed.security.spi.impl.ldap.LdapUserPrincipalDao#removeGroup(java.lang.String,
+     *      java.lang.String)
      */
     public void removeGroup(String userPrincipalUid, String groupPrincipalUid) throws SecurityException
     {
@@ -128,8 +123,7 @@
 
     /**
      * <p>
-     * A template method for defining the attributes for a particular LDAP
-     * class.
+     * A template method for defining the attributes for a particular LDAP class.
      * </p>
      * 
      * @param principalUid The principal uid.
@@ -150,10 +144,29 @@
         attrs.put("cn", principalUid);
         attrs.put("uid", principalUid);
         attrs.put("sn", principalUid);
+        attrs.put("ou", getUsersOu());
+
         return attrs;
     }
 
     /**
+     * @see org.apache.jetspeed.security.spi.impl.ldap.LdapPrincipalDaoImpl#getDnSuffix()
+     */
+    protected String getDnSuffix()
+    {
+        String suffix = "";
+        if (!StringUtils.isEmpty(getUsersOu()))
+        {
+            suffix += ",ou=" + getUsersOu();
+        }
+        if (!StringUtils.isEmpty(getDefaultDnSuffix()))
+        {
+            suffix += getDefaultDnSuffix();
+        }
+        return suffix;
+    }
+
+    /**
      * <p>
      * Creates a GroupPrincipal object.
      * </p>
@@ -194,13 +207,10 @@
         NamingEnumeration results;
         try
         {
-            LOG.debug("1");
             List userPrincipalUids = new ArrayList();
             results = searchUserByGroup(groupPrincipalUid, cons);
-            LOG.debug("2");
             while (results.hasMore())
             {
-                LOG.debug("3");
                 SearchResult result = (SearchResult) results.next();
                 Attributes answer = result.getAttributes();
 
@@ -229,7 +239,10 @@
     {
         String query = "(&(" + GROUP_ATTR_NAME + "=" + (groupPrincipalUid) + ") (objectclass="
+ getObjectClass()
                 + "))";
-        LOG.debug("query[" + query + "]");
+        if (logger.isDebugEnabled())
+        {
+            logger.debug("query[" + query + "]");
+        }
         NamingEnumeration searchResults = ((DirContext) ctx).search("", "(&(" + GROUP_ATTR_NAME
+ "="
                 + (groupPrincipalUid) + ") (objectclass=" + getObjectClass() + "))", cons);
 



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


Mime
View raw message