remove roles from user via SDK

Description
kevin1119
Posts: 5
Joined: Tue Mar 20, 2018 3:27 am

remove roles from user via SDK

Postby kevin1119 » Tue Mar 20, 2018 3:34 am

hi all

i'm trying to remove roles from user account via Java SDK, but not able to find available methods in SecurityWebService, ProjectWebService or SessionWebService to do it

is there any other way to do it?

thanks and regards
Kevin

ALMighty
Posts: 71
Joined: Wed Apr 27, 2016 10:34 am
Location: Austria

Re: remove roles from user via SDK

Postby ALMighty » Tue Mar 20, 2018 2:37 pm

kevin1119 wrote:i'm trying to remove roles from user account via Java SDK, but not able to find available methods in SecurityWebService, ProjectWebService or SessionWebService to do it


Apart from the classes that are directly generated by the WebServiceFactory class, I checked the User and Project class (because there is at least the possibility to update users via API). However there is nothing in there that would fit your needs and I guess this was done intentionally by the Polarion Developers because not many things that can be done in the Admin Panel of a project can be done via the API. :cry:
---------------------------------------------------------------------------------------------------
Playing a good game is never lame. :D
Image

kevin1119
Posts: 5
Joined: Tue Mar 20, 2018 3:27 am

Re: remove roles from user via SDK

Postby kevin1119 » Wed Mar 21, 2018 12:23 am

thanks Almighty

that update method only applies to email/description. it can't even change user id.
it's a pain to update hundred of users manually

PatrickClaus
Posts: 5
Joined: Thu Jan 18, 2018 11:02 am
Location: Frauenauracher Str. 85, 91056 Erlangen

Re: remove roles from user via SDK

Postby PatrickClaus » Wed Mar 21, 2018 1:46 pm

Hey Almighty and Kevin,

I'll post a code snippet of a servlet that managed to do the job. (changing roles of users, etc.)
As Almighty already mentioned, you can not change such settings for a user over the WebServices (!)

You have to do this over servlets (see SDK examples, there's one there I believe, as basis) and call methods from the Open SDK API (https://almdemo.polarion.com/polarion/s ... index.html).

In there, you have methods that can actually do the things an admin can do over his Admin Panel.

Exemplary code (its a draft stage, so might be clumsy) right here:
From Servlet.Java:

Code: Select all

some.debug.print("Removing access to project...");
   currentuser = projecserv.getUser("some_user_id");
   currentproject = projecserv.getProject("myproject_id");
                      
   some_debug_string += "Firstly, displaying global + context roles for user";
   some_debug_string += secserv.getRolesForUser(userid,currentuser
   .getContextId()).toString();
   
   some_debug_string += "Now, removing project rights for test purposes.<br>";   
                  
   transserv.beginTx();
   secserv.removeContextRoleFromUser(userid, "project_user",
   currentproject.getContextId());
   
   try {
      transserv.commitTx();
   } catch (Exception e) {
      e.printStackTrace();
   }
   
   some_debug_string += "Results: "+secserv.getContextRolesForUser(userid,
   currentproject.getContextId()).toString() + "<br>";                


Important parts here are:
- Get projecserv = IProjectService (check API):

Code: Select all

IProjectService projecserv = (IProjectService) PlatformContext.getPlatform()
            .lookupService(IProjectService.class);

- Get secserv = ISecurityService (check API):

Code: Select all

ISecurityService secserv = (ISecurityService) PlatformContext.getPlatform()
            .lookupService(ISecurityService.class);

- Get current user and project, call removeContextRoleFromUser and give id, role, currentProjectID
- wrap in beginTx - commitTx (this can be tricky, best of luck)
- check results and hopefully be happy

Sorry if this was confusing. This is how we managed to execute code to adapt users.
I'll check in here again, just ask away if there's any confusion.
Best Regards,
Patrick Claus

External service provider at Valeo Siemens eAutomotive GmbH
Frauenauracher Str. 85
91056 Erlangen, Germany
Mail Address

ALMighty
Posts: 71
Joined: Wed Apr 27, 2016 10:34 am
Location: Austria

Re: remove roles from user via SDK

Postby ALMighty » Wed Mar 21, 2018 3:15 pm

PatrickClaus wrote:Important parts here are:
- Get projecserv = IProjectService (check API):

Code: Select all

IProjectService projecserv = (IProjectService) PlatformContext.getPlatform()
            .lookupService(IProjectService.class);

- Get secserv = ISecurityService (check API):

Code: Select all

ISecurityService secserv = (ISecurityService) PlatformContext.getPlatform()
            .lookupService(ISecurityService.class);

- Get current user and project, call removeContextRoleFromUser and give id, role, currentProjectID
- wrap in beginTx - commitTx (this can be tricky, best of luck)
- check results and hopefully be happy


Very interesting. How did you manage to use the IProjectService and ISecurityService classes in a Java/JSP project although both classes are actually meant for usage in Wikipages or at least I have thought that)? :shock:

What librares do you use in your Java/JSP project in order to use the IProjectService and ISecurityService? :)
---------------------------------------------------------------------------------------------------
Playing a good game is never lame. :D
Image

kevin1119
Posts: 5
Joined: Tue Mar 20, 2018 3:27 am

Re: remove roles from user via SDK

Postby kevin1119 » Wed Mar 21, 2018 11:51 pm

thanks Patrick and Almighty for providing some light in the tunnel

i'm trying to find out which lib contains those classes but no lucks.

PatrickClaus
Posts: 5
Joined: Thu Jan 18, 2018 11:02 am
Location: Frauenauracher Str. 85, 91056 Erlangen

Re: remove roles from user via SDK

Postby PatrickClaus » Thu Mar 22, 2018 3:59 pm

Hello again,

IProjectService and ISecurityService were used from libs that were referenced from Polarion.
I think this was mentioned in one of the examples for the SDK Servlet as well, and which configuration is necessary for Eclipse (e.g.) to reference the dependencies / libraries.

As can be seen in the links from Open API SDK:
For ISecurityService:
https://almdemo.polarion.com/polarion/s ... rvice.html
it is com.polarion.platform.security

and for IProjectService:
https://almdemo.polarion.com/polarion/s ... rvice.html
it is com.polarion.alm.projects

So, we need:
- alm.projects
- platform.security

from libs: projects.jar and security.jar
found under: \Polarion\polarion\plugins\com.polarion.alm.projects_3.17.3
and \Polarion\polarion\plugins\com.polarion.platform_3.17.3

Plug those into dependencies, and
Import statement for Java-File in Eclipse:

Code: Select all

package com.polarion.siemens.somePackage.servlet;
...
import com.polarion.platform.security.ISecurityService;
import com.polarion.alm.projects.IProjectService;
...


and voila.
Of course, you need additional imports, depending on the functionality of the code and what you want to do inside of Polarion.

I really recommend looking at \polarion\SDK\examples\com.polarion.example.administration
as this example provides functionality for admin-user login and accessing general admin functionality. For the rest, its happy digging through the OpenApi JavaDoc, i'm afraid.
Best Regards,
Patrick Claus

External service provider at Valeo Siemens eAutomotive GmbH
Frauenauracher Str. 85
91056 Erlangen, Germany
Mail Address

kevin1119
Posts: 5
Joined: Tue Mar 20, 2018 3:27 am

Re: remove roles from user via SDK

Postby kevin1119 » Sun Mar 25, 2018 4:18 am

hi Patrick

i'm new to Polarion and trying to import the servlet exmple into eclipse.
for the sake of not missing any thing, i imported it and added the following jars to class path
platform-persistence.jar
platform.jar
projects.jar
tracker.jar
util.jar

that resolved all errors in the java file. but the plugin.xm keeps complaining about
Bundle 'com.polarion.alm.tracker' and 'com.polarion.portal.tomcat' can't be resovled
and unknow extension point: 'com.polarion.portal.tomcat.webapps'

i have the tracker lib in the class path of the MANIFEST.MF, but it fails
and i can't find the tomcat jar

do you know why ?

thanks and regards
K


Return to “Polarion Application Lifecycle Management (ALM)”

Who is online

Users browsing this forum: No registered users and 2 guests