#1 2016-10-13 11:03:06

DennisM
Member
Registered: 2016-10-12

Multiple root OUs in usermanager.

Hi

I have accidentally imported my AD into root folder so i have alot of OUs that are empty, but cant remove them as i get a message saying "root cannot be deleted"

I cant find them with the terminal that will not list them.

What can i do to clean up this mess.

Offline

#2 2016-10-13 11:48:34

Arno Mittelbach
datenwerke
Registered: 2012-02-14

Re: Multiple root OUs in usermanager.

Hi Dennis,

you will need to use a bit of scripting for this. Do you have the IDs of the "root" folders that you want to delete? If so, you should be able to do so with the following script:

import net.datenwerke.security.service.usermanager.entities.OrganisationalUnit;
import net.datenwerke.security.service.usermanager.UserManagerService;

def ouID = 236082L; // note the L to ensure it is treated as Long

def userService = GLOBALS.getInstance(UserManagerService.class);

def ou = GLOBALS.findEntity(OrganisationalUnit.class, ouID);

userService.forceRemove(ou);

"deleted " + ouID

This should bypass the check whether or not the node to be deleted is a "root" node.

Regards,
Arno

Offline

#3 2016-10-13 12:21:36

DennisM
Member
Registered: 2016-10-12

Re: Multiple root OUs in usermanager.

Hi Arno

Just tried with 1 of the IDs and get an error in line 10, that will be "userServer.forceRemove(ou);

Script execution failed.
error message: No signature of method: net.datenwerke.security.service.usermanager.UserManagerServiceImpl$$EnhancerByGuice$$980d92f3.ForceRemove() is applicable for argument types: (net.datenwerke.security.service.usermanager.entities.OrganisationalUnit) values: [net.datenwerke.security.service.usermanager.entities.OrganisationalUnit@7132]
Possible solutions: forceRemove(net.datenwerke.treedb.service.treedb.AbstractNode), forceRemove(net.datenwerke.treedb.service.treedb.AbstractNode), forceRemove(net.datenwerke.security.service.treedb.entities.SecuredAbstractNode), forceRemove(net.datenwerke.security.service.usermanager.entities.AbstractUserManagerNode), forceRemove(net.datenwerke.security.service.usermanager.entities.AbstractUserManagerNode) (groovy.lang.MissingMethodException)
script arguments:
file: DeleteOU.groovy (id: 51427, line 10)
line number: 10
line: userService.ForceRemove(ou);

Offline

#4 2016-10-13 15:12:58

Arno Mittelbach
datenwerke
Registered: 2012-02-14

Re: Multiple root OUs in usermanager.

I think you accidentally replaced forceRemove by ForceRemove.

Offline

#5 2016-10-13 16:46:07

DennisM
Member
Registered: 2016-10-12

Re: Multiple root OUs in usermanager.

I did also try with small "f" and got same error.

Offline

#6 2016-10-13 17:56:58

Arno Mittelbach
datenwerke
Registered: 2012-02-14

Re: Multiple root OUs in usermanager.

Could you post the error message. I am pretty sure that there must be a typo somewhere in your script.

Offline

#7 2016-10-13 18:02:57

DennisM
Member
Registered: 2016-10-12

Re: Multiple root OUs in usermanager.

I get the following error:

reportserver$ exec DeleteOU.groovy
Script execution failed.
error message: javax.script.ScriptException: java.lang.IllegalArgumentException: Object is write protected (java.lang.IllegalArgumentException)
script arguments:
file: DeleteOU.groovy (id: 51427, line 10)
line number: 10
line: userService.forceRemove(ou);
reportserver$


Looks like write protected sad

Offline

#8 2016-10-14 06:23:46

Arno Mittelbach
datenwerke
Registered: 2012-02-14

Re: Multiple root OUs in usermanager.

Good point. The LDAP sample script write protects any imported objects, such that they are not accidentally deleted/changed. In order to delete them, you would need to remove the write protection. Following is the adapted script, that does exactly this.

import net.datenwerke.security.service.usermanager.entities.OrganisationalUnit;
import net.datenwerke.security.service.usermanager.UserManagerService;

def ouID = 236082L; // note the L to ensure it is treated as Long

def userService = GLOBALS.getInstance(UserManagerService.class);

def ou = GLOBALS.findEntity(OrganisationalUnit.class, ouID);

/* remove write protection */
def remWP;
remWP = { node ->
  node.setWriteProtection(false);
  node.getChildren().each{ remWP(it) }
}
remWP(ou);

/* now that write protection is removed, nodes can be deleted */
userService.forceRemove(ou);

"deleted " + ouID

Cheers,
Arno

Offline

#9 2016-10-14 06:34:55

DennisM
Member
Registered: 2016-10-12

Re: Multiple root OUs in usermanager.

Now the scritp is going good and reports "deleted 28978" but to OU is still there, even after relog.

Seems like i have to reinstall the whole thing to get rid of them. sad

Offline

#10 2016-10-14 06:44:47

DennisM
Member
Registered: 2016-10-12

Re: Multiple root OUs in usermanager.

Just tried to remove the writeprotection and then manually delete it, but same result.

Offline

#11 2016-10-14 07:27:22

Arno Mittelbach
datenwerke
Registered: 2012-02-14

Re: Multiple root OUs in usermanager.

did you run it with the -c flag for "commit"? that is

exec -c THE_SCRIPT

Offline

#12 2016-10-14 07:45:20

DennisM
Member
Registered: 2016-10-12

Re: Multiple root OUs in usermanager.

Oh i missed that one.

Thanks alot now i can start deleting 200 OUs.

Offline

#13 2016-10-14 08:10:04

Arno Mittelbach
datenwerke
Registered: 2012-02-14

Re: Multiple root OUs in usermanager.

If you want to fiddle a bit with the script, you can also try:

userService.getRoots()

This gives you all the root nodes. But careful, this also gives you the root node that you should not delete!

Offline

Board footer

Powered by FluxBB