Search in sources :

Example 16 with IUser

use of org.pentaho.di.repository.IUser in project pentaho-kettle by pentaho.

the class GetRepositoryNamesTest method testShowHidden.

@Test
public // PDI-16258
void testShowHidden() throws KettleException {
    IUser user = Mockito.mock(IUser.class);
    Mockito.when(user.isAdmin()).thenReturn(true);
    Mockito.when(repoExtended.getUserInfo()).thenReturn(user);
    init(repoExtended, "/", false, ".*", "", All, 0);
    Mockito.verify(repoExtended, Mockito.never()).loadRepositoryDirectoryTree(Mockito.anyString(), Mockito.anyString(), Mockito.anyInt(), Mockito.eq(false), Mockito.anyBoolean(), anyBoolean());
    Mockito.when(user.isAdmin()).thenReturn(false);
    init(repoExtended, "/", false, ".*", "", All, 0);
    Mockito.verify(repoExtended).loadRepositoryDirectoryTree(Mockito.anyString(), Mockito.anyString(), Mockito.anyInt(), Mockito.eq(false), Mockito.anyBoolean(), Mockito.anyBoolean());
}
Also used : IUser(org.pentaho.di.repository.IUser) Test(org.junit.Test)

Example 17 with IUser

use of org.pentaho.di.repository.IUser 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 18 with IUser

use of org.pentaho.di.repository.IUser in project pentaho-kettle by pentaho.

the class GetRepositoryNamesTest method prepareExtendedRepository.

@SuppressWarnings("deprecation")
private static void prepareExtendedRepository() throws KettleException {
    repoExtended = mock(RepositoryExtended.class);
    when(repoExtended.loadRepositoryDirectoryTree(anyString(), anyString(), anyInt(), anyBoolean(), anyBoolean(), anyBoolean())).then(new Answer<RepositoryDirectoryInterface>() {

        @Override
        public RepositoryDirectoryInterface answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            RepositoryDirectoryInterface root = new RepositoryDirectory();
            root.setName("/");
            RepositoryDirectoryInterface subdir1 = new RepositoryDirectory(root, "subdir1");
            RepositoryDirectoryInterface subdir2 = new RepositoryDirectory(subdir1, "subdir2");
            RepositoryElementMetaInterface trans1 = new RepositoryObject(null, "Trans1", subdir1, "user", null, RepositoryObjectType.TRANSFORMATION, "", false);
            RepositoryElementMetaInterface trans2 = new RepositoryObject(null, "Trans2", subdir2, "user", null, RepositoryObjectType.TRANSFORMATION, "", false);
            RepositoryElementMetaInterface job1 = new RepositoryObject(null, "Job1", subdir1, "user", null, RepositoryObjectType.JOB, "", false);
            RepositoryElementMetaInterface job2 = new RepositoryObject(null, "Job2", subdir2, "user", null, RepositoryObjectType.JOB, "", false);
            List<RepositoryElementMetaInterface> list1 = new ArrayList<RepositoryElementMetaInterface>();
            List<RepositoryElementMetaInterface> list2 = new ArrayList<RepositoryElementMetaInterface>();
            if (((String) args[1]).contains("ktr")) {
                list1.add(trans1);
                list2.add(trans2);
            }
            if (((String) args[1]).contains("kjb")) {
                list1.add(job1);
                list2.add(job2);
            }
            subdir1.setRepositoryObjects(list1);
            subdir2.setRepositoryObjects(list2);
            if (((Integer) args[2]) == -1) {
                subdir1.addSubdirectory(subdir2);
                root.addSubdirectory(subdir1);
            }
            String actualPath = ((String) args[0]);
            if (actualPath.equals("/")) {
                return root;
            } else if (actualPath.equals(subdir1.getPath())) {
                return subdir1;
            } else if (actualPath.equals(subdir2.getPath())) {
                return subdir2;
            } else {
                return null;
            }
        }
    });
    IUser user = Mockito.mock(IUser.class);
    Mockito.when(user.isAdmin()).thenReturn(true);
    Mockito.when(repoExtended.getUserInfo()).thenReturn(user);
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) RepositoryObject(org.pentaho.di.repository.RepositoryObject) Mockito.anyString(org.mockito.Mockito.anyString) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IUser(org.pentaho.di.repository.IUser) RepositoryExtended(org.pentaho.di.repository.RepositoryExtended) ArrayList(java.util.ArrayList) List(java.util.List) RepositoryElementMetaInterface(org.pentaho.di.repository.RepositoryElementMetaInterface)

Example 19 with IUser

use of org.pentaho.di.repository.IUser in project pentaho-kettle by pentaho.

the class RepositoryBrowserController method getRecentFiles.

public List<RepositoryFile> getRecentFiles() {
    PropsUI props = PropsUI.getInstance();
    List<RepositoryFile> repositoryFiles = new ArrayList<>();
    IUser userInfo = Spoon.getInstance().rep.getUserInfo();
    String repoAndUser = Spoon.getInstance().rep.getName() + ":" + (userInfo != null ? userInfo.getLogin() : "");
    List<LastUsedFile> lastUsedFiles = props.getLastUsedRepoFiles().getOrDefault(repoAndUser, Collections.emptyList());
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DATE, -30);
    Date dateBefore = calendar.getTime();
    for (int i = 0; i < lastUsedFiles.size(); i++) {
        LastUsedFile lastUsedFile = lastUsedFiles.get(i);
        if (lastUsedFile.getLastOpened().before(dateBefore)) {
            continue;
        }
        if (lastUsedFile.getRepositoryName() != null && lastUsedFile.getRepositoryName().equals(Spoon.getInstance().rep.getName())) {
            RepositoryFile repositoryFile = new RepositoryFile();
            final String index = String.valueOf(i);
            repositoryFile.setObjectId(() -> index);
            repositoryFile.setType(lastUsedFile.isTransformation() ? TRANSFORMATION : JOB);
            repositoryFile.setName(lastUsedFile.getFilename());
            repositoryFile.setPath(lastUsedFile.getDirectory());
            repositoryFile.setDate(lastUsedFile.getLastOpened());
            repositoryFile.setRepository(lastUsedFile.getRepositoryName());
            repositoryFile.setUsername(lastUsedFile.getUsername());
            repositoryFiles.add(repositoryFile);
        }
    }
    return repositoryFiles;
}
Also used : Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) IUser(org.pentaho.di.repository.IUser) RepositoryFile(org.pentaho.repo.model.RepositoryFile) LastUsedFile(org.pentaho.di.core.LastUsedFile) Date(java.util.Date) PropsUI(org.pentaho.di.ui.core.PropsUI)

Example 20 with IUser

use of org.pentaho.di.repository.IUser in project pentaho-kettle by pentaho.

the class UserRoleHelperTest method mockSecurityManager.

private static IRoleSupportSecurityManager mockSecurityManager(final boolean eeUsers) throws KettleException {
    IRoleSupportSecurityManager manager = mock(IRoleSupportSecurityManager.class);
    when(manager.constructUser()).thenAnswer(new Answer<IUser>() {

        @Override
        public IUser answer(InvocationOnMock invocation) throws Throwable {
            return eeUsers ? new EEUserInfo() : new UserInfo();
        }
    });
    when(manager.constructRole()).thenAnswer(new Answer<IRole>() {

        @Override
        public IRole answer(InvocationOnMock invocation) throws Throwable {
            return new EERoleInfo();
        }
    });
    return manager;
}
Also used : IRoleSupportSecurityManager(org.pentaho.di.ui.repository.pur.services.IRoleSupportSecurityManager) IRole(org.pentaho.di.repository.pur.model.IRole) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IUser(org.pentaho.di.repository.IUser) EEUserInfo(org.pentaho.di.repository.pur.model.EEUserInfo) EEUserInfo(org.pentaho.di.repository.pur.model.EEUserInfo) UserInfo(org.pentaho.di.repository.UserInfo) EERoleInfo(org.pentaho.di.repository.pur.model.EERoleInfo)

Aggregations

IUser (org.pentaho.di.repository.IUser)34 KettleException (org.pentaho.di.core.exception.KettleException)12 Test (org.junit.Test)8 ProxyPentahoUser (org.pentaho.platform.security.userroledao.ws.ProxyPentahoUser)7 UserInfo (org.pentaho.di.repository.UserInfo)6 IEEUser (org.pentaho.di.repository.pur.model.IEEUser)5 IRoleSupportSecurityManager (org.pentaho.di.ui.repository.pur.services.IRoleSupportSecurityManager)5 ArrayList (java.util.ArrayList)4 EEUserInfo (org.pentaho.di.repository.pur.model.EEUserInfo)3 IUIUser (org.pentaho.di.ui.repository.repositoryexplorer.model.IUIUser)3 UserRoleException (org.pentaho.platform.security.userroledao.ws.UserRoleException)3 HashSet (java.util.HashSet)2 JSONException (org.json.JSONException)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 UserRoleHelper.convertFromProxyPentahoUser (org.pentaho.di.repository.pur.UserRoleHelper.convertFromProxyPentahoUser)2 IRole (org.pentaho.di.repository.pur.model.IRole)2 IUIRole (org.pentaho.di.ui.repository.pur.repositoryexplorer.IUIRole)2 UserRoleSecurityInfo (org.pentaho.platform.security.userroledao.ws.UserRoleSecurityInfo)2 UserToRoleAssignment (org.pentaho.platform.security.userroledao.ws.UserToRoleAssignment)2 IRepositorySyncWebService (com.pentaho.pdi.ws.IRepositorySyncWebService)1