rinku_chowdhury
I'm new here

script to add users to the Administrator group. Is there any better approach?

Jump to solution

Sometime users get removed from the Administrator Group, hence the plan is to run a script to add users to that group without doing it manually. here below is my initial approach.

Or any function that will give access to act as an admin to the following instructions?

element = context.getStoreElement ();

Connection con = element.getProject ().getConnection ();

Project project = con.getProjectById (pid);

List <Group> prGroup = project.getGroups ();

List <User> prUser = project.getUsers ();

List <User> adminUser = new ArrayList <User> (int i);

adminUser.add (prUser.get (int i)); // loop to add

User [] adminUsers = adminUser.toArray (new User [adminUser.size ()]); // conversion

// as the current user doesnt have admin permission hence running this method will throw Target exception: java.lang.SecurityException

project.lock ();

prGroup.get (int adminIndex) .addUsers (adminUser);

project.save ();

project.unlock ();

con.disconnet ();

0 Kudos
1 Solution

Accepted Solutions

Hi Rinku,

which FirstSpirit version du you use?

ConnectionManager.getConnection should work. Are you sure the user you use to connect is at least a project level admin?

Regards,

Tim

View solution in original post

0 Kudos
5 Replies
tenter
I'm new here

Hi RInku,

I'm afraid I didn't understand your question - I would expect that you need an admin user in order to add people to an admin group. Is this your problem?

Regards,

Hannes

0 Kudos

Hi Hannes,
Is it possible that a user with no admin permission can have a connection to FS server as an admin (with credentials) and then add users to the administrator group? I am writing a script for such scenario. I have tried connectionManager.getConnection(parameters) / connection.getAdminService() to connect as an admin but somehow not working. have I explained clearly? please do let me know if you need more info.

0 Kudos

Hi Rinku,

which FirstSpirit version du you use?

ConnectionManager.getConnection should work. Are you sure the user you use to connect is at least a project level admin?

Regards,

Tim

0 Kudos

Hi Rinku,


do you need further help or did Tims's reply already help you? If so, it would be great if you marked his reply as "correct answer" so that other community users find the solution easily. If you have already found a solution by yourself, it would be very kind of you, if you posted it here.   

Best regards

Sebastian

0 Kudos

Hi Tim,
thanks for the clue. It works.

0 Kudos