use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-kettle by pentaho.
the class RepositoryFactoryTest method testDefaultFactoryConnect.
@Test
public void testDefaultFactoryConnect() throws Exception {
IRepositoryFactory.DefaultRepositoryFactory repositoryFactory = new IRepositoryFactory.DefaultRepositoryFactory();
repositoryFactory.setRepositoryId("KettleFileRepository");
IPentahoSession session = new StandaloneSession("joe");
PentahoSessionHolder.setSession(session);
repositoryFactory.connect("foo");
}
use of org.pentaho.platform.api.engine.IPentahoSession 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.engine.IPentahoSession in project pentaho-kettle by pentaho.
the class PurRepositoryIT method createUserHomeFolder.
protected 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);
String principleId = userNameUtils.getPrincipleId(theTenant, theUsername);
String authenticatedRoleId = roleNameUtils.getPrincipleId(theTenant, tenantAuthenticatedRoleName);
TransactionCallbackWithoutResult callback = PurRepositoryTestingUtils.createUserHomeDirCallback(theTenant, theUsername, principleId, authenticatedRoleId, repositoryFileDao);
try {
txnTemplate.execute(callback);
} finally {
// Switch our identity back to the original user.
PurRepositoryTestingUtils.setSession(origPentahoSession, origAuthentication);
}
}
use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-kettle by pentaho.
the class PurRepositoryTestBase method createUserHomeFolder.
private void createUserHomeFolder(final ITenant theTenant, final String theUsername) {
IPentahoSession origPentahoSession = PentahoSessionHolder.getSession();
Authentication origAuthentication = SecurityContextHolder.getContext().getAuthentication();
String principleId = userNameUtils.getPrincipleId(theTenant, theUsername);
String authenticatedRoleId = roleNameUtils.getPrincipleId(theTenant, tenantAuthenticatedRole);
TransactionCallbackWithoutResult callback = PurRepositoryTestingUtils.createUserHomeDirCallback(theTenant, theUsername, principleId, authenticatedRoleId, repositoryFileDao);
try {
loginAsRepositoryAdmin();
txnTemplate.execute(callback);
} finally {
PurRepositoryTestingUtils.setSession(origPentahoSession, origAuthentication);
}
}
use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-metaverse by pentaho.
the class RepositoryLocatorTest method setUp.
@Before
public void setUp() throws Exception {
RepositoryLocator loc = new RepositoryLocator() {
@Override
protected IUnifiedRepository getUnifiedRepository(IPentahoSession session) throws Exception {
return null;
}
@Override
protected Object getContents(RepositoryFile locatedItem) throws Exception {
return null;
}
/**
* Returns the locator node for this locator. The locator node is the node in the metaverse
* that represents this locator. It is used to create a link from this locator to the documents
* that are found by/within it.
*
* @return The locator node in the metaverse
*/
@Override
public IMetaverseNode getLocatorNode() {
return new MetaverseNode(mock(Vertex.class));
}
@Override
public URI getRootUri() {
return null;
}
};
loc.setMetaverseBuilder(metaverseBuilder);
baseLocator = spy(loc);
when(baseLocator.getMetaverseBuilder()).thenReturn(metaverseBuilder);
when(metaverseBuilder.getMetaverseObjectFactory()).thenReturn(metaverseObjectFactory);
when(metaverseObjectFactory.createDocumentObject()).thenReturn(new MetaverseDocument());
}
Aggregations