[jboss-cvs] JBossAS SVN: r100725 - projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Feb 8 17:46:23 EST 2010


Author: anil.saldhana at jboss.com
Date: 2010-02-08 17:46:23 -0500 (Mon, 08 Feb 2010)
New Revision: 100725

Added:
   projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/StaxParserUtil.java
Modified:
   projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AclConfigParser.java
   projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/ApplicationPolicyParser.java
   projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AuditConfigParser.java
   projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AuthenticationConfigParser.java
   projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AuthenticationJASPIConfigParser.java
   projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AuthorizationConfigParser.java
   projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/IdentityTrustConfigParser.java
   projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/JavaPropertiesConfigParser.java
   projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/MappingConfigParser.java
   projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/ModuleOptionParser.java
   projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/StaxBasedConfigParser.java
   projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/UsersConfigParser.java
Log:
make the parser take in trimmed string values

Modified: projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AclConfigParser.java
===================================================================
--- projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AclConfigParser.java	2010-02-08 22:03:57 UTC (rev 100724)
+++ projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AclConfigParser.java	2010-02-08 22:46:23 UTC (rev 100725)
@@ -59,7 +59,7 @@
          
          StartElement peekedStartElement = (StartElement) xmlEvent;
          ACLProviderEntry entry = null;
-         if("acl-module".equals(peekedStartElement.getName().getLocalPart()))
+         if("acl-module".equals(StaxParserUtil.getStartElementName(peekedStartElement)))
          {
             entry = this.getEntry(xmlEventReader);
          } 
@@ -89,14 +89,14 @@
          Attribute attribute = attrs.next();
          
          QName attQName = attribute.getName();
+         String attributeValue = StaxParserUtil.getAttributeValue(attribute);
          if("code".equals(attQName.getLocalPart()))
          {
-            codeName = attribute.getValue();
-             
+            codeName = attributeValue; 
          }
          else if("flag".equals(attQName.getLocalPart()))
          {
-            controlFlag = ControlFlag.valueOf(attribute.getValue());
+            controlFlag = ControlFlag.valueOf(attributeValue);
          } 
       } 
       //See if there are options

Modified: projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/ApplicationPolicyParser.java
===================================================================
--- projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/ApplicationPolicyParser.java	2010-02-08 22:03:57 UTC (rev 100724)
+++ projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/ApplicationPolicyParser.java	2010-02-08 22:46:23 UTC (rev 100725)
@@ -27,6 +27,7 @@
 import java.util.Set;
 
 import javax.security.auth.login.AppConfigurationEntry;
+import javax.xml.namespace.QName;
 import javax.xml.stream.XMLEventReader;
 import javax.xml.stream.XMLStreamConstants;
 import javax.xml.stream.XMLStreamException;
@@ -68,6 +69,9 @@
           {
               case XMLStreamConstants.START_ELEMENT:  
                  StartElement appPolicyElement = (StartElement) xmlEvent;
+                 if("application-policy".equals(StaxParserUtil.getStartElementName(appPolicyElement)) == false)
+                    throw new RuntimeException("<application-policy> element expected at " + 
+                          StaxParserUtil.getLineColumnNumber(xmlEvent.getLocation()));
                  //We got the application-policy element. It just has one attribute "name"
                  Iterator<Attribute> attrs = appPolicyElement.getAttributes(); 
                  String extendsName = null;
@@ -76,10 +80,13 @@
                  while(attrs.hasNext())
                  {
                     Attribute attribute = attrs.next();
-                    if("name".equals(attribute.getName().getLocalPart()))
-                       appPolicyName = attribute.getValue(); 
-                    else if("extends".equals(attribute.getName().getLocalPart()))
-                       extendsName = attribute.getValue();  
+                    QName attributeName = attribute.getName();
+                    String attributeValue = StaxParserUtil.getAttributeValue(attribute);
+                    
+                    if("name".equals(attributeName.getLocalPart()))
+                       appPolicyName = attributeValue; 
+                    else if("extends".equals(attributeName.getLocalPart()))
+                       extendsName = attributeValue;  
                  }
 
                  ApplicationPolicy applicationPolicy = new ApplicationPolicy(appPolicyName); 
@@ -102,7 +109,7 @@
          if(xmlEvent == null)
             return;
          StartElement startElement = xmlEvent.asStartElement();
-         String elementName = startElement.getName().getLocalPart();
+         String elementName = StaxParserUtil.getStartElementName(startElement);
          if("authentication".equals(elementName))
          {
             xmlEvent = xmlEventReader.nextEvent();
@@ -181,7 +188,8 @@
          } 
          else if("application-policy".equals(elementName))
             break; 
-         else throw new RuntimeException("Unknown "  + elementName); 
+         else throw new RuntimeException("Unknown element "  + elementName + " at location " + 
+               StaxParserUtil.getLineColumnNumber(xmlEvent.getLocation())); 
       }
    }
 }
\ No newline at end of file

Modified: projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AuditConfigParser.java
===================================================================
--- projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AuditConfigParser.java	2010-02-08 22:03:57 UTC (rev 100724)
+++ projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AuditConfigParser.java	2010-02-08 22:46:23 UTC (rev 100725)
@@ -58,7 +58,7 @@
          
          StartElement peekedStartElement = (StartElement) xmlEvent;
          AuditProviderEntry entry = null;
-         if("provider-module".equals(peekedStartElement.getName().getLocalPart()))
+         if("provider-module".equals(StaxParserUtil.getStartElementName(peekedStartElement)))
          {
             entry = this.getEntry(xmlEventReader);
          } 
@@ -87,10 +87,10 @@
          Attribute attribute = attrs.next();
          
          QName attQName = attribute.getName();
+         String attributeValue = StaxParserUtil.getAttributeValue(attribute);
          if("code".equals(attQName.getLocalPart()))
          {
-            codeName = attribute.getValue();
-             
+            codeName = attributeValue; 
          } 
       } 
       //See if there are options

Modified: projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AuthenticationConfigParser.java
===================================================================
--- projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AuthenticationConfigParser.java	2010-02-08 22:03:57 UTC (rev 100724)
+++ projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AuthenticationConfigParser.java	2010-02-08 22:46:23 UTC (rev 100725)
@@ -58,7 +58,7 @@
          
          StartElement peekedStartElement = (StartElement) xmlEvent;
          AppConfigurationEntry entry = null;
-         if("login-module".equals(peekedStartElement.getName().getLocalPart()))
+         if("login-module".equals(StaxParserUtil.getStartElementName(peekedStartElement)))
          {
             entry = this.getEntry(xmlEventReader);
          } 
@@ -87,14 +87,15 @@
          Attribute attribute = attrs.next();
          
          QName attQName = attribute.getName();
+         String attributeValue = StaxParserUtil.getAttributeValue(attribute);
+         
          if("code".equals(attQName.getLocalPart()))
          {
-            codeName = attribute.getValue();
-             
+            codeName = attributeValue;
          }
          else if("flag".equals(attQName.getLocalPart()))
          {
-            controlFlag = getControlFlag(attribute.getValue());
+            controlFlag = getControlFlag(attributeValue);
          } 
       } 
       //See if there are options

Modified: projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AuthenticationJASPIConfigParser.java
===================================================================
--- projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AuthenticationJASPIConfigParser.java	2010-02-08 22:03:57 UTC (rev 100724)
+++ projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AuthenticationJASPIConfigParser.java	2010-02-08 22:46:23 UTC (rev 100725)
@@ -62,11 +62,13 @@
          XMLEvent xmlEvent = xmlEventReader.peek(); 
          
          StartElement peekedStartElement = (StartElement) xmlEvent;
-         if("login-module-stack".equals(peekedStartElement.getName().getLocalPart()))
+         String peekedStartElementName = StaxParserUtil.getStartElementName(peekedStartElement); 
+         if("login-module-stack".equals(peekedStartElementName))
          {
             StartElement lmshEvent = (StartElement) xmlEventReader.nextEvent();
             Attribute nameAttribute = (Attribute) lmshEvent.getAttributes().next();
-            lmsh = new LoginModuleStackHolder(nameAttribute.getValue(), null);
+            String nameAttributeValue = StaxParserUtil.getAttributeValue(nameAttribute);
+            lmsh = new LoginModuleStackHolder(nameAttributeValue, null);
             authInfo.add(lmsh);
             
             while(true)
@@ -74,7 +76,8 @@
                //Get all the login modules
                xmlEvent = xmlEventReader.peek();
                peekedStartElement = (StartElement) xmlEvent;
-               if("login-module".equals(peekedStartElement.getName().getLocalPart()))
+               peekedStartElementName = StaxParserUtil.getStartElementName(peekedStartElement);
+               if("login-module".equals(peekedStartElementName))
                {
                   lmsh.addAppConfigurationEntry(this.getJAASEntry(xmlEventReader) );
                } 
@@ -82,7 +85,7 @@
                   break;
             }
          }
-         else if("auth-module".equals(peekedStartElement.getName().getLocalPart()))
+         else if("auth-module".equals(peekedStartElementName))
          {
             AuthModuleEntry entry = getJaspiEntry(xmlEventReader);
             if(lmsh != null)
@@ -115,14 +118,15 @@
          Attribute attribute = attrs.next();
          
          QName attQName = attribute.getName();
+         String attributeValue = StaxParserUtil.getAttributeValue(attribute);
+         
          if("code".equals(attQName.getLocalPart()))
          {
-            codeName = attribute.getValue();
-             
+            codeName = attributeValue;
          }
          else if("flag".equals(attQName.getLocalPart()))
          {
-            controlFlag = getControlFlag(attribute.getValue());
+            controlFlag = getControlFlag(attributeValue);
          } 
       } 
       //See if there are options
@@ -151,14 +155,15 @@
          Attribute attribute = attrs.next();
          
          QName attQName = attribute.getName();
+         String attributeValue = StaxParserUtil.getAttributeValue(attribute);
+         
          if("code".equals(attQName.getLocalPart()))
          {
-            codeName = attribute.getValue();
-             
+            codeName = attributeValue; 
          }
          else if("flag".equals(attQName.getLocalPart()))
          {
-            flag = ControlFlag.valueOf(attribute.getValue());
+            flag = ControlFlag.valueOf(attributeValue);
          } 
       } 
     

Modified: projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AuthorizationConfigParser.java
===================================================================
--- projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AuthorizationConfigParser.java	2010-02-08 22:03:57 UTC (rev 100724)
+++ projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AuthorizationConfigParser.java	2010-02-08 22:46:23 UTC (rev 100725)
@@ -59,7 +59,7 @@
          
          StartElement peekedStartElement = (StartElement) xmlEvent;
          AuthorizationModuleEntry entry = null;
-         if("policy-module".equals(peekedStartElement.getName().getLocalPart()))
+         if("policy-module".equals(StaxParserUtil.getStartElementName(peekedStartElement)))
          {
             entry = this.getEntry(xmlEventReader);
          } 
@@ -89,14 +89,15 @@
          Attribute attribute = attrs.next();
          
          QName attQName = attribute.getName();
+         String attributeValue = StaxParserUtil.getAttributeValue(attribute);
+         
          if("code".equals(attQName.getLocalPart()))
          {
-            codeName = attribute.getValue();
-             
+            codeName = attributeValue; 
          }
          else if("flag".equals(attQName.getLocalPart()))
          {
-            controlFlag = ControlFlag.valueOf(attribute.getValue());
+            controlFlag = ControlFlag.valueOf(attributeValue);
          } 
       } 
       //See if there are options

Modified: projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/IdentityTrustConfigParser.java
===================================================================
--- projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/IdentityTrustConfigParser.java	2010-02-08 22:03:57 UTC (rev 100724)
+++ projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/IdentityTrustConfigParser.java	2010-02-08 22:46:23 UTC (rev 100725)
@@ -58,7 +58,7 @@
          
          StartElement peekedStartElement = (StartElement) xmlEvent;
          IdentityTrustModuleEntry entry = null;
-         if("trust-module".equals(peekedStartElement.getName().getLocalPart()))
+         if("trust-module".equals(StaxParserUtil.getStartElementName(peekedStartElement)))
          {
             entry = this.getEntry(xmlEventReader);
          } 
@@ -73,9 +73,8 @@
    private IdentityTrustModuleEntry getEntry(XMLEventReader xmlEventReader) throws XMLStreamException
    {
       XMLEvent xmlEvent = xmlEventReader.nextEvent(); 
-      Map<String, Object> options = new HashMap<String,Object>();
+      Map<String, Object> options = new HashMap<String,Object>(); 
       
-      
       String codeName = null; 
       
       //We got the login-module element
@@ -87,10 +86,11 @@
          Attribute attribute = attrs.next();
          
          QName attQName = attribute.getName();
+         String attributeValue = StaxParserUtil.getAttributeValue(attribute);
+         
          if("code".equals(attQName.getLocalPart()))
          {
-            codeName = attribute.getValue();
-             
+            codeName = attributeValue; 
          } 
       } 
       //See if there are options

Modified: projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/JavaPropertiesConfigParser.java
===================================================================
--- projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/JavaPropertiesConfigParser.java	2010-02-08 22:03:57 UTC (rev 100724)
+++ projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/JavaPropertiesConfigParser.java	2010-02-08 22:46:23 UTC (rev 100725)
@@ -36,13 +36,14 @@
  */
 public class JavaPropertiesConfigParser implements ParserNamespaceSupport
 {
+   private static final String NAMESPACE_URI ="urn:jboss:java-properties"; 
 
    /**
     * @see {@code ParserNamespaceSupport#supports(String)}
     */
    public boolean supports(String namespaceURI)
    {
-      return "urn:jboss:java-properties".equals(namespaceURI);
+      return NAMESPACE_URI.equals(namespaceURI);
    }
 
    /**
@@ -58,7 +59,7 @@
          if(xmlEvent instanceof StartElement)
          {
             StartElement se = (StartElement) xmlEvent;
-            if("module-option".equals(se.getName().getLocalPart()))
+            if("module-option".equals(StaxParserUtil.getStartElementName(se)))
                return props;
          }
          if(xmlEvent instanceof EndElement)
@@ -70,17 +71,20 @@
          xmlEvent = xmlEventReader.nextEvent(); 
          
          StartElement peekedStartElement = (StartElement) xmlEvent;
+         String peekedStartElementName = StaxParserUtil.getStartElementName(peekedStartElement);
+         
          String key = null, value = null;
-         if(peekedStartElement.getName().getLocalPart().contains("property") == false)
+         if(peekedStartElementName.contains("property") == false)
             throw new RuntimeException("property element not found");
          xmlEvent = xmlEventReader.nextEvent();
          peekedStartElement = (StartElement) xmlEvent;
-         if("key".equals(peekedStartElement.getName().getLocalPart()))
+         peekedStartElementName = StaxParserUtil.getStartElementName(peekedStartElement);
+         if("key".equals(peekedStartElementName))
          {
             key = xmlEventReader.getElementText();
             xmlEvent = xmlEventReader.nextEvent();
             value = xmlEventReader.getElementText();
-         } else if("value".equals(peekedStartElement.getName().getLocalPart()))
+         } else if("value".equals(peekedStartElementName))
          {
             throw new RuntimeException("key element not found. Check order of key and value");
          }

Modified: projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/MappingConfigParser.java
===================================================================
--- projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/MappingConfigParser.java	2010-02-08 22:03:57 UTC (rev 100724)
+++ projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/MappingConfigParser.java	2010-02-08 22:46:23 UTC (rev 100725)
@@ -64,8 +64,9 @@
          XMLEvent xmlEvent = xmlEventReader.peek(); 
          
          StartElement peekedStartElement = (StartElement) xmlEvent;
+         String peekedStartElementName = StaxParserUtil.getStartElementName(peekedStartElement);
          MappingModuleEntry entry = null;
-         if("mapping-module".equals(peekedStartElement.getName().getLocalPart()))
+         if("mapping-module".equals(peekedStartElementName))
          {
             entry = this.getEntry(xmlEventReader);
          } 
@@ -93,15 +94,15 @@
          Attribute attribute = attrs.next();
          
          QName attQName = attribute.getName();
+         String attributeValue = StaxParserUtil.getAttributeValue(attribute);
+         
          if("code".equals(attQName.getLocalPart()))
          {
-            codeName = attribute.getValue();
-             
+            codeName = attributeValue; 
          } 
          else if("type".equals(attQName.getLocalPart()))
          {
-            typeName = attribute.getValue();
-             
+            typeName = attributeValue; 
          }
       } 
       //See if there are options

Modified: projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/ModuleOptionParser.java
===================================================================
--- projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/ModuleOptionParser.java	2010-02-08 22:03:57 UTC (rev 100724)
+++ projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/ModuleOptionParser.java	2010-02-08 22:46:23 UTC (rev 100725)
@@ -72,7 +72,10 @@
          StartElement peekedStartElement = (StartElement) xmlEvent;
          if(xmlEvent == null)
             break; //no module options
-         if("module-option".equals(peekedStartElement.getName().getLocalPart()))
+         
+         String peekedStartElementName = StaxParserUtil.getStartElementName(peekedStartElement);
+         
+         if("module-option".equals(peekedStartElementName))
          {
             xmlEvent = xmlEventReader.nextEvent();
             Attribute attribute = (Attribute) peekedStartElement.getAttributes().next();

Modified: projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/StaxBasedConfigParser.java
===================================================================
--- projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/StaxBasedConfigParser.java	2010-02-08 22:03:57 UTC (rev 100724)
+++ projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/StaxBasedConfigParser.java	2010-02-08 22:46:23 UTC (rev 100725)
@@ -32,6 +32,7 @@
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamConstants;
 import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.events.StartElement;
 import javax.xml.stream.events.XMLEvent;
 import javax.xml.transform.Source;
 import javax.xml.transform.stream.StreamSource;
@@ -107,6 +108,10 @@
             case XMLStreamConstants.START_ELEMENT: 
                //We got the policy element. We can go over the attributes if we want
                //But there is no immediate need.
+               StartElement policyConfigElement = (StartElement) xmlEvent;
+               if("policy".equals(StaxParserUtil.getStartElementName(policyConfigElement)) == false)
+                     throw new IllegalArgumentException("<policy> root element expected at " 
+                           + StaxParserUtil.getLineColumnNumber(xmlEvent.getLocation()));
                
                ApplicationPolicyParser appPolicyParser = new ApplicationPolicyParser(); 
                List<ApplicationPolicy> appPolicies = appPolicyParser.parse(xmlEventReader);
@@ -187,5 +192,5 @@
         throw new RuntimeException(ex);
       }
       return xmlEventReader;
-    }
+    }  
 }
\ No newline at end of file

Added: projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/StaxParserUtil.java
===================================================================
--- projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/StaxParserUtil.java	                        (rev 0)
+++ projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/StaxParserUtil.java	2010-02-08 22:46:23 UTC (rev 100725)
@@ -0,0 +1,81 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.security.config.parser;
+
+import javax.xml.stream.Location;
+import javax.xml.stream.events.Attribute;
+import javax.xml.stream.events.StartElement;
+ 
+
+/**
+ * Utility for the stax based parser
+ * @author Anil.Saldhana at redhat.com
+ * @since Feb 8, 2010
+ */
+public class StaxParserUtil
+{  
+   /**
+    * Given an {@code Attribute}, get its trimmed value
+    * @param attribute
+    * @return
+    */
+   public static String getAttributeValue(Attribute attribute)
+   {
+      return trim(attribute.getValue());
+   }
+   
+   /**
+    * Given a {@code Location}, return a formatted string
+    * [lineNum,colNum]
+    * @param location
+    * @return
+    */
+   public static String getLineColumnNumber(Location location)
+   {
+     StringBuilder builder = new StringBuilder("[");
+     builder.append(location.getLineNumber()).append(",").append(location.getColumnNumber()).append("]");
+     return builder.toString();
+   }
+   
+   /**
+    * Return the name of the start element
+    * @param startElement
+    * @return
+    */
+   public static String getStartElementName(StartElement startElement)
+   {
+      return trim(startElement.getName().getLocalPart());
+   }
+   
+   /**
+    * Given a string, trim it
+    * @param str
+    * @return
+    * @throws {@code IllegalArgumentException} if the passed str is null
+    */
+   public static final String trim(String str)
+   {
+      if(str == null || str.length() == 0)
+         throw new IllegalArgumentException("Input str is null");
+      return str.trim();
+   }
+}
\ No newline at end of file

Modified: projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/UsersConfigParser.java
===================================================================
--- projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/UsersConfigParser.java	2010-02-08 22:03:57 UTC (rev 100724)
+++ projects/security/picketbox/trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/UsersConfigParser.java	2010-02-08 22:46:23 UTC (rev 100725)
@@ -42,7 +42,9 @@
  * @since Jan 27, 2010
  */
 public class UsersConfigParser implements ParserNamespaceSupport
-{
+{ 
+   private static final String NAMESPACE_URI ="urn:jboss:user-roles"; 
+   
    /**
     * Parse the embedded xml in the module option representing
     * the {@code Users} object
@@ -61,7 +63,7 @@
          if(xmlEvent instanceof StartElement)
          {
             StartElement se = (StartElement) xmlEvent;
-            if("module-option".equals(se.getName().getLocalPart()))
+            if("module-option".equals(StaxParserUtil.getStartElementName(se)))
                return users;
          }
          if(xmlEvent instanceof EndElement)
@@ -107,14 +109,15 @@
                while(roleAttribs.hasNext())
                {
                   Attribute roleAttribute = roleAttribs.next();
+                  String attributeValue = StaxParserUtil.getAttributeValue(roleAttribute);
                   
                   if("name".equals(roleAttribute.getName().getLocalPart()))
                   {
-                    roleName = roleAttribute.getValue();  
+                    roleName = attributeValue;  
                   }
                   else if("group".equals(roleAttribute.getName().getLocalPart()))
                   {
-                     groupName = roleAttribute.getValue();  
+                     groupName = attributeValue;  
                   } 
                }
                if(roleName != null)
@@ -134,6 +137,6 @@
     */
    public boolean supports(String namespaceURI)
    {
-      return "urn:jboss:user-roles".equals(namespaceURI);
+      return NAMESPACE_URI.equals(namespaceURI);
    }
 }
\ No newline at end of file




More information about the jboss-cvs-commits mailing list