4 Replies Latest reply on May 9, 2014 2:23 AM by swiderski.maciej

    Issue Authenticating to Kie Rest Service

    tmcclure0501

      I got the code below from the link above it - recent code so it should work but for some reason I get an authentication error when I execute it using admin/admin however I can log in on the web page using the same credentials.  I get a 401 error - I know it must be something stupid I am doing - is there something I need to change in the JBoss configuration for my url: Localhost:8080/kie-wb?

       

      <html><head><title>JBoss Web/7.0.13.Final - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 401 - Validation fails.</h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u>Validation fails.</u></p><p><b>description</b> <u>This request requires HTTP authentication (Validation fails.).</u></p><HR size="1" noshade="noshade"><h3>JBoss Web/7.0.13.Final</h3></body></html>

       

       

      http://simplesassim.wordpress.com/2013/07/07/how-to-list-assets-with-the-drools-guvnor-rest-api/

       

      package com.apimg.com.dakota;

      import javax.ws.rs.client.Client;

      import javax.ws.rs.client.ClientBuilder;

      import javax.ws.rs.core.Response;

      import org.glassfish.jersey.client.filter.HttpBasicAuthFilter;

       

      public final class KiePackage {

        public static void main(final String[] args) {

         final Client client = ClientBuilder.newClient();

           client.register(new HttpBasicAuthFilter("admin", "admin"));

           final Response res = client.target("http://localhost:8080/kie-wb/rest/packages").request().get();

           System.out.println(res.readEntity(String.class));

           client.close();

        }

       

      }

        • 1. Re: Issue Authenticating to Kie Rest Service
          swiderski.maciej

          looks like the BASIC authentication info is not set properly. REST api expects it to be valid BASIC header with Base64 encoded string. Could you check what is the actual request that is being sent? Have you tried with other client library like apache http client?

           

          HTH

          • 2. Re: Issue Authenticating to Kie Rest Service
            tmcclure0501

            I tried with httpclient - still get 401 code below:

             

            package com.apimg.com.dakota;

            import java.io.IOException;

             

             

            import org.apache.http.HttpResponse;

            import org.apache.http.StatusLine;

            import org.apache.http.auth.AuthScope;

            import org.apache.http.auth.Credentials;

            import org.apache.http.auth.UsernamePasswordCredentials;

            import org.apache.http.client.methods.HttpGet;

            import org.apache.http.impl.client.DefaultHttpClient;

              

            public final class KiePackage {

              

               public static void main(final String[] args) {

              

               try

               {

              HttpGet httpget = new HttpGet("http://localhost:8080/kie-wb-6.0.0.Final-jboss-as7/rest/packages");// Execute HTTP Get Request

              DefaultHttpClient httpClient =new DefaultHttpClient();

              Credentials credentials =new UsernamePasswordCredentials("admin", "admin");

              httpClient.getCredentialsProvider().setCredentials(new AuthScope("localhost",8080),

              credentials);

             

             

              HttpResponse response = httpClient.execute(httpget);

              StatusLine status = response.getStatusLine();

              System.out.println("Status = " + status.getStatusCode());

             

             

                }

                catch (IOException e) {

              e.printStackTrace();

              }

              }

            }

            • 3. Re: Issue Authenticating to Kie Rest Service
              marccbr

              Did you ever get an answer to this?  I am running into the same problem after installing it on Tomcat 7.  The jboss version works good but no go on the Tomcat version.

              • 4. Re: Issue Authenticating to Kie Rest Service
                swiderski.maciej

                you need to set preemptive authentication so http client sends the authentication data in the first request without a need to wait for a challenge from the server.

                 

                HTH