4 Replies Latest reply on Oct 13, 2006 8:36 AM by adrian.brock

    Marshalling Into java.util.properties

    anil.saldhana

      I tried using the jbxb marshalling into properties in conf/login-config.xml

      <policy
       xsi:schemaLocation="urn:jboss:security-config:5.0 resource:security-config_5_0
      .xsd"
       xmlns="urn:jboss:security-config:5.0"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      
       <application-policy name="TEST">
       <authentication>
       <login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule"
       flag="required">
       <module-option name="usersProperties">test-users.properties</module-option>
       <module-option name="rolesProperties">test-roles.properties</module-option>
       <module-option name="password-stacking">useFirstPass</module-option>
       <module-option name="unauthenticatedIdentity">test-user</module-option>
       </login-module>
       </authentication>
       <authorization>
       <policy-module code="org.jboss.security.authorization.modules.JACCAuthorizationModule" flag="required"/>
       </authorization>
       <rolemapping>
       <mapping-module code="org.jboss.security.mapping.providers.PolicyContextIdRoleMappingProvider">
       <module-option name="map" serialDataType="jbxb">
       <java:properties xmlns:java="urn:jboss:java-properties"
       xsi:schemaLocation="urn:jboss:java-properties resource:java-properties_1_0.xsd">
       <java:property>
       <java:key>jacc_principal2role_first_module_web.war</java:key>
       <java:value>props/jacc_principal2role.ear.properties</java:value>
       </java:property>
       </java:properties>
       </module-option>
       </mapping-module>
       </rolemapping>
       </application-policy>
      


      I see that on the setValue to ModuleOption, XB should have picked up the properties object, but it does not:

      2006-10-10 13:52:40,900 TRACE [org.jboss.security.authorization.config.SecurityConfigObjectModelFactory] newChild.RoleMappingInfo, mapping-module code: org.jbos
      s.security.mapping.providers.PolicyContextIdRoleMappingProvider
      2006-10-10 13:52:40,900 TRACE [org.jboss.xb.binding.ObjectModelBuilder] accepted
       urn:jboss:security-config:5.0:mapping-module
      2006-10-10 13:52:40,900 TRACE [org.jboss.xb.binding.parser.sax.SaxJBossXBParser]
       Exit startElement urn:jboss:security-config:5.0:mapping-module
      2006-10-10 13:52:40,900 TRACE [org.jboss.xb.binding.parser.sax.SaxJBossXBParser]
       Enter startElement urn:jboss:security-config:5.0:module-option
      2006-10-10 13:52:40,900 TRACE [org.jboss.security.authorization.config.SecurityConfigObjectModelFactory] newChild.MappingModuleEntry, localName: module-option
      2006-10-10 13:52:40,900 TRACE [org.jboss.security.authorization.config.SecurityConfigObjectModelFactory] newChild.MappingModuleEntry, module-option name: map
      2006-10-10 13:52:40,900 TRACE [org.jboss.xb.binding.ObjectModelBuilder] accepted
       urn:jboss:security-config:5.0:module-option
      2006-10-10 13:52:40,900 TRACE [org.jboss.xb.binding.parser.sax.SaxJBossXBParser]
       Exit startElement urn:jboss:security-config:5.0:module-option
      2006-10-10 13:52:40,900 TRACE [org.jboss.xb.binding.parser.sax.SaxJBossXBParser]
       Enter startElement urn:jboss:java-properties:properties
      2006-10-10 13:52:40,900 TRACE [org.jboss.xb.binding.ObjectModelBuilder] ignored
      urn:jboss:java-properties:java:properties
      2006-10-10 13:52:40,900 TRACE [org.jboss.xb.binding.parser.sax.SaxJBossXBParser]
       Exit startElement urn:jboss:java-properties:properties
      


      It is ignoring the java:xxx elements. The JBossEntityResolver did resolve the java-properties_1_0.xsd schema successfully.

      Anything obvious?

        • 1. Re: Marshalling Into java.util.properties
          aloubyansky

          The elements were ignored because the ObjectModelFactory impl returned null for those elements.

          • 2. Re: Marshalling Into java.util.properties
            anil.saldhana

            So I have to manually take care of the Properties structure in my impl? I do not get the same help from JBossXB as in ServiceDotXML, I mean the jbxb style attributes?
            http://wiki.jboss.org/wiki/Wiki.jsp?page=SERVICEdotXML

            • 3. Re: Marshalling Into java.util.properties
              aloubyansky

              serialDataType="jbxb" is a feature of the Service Deployment parsing. You are using your own.

              • 4. Re: Marshalling Into java.util.properties

                The code to do this is really trivial

                org.jboss.system.metadata.ServiceJBXBValueMetaData

                 // Get the attribute element content in a parsable form
                 StringBuffer buffer = ServiceConfigurator.getElementContent(getElement());
                
                 Thread current = Thread.currentThread();
                 ClassLoader oldTcl = current.getContextClassLoader();
                 ClassLoader cl = valueContext.getClassloader();
                 if (cl != null)
                 current.setContextClassLoader(cl);
                 try
                 {
                 // Parse the attribute element content
                 SchemaBindingResolver resolver = SingletonSchemaResolverFactory.getInstance().getSchemaBindingResolver();
                 Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
                 StringReader reader = new StringReader(buffer.toString());
                 Object bean = unmarshaller.unmarshal(reader, resolver);
                 return bean;
                 }
                 finally
                 {
                 if (cl != null)
                 current.setContextClassLoader(oldTcl);
                 }
                


                In fact, it is really redundant since this code is executed automatically
                if you have the namespace registered properly with the schema binding
                resolver and you are using the schema unmarshaller
                (which is not currently the case for the -service.xml)