public static void setupGroupsAndUsers ( InstallContext ctx , Map < String , List < String > > groups , Map < String , List < String > > systemUsers , Map < String , List < String > > users ) throws PackageException { UserManagementService userManagementService = getService ( UserManagementService . class ) ; try { JackrabbitSession session = ( JackrabbitSession ) ctx . getSession ( ) ; UserManager userManager = session . getUserManager ( ) ; if ( groups != null ) { for ( Map . Entry < String , List < String > > entry : groups . entrySet ( ) ) { Group group = userManagementService . getOrCreateGroup ( session , userManager , entry . getKey ( ) ) ; if ( group != null ) { for ( String memberName : entry . getValue ( ) ) { userManagementService . assignToGroup ( session , userManager , memberName , group ) ; } } } session . save ( ) ; } if ( systemUsers != null ) { for ( Map . Entry < String , List < String > > entry : systemUsers . entrySet ( ) ) { Authorizable user = userManagementService . getOrCreateUser ( session , userManager , entry . getKey ( ) , true ) ; if ( user != null ) { for ( String groupName : entry . getValue ( ) ) { userManagementService . assignToGroup ( session , userManager , user , groupName ) ; } } } session . save ( ) ; } if ( users != null ) { for ( Map . Entry < String , List < String > > entry : users . entrySet ( ) ) { Authorizable user = userManagementService . getOrCreateUser ( session , userManager , entry . getKey ( ) , false ) ; if ( user != null ) { for ( String groupName : entry . getValue ( ) ) { userManagementService . assignToGroup ( session , userManager , user , groupName ) ; } } } session . save ( ) ; } } catch ( RepositoryException | RuntimeException rex ) { LOG . error ( rex . getMessage ( ) , rex ) ; throw new PackageException ( rex ) ; } }
Creates or updates a set of groups users and system users