glassfish
  1. glassfish
  2. GLASSFISH-18654

Password parameters not always handled correctly by CRUD command framework

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 4.0_b34
    • Component/s: configuration
    • Labels:
      None

      Description

      I tried to add an optional password parameter to the VirtUser config class to be used by the create-machine-user and create-pool-user CRUD commands. I did this by adding the following to VirtUser:

          @Attribute
          String getIaasPassword();
          @Param(name="iaaspassword", password=true, optional = true)
          void setIaasPassword(String password);
      

      But this did not work. Even if I specified this in the asadmin password file:

      AS_ADMIN_IAASPASSWORD=Welcome1
      

      the password was not passed to the command.

      After some debugging in the asadmin client it appears as though the server never translates the "iaaspassword" parameter name to "AS_ADMIN_IAASPASSWORD", and that's why the client doesn't find the parameter in the asadmin password file. Based on trying other commands it appears as though this translation is supposed to happen in the server before the parameter model is passed to the client, but for some reason in this case it is not getting translated.

      Note that other commands (like create-node-ssh) are working correctly – it's just this particular use of a CRUD command that is not working.

        Issue Links

          Activity

          Hide
          Joe Di Pol added a comment - - edited

          This parameter name translation for password parameters is handled by calls to org.glassfish.api.admin.CommandModel.getParamName(). The CRUD command in question uses GenericCommandModel which is is not translating the parameter names in its constructor. The problem looks to be here in the GenericCommandModel constructor:

                  if (useAnnotations && targetType!=null &&
          		ConfigBeanProxy.class.isAssignableFrom(targetType)) {
                      ConfigModel cm = document.buildModel(targetType);
                      for (Method m : targetType.getMethods()) {
                          ConfigModel.Property prop = cm.toProperty(m);
                          if (prop == null) continue;
                          String attributeName = prop.xmlName;
                          I18n paramI18n = m.getAnnotation(I18n.class);
                          if (m.isAnnotationPresent(Param.class)) {
                              Param p = m.getAnnotation(Param.class);
                              if (p.name() != null && !p.name().isEmpty()) {
                                  params.put(p.name(), new ParamBasedModel(p.name(), p, paramI18n));
                              } else {
                                  if (m.isAnnotationPresent(Attribute.class)) {
                                      Attribute attr = m.getAnnotation(Attribute.class);
                                      if (attr.value() != null && !attr.value().isEmpty()) {
                                          params.put(attr.value(), new AttributeBasedModel(attr.value(), attr, paramI18n));
                                      } else {
                                          params.put(attributeName, new AttributeBasedModel(attributeName, attr, paramI18n));
                                      }
                                  } else {
                                      // use method name.
                                      String name = cm.trimPrefix(m.getName());
                                      params.put(name, new ParamBasedModel(name, p, paramI18n));
                                  }
                              }
                          }
                      }
                  }
          

          For example:

                              if (p.name() != null && !p.name().isEmpty()) {
                                  params.put(p.name(), new ParamBasedModel(p.name(), p, paramI18n));
          

          This should be using CommandModel.getParamName() instead of just p.name(). getParamsName() handles mapping the parameter name to the asadmin password file syntax.

          Show
          Joe Di Pol added a comment - - edited This parameter name translation for password parameters is handled by calls to org.glassfish.api.admin.CommandModel.getParamName(). The CRUD command in question uses GenericCommandModel which is is not translating the parameter names in its constructor. The problem looks to be here in the GenericCommandModel constructor: if (useAnnotations && targetType!=null && ConfigBeanProxy.class.isAssignableFrom(targetType)) { ConfigModel cm = document.buildModel(targetType); for (Method m : targetType.getMethods()) { ConfigModel.Property prop = cm.toProperty(m); if (prop == null) continue; String attributeName = prop.xmlName; I18n paramI18n = m.getAnnotation(I18n.class); if (m.isAnnotationPresent(Param.class)) { Param p = m.getAnnotation(Param.class); if (p.name() != null && !p.name().isEmpty()) { params.put(p.name(), new ParamBasedModel(p.name(), p, paramI18n)); } else { if (m.isAnnotationPresent(Attribute.class)) { Attribute attr = m.getAnnotation(Attribute.class); if (attr.value() != null && !attr.value().isEmpty()) { params.put(attr.value(), new AttributeBasedModel(attr.value(), attr, paramI18n)); } else { params.put(attributeName, new AttributeBasedModel(attributeName, attr, paramI18n)); } } else { // use method name. String name = cm.trimPrefix(m.getName()); params.put(name, new ParamBasedModel(name, p, paramI18n)); } } } } } For example: if (p.name() != null && !p.name().isEmpty()) { params.put(p.name(), new ParamBasedModel(p.name(), p, paramI18n)); This should be using CommandModel.getParamName() instead of just p.name(). getParamsName() handles mapping the parameter name to the asadmin password file syntax.
          Hide
          Joe Di Pol added a comment - - edited

          Fixed in trunk r53623. Diff is attached.

          In addition to fixing the base bug I fixed CommandModel.java to handle methods that start with "is" (in addition to set/get/has which it already handled).

          Note that this bug did not impact any existing commands, it was just preventing implementation of new commands that had password parameters and used the CRUD framework in a particular way.

          Show
          Joe Di Pol added a comment - - edited Fixed in trunk r53623. Diff is attached. In addition to fixing the base bug I fixed CommandModel.java to handle methods that start with "is" (in addition to set/get/has which it already handled). Note that this bug did not impact any existing commands, it was just preventing implementation of new commands that had password parameters and used the CRUD framework in a particular way.

            People

            • Assignee:
              Joe Di Pol
              Reporter:
              Joe Di Pol
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: