Search in sources :

Example 11 with UserInfo

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;
    }
}
Also used : KettleDatabaseRepositoryMetaStore(org.pentaho.di.repository.kdr.delegates.metastore.KettleDatabaseRepositoryMetaStore) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) IUser(org.pentaho.di.repository.IUser) UserInfo(org.pentaho.di.repository.UserInfo)

Example 12 with UserInfo

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());
}
Also used : UserInfo(org.pentaho.di.repository.UserInfo) StringObjectId(org.pentaho.di.repository.StringObjectId)

Example 13 with UserInfo

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));
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) UserInfo(org.pentaho.di.repository.UserInfo) LongObjectId(org.pentaho.di.repository.LongObjectId) Matchers.anyString(org.mockito.Matchers.anyString) Date(java.util.Date) Test(org.junit.Test)

Example 14 with UserInfo

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());
}
Also used : Serializable(java.io.Serializable) UserInfo(org.pentaho.di.repository.UserInfo) TestContextManager(org.springframework.test.context.TestContextManager) IRepositoryVersionManager(org.pentaho.platform.api.repository2.unified.IRepositoryVersionManager) ITenant(org.pentaho.platform.api.mt.ITenant) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileProxyFactory(org.pentaho.platform.repository2.unified.jcr.RepositoryFileProxyFactory) Before(org.junit.Before)

Example 15 with UserInfo

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);
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) RepositoryExtended(org.pentaho.di.repository.RepositoryExtended) UserInfo(org.pentaho.di.repository.UserInfo) Test(org.junit.Test)

Aggregations

UserInfo (org.pentaho.di.repository.UserInfo)19 Test (org.junit.Test)10 IUser (org.pentaho.di.repository.IUser)6 Before (org.junit.Before)4 Serializable (java.io.Serializable)2 ArrayList (java.util.ArrayList)2 LongObjectId (org.pentaho.di.repository.LongObjectId)2 RepositoryExtended (org.pentaho.di.repository.RepositoryExtended)2 UIEERepositoryUser (org.pentaho.di.ui.repository.pur.repositoryexplorer.model.UIEERepositoryUser)2 UISecurityRole (org.pentaho.di.ui.repository.pur.repositoryexplorer.model.UISecurityRole)2 IUIUser (org.pentaho.di.ui.repository.repositoryexplorer.model.IUIUser)2 UIRepositoryUser (org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryUser)2 ITenant (org.pentaho.platform.api.mt.ITenant)2 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)2 RepositoryFileProxyFactory (org.pentaho.platform.repository2.unified.jcr.RepositoryFileProxyFactory)2 ProxyPentahoUser (org.pentaho.platform.security.userroledao.ws.ProxyPentahoUser)2 MicroPlatform (org.pentaho.test.platform.engine.core.MicroPlatform)2 TestContextManager (org.springframework.test.context.TestContextManager)2 Date (java.util.Date)1 Matchers.anyString (org.mockito.Matchers.anyString)1