use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl.Builder in project pentaho-platform by pentaho.
the class AbstractJcrBackedUserRoleDao method createUserHomeFolder.
private RepositoryFile createUserHomeFolder(ITenant theTenant, String username, Session session) throws RepositoryException {
Builder aclsForUserHomeFolder = null;
Builder aclsForTenantHomeFolder = null;
if (theTenant == null) {
theTenant = JcrTenantUtils.getTenant(username, true);
username = JcrTenantUtils.getPrincipalName(username, true);
}
if (theTenant == null || theTenant.getId() == null) {
theTenant = JcrTenantUtils.getCurrentTenant();
}
if (theTenant == null || theTenant.getId() == null) {
theTenant = JcrTenantUtils.getDefaultTenant();
}
RepositoryFile userHomeFolder = null;
String userId = tenantedUserNameUtils.getPrincipleId(theTenant, username);
final RepositoryFileSid userSid = new RepositoryFileSid(userId);
RepositoryFile tenantHomeFolder = null;
RepositoryFile tenantRootFolder = null;
RepositoryFileSid ownerSid = null;
// Get the Tenant Root folder. If the Tenant Root folder does not exist then exit.
tenantRootFolder = JcrRepositoryFileUtils.getFileByAbsolutePath(session, ServerRepositoryPaths.getTenantRootFolderPath(theTenant), pathConversionHelper, lockHelper, false, null);
if (tenantRootFolder != null) {
// Try to see if Tenant Home folder exist
tenantHomeFolder = JcrRepositoryFileUtils.getFileByAbsolutePath(session, ServerRepositoryPaths.getTenantHomeFolderPath(theTenant), pathConversionHelper, lockHelper, false, null);
if (tenantHomeFolder == null) {
String ownerId = tenantedUserNameUtils.getPrincipleId(theTenant, username);
ownerSid = new RepositoryFileSid(ownerId, Type.USER);
String tenantAuthenticatedRoleId = tenantedRoleNameUtils.getPrincipleId(theTenant, authenticatedRoleName);
RepositoryFileSid tenantAuthenticatedRoleSid = new RepositoryFileSid(tenantAuthenticatedRoleId, 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 = internalCreateFolder(session, tenantRootFolder.getId(), new RepositoryFile.Builder(ServerRepositoryPaths.getTenantHomeFolderName()).folder(true).title(Messages.getInstance().getString("AbstractJcrBackedUserRoleDao.usersFolderDisplayName")).build(), aclsForTenantHomeFolder.build(), // $NON-NLS-1$
"tenant home folder");
} else {
String ownerId = tenantedUserNameUtils.getPrincipleId(theTenant, username);
ownerSid = new RepositoryFileSid(ownerId, Type.USER);
aclsForUserHomeFolder = new RepositoryFileAcl.Builder(userSid).ace(ownerSid, EnumSet.of(RepositoryFilePermission.ALL));
}
// now check if user's home folder exist
userHomeFolder = JcrRepositoryFileUtils.getFileByAbsolutePath(session, ServerRepositoryPaths.getUserHomeFolderPath(theTenant, username), pathConversionHelper, lockHelper, false, null);
if (userHomeFolder == null) {
userHomeFolder = internalCreateFolder(session, tenantHomeFolder.getId(), new RepositoryFile.Builder(username).folder(true).build(), aclsForUserHomeFolder.build(), // $NON-NLS-1$
"user home folder");
}
}
return userHomeFolder;
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl.Builder in project pentaho-platform by pentaho.
the class RepositoryFileAdapter method toFile.
public static RepositoryFile toFile(final RepositoryFileDto v) {
if (v == null) {
return null;
}
RepositoryFile.Builder builder = null;
if (v.id != null) {
builder = new RepositoryFile.Builder(v.id, v.name);
} else {
builder = new RepositoryFile.Builder(v.name);
}
if (v.ownerType != -1) {
new RepositoryFileSid(v.owner, RepositoryFileSid.Type.values()[v.ownerType]);
}
if (v.localePropertiesMapEntries != null) {
for (LocaleMapDto localeMapDto : v.localePropertiesMapEntries) {
String locale = localeMapDto.getLocale();
Properties localeProperties = new Properties();
if (localeMapDto.getProperties() != null) {
for (StringKeyStringValueDto keyValueDto : localeMapDto.getProperties()) {
localeProperties.put(keyValueDto.getKey(), keyValueDto.getValue());
}
}
builder.localeProperties(locale, localeProperties);
}
}
return builder.path(v.path).createdDate(v.createdDate).creatorId(v.creatorId).description(v.description).folder(v.folder).fileSize(v.fileSize).lastModificationDate(v.lastModifiedDate).locale(v.locale).lockDate(v.lockDate).locked(v.locked).lockMessage(v.lockMessage).lockOwner(v.lockOwner).title(v.title).versioned(v.versioned).versionId(v.versionId).originalParentFolderPath(v.originalParentFolderPath).deletedDate(v.deletedDate).hidden(v.hidden).schedulable(!v.isNotSchedulable()).aclNode(v.aclNode).build();
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl.Builder in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryContentIT method testFileCreator.
@Test
public void testFileCreator() throws Exception {
loginAsSysTenantAdmin();
ITenant tenantAcme = tenantManager.createTenant(systemTenant, TENANT_ID_ACME, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(tenantAcme, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
login(USERNAME_ADMIN, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
userRoleDao.createUser(tenantAcme, USERNAME_SUZY, PASSWORD, "", null);
login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
final String parentFolderPath = ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY);
String sampleString1 = "sampleString1";
String sampleString2 = "sampleString2";
RepositoryFile newFile1 = createSampleFile(parentFolderPath, "helloworld.sample1", sampleString1, true, 1, true);
RepositoryFile newFile2 = createSampleFile(parentFolderPath, "helloworld.sample2", sampleString2, true, 1, true);
RepositoryFile.Builder builder = new RepositoryFile.Builder(newFile1);
builder.creatorId((String) newFile2.getId());
final String mimeType = "text/plain";
final String dataString = "Hello World!";
final String encoding = "UTF-8";
byte[] data = dataString.getBytes(encoding);
ByteArrayInputStream dataStream = new ByteArrayInputStream(data);
final SimpleRepositoryFileData content = new SimpleRepositoryFileData(dataStream, encoding, mimeType);
RepositoryFile updatedFile = repo.updateFile(builder.build(), content, null);
RepositoryFile reconstituedFile = repo.getFileById(updatedFile.getId());
assertEquals(reconstituedFile.getCreatorId(), newFile2.getId());
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl.Builder in project pentaho-kettle by pentaho.
the class PurRepository method renameTransOrJob.
/**
* Renames and optionally moves a file having {@code idObject}. If {@code newDirectory} is <tt>null</tt>, then the
* file is just renamed. If {@code newTitle} is <tt>null</tt>, then the file should keep its name.
* <p/>
* Note, it is expected that the file exists
*
* @param idObject
* file's id
* @param versionComment
* comment on the revision
* @param newDirectory
* new folder, where to move the file; <tt>null</tt> means the file should be left in its current
* @param newTitle
* new file's title (title is a name w/o extension); <tt>null</tt> means the file should keep its current
* @param objectType
* file's type; {@linkplain RepositoryObjectType#TRANSFORMATION} or {@linkplain RepositoryObjectType#JOB} are
* expected
* @param errorMsgKey
* key for the error message passed with the exception
* @throws KettleException
* if file with same path exists
*/
private ObjectId renameTransOrJob(ObjectId idObject, String versionComment, RepositoryDirectoryInterface newDirectory, String newTitle, RepositoryObjectType objectType, String errorMsgKey) throws KettleException {
RepositoryFile file = pur.getFileById(idObject.getId());
RepositoryFile.Builder builder = new RepositoryFile.Builder(file);
// fullName = title + extension
String fullName;
if (newTitle == null) {
// keep existing file name
fullName = file.getName();
} else {
// set new title
builder.title(RepositoryFile.DEFAULT_LOCALE, newTitle).createdDate(null);
fullName = checkAndSanitize(newTitle) + objectType.getExtension();
}
String absPath = calcDestAbsPath(file, newDirectory, fullName);
// get file from destination path, should be null for rename goal
RepositoryFile fileFromDestination = pur.getFile(absPath);
if (fileFromDestination == null) {
file = builder.build();
NodeRepositoryFileData data = pur.getDataAtVersionForRead(file.getId(), null, NodeRepositoryFileData.class);
if (newTitle != null) {
// update file's content only if the title should be changed
// as this action creates another revision
pur.updateFile(file, data, versionComment);
}
pur.moveFile(idObject.getId(), absPath, null);
rootRef.clearRef();
return idObject;
} else {
throw new KettleException(BaseMessages.getString(PKG, errorMsgKey, file.getName(), newTitle));
}
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl.Builder in project pentaho-kettle by pentaho.
the class PurRepositoryMetaStore method validateElementTypeRepositoryFolder.
protected RepositoryFile validateElementTypeRepositoryFolder(String namespace, IMetaStoreElementType elementType) throws MetaStoreException {
// The element type needs to be known in this repository, we need to have a match by ID
//
RepositoryFile elementTypeFolder = pur.getFileById(elementType.getId());
if (elementTypeFolder == null) {
StringBuilder builder = new StringBuilder();
builder.append(namespacesFolder.getPath()).append(Const.CR);
String available = getMetaStoreFolders(builder, namespacesFolder, 0);
throw new MetaStoreException("The element type with name '" + elementType.getName() + " doesn't exist in namespace '" + namespace + "'." + Const.CR + "Available nodes:" + Const.CR + available);
}
return elementTypeFolder;
}
Aggregations