use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-kettle by pentaho.
the class PurRepository_DatabaseNames_Test method setUp.
@Before
public void setUp() throws Exception {
RepositoryFile dbFile = file(EXISTING_DB);
unifiedRepository = mock(IUnifiedRepository.class);
when(unifiedRepository.getFile(EXISTING_DB_PATH)).thenReturn(dbFile);
PurRepositoryMeta mockMeta = mock(PurRepositoryMeta.class);
purRepository = new PurRepository();
purRepository.init(mockMeta);
purRepository.setTest(unifiedRepository);
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-kettle by pentaho.
the class UIEERepositoryDirectoryIT method createUserHomeFolder.
private void createUserHomeFolder(final ITenant theTenant, final String theUsername) {
IPentahoSession origPentahoSession = PentahoSessionHolder.getSession();
Authentication origAuthentication = SecurityContextHolder.getContext().getAuthentication();
StandaloneSession pentahoSession = new StandaloneSession(repositoryAdminUsername);
pentahoSession.setAuthenticated(null, repositoryAdminUsername);
PentahoSessionHolder.setSession(pentahoSession);
try {
txnTemplate.execute(new TransactionCallbackWithoutResult() {
public void doInTransactionWithoutResult(final TransactionStatus status) {
Builder aclsForUserHomeFolder = null;
Builder aclsForTenantHomeFolder = null;
ITenant tenant = null;
String username = null;
if (theTenant == null) {
tenant = getTenant(username, true);
username = getPrincipalName(theUsername, true);
} else {
tenant = theTenant;
username = theUsername;
}
if (tenant == null || tenant.getId() == null) {
tenant = getCurrentTenant();
}
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, Type.USER);
String tenantAuthenticatedRoleId = roleNameUtils.getPrincipleId(theTenant, tenantAuthenticatedRoleName);
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 = 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, Type.USER);
aclsForUserHomeFolder = new RepositoryFileAcl.Builder(userSid).ace(ownerSid, EnumSet.of(RepositoryFilePermission.ALL));
}
// now check if user's home folder exist
userHomeFolder = repositoryFileDao.getFileByAbsolutePath(ServerRepositoryPaths.getUserHomeFolderPath(theTenant, username));
if (userHomeFolder == null) {
userHomeFolder = repositoryFileDao.createFolder(tenantHomeFolder.getId(), new RepositoryFile.Builder(username).folder(true).build(), aclsForUserHomeFolder.build(), // $NON-NLS-1$
"user home folder");
}
}
}
});
} finally {
// Switch our identity back to the original user.
PentahoSessionHolder.setSession(origPentahoSession);
SecurityContextHolder.getContext().setAuthentication(origAuthentication);
}
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-kettle by pentaho.
the class UIEERepositoryDirectoryIT method setUp.
@Before
public void setUp() throws Exception {
this.testContextManager = new TestContextManager(getClass());
this.testContextManager.prepareTestInstance(this);
loginAsRepositoryAdmin();
SimpleJcrTestUtils.deleteItem(testJcrTemplate, ServerRepositoryPaths.getPentahoRootFolderPath());
mp = new MicroPlatform();
// used by DefaultPentahoJackrabbitAccessControlHelper
mp.defineInstance("tenantedUserNameUtils", userNameUtils);
mp.defineInstance("tenantedRoleNameUtils", roleNameUtils);
mp.defineInstance(IAuthorizationPolicy.class, authorizationPolicy);
mp.defineInstance(ITenantManager.class, tenantManager);
mp.defineInstance("roleAuthorizationPolicyRoleBindingDaoTarget", roleBindingDaoTarget);
mp.defineInstance("repositoryAdminUsername", repositoryAdminUsername);
mp.defineInstance("RepositoryFileProxyFactory", new RepositoryFileProxyFactory(testJcrTemplate, repositoryFileDao));
mp.defineInstance("useMultiByteEncoding", new Boolean(false));
mp.defineInstance(IAclService.class, new Boolean(false));
// Start the micro-platform
mp.start();
loginAsRepositoryAdmin();
setAclManagement();
systemTenant = tenantManager.createTenant(null, ServerRepositoryPaths.getPentahoRootFolderName(), singleTenantAdminRoleName, tenantAuthenticatedRoleName, "Anonymous");
userRoleDao.createUser(systemTenant, sysAdminUserName, "password", "", new String[] { singleTenantAdminRoleName });
logout();
super.setUp();
KettleEnvironment.init();
// programmatically register plugins, annotation based plugins do not get loaded unless
// they are in kettle's plugins folder.
JobEntryPluginType.getInstance().registerCustom(JobEntryAttributeTesterJobEntry.class, "test", "JobEntryAttributeTester", "JobEntryAttributeTester", "JobEntryAttributeTester", "");
StepPluginType.getInstance().registerCustom(TransStepAttributeTesterTransStep.class, "test", "StepAttributeTester", "StepAttributeTester", "StepAttributeTester", "");
repositoryMeta = new PurRepositoryMeta();
repositoryMeta.setName("JackRabbit");
repositoryMeta.setDescription("JackRabbit test repository");
userInfo = new UserInfo(EXP_LOGIN, "password", EXP_USERNAME, "Apache Tomcat user", true);
repository = new PurRepository();
repository.init(repositoryMeta);
login(sysAdminUserName, systemTenant, new String[] { singleTenantAdminRoleName, tenantAuthenticatedRoleName });
ITenant tenantAcme = tenantManager.createTenant(systemTenant, EXP_TENANT, singleTenantAdminRoleName, tenantAuthenticatedRoleName, "Anonymous");
userRoleDao.createUser(tenantAcme, EXP_LOGIN, "password", "", new String[] { singleTenantAdminRoleName });
logout();
setUpUser();
PurRepository purRep = (PurRepository) repository;
final PurRepositoryConnector purRepositoryConnector = new PurRepositoryConnector(purRep, (PurRepositoryMeta) repositoryMeta, purRep.getRootRef());
purRep.setPurRepositoryConnector(purRepositoryConnector);
purRep.setTest(repo);
repository.connect(EXP_LOGIN, "password");
login(EXP_LOGIN, tenantAcme, new String[] { singleTenantAdminRoleName, tenantAuthenticatedRoleName });
System.out.println("PUR NAME!!!: " + repo.getClass().getCanonicalName());
RepositoryFile repositoryFile = repo.getFile(ClientRepositoryPaths.getPublicFolderPath());
Serializable repositoryFileId = repositoryFile.getId();
List<RepositoryFile> files = repo.getChildren(repositoryFileId);
StringBuilder buf = new StringBuilder();
for (RepositoryFile file : files) {
buf.append("\n").append(file);
}
assertTrue("files not deleted: " + buf, files.isEmpty());
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-kettle by pentaho.
the class StreamToNodeConvertersPrivateDatabasesTest method getData.
@Parameterized.Parameters
public static List<Object[]> getData() throws Exception {
RepositoryFile repositoryFile = new RepositoryFile.Builder("test file").build();
IUnifiedRepository pur = mock(IUnifiedRepository.class);
when(pur.getFileById(FILE_ID)).thenReturn(repositoryFile);
TransMeta transMeta = new TransMeta();
JobMeta jobMeta = new JobMeta();
Repository repository = mock(Repository.class);
when(repository.loadTransformation(any(StringObjectId.class), anyString())).thenReturn(transMeta);
when(repository.loadJob(any(StringObjectId.class), anyString())).thenReturn(jobMeta);
StreamToTransNodeConverter transNodeConverter = new StreamToTransNodeConverter(pur);
transNodeConverter = spy(transNodeConverter);
doReturn(repository).when(transNodeConverter).connectToRepository();
StreamToJobNodeConverter jobNodeConverter = new StreamToJobNodeConverter(pur);
jobNodeConverter = spy(jobNodeConverter);
doReturn(repository).when(jobNodeConverter).connectToRepository();
Object[] trans = { transNodeConverter, TransMeta.XML_TAG, transMeta };
Object[] job = { jobNodeConverter, JobMeta.XML_TAG, jobMeta };
return asList(trans, job);
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-kettle by pentaho.
the class PurRepositoryTestingUtils method createUserHomeDirCallback.
/**
* Creates a callback for setting up {@code username}'s home folder. In the folder exists, noting is done. If
* {@code tenant}'s home folder does not exist nothing is done.
*
* @param tenant
* tenant
* @param username
* user name
* @param principleId
* user principle's id
* @param authenticatedRoleId
* user authenticated role's id
* @param fileDao
* file dao
* @return callback for performing the action
*/
static TransactionCallbackWithoutResult createUserHomeDirCallback(final ITenant tenant, final String username, final String principleId, final String authenticatedRoleId, final IRepositoryFileDao fileDao) {
return new TransactionCallbackWithoutResult() {
public void doInTransactionWithoutResult(final TransactionStatus status) {
String tenantRootFolderPath = ServerRepositoryPaths.getTenantRootFolderPath(tenant);
RepositoryFile tenantRootFolder = fileDao.getFileByAbsolutePath(tenantRootFolderPath);
if (tenantRootFolder == null) {
return;
}
String userHomeFolderPath = ServerRepositoryPaths.getUserHomeFolderPath(tenant, username);
RepositoryFile userHomeFolder = fileDao.getFileByAbsolutePath(userHomeFolderPath);
if (userHomeFolder != null) {
return;
}
RepositoryFileSid userSid = new RepositoryFileSid(principleId);
String tenantHomeFolderPath = ServerRepositoryPaths.getTenantHomeFolderPath(tenant);
RepositoryFile tenantHomeFolder = fileDao.getFileByAbsolutePath(tenantHomeFolderPath);
RepositoryFileAcl.Builder aclsForUserHomeFolder;
if (tenantHomeFolder == null) {
RepositoryFileSid ownerSid = new RepositoryFileSid(principleId, RepositoryFileSid.Type.USER);
RepositoryFileSid tenantAuthenticatedRoleSid = new RepositoryFileSid(authenticatedRoleId, RepositoryFileSid.Type.ROLE);
RepositoryFileAcl.Builder aclsForTenantHomeFolder = new RepositoryFileAcl.Builder(userSid).ace(tenantAuthenticatedRoleSid, EnumSet.of(RepositoryFilePermission.READ));
aclsForUserHomeFolder = new RepositoryFileAcl.Builder(userSid).ace(ownerSid, EnumSet.of(RepositoryFilePermission.ALL));
tenantHomeFolder = fileDao.createFolder(tenantRootFolder.getId(), new RepositoryFile.Builder(ServerRepositoryPaths.getTenantHomeFolderName()).folder(true).build(), aclsForTenantHomeFolder.build(), "tenant home folder");
} else {
RepositoryFileSid ownerSid = new RepositoryFileSid(principleId, RepositoryFileSid.Type.USER);
aclsForUserHomeFolder = new RepositoryFileAcl.Builder(userSid).ace(ownerSid, EnumSet.of(RepositoryFilePermission.ALL));
}
fileDao.createFolder(tenantHomeFolder.getId(), new RepositoryFile.Builder(username).folder(true).build(), aclsForUserHomeFolder.build(), "user home folder");
}
};
}
Aggregations