Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Changing user roles in java server api

Avatar

Level 1

I'm trying to change the role of a user using the java server libraries. Here is the code I am running:

AccountManager am  = new AccountManager(<MY URL>);

am.login(<MY OWNER USERNAME>,<PASSWORD>);

am.setUserRole(roomID,am.getSession(roomID).getUserID(<username>), UserRoles.PUBLISHER);

Nothing seems to happen when I run this, not even an error.

I have also tried running the setUserRole method like this:

am.setUserRole(roomID,<username>, UserRoles.PUBLISHER);

I know I am connecting to the lccs service because I am able to create rooms just fine using:

am.createRoom(<room>, <template>);

0 Replies

Avatar

Level 10

Hi,

Your first call looks correct i.e. it should be am.setUserRole("roomName", "userID",role);

The second parameter should not be username but userID. Do you get any error when you set this ?

I was actually the Java APIs with BlazeDS to exactly similar call and mine works fine.

So, I am really not sure the problem. Does APIs to subscribeCollection and others work in the room ?

Thanks

Hironmay Basu

Avatar

Employee

I am assuming you are using external authentication. If you are not, you can't use am.getSession(room).getUserId(id)

If you are using external authentication, as Hironmay says you need to pass your userID in order to get the internal LCCS user id (i.e. if you generated the authentication token with a user id of 1234, calling getUserID("1234") will return something like EXT-ACCOUNTNAME-1234, that is the real LCCS id.

The reason why you are not seeing any error is that these calls are asynchronous. We send them to the "RTC runtime" (FMS) and don't get any response back.

If you were to use the "server-side notification APIs" you could subscribe to the UserManager messages and would receive a notification when the user role changes.

Anyway, if you still have problems you should send us the logs ( call com.adobe.rtc.utils.Util.setDebug(true) or set Util.DEBUG=true ) and we'll look at it.

Avatar

Level 1

What I have is a simple mxml file here:

<?xml version="1.0" encoding="utf-8"?>

<s:VGroup

    xmlns="library://ns.adobe.com/flex/spark"

    xmlns:fx="http://ns.adobe.com/mxml/2009"

    xmlns:mx="library://ns.adobe.com/flex/mx"

xmlns:s="library://ns.adobe.com/flex/spark"

xmlns:rtc="http://ns.adobe.com/rtc" activate="init()"

    width="100%" height="100%">

<!--creationComplete="init()"-->

<fx:Script source="ChatRoomController.as"/>

<fx:Declarations>

<!-- Place non-visual elements (e.g., services, value objects) here -->

<rtc:AdobeHSAuthenticator

id="auth"

userName="Guest"/>

</fx:Declarations>

<Button  id="roleBtn" label="SET ROLE" click="setRole()"/>

<rtc:ConnectSessionContainer roomURL="https://connectnow.acrobat.com/smithbd99/joe" id="cSession" authenticator="{auth}" width="100%" height="100%" creationComplete="setRole()">

<mx:HDividedBox width="100%" height="100%">

<s:VGroup width="100%" height="100%">

<rtc:SimpleChat width="100%" height="70%"/> 

<rtc:Roster width="100%" height="30%"/>

</s:VGroup>

<rtc:SharedWhiteBoard width="100%" height="100%"/>

</mx:HDividedBox>

</rtc:ConnectSessionContainer>

</s:VGroup>

With an associated actionscript file:

import edu.byu.mtc.referral.mccp.presentation.model.AppModel;

import edu.byu.mtc.referral.mccp.presentation.view.ChatRoom.ChatRoom;

private function init() : void

{

   auth.userName = AppModel.getInstance().user.firstName;

   AppModel.getInstance().user.createChatRoom();

   cSession.roomURL="https://connectnow.acrobat.com/smithbd99/" + AppModel.getInstance().user.username;

}

private function setRole() : void

{

AppModel.getInstance().user.setChatUserRole();

}

And a server side java file here:

package edu.byu.mtc.referral.mccp.integration.utilities;

import edu.byu.mtc.referral.mccp.integration.vo.User;

import com.adobe.rtc.account.AccountManager;

import com.adobe.rtc.messaging.UserRoles;

public class LCCSTools

{

   public void createRoom(String roomID, User u)

   {

      try

      {

         com.adobe.rtc.util.Utils.setDebug(true);

         AccountManager am  = new AccountManager("https://collaboration.adobelivecycle.com/smithbd99");

         am.login(myusername, mypassword);

         am.createRoom(roomID, "cChat");  

      }

      catch(Exception e)

      {

         e.printStackTrace();

      }              

   }

   public void setChatUserRole(String roomID, User u)

   {     

      try

      {

         com.adobe.rtc.util.Utils.setDebug(true);

         AccountManager am  = new AccountManager("https://collaboration.adobelivecycle.com/smithbd99");

         am.login(myusername, mypassword);

         am.setUserRole(roomID,am.getSession(roomID).getUserID(u.firstName), UserRoles.PUBLISHER);

         //System.out.println("NUM USERS IN ROOM: " + am.getRoomInfo(roomID).userCount);        

         //System.out.println("USER ID: " + am.getSession(roomID).getUserID(u.firstName));

         //System.out.println(am.getRoomInfo(roomID).toString());

      }

      catch(Exception e)

      {

         e.printStackTrace();

      }              

   }

}

So a room is created dynamically and given an id that is the same as the username of the user that has logged into the app whenever the user goes to the screen. He then enters the chat room as a guest user using his first name. I then want to be able to promote the user to publisher. I want to do this dynamically, because not all uses will be promoted. To test this I put a button that runs the "setChatUserRole" method. It doesn't promote the user when I run it. Here is the debug log output:

2010-11-01 12:54:17,340 INFO  [STDOUT] http_get: https://collaboration.adobelivecycle.com/smithbd99?mode=xml&accountonly=true&;

2010-11-01 12:54:17,341 INFO  [STDOUT] {}

2010-11-01 12:54:18,541 INFO  [STDOUT] Content-Type: text/xml;charset=UTF-8

2010-11-01 12:54:18,542 INFO  [STDOUT] Content-Length: 190

2010-11-01 12:54:18,543 INFO  [STDOUT] http_post: https://na1r.services.adobe.com/account/wsapi/auth/v1 <request><username>myusername</username><password>mypassword</password></request>

2010-11-01 12:54:18,543 INFO  [STDOUT] {Content-Type=text/xml}

2010-11-01 12:54:19,171 INFO  [STDOUT] Content-Type: text/xml;charset=UTF-8

2010-11-01 12:54:19,171 INFO  [STDOUT] Content-Length: 127

2010-11-01 12:54:19,172 INFO  [STDOUT] http_get: https://na2.collaboration.adobelivecycle.com:443/smithbd99?mode=xml&accountonly=true&gak=cmVuZ2EqbmE...

2010-11-01 12:54:19,173 INFO  [STDOUT] {}

2010-11-01 12:54:19,983 INFO  [STDOUT] Content-Type: text/xml;charset=UTF-8

2010-11-01 12:54:19,983 INFO  [STDOUT] Content-Length: 333

2010-11-01 12:54:19,984 INFO  [STDOUT] http_get: https://na2.collaboration.adobelivecycle.com:443/app/session?instance=na2-sdk-c5373415-3db7-456b-85f...

2010-11-01 12:54:19,985 INFO  [STDOUT] {}

2010-11-01 12:54:20,166 INFO  [STDOUT] Content-Type: text/xml;charset=UTF-8

2010-11-01 12:54:20,166 INFO  [STDOUT] Content-Length: 109

2010-11-01 12:54:20,168 INFO  [STDOUT] <?xml version="1.0" encoding="UTF-16"?>

<result>

<status code="ok"/>

<session-secret>218fd2c246634177a6da6986b8bfb88b</session-secret>

</result>

2010-11-01 12:54:20,168 INFO  [STDOUT] http_post: https://na2.collaboration.adobelivecycle.com:443/app/rtc instance=na2-sdk-c5373415-3db7-456b-85f6-492a44ac8499/bds8&action=setrole&user=EXT-SMITHBD99-BRIAN&role=50&gak=cmVuZ2EqbmExcioxMmMwOGNhYmQ0Myo1RFg0M0o1VjNOMVlLODM4UlJETk5ZMVRSUg==

2010-11-01 12:54:20,168 INFO  [STDOUT] {}

2010-11-01 12:54:20,548 INFO  [STDOUT] Content-Type: text/xml;charset=UTF-8

2010-11-01 12:54:20,548 INFO  [STDOUT] Content-Length: 42

Avatar

Level 10

Hi Brian,

Out of curiosity (and to zoom out one level here), do you simply want guest

users to be able to enter a room as PUBLISHER? Or are you looking at a

system where arbitrary role values are set at runtime (not just as they

enter; rather, based on some other event while they're already in the room)?

I ask because depending on what you're trying to do, there might be a

shorter path between here and there.

cheers,

nigel

Avatar

Level 1

Nigel,

Different users will have different roles in the same room. Some guest users will be just viewers, others publishers. I have an application where 'users' keep track of a list of their 'contacts'. We want the ability for a 'user' to send an invitation to these contacts with a url to meet in a 'room' . So in general, the 'contacts' will be viewers and the 'users' will be publishers. I found out about lccs and thought it looked like a nice solution. So I'm new to this. We already use flex with a java backend using BlazeDS. So I figured I could just create the rooms dynamically using the java api and set the roles accordingly. Does this seem like the best way to do this? Thank you very much for your help & time. If this works for us, the volume will send some money your way eventually.

-Brian

Avatar

Employee

At a quick glance what you really want to do is use external authentication and create users with the correct role from the beginning.

What you would do on the server side is that instead of this:

am.setUserRole(roomID,am.getSession(roomID).getUserID(<username>), UserRoles.PUBLISHER);

you would do something like:

session = am.getSession(roomID);

token = session.getAuthenticationToken(accountSecret, guestName, randomID, UserRoles.Publisher);

and then pass the token to the Flex application and do:

auth.authenticationKey = serverToken;

instead of setting the guest name.

Avatar

Level 10

Hi Brian,

Thanks for the extra detail - I'll echo Raff in that, unless you see user

roles needing to change after some time of being in the room (so,

"dynamically" or "at runtime"), then external authentication is likely

exactly what you need. It allows you to allow users into your room with the

role that you specify, and has the added benefit that your rooms can be

locked down such that only the users you explicitly allow enter the room.

Check out Raff's post for more details, and the docs are here for general

workflow : http://learn.adobe.com/wiki/display/lccs/6.4Authenticationsetup

hope that helps!

nigel