if ( tenant == null || tenant.getId() == null ) {
tenant = JcrTenantUtils.getDefaultTenant();
}
RepositoryFile userHomeFolder = null;
String userId = userNameUtils.getPrincipleId( theTenant, username );
final RepositoryFileSid userSid = new RepositoryFileSid( userId );
RepositoryFile tenantHomeFolder = null;
RepositoryFile tenantRootFolder = null;
// Get the Tenant Root folder. If the Tenant Root folder does not exist then exit.
tenantRootFolder =
repositoryFileDao.getFileByAbsolutePath( ServerRepositoryPaths.getTenantRootFolderPath( theTenant ) );
if ( tenantRootFolder != null ) {
// Try to see if Tenant Home folder exist
tenantHomeFolder =
repositoryFileDao.getFileByAbsolutePath( ServerRepositoryPaths.getTenantHomeFolderPath( theTenant ) );
if ( tenantHomeFolder == null ) {
String ownerId = userNameUtils.getPrincipleId( theTenant, username );
RepositoryFileSid ownerSid = new RepositoryFileSid( ownerId, RepositoryFileSid.Type.USER );
String tenantAuthenticatedRoleId = roleNameUtils.getPrincipleId( theTenant, tenantAuthenticatedRoleName );
RepositoryFileSid tenantAuthenticatedRoleSid =
new RepositoryFileSid( tenantAuthenticatedRoleId, RepositoryFileSid.Type.ROLE );
aclsForTenantHomeFolder =
new RepositoryFileAcl.Builder( userSid ).ace( tenantAuthenticatedRoleSid, EnumSet
.of( RepositoryFilePermission.READ ) );
aclsForUserHomeFolder =
new RepositoryFileAcl.Builder( userSid ).ace( ownerSid, EnumSet.of( RepositoryFilePermission.ALL ) );
tenantHomeFolder =
repositoryFileDao.createFolder( tenantRootFolder.getId(), new RepositoryFile.Builder(
ServerRepositoryPaths.getTenantHomeFolderName() ).folder( true ).build(), aclsForTenantHomeFolder
.build(), "tenant home folder" );
} else {
String ownerId = userNameUtils.getPrincipleId( theTenant, username );
RepositoryFileSid ownerSid = new RepositoryFileSid( ownerId, RepositoryFileSid.Type.USER );
aclsForUserHomeFolder =
new RepositoryFileAcl.Builder( userSid ).ace( ownerSid, EnumSet.of( RepositoryFilePermission.ALL ) );
}
// now check if user's home folder exist