Fórum

Android create user AuthenticationException

thumbnail
Jonathan Villegas, modificado 8 Anos atrás.

Android create user AuthenticationException

New Member Postagens: 14 Data de Entrada: 27/06/14 Postagens Recentes
Hi,


I want to create a new portal user from a android app.
This is the code:


public static void crearCuentaPortal(){

        Log.d(TAG,">>>> Entro a crear el nuevo usuario....");
        long companyId = 20155;
        boolean autoPassword = false;
        String password1 = "123456";
        String password2 = "123456";
        boolean autoScreenName = false;
        String screenName = "prueba";
        String emailAddress = "test@test.cl";
        long facebookId = 0;
        String openId = "";
        String locale = "es_ES";
        String firstName = "prueba";
        String middleName = "prueba";
        String lastName = "prueba";
        int prefixId = 0;
        int suffixId = 0;
        boolean male = true;
        int birthdayMonth = 8;
        int birthdayDay = 13;
        int birthdayYear = 2000;
        String jobTitle = "";
        JSONArray groupIds = null;
        JSONArray organizationIds = null;
        JSONArray roleIds = null;
        JSONArray userGroupIds = null;
        boolean sendEmail = false;
        JSONObjectWrapper serviceContext = null;

        Session s = new SessionImpl(PortalValues.URL_BASE_PORTAL);
        UserService userService = new UserService(s);
        AsyncTaskCallback callback = new JSONObjectAsyncTaskCallback() {
            public void onFailure(Exception exception) {
                Log.e(TAG , "Error al crear el usuario : " + exception);
                exception.printStackTrace();
            }
            public void onSuccess(JSONObject result) {
               Log.d(TAG, "Usuario creado con exito : " + result);
            }
        };
        s.setCallback(callback);
        try {
            userService.addUser(companyId ,autoPassword,password1,password2 , autoScreenName,screenName ,
                    emailAddress, facebookId, openId , locale, firstName, middleName,lastName,prefixId,
                    suffixId,male,birthdayMonth,birthdayDay,birthdayYear, jobTitle,groupIds,
                    organizationIds, roleIds, userGroupIds, sendEmail, serviceContext);
        }
        catch (Exception e) {
            Log.e(TAG , "Error al crear el usuario nuevo : " + e);
            e.printStackTrace();
        }
    }




This is the exception i am getting :




10-08 23:31:41.985 7460-7460/? E/PortalUtil: Error al crear el usuario : com.liferay.mobile.android.exception.AuthenticationException: java.lang.SecurityException
10-08 23:31:41.987 7460-7460/? W/System.err: com.liferay.mobile.android.exception.AuthenticationException: java.lang.SecurityException
10-08 23:31:41.989 7460-7460/? W/System.err:     at com.liferay.mobile.android.http.HttpUtil.handlePortalException(HttpUtil.java:266)
10-08 23:31:41.989 7460-7460/? W/System.err:     at com.liferay.mobile.android.http.HttpUtil.handleServerError(HttpUtil.java:180)
10-08 23:31:41.989 7460-7460/? W/System.err:     at com.liferay.mobile.android.http.HttpUtil.post(HttpUtil.java:194)
10-08 23:31:41.990 7460-7460/? W/System.err:     at com.liferay.mobile.android.task.ServiceAsyncTask.doInBackground(ServiceAsyncTask.java:39)
10-08 23:31:41.990 7460-7460/? W/System.err:     at com.liferay.mobile.android.task.ServiceAsyncTask.doInBackground(ServiceAsyncTask.java:29)
10-08 23:31:41.990 7460-7460/? W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:292)
10-08 23:31:41.990 7460-7460/? W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
10-08 23:31:41.990 7460-7460/? W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
10-08 23:31:41.990 7460-7460/? W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
10-08 23:31:41.990 7460-7460/? W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
10-08 23:31:41.990 7460-7460/? W/System.err:     at java.lang.Thread.run(Thread.java:818)



Any suggestions?

Thanks in advance.

Greetings!
thumbnail
David H Nebinger, modificado 8 Anos atrás.

RE: Android create user AuthenticationException

Liferay Legend Postagens: 14914 Data de Entrada: 02/09/06 Postagens Recentes
Have you configured your portal to allow external access to the web service APIs?

The authentication exception normally means you're not logged in when you invoke the api. Although understandably if you're trying to add your own new user you wouldn't be logged in yet.

For mobile dev, have you tried Liferay Screens? I know there's a login and registration panel that comes in Screens that may help you get around this issue.
thumbnail
Juan Fernández, modificado 8 Anos atrás.

RE: Android create user AuthenticationException

Liferay Legend Postagens: 1261 Data de Entrada: 02/10/08 Postagens Recentes
Hola Jonathan:
David is completely right. Why waste your time implementing something that is already implemented for you?
Have a look at this documentation and video guide on how to achieve what you are trying to achieve:

https://dev.liferay.com/develop/reference/-/knowledge_base/6-2/loginscreenlet-for-android

Please let us know if we can help you build a great android app ;)
Best,
Juan
thumbnail
Javier Gamarra, modificado 8 Anos atrás.

RE: Android create user AuthenticationException

Expert Postagens: 348 Data de Entrada: 12/02/15 Postagens Recentes
I'm afraid that you be logged in with a user to be able to create a new user. When creating the session you should pass some valid credentials.

What we recommend is creating a user with the minimal set of permissions (create new users and assign to site) and use those credentials to do the API call.

If you use Liferay Screens it's quite easy to set up and you don't have to worry about those required parameters.
thumbnail
Jonathan Villegas, modificado 8 Anos atrás.

RE: Android create user AuthenticationException

New Member Postagens: 14 Data de Entrada: 27/06/14 Postagens Recentes
Thanks guys for yours answers.

The scene is this; the user registration should be programmatically because i am consuming a web service and the facebook api to get some user values.
In this case i think Liferay screens will not be useful.

I am thinking in the Javier Suggestion; create a user in the portal only to "create new mobile account" and use this session in the app if the user don´t have a account in the portal.
This is a valid way?

Thanks in advance.
Greetings !
thumbnail
Javier Gamarra, modificado 8 Anos atrás.

RE: Android create user AuthenticationException

Expert Postagens: 348 Data de Entrada: 12/02/15 Postagens Recentes
You can use Liferay Screens even if you are not showing anything but we should document how because it can be a little bit tricky if you haven't got a lot of Android experience.

The option of the user is completely valid and will work fine.