portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject svn commit: r1726811 - /portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/JetspeedPrincipalLookupManagerAbstract.java
Date Tue, 26 Jan 2016 14:56:02 GMT
Author: woonsan
Date: Tue Jan 26 14:56:02 2016
New Revision: 1726811

URL: http://svn.apache.org/viewvc?rev=1726811&view=rev
Log:
replacing fore- or back- wildcards with percent for like statements

Modified:
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/JetspeedPrincipalLookupManagerAbstract.java

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/JetspeedPrincipalLookupManagerAbstract.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/JetspeedPrincipalLookupManagerAbstract.java?rev=1726811&r1=1726810&r2=1726811&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/JetspeedPrincipalLookupManagerAbstract.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/JetspeedPrincipalLookupManagerAbstract.java
Tue Jan 26 14:56:02 2016
@@ -29,6 +29,7 @@ import java.util.regex.Pattern;
 
 import javax.swing.text.Segment;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.jetspeed.security.JetspeedPrincipal;
 import org.apache.jetspeed.security.JetspeedPrincipalAssociationType;
 import org.apache.jetspeed.security.JetspeedPrincipalQueryContext;
@@ -209,14 +210,14 @@ public abstract class JetspeedPrincipalL
                     attributeConstraint = " a" + cnt + ".PRINCIPAL_ID=SECURITY_PRINCIPAL.PRINCIPAL_ID
AND a" + cnt
                             + ".ATTR_NAME = " + _paramPlaceHolderName;
 
-                    _paramPlaceHolderName = putParamPlaceHolder(_paramPlaceHolders, attribute.getValue());
+                    _paramPlaceHolderName = putParamPlaceHolder(_paramPlaceHolders, convertWildcardsForLike(attribute.getValue()));
                     attributeConstraint += " AND a" + cnt + ".ATTR_VALUE LIKE " + _paramPlaceHolderName;
                 } else {
                     _paramPlaceHolderName = putParamPlaceHolder(_paramPlaceHolders, attribute.getKey());
                     attributeConstraint += " AND a" + cnt + ".PRINCIPAL_ID=SECURITY_PRINCIPAL.PRINCIPAL_ID
AND a" + cnt
                             + ".ATTR_NAME = " + _paramPlaceHolderName;
 
-                    _paramPlaceHolderName = putParamPlaceHolder(_paramPlaceHolders, attribute.getValue());
+                    _paramPlaceHolderName = putParamPlaceHolder(_paramPlaceHolders, convertWildcardsForLike(attribute.getValue()));
                     attributeConstraint += " AND a" + cnt + ".ATTR_VALUE LIKE " + _paramPlaceHolderName;
                 }
 
@@ -229,7 +230,7 @@ public abstract class JetspeedPrincipalL
 
         if (queryContext.getNameFilter() != null && queryContext.getNameFilter().length()
> 0) {
             _paramPlaceHolderName = putParamPlaceHolder(_paramPlaceHolders,
-                    queryContext.getNameFilter().replace('*', '%'));
+                    convertWildcardsForLike(queryContext.getNameFilter()));
             constraint = "SECURITY_PRINCIPAL.PRINCIPAL_NAME LIKE " + _paramPlaceHolderName;
         }
 
@@ -242,7 +243,7 @@ public abstract class JetspeedPrincipalL
             int cnt = 1;
 
             for (String roleName : queryContext.getAssociatedRoles()) {
-                _paramPlaceHolderName = putParamPlaceHolder(_paramPlaceHolders, roleName);
+                _paramPlaceHolderName = putParamPlaceHolder(_paramPlaceHolders, convertWildcardsForLike(roleName));
 
                 if (roleConstraints == null) {
                     roleConstraints = "r" + cnt + ".ASSOC_NAME = '" + JetspeedPrincipalAssociationType.IS_MEMBER_OF
@@ -272,7 +273,7 @@ public abstract class JetspeedPrincipalL
             int cnt = 1;
 
             for (String groupName : queryContext.getAssociatedGroups()) {
-                _paramPlaceHolderName = putParamPlaceHolder(_paramPlaceHolders, groupName);
+                _paramPlaceHolderName = putParamPlaceHolder(_paramPlaceHolders, convertWildcardsForLike(groupName));
 
                 if (groupConstraints == null) {
                     groupConstraints = "r" + cnt + ".ASSOC_NAME='" + JetspeedPrincipalAssociationType.IS_MEMBER_OF
@@ -301,7 +302,7 @@ public abstract class JetspeedPrincipalL
             int cnt = 1;
 
             for (String userName : queryContext.getAssociatedGroups()) {
-                _paramPlaceHolderName = putParamPlaceHolder(_paramPlaceHolders, userName);
+                _paramPlaceHolderName = putParamPlaceHolder(_paramPlaceHolders, convertWildcardsForLike(userName));
 
                 if (userConstraints == null) {
                     userConstraints = "r" + cnt + ".ASSOC_NAME='" + JetspeedPrincipalAssociationType.IS_MEMBER_OF
@@ -418,6 +419,44 @@ public abstract class JetspeedPrincipalL
         return countSql;
     }
 
+    private String convertWildcardsForLike(String s) {
+        String converted = s;
+
+        if (s != null) {
+            String textOnly = s;
+            boolean foreWildcard = false;
+            boolean rearWildcard = false;
+
+            if (textOnly.length() > 0 && textOnly.charAt(0) == '*') {
+                textOnly = textOnly.substring(1);
+                foreWildcard = true;
+            }
+
+            if (textOnly.length() > 0 && textOnly.charAt(s.length() - 1) == '*')
{
+                textOnly = textOnly.substring(0, textOnly.length() - 1);
+                rearWildcard = true;
+            }
+
+            if (textOnly.length() > 0) {
+                StringBuilder sb = new StringBuilder(textOnly.length() + 2);
+
+                if (foreWildcard) {
+                    sb.append('%');
+                }
+
+                sb.append(StringUtils.remove(textOnly, '%'));
+
+                if (rearWildcard) {
+                    sb.append('%');
+                }
+
+                converted = sb.toString();
+            }
+        }
+
+        return converted;
+    }
+
     /**
 	 * Generate the base SQL syntax for selecting principals. This must not
 	 * contain any database specifics.



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