It's all about the answers!

Ask a question

Programmatically create users (application server)


0
1
Chetna Warade (106123) | asked Oct 22 '08, 9:41 p.m.
JAZZ DEVELOPER
I am trying to programmatically create new application server users in RTC. Currently, a user can log into the url https://localhost:9443/jazz and Click User Management and add users by hand. I need to create hundreds of users which is cumbersome. I am playing with the RTC server to see if I can programmatically create new users.

As a start, any http server accepts either GET or POST messages. It is possible to use java.net technique, to open a connection (URLConnection) with the http server and manipulate the server to serve the request. I have had success with many commercial websites.

In context of RTC E,g. When I create a user by hand a url like this is autogenerated in the JavaScript and POST message is sent, so the server can process the request.

https://9.34.120.71:9443/jazz/service/com.ibm.team.repository.service.internal.IAdminRestService/contributor?emailAddress=st3&itemId=new&jsonLicenses=%7B%22add%22%3A%20%5B%22com.ibm.team.rtc.developer%22%5D%2C%20%22remove%22%3A%20%5B%5D%7D&jsonRoles=%5B%22JazzAdmins%22%2C%20%22JazzUsers%22%5D&name=st3&userId=st3

I wrote a plain java client to handle this via SSL (IBM JSSE Provider com.ibm.jsse) since now https:// is being provided with RTC. I created a client keystore file from the server keystore file and imported server keys/certificates. I am not getting any errors, but neither am I seeing any results. Nothing particular in the tomcat logs. I can post the code on request. I was looking if this is the way to go. Any alternative ideas..? Thanks for your time.

23 answers



permanent link
Matt Lavin (2.7k2) | answered Oct 27 '08, 8:23 a.m.
FORUM MODERATOR / JAZZ DEVELOPER
Creating a user with the the IContributorManager only creates the users
data in the Jazz DB. To log in wit the user, the username / password
has to be configured in the External User Registry (which could be LDAP,
Tomcat, or unknown/unsupported).

If your user registry is Tomcat then you can add your new user to the
registry with IExternalUserRegistryManager. You can check to see if the
user registry if writeable with isExternalRegistryWriteable(). If it is
writable then you should be able to create a new users entry for your
new user. If your server is configured with LDAP then you would need to
modify the LDAP registry to allow logging in with the new users.

Matt Lavin
Jazz Server Team


warade wrote:
After getworkingcopy() a user is created but it cannot log in.

When I log in as ADMIN, and navigate to User Management page and click
the newly created user to see details, I get this message.

This user is not in the directory service. The
user will not be able to login unless they an account in the
directory service.

What is this directory service? How to access it from the client API?
Thanks again.

permanent link
Matt Lavin (2.7k2) | answered Oct 23 '08, 9:25 a.m.
FORUM MODERATOR / JAZZ DEVELOPER
Is your server configured for FORM or BASIC auth? Can you attach the
result that is sent back from the server when you attempt the request?

An alternate approach is to build a small RCP application that re-uses
the RTC client libraries. Taking that approach will enable you to reuse
the same login / service execution code that RTC uses and should save
you a significant amount of reverse-engineering time.

Matt Lavin
Jazz Server Team


warade wrote:
I am trying to programmatically create new application server users in
RTC. Currently, a user can log into the url
https://localhost:9443/jazz and Click User Management and add users
by hand. I need to create hundreds of users which is cumbersome. I am
playing with the RTC server to see if I can programmatically create
new users.

As a start, any http server accepts either GET or POST messages. It is
possible to use java.net technique, to open a connection
(URLConnection) with the http server and manipulate the server to
serve the request. I have had success with many commercial websites.

In context of RTC E,g. When I create a user by hand a url like this is
autogenerated in the JavaScript and POST message is sent, so the
server can process the request.

https://9.34.120.71:9443/jazz/service/com.ibm.team.repository.service.internal.IAdminRestService/contributor?emailAddress=st3&itemId=new&jsonLicenses=%7B%22add%22%3A%20%5B%22com.ibm.team.rtc.developer%22%5D%2C%20%22remove%22%3A%20%5B%5D%7D&jsonRoles=%5B%22JazzAdmins%22%2C%20%22JazzUsers%22%5D&name=st3&userId=st3

I wrote a plain java client to handle this via SSL (IBM JSSE Provider
com.ibm.jsse) since now https:// is being provided with RTC. I
created a client keystore file from the server keystore file and
imported server keys/certificates. I am not getting any errors, but
neither am I seeing any results. Nothing particular in the tomcat
logs. I can post the code on request. I was looking if this is the
way to go. Any alternative ideas..? Thanks for your time.

permanent link
Chetna Warade (106123) | answered Oct 24 '08, 3:19 p.m.
JAZZ DEVELOPER
Thanks for the response. I tried following and I am getting this exception, what am I missing. I have a successful connection.

IContributorManager icm = repository.contributorManager();

IContributor user = icm.fetchContributorByUserId("st1", monitor);
user.setName("test2");
user.setUserId("test2");

user.setEmailAddress("test2");

icm.saveContributor(user, monitor);

I am counting that the saveContributor will create a new user. I can't find a way to instantiate the IContributor without reading from the IContributorManager.

The exception I get is:

Exception in thread "main" com.ibm.team.repository.common.internal.ImmutablePropertyException
at com.ibm.team.repository.common.internal.util.ItemUtil$ProtectAdapter.notifyChanged(ItemUtil.java:2047)
at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:247)
at com.ibm.team.repository.common.model.impl.ContributorImpl.setNameGen(ContributorImpl.java:352)
at com.ibm.team.repository.common.model.impl.ContributorImpl.setName(ContributorImpl.java:338)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:618)
at com.ibm.team.repository.common.internal.util.ItemStore$ItemInvocationHandler.invoke(ItemStore.java:596)
at $Proxy7.setName(Unknown Source)
at snippets.Snippet1.login(Snippet1.java:66)
at snippets.Snippet1.main(Snippet1.java:31)

permanent link
Chetna Warade (106123) | answered Oct 24 '08, 4:14 p.m.
JAZZ DEVELOPER
I gave another shot.

Contributor contrib = RepositoryFactory.eINSTANCE.createContributor();
contrib.setUserId("test2");
contrib.setName("test2");
contrib.setEmailAddress("test2");
........
icm.saveContributor(contrib, monitor);
...

Exception in thread "main" java.lang.IllegalArgumentException: The contributor is not a working copy
at com.ibm.team.repository.client.internal.ContributorManager.saveContributor(ContributorManager.java:76)
at snippets.Snippet1.login(Snippet1.java:83)
at snippets.Snippet1.main(Snippet1.java:35)
I forgot to mention, I am writing a plain java client

permanent link
Evan Hughes (2.4k1318) | answered Oct 24 '08, 4:54 p.m.
JAZZ DEVELOPER
Take a look at IItem#getWorkingCopy().

permanent link
Chetna Warade (106123) | answered Oct 25 '08, 1:49 p.m.
JAZZ DEVELOPER
After getworkingcopy() a user is created but it cannot log in.

When I log in as ADMIN, and navigate to User Management page and click the newly created user to see details, I get this message.

This user is not in the directory service. The user will not be able to login unless they an account in the directory service.

What is this directory service? How to access it from the client API?
Thanks again.

permanent link
Chetna Warade (106123) | answered Nov 04 '08, 10:20 a.m.
JAZZ DEVELOPER
How is the license assignments particularly newly created users handled? I am playing with LicenseAssignment from RepositoryFactory where I see a setLicense method but I don't think its enough. I tried printing a getLicense and obviously it is 0 because it is created new. How do I stuff com.ibm.team.rtc.developer or com.ibm.team.rtc.contributor client access so I exhaust all the licenses. Thanks.

permanent link
Matt Lavin (2.7k2) | answered Nov 04 '08, 1:08 p.m.
FORUM MODERATOR / JAZZ DEVELOPER
There is not a supported Java API for assigning assigning licenses. The
best way to assign a license to a contributor is to take the same
approach as the web UI and use the ILicenseAdminRestService to request
the assignment. I would look at the HTTP calls that the web UI makes
and learn how to do the same thing.

-
Matt Lavin
Jazz Server Team


On Tue, 2008-11-04 at 15:27 +0000, warade wrote:
How is the license assignments particularly newly created users
handled? I am playing with LicenseAssignment from RepositoryFactory
where I see a setLicense method but I don't think its enough. I tried
printing a getLicense and obviously it is 0 because it is created new.
How do I stuff com.ibm.team.rtc.developer or
com.ibm.team.rtc.contributor client access so I exhaust all the
licenses. Thanks.

permanent link
Chetna Warade (106123) | answered Nov 04 '08, 3:26 p.m.
JAZZ DEVELOPER
thanks for responding to my post in the forum
I can't locate the web ui code, in either the server or client API bundle. The server side code is password protected so I can't do wide grep on the code?

permanent link
Chetna Warade (106123) | answered Nov 04 '08, 4:07 p.m.
JAZZ DEVELOPER
I dont think the TeamPlatform exposes the com.ibm.team.repository.service.internal.ILicenseAdminRestService as a service,yet?

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.