REST API Bonita 6.x - Auth - Error while logging in on the engine API

Server Enviroment

- CentOS 6.4 (Final);

- Java(TM) SE Runtime Environment (build 1.7.0_45-b18);

- BonitaBPMCommunity-6.2.0-Tomcat-6.0.37 (bundle);

- Postgresql 9.2.6;

REST client

package com.mkyong.rest.client;

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.net.MalformedURLException;

import org.apache.http.HttpResponse;

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

import org.apache.http.entity.StringEntity;

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

public class ApacheHttpClientPost {

// http://localhost:8080/RESTfulExample/json/product/post

    public static void main(String[] args) {

        try {

            DefaultHttpClient httpClient = new DefaultHttpClient();

            //HttpPost postRequest = new HttpPost(

            //        "http://localhost:8080/RESTfulExample/json/product/post");

            HttpPost postRequest = new HttpPost("http://<publicIPserver>:<port>/bonita/loginservice");

            //StringEntity input = new StringEntity(

            //        "{\"qty\":100,\"name\":\"iPad 4\"}");

            StringEntity input = new StringEntity("{\"username\":\"myusername\",\"password\":\"mypassword\",\"redirect\":\"false\"}");

            input.setContentType("application/json");

            postRequest.setEntity(input);

            HttpResponse response = httpClient.execute(postRequest);

            if (response.getStatusLine().getStatusCode() != 200) {

                throw new RuntimeException("Failed : HTTP error code : "

                        + response.getStatusLine().getStatusCode());

            }

            BufferedReader br = new BufferedReader(new InputStreamReader(

                    (response.getEntity().getContent())));

            String output;

            System.out.println("Output from Server .... \n");

            while ((output = br.readLine()) != null) {

                System.out.println(output);

            }

            httpClient.getConnectionManager().shutdown();

        } catch (MalformedURLException e) {

            e.printStackTrace();

        } catch (IOException e) {

            e.printStackTrace();

        }

    }

Output server

Output from Server .... 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>

<head>

<meta http-equiv="content-type" content="text/html; charset=UTF-8" />

<title>Bonita BPM Portal</title>

<link rel="icon" type="image/png" href="images/favicon2.ico" />

<!-- Load LESS CSS -->

<script type="text/javascript" src="portal/scripts/includes/array.prototype.js"></script>

<link rel="stylesheet" type="text/css" href="portal/themeResource?theme=portal&location=bonita.css"/>

<script type="text/javascript" src="portal/scripts/jquery/jquery-1.6.4.js"></script>

<script>

    /* Add url hash to form action url */

    $(document).ready(function() {

        var form = $('#LoginForm');

        form.attr('action', form.attr('action') + encodeURI(window.location.hash));

    });

</script>

</head>

<body id="LoginPage">

    <div id="LoginHeader"><h1><span>Welcome to</span> Bonita BPM Portal</h1></div>

    <div id="floater"></div>

    <div id="LoginFormContainer" >

        <div id="logo">

            <img src="portal/themeResource?theme=portal&location=skin/images/login-logo.png"/>

        </div>

        <div class="body">

            <form id="LoginForm" action="loginservice?" method="post">

                <div class="header">

                    <h2>Login form</h2>

                </div>

                <p class="error">Unable to log in. Please check your username and password.</p>

                <div class="formentries">

                    <div class="formentry" title="Enter your login (username)">

                        <div class="label">

                            <label for="username">User</label>

                        </div>

                        <div class="input">

                            <input title="Login" id="username" name="username" value="" placeholder="User" type="text" tabindex="1" maxlength="50"  />

                        </div>

                    </div>

                    <div class="formentry" title="Enter your password">

                        <div class="label">

                            <label for="password">Password</label>

                        </div>

                        <div class="input">

                            <input title="Password" id="password" name="password" type="password" tabindex="2" maxlength="50" placeholder="Password"  />

                        </div>

                        <input name="_l" type="hidden" value="en_US" />

                    </div>

                </div>

                <div class="formactions">

                    <input type="submit" value="Login"  />

                </div>

            </form>

        </div>

    </div>

    <div class="footer" id="footer">

        Bonitasoft ?? 2013 All rights reserved.

    </div>

</body>

</html>

bonita.2014-01-15.log

gen 15, 2014 9:48:48 AM org.bonitasoft.console.common.server.login.datastore.LoginDatastore login
Grave: Error while logging in on the engine API.

---

Of course user myuser : mypassword is in db of the engine.

What's wrong?

Thanks in advance

 

 

look here. http://community.bonitasoft.com//answers/rest-api-bonita-6x-authentication-401-unauthorized#comment-37864

did you use the technical account (install / install) to create the first admin users ?

Yes I did

If I understand, you try to log in through the API, via a third party application? can you log in with Bonita BPM Portal, to check if the problem is with your script, or with Bonita.

Unfortunately, I can login to the portal with the same credentials. The problem is my script. If I understand the portal is "like" third part application (because use REST API). Do you know where I can find the code?