How to create, delete and update groups and users programmatically

In my Custom Authentication plugin, all users get created in the default all users group. I am exploring the option of implementing and maintaining the users / groups structure in TeamCity as they appear in my source system.

The best option is probably to use UserGroupManager class for creating, deleting and updating users and groups but how to get an instance of the class in first place? Trying to include all the beans from Spring.jar xml along in my plugin beans file is not helping as I end up with the following error: Error creating bean with name 'loginConfiguration': Requested bean is currently in creation:...

Can't I somehow access the instance that already gets created as the server loads.

Else, should I be writing a separate plugin for this ... but then of which type? And still how will the object be instantiated?

(PS: the UserGroupManager class will be used with the caveat that its interfaces can get changed in future releases but for now it solves my problem)

5 comments

Ravi,

> but how to get an instance of the class in first place?

As usual with TeamCity-provided services: just add a parameter to contructor of your bean that is defined in Spring config. e.g. here is an example.

> Else, should I be writing a separate plugin for this ... but then of which type?

You should probably figure out how your logic can be implemented with existing API and use the approach (e.g. you might want to perform some action on user creation, see UserModelListener interface).
This can be part of the same authentication plugin or a separate plugin.

0

Thanks Yegor.

Yes, I figured it out only a couple of hours back! I was trying to create UserGroupManger through ref of UserGroupManagerImpl and that's where things were getting really difficult. Simply tried ref="UserGroupManager" and I have the object (jetbrains.buildServer.groups.impl.SecuredUserGroupManager@9cd7cd ).

Have been able to successfully call getAllUsersGroup() on it. Now I will try solve the mystery of createUserGroup() as it shows strings arg0, arg1 and arg2 as parameters

The real question is now how often do we have releases of TeamCity that could change the internal APIs and are some new set of open-APIs expected any time soon (with hopefully these ones)? The decision to put the code in production could depend on such information

0

Ravi,

Actually, we added the class to open API and you can already get the change in the latest EAP build.

The real question is now how often do we have releases of TeamCity that could change the internal APIs and are some new set of open-APIs expected any time soon (with hopefully these ones)?


That all depends on a specific release. Usually we try to introduce only minor non-breaking changes in dot releases (like 6.0.2 compared to 6.0). Major releases (and minor ones) can change open API (usually that is required for the new functionality that we introduce).

We try to document most important API changes in the doc, but unfortunately not all of them get documented.
Anyway, we are ready to answer any related questions, provide fixes and listen to your feedback.

0

Excellent!

I have now completed the module for users and groups synchronization using UserGroupManager and UserModel classes and it works fine.

The documentation provided with EAP helped! thanks.

There seems to be some consensus now on procuring 5.1 release and using the plugin with it for the time being and upgrade to 6.x once it is officially released. Hopefully both the above classes will work the same.

For now the code resides in a custom authentication plugin with synchronization to take place when a specific 'syncgroups' user logs in. What will be the best alternative way to deploy it (what type of plugin) for us to invoke the functionality at configured intervals instead of requiring to login?

cheers

0

Hi Ravi,

> For now the code resides in a custom authentication plugin with synchronization to take place when a specific 'syncgroups' user logs in. What will be the best alternative way to deploy it (what type of plugin) for us to invoke the functionality at configured intervals instead of requiring to login?

TeamCity has a useful util to invoke periodical requests in a separate thread: jetbrains.buildServer.util.Alarm.


---
Maxim

0

Please sign in to leave a comment.