# security groups problem

**URL:** <https://forum.servoy.com/t/security-groups-problem/4601>\
**Category:** Classic Servoy\
**Created:** [August 12, 2005, 8:13pm UTC](https://forum.servoy.com/t/security-groups-problem/4601 "2005-08-12T20:13:38Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![sammyzheng](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@sammyzheng](https://forum.servoy.com/u/sammyzheng)\
**Post date:** [August 12, 2005, 8:13pm UTC](https://forum.servoy.com/t/security-groups-problem/4601/1 "2005-08-12T20:13:38Z")

</div>

Hi all,

I need to have in my script to check the security login group. And if the login group matches, to go to a layout, if not, give error message.

I tried using this coding

var usercode = security.getGroups

if (usercode == ‘doc\_control’)  
{  
forms.parts\_modify.controller.show();  
}  
else  
{  
(error message code)  
}

What am I doing wrong? I keep getting “conversion error null value”

please help! i know i must be doing something wrong…

---

<div class="post-metadata">

**Author:** ![bcusick](https://avatars.discourse-cdn.com/v4/letter/b/ed8c4c/32.png) [@bcusick](https://forum.servoy.com/u/bcusick)\
**Post date:** [August 12, 2005, 9:00pm UTC](https://forum.servoy.com/t/security-groups-problem/4601/2 "2005-08-12T21:00:35Z")

</div>

Sammy,

If you click on the “getGroups” function in the editor - you’ll notice that it returns a JSDataSet, NOT a string.

If you then expand the “Security” node - you’ll notice a “JSDataSet” node that has all the functions you can do on a JSDataSet.

You would have to loop through the JSDataSet (because you can have more than one group returned) - and see if ‘doc\_control’ is one of them.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![sammyzheng](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@sammyzheng](https://forum.servoy.com/u/sammyzheng)\
**Post date:** [August 12, 2005, 9:23pm UTC](https://forum.servoy.com/t/security-groups-problem/4601/3 "2005-08-12T21:23:40Z")

</div>

> bcusick:  
> Sammy,
> 
> If you click on the “getGroups” function in the editor - you’ll notice that it returns a JSDataSet, NOT a string.
> 
> If you then expand the “Security” node - you’ll notice a “JSDataSet” node that has all the functions you can do on a JSDataSet.
> 
> You would have to loop through the JSDataSet (because you can have more than one group returned) - and see if ‘doc\_control’ is one of them.
> 
> Hope this helps.

I tried this code (from another post in the forum) but still get a different error. Alto the debugger does pick up userID = my group name (‘admin’) that i was logged into.

var userId = security.getUserName() // user id  
var userGroupId = security.getUserGroups(userId) // dataset containg the groups authorized for the selected user  
for (var i = 1; i \<= userGroupId.getMaxRowIndex() ; i++)  
{  
var ug\_id = userGroupId.getValue(i,1) // group id for the user  
var ug\_name = userGroupId.getValue(i,2) // group name  
}

I get error message "JDBC SQL server 200 driver error. Syntax error converting the nvarcar value ‘admin’ to a column of data type int.

---

<div class="post-metadata">

**Author:** ![bcusick](https://avatars.discourse-cdn.com/v4/letter/b/ed8c4c/32.png) [@bcusick](https://forum.servoy.com/u/bcusick)\
**Post date:** [August 12, 2005, 10:22pm UTC](https://forum.servoy.com/t/security-groups-problem/4601/4 "2005-08-12T22:22:25Z")

</div>

Ummmm… you’re using the wrong function.

Try this instead:

```auto
var userID = security.getUserId(security.getUserName())
var groupID = security.getGroupId(userID) //optional not used in this method
var userGroupId = security.getUserGroups(userID)
for (var i = 1; i <= userGroupId.getMaxRowIndex() ; i++)
{
	var ug_id = userGroupId.getValue(i,1) // group id for the user
	var ug_name = userGroupId.getValue(i,2) // group name
}

```

---

<div class="post-metadata">

**Author:** ![sammyzheng](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@sammyzheng](https://forum.servoy.com/u/sammyzheng)\
**Post date:** [August 12, 2005, 10:52pm UTC](https://forum.servoy.com/t/security-groups-problem/4601/5 "2005-08-12T22:52:54Z")

</div>

> bcusick:  
> Ummmm… you’re using the wrong function.
> 
> Try this instead:
> 
> ```auto
> var userID = security.getUserId(security.getUserName())
> 
> ```

var groupID = security.getGroupId(userID) //optional not used in this method  
var userGroupId = security.getUserGroups(userID)  
for (var i = 1; i \<= userGroupId.getMaxRowIndex() ; i++)  
{  
var ug\_id = userGroupId.getValue(i,1) // group id for the user  
var ug\_name = userGroupId.getValue(i,2) // group name  
}

> ```auto
> 
> ```

DOH! still doens’t look liek it works, it went back to the first error message of null values.On the debugger, the group\_ID = null, group\_name = null as well.

so close…

---

<div class="post-metadata">

**Author:** ![bcusick](https://avatars.discourse-cdn.com/v4/letter/b/ed8c4c/32.png) [@bcusick](https://forum.servoy.com/u/bcusick)\
**Post date:** [August 12, 2005, 10:57pm UTC](https://forum.servoy.com/t/security-groups-problem/4601/6 "2005-08-12T22:57:05Z")

</div>

This code DOES work. Choose “logout” from the file menu - then re-open your solution.

---

<div class="post-metadata">

**Author:** ![sammyzheng](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@sammyzheng](https://forum.servoy.com/u/sammyzheng)\
**Post date:** [August 12, 2005, 11:30pm UTC](https://forum.servoy.com/t/security-groups-problem/4601/7 "2005-08-12T23:30:33Z")

</div>

> bcusick:  
> This code DOES work. Choose “logout” from the file menu - then re-open your solution.

AH HA! it does work now! thanks again Bob. Has anyone told you lately you’re a genius!

---

<div class="post-metadata">

**Author:** ![gabid](https://avatars.discourse-cdn.com/v4/letter/g/7ab992/32.png) [@gabid](https://forum.servoy.com/u/gabid)\
**Post date:** [December 17, 2009, 5:04pm UTC](https://forum.servoy.com/t/security-groups-problem/4601/8 "2009-12-17T17:04:49Z")

</div>

I have a small problem on this matter.

If I do:

var userID = security.getUserId(security.getUserName())  
var userGroups = security.getUserGroups(userID);

where userID is the current UUID for the currently logged on user, it returns the list with ALL AVAILABLE groups. If on the other hand I call getUserGroups with a different userID, it returns the correct list of groups to which the respective user is member.

I create the users from code with:

var uid = security.createUser(username, pass);

I add a user to a group with:  
security.addUserToGroup(user\_uuid,groupName);

which shows correctly on the “User/Group Editor”.

So, as a conclusion, getUserGroups(userID) acts as getGroups for the current user, and behaves as expected for the other users, other than the logged on one.

Thanks  
Gabriel - Iulian Dumbrava

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [December 18, 2009, 2:30pm UTC](https://forum.servoy.com/t/security-groups-problem/4601/9 "2009-12-18T14:30:43Z")

</div>

do you use security.login(user,groups) ?

---

<div class="post-metadata">

**Author:** ![gabid](https://avatars.discourse-cdn.com/v4/letter/g/7ab992/32.png) [@gabid](https://forum.servoy.com/u/gabid)\
**Post date:** [December 20, 2009, 4:28pm UTC](https://forum.servoy.com/t/security-groups-problem/4601/10 "2009-12-20T16:28:19Z")

</div>

Yes, I am using login, otherwise I don’t think that Servoy would let me leave the login form.

---

<div class="post-metadata">

**Author:** ![gabid](https://avatars.discourse-cdn.com/v4/letter/g/7ab992/32.png) [@gabid](https://forum.servoy.com/u/gabid)\
**Post date:** [December 20, 2009, 4:37pm UTC](https://forum.servoy.com/t/security-groups-problem/4601/11 "2009-12-20T16:37:48Z")

</div>

You are great! That was actually the problem. This is the code I used:

```auto
		groups = security.getGroups().getColumnAsArray(2);
		if (security.checkPassword(user_uuid,txtPassword)){
			var ok = security.login(txtUsername, user_uuid, groups);
			if (!ok) {
				plugins.dialogs.showErrorDialog('i18n:login_error', 'i18n:login_error_msg', 'OK')
			}	
		} else {
			plugins.dialogs.showErrorDialog('i18n:login_error', 'i18n:login_error_msg', 'OK')
		}

```

Now I have changed the login line to:

```auto
groups = security.getUserGroups(user_uuid).getColumnAsArray(2);

```

I thought that the groups that are passed as parameter, should be all available groups, so that the servoy login function can check access against those. Thanks for pointing me into the right direction.

Gabriel - Iulian Dumbrava
