1 Reply Latest reply on Oct 19, 2012 3:48 PM by ctomc

    Programmatic configuration

    alexkashrus

      I am trying to programatically configure JBoss 7 using the remoting API. I am having problems with configuring the login-modules.

       

       

      creating security domain works fine, here is the code:

       

      {code}

          public static void addSecurityDomain(ModelControllerClient client,String securityDomain)  throws IOException

          {

              ModelNode request = new ModelNode();

              request.get(ClientConstants.OP).set(ClientConstants.ADD);

              request.get(ClientConstants.OP_ADDR).add("subsystem",

                      "security");

              request.get(ClientConstants.OP_ADDR).add("security-domain",

                      securityDomain);

       

       

              ModelNode result = client.execute(new OperationBuilder(request).build());

       

       

              String outcome = result.get(ClientConstants.OUTCOME).asString();

              String description = "";

              if (outcome.equalsIgnoreCase("failed")) {

                  description += " ,Reason: " + result.get(ClientConstants.FAILURE_DESCRIPTION).asString();

              }

              System.out.println("Adding Security Domain: " + securityDomain + " Result: " + outcome + description);

       

          }

      {code}

       

       

       

       

      now trying to create the security domain fails with error:

       

          "JBAS014798: Validation failed for login-modules",

          "JBAS014746: flag may not be null"

      here is the code:

       

      {code}

          public static void addAuthenticationToSecDomain(ModelControllerClient client,String securityDomain)  throws IOException

          {

              ModelNode request = new ModelNode();

              request.get(ClientConstants.OP).set(ClientConstants.ADD);

              request.get(ClientConstants.OP_ADDR).

                      add("subsystem", "security").

                      add("security-domain",securityDomain)

                      .add("authentication","classic");

       

       

             ModelNode list=new ModelNode() ;

       

       

              ModelNode module1=new ModelNode();//list.addEmptyList();

              module1.add("flag","required");

              module1.add("code", "com.kosherid.security.OSKMLoginModule");

              list.add(module1);

               request.get("login-modules").set(list);

       

              OperationBuilder ob=new OperationBuilder(request);

              Operation op= ob.build() ;

              ModelNode result = client.execute(op);

       

       

              String outcome = result.get(ClientConstants.OUTCOME).asString();

              String description = "";

              if (outcome.equalsIgnoreCase("failed")) {

                  description += " ,Reason: " + result.get(ClientConstants.FAILURE_DESCRIPTION).asString();

              }

              System.out.println("Adding Authentication: " + securityDomain + " Result: " + outcome + description);

       

          }

       

      {code}

      basically it seems the JBoss doesn't see the flag field in the list item. It all works fine when trying to add from cli

      Version:

      14:04:24,745 INFO  [org.jboss.as] JBAS015899: JBoss AS 7.1.1.Final "Brontes" starting

        • 1. Re: Programmatic configuration
          ctomc

          Hi,

           

          i think you should fix bit the way you set login-modules

           

          ModelNode list=new ModelNode() ;
          ModelNode module1=new ModelNode();//list.addEmptyList();
          module1.get("flag").set("required");
          module1.get("code").set("com.kosherid.security.OSKMLoginModule");
          list.add(module1);
          request.get("login-modules").set(list);

           

          ---

          tomaz