userRoleDao.createRole( newTenant, anonymousRoleName, "", new String[0] );
roleBindingDao
.setRoleBindings( newTenant, authenticatedRoleName, singleTenantAuthenticatedAuthorityRoleBindingList );
String tenantAdminRoleId = tenantedRoleNameResolver.getPrincipleId( newTenant, tenantAdminRoleName );
RepositoryFileSid tenantAdminRoleSid = new RepositoryFileSid( tenantAdminRoleId, Type.ROLE );
this.jcrTemplate.save();
// If parent tenant is null then we assume we're creating the system tenant. In which case we'll give the
// system
// tenant admin permissions on the root folder.
if ( parentTenant == null ) {
repositoryFileAclDao.addAce( tenantRootFolder.getId(), tenantAdminRoleSid, EnumSet
.of( RepositoryFilePermission.ALL ) );
} else {
RepositoryFileAcl acl = repositoryFileAclDao.getAcl( tenantRootFolder.getId() );
Builder aclBuilder =
new RepositoryFileAcl.Builder( acl ).ace( tenantAdminRoleSid, EnumSet.of( RepositoryFilePermission.ALL ) );
IPentahoSession origPentahoSession = PentahoSessionHolder.getSession();
Authentication origAuthentication = SecurityContextHolder.getContext().getAuthentication();
login( repositoryAdminUsername, tenantAdminRoleId );
try {
// Give all to Tenant Admin of all ancestors
while ( !parentTenantFolder.equals( "/" ) ) {
ITenant tenant = new Tenant( parentTenantFolder, true );
String parentTenantAdminRoleId = tenantedRoleNameResolver.getPrincipleId( tenant, tenantAdminRoleName );
RepositoryFileSid parentTenantAdminSid = new RepositoryFileSid( parentTenantAdminRoleId, Type.ROLE );
aclBuilder.ace( parentTenantAdminSid, EnumSet.of( RepositoryFilePermission.ALL ) );
parentTenantFolder = FilenameUtils.getFullPathNoEndSeparator( parentTenantFolder );
}
repositoryFileAclDao.updateAcl( aclBuilder.build() );
} catch ( Throwable th ) {
th.printStackTrace();
} finally {
PentahoSessionHolder.setSession( origPentahoSession );
SecurityContextHolder.getContext().setAuthentication( origAuthentication );
}
}
try {
RepositoryFileSid fileOwnerSid = new RepositoryFileSid( tenantCreatorId );
createInitialTenantFolders( newTenant, tenantRootFolder, fileOwnerSid );
} catch ( Exception ex ) {
throw new RuntimeException( "Error creating initial tenant folders", ex );
}
return newTenant;