use of org.pentaho.di.repository.UserInfo in project pentaho-kettle by pentaho.
the class KettleDatabaseRepository method connect.
/**
* Connect to the repository.
*
* @throws KettleException
* in case there is a general unexpected error or if we're already connected
*/
public void connect(String username, String password, boolean upgrade) throws KettleException {
// first disconnect if already connected
connectionDelegate.connect(upgrade, upgrade);
try {
IUser userinfo = userDelegate.loadUserInfo(new UserInfo(), username, password);
securityProvider = new KettleDatabaseRepositorySecurityProvider(this, repositoryMeta, userinfo);
// We need to add services in the list in the order of dependencies
registerRepositoryService(RepositorySecurityProvider.class, securityProvider);
registerRepositoryService(RepositorySecurityManager.class, securityProvider);
// Apparently, MySQL InnoDB opens a new transaction simply by doing a
// lookup.
//
connectionDelegate.closeReadTransaction();
// Open the metaStore for business too...
//
metaStore = new KettleDatabaseRepositoryMetaStore(this);
} catch (KettleDatabaseException e) {
// if we fail to log in, disconnect and then rethrow the exception
connectionDelegate.disconnect();
throw e;
}
}
use of org.pentaho.di.repository.UserInfo in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositorySecurityProviderTest method testSaveUserInfo_Passes.
private void testSaveUserInfo_Passes(String login, String expectedLogin, String existing) throws Exception {
doReturn(new StringObjectId(existing)).when(repository.userDelegate).getUserID(eq(existing));
provider.saveUserInfo(new UserInfo(login));
ArgumentCaptor<UserInfo> captor = ArgumentCaptor.forClass(UserInfo.class);
verify(repository.userDelegate).saveUserInfo(captor.capture());
assertEquals("UserInfo should be passed", expectedLogin, captor.getValue().getLogin());
}
use of org.pentaho.di.repository.UserInfo in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryTest method testInsertLogEntry.
@Test
public void testInsertLogEntry() throws KettleException {
doReturn(new LongObjectId(123)).when(repo.connectionDelegate).getNextLogID();
doReturn("2.4").when(repo.connectionDelegate).getVersion();
doReturn(new UserInfo("John Doe")).when(repo).getUserInfo();
ArgumentCaptor<String> argumentTableName = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<RowMetaAndData> argumentTableData = ArgumentCaptor.forClass(RowMetaAndData.class);
doNothing().when(repo.connectionDelegate).insertTableRow(argumentTableName.capture(), argumentTableData.capture());
Date beforeLogEntryDate = Calendar.getInstance().getTime();
repo.insertLogEntry("testDescription");
Date afterLogEntryDate = Calendar.getInstance().getTime();
RowMetaAndData insertRecord = argumentTableData.getValue();
assertEquals(KettleDatabaseRepository.TABLE_R_REPOSITORY_LOG, argumentTableName.getValue());
assertEquals(5, insertRecord.size());
assertEquals(ValueMetaInterface.TYPE_INTEGER, insertRecord.getValueMeta(0).getType());
assertEquals(KettleDatabaseRepository.FIELD_REPOSITORY_LOG_ID_REPOSITORY_LOG, insertRecord.getValueMeta(0).getName());
assertEquals(Long.valueOf(123), insertRecord.getInteger(0));
assertEquals(ValueMetaInterface.TYPE_STRING, insertRecord.getValueMeta(1).getType());
assertEquals(KettleDatabaseRepository.FIELD_REPOSITORY_LOG_REP_VERSION, insertRecord.getValueMeta(1).getName());
assertEquals("2.4", insertRecord.getString(1, null));
assertEquals(ValueMetaInterface.TYPE_DATE, insertRecord.getValueMeta(2).getType());
assertEquals(KettleDatabaseRepository.FIELD_REPOSITORY_LOG_LOG_DATE, insertRecord.getValueMeta(2).getName());
assertTrue(beforeLogEntryDate.compareTo(insertRecord.getDate(2, new Date(Long.MIN_VALUE))) <= 0 && afterLogEntryDate.compareTo(insertRecord.getDate(2, new Date(Long.MIN_VALUE))) >= 0);
assertEquals(ValueMetaInterface.TYPE_STRING, insertRecord.getValueMeta(3).getType());
assertEquals(KettleDatabaseRepository.FIELD_REPOSITORY_LOG_LOG_USER, insertRecord.getValueMeta(3).getName());
assertEquals("John Doe", insertRecord.getString(3, null));
assertEquals(ValueMetaInterface.TYPE_STRING, insertRecord.getValueMeta(4).getType());
assertEquals(KettleDatabaseRepository.FIELD_REPOSITORY_LOG_OPERATION_DESC, insertRecord.getValueMeta(4).getName());
assertEquals("testDescription", insertRecord.getString(4, null));
}
use of org.pentaho.di.repository.UserInfo in project pentaho-kettle by pentaho.
the class PurRepositoryIT method setUp.
@Before
public void setUp() throws Exception {
this.testContextManager = new TestContextManager(getClass());
this.testContextManager.prepareTestInstance(this);
IRepositoryVersionManager mockRepositoryVersionManager = mock(IRepositoryVersionManager.class);
when(mockRepositoryVersionManager.isVersioningEnabled(anyString())).thenReturn(true);
when(mockRepositoryVersionManager.isVersionCommentEnabled(anyString())).thenReturn(false);
JcrRepositoryFileUtils.setRepositoryVersionManager(mockRepositoryVersionManager);
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));
// 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;
purRep.setPurRepositoryConnector(new PurRepositoryConnector(purRep, (PurRepositoryMeta) repositoryMeta, purRep.getRootRef()));
((PurRepository) repository).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.di.repository.UserInfo in project pentaho-kettle by pentaho.
the class BrowseControllerTest method testInit.
// PDI-16258
@Test
public void testInit() throws Exception {
RepositoryExtended repository = Mockito.mock(RepositoryExtended.class);
UserInfo userInfo = new UserInfo("user", "password", "user", "test user", true);
userInfo.setAdmin(true);
Mockito.doReturn(userInfo).when(repository).getUserInfo();
Mockito.doReturn(Mockito.mock(RepositoryDirectoryInterface.class)).when(repository).loadRepositoryDirectoryTree(anyString(), anyString(), anyInt(), anyBoolean(), anyBoolean(), anyBoolean());
BrowseController browseController = Mockito.spy(controller);
doNothing().when(browseController).createBindings();
browseController.init(repository);
Mockito.verify(repository).loadRepositoryDirectoryTree("/", "*.ktr|*.kjb", -1, true, true, true);
userInfo.setAdmin(false);
browseController.init(repository);
Mockito.verify(repository).loadRepositoryDirectoryTree("/", "*.ktr|*.kjb", -1, false, true, true);
userInfo.setAdmin(null);
browseController.init(repository);
Mockito.verify(repository, Mockito.times(2)).loadRepositoryDirectoryTree("/", "*.ktr|*.kjb", -1, false, true, true);
}
Aggregations