Search in sources :

Example 1 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 2 with IUser

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

the class PurRepository method loadRepositoryDirectoryTree.

@Deprecated
@Override
public RepositoryDirectoryInterface loadRepositoryDirectoryTree(boolean eager) throws KettleException {
    // this method forces a reload of the repository directory tree structure
    // a new rootRef will be obtained - this is a SoftReference which will be used
    // by any calls to getRootDir()
    RepositoryDirectoryInterface rootDir;
    if (eager) {
        RepositoryFileTree rootFileTree = loadRepositoryFileTree(ClientRepositoryPaths.getRootFolderPath());
        rootDir = initRepositoryDirectoryTree(rootFileTree);
    } else {
        readWriteLock.readLock().lock();
        RepositoryFile root;
        try {
            root = pur.getFile("/");
        } finally {
            readWriteLock.readLock().unlock();
        }
        IUser user = this.getUserInfo();
        boolean showHidden = user != null ? user.isAdmin() : true;
        rootDir = new LazyUnifiedRepositoryDirectory(root, null, pur, purRepositoryServiceRegistry, showHidden);
    }
    rootRef.setRef(rootDir);
    return rootDir;
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) IUser(org.pentaho.di.repository.IUser) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree)

Example 3 with IUser

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

the class UserRoleDelegate method updateRole.

public void updateRole(IRole role) throws KettleException {
    ensureHasPermissions();
    try {
        List<String> users = new ArrayList<String>();
        for (IUser user : role.getUsers()) {
            users.add(user.getLogin());
        }
        userRoleWebService.updateRole(role.getName(), role.getDescription(), users);
        lookupCache.updateRoleInLookupSet(role);
        fireUserRoleListChange();
    } catch (Exception e) {
        throw new KettleException(BaseMessages.getString(UserRoleDelegate.class, "UserRoleDelegate.ERROR_0012_UNABLE_TO_UPDATE_ROLE", role.getName()), // $NON-NLS-1$
        e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) ArrayList(java.util.ArrayList) IUser(org.pentaho.di.repository.IUser) KettleException(org.pentaho.di.core.exception.KettleException) UserRoleException(org.pentaho.platform.security.userroledao.ws.UserRoleException) JSONException(org.json.JSONException)

Example 4 with IUser

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

the class PurRepositorySecurityManager method loadUserInfo.

public IUser loadUserInfo(String login) throws KettleException {
    // Create a UserInfo object
    IUser user = constructUser();
    user.setLogin(login);
    user.setName(login);
    return user;
}
Also used : IUser(org.pentaho.di.repository.IUser)

Example 5 with IUser

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

the class PurRepositoryConnector method connect.

public synchronized RepositoryConnectResult connect(final String username, final String password) throws KettleException {
    if (serviceManager != null) {
        disconnect();
    }
    serviceManager = new WebServiceManager(repositoryMeta.getRepositoryLocation().getUrl(), username);
    RepositoryServiceRegistry purRepositoryServiceRegistry = new RepositoryServiceRegistry();
    IUser user1 = new EEUserInfo();
    final String decryptedPassword = Encr.decryptPasswordOptionallyEncrypted(password);
    final RepositoryConnectResult result = new RepositoryConnectResult(purRepositoryServiceRegistry);
    try {
        /*
       * Three scenarios: 1. Connect in process: username fetched using PentahoSessionHolder; no authentication occurs
       * 2. Connect externally with trust: username specified is assumed authenticated if IP of calling code is trusted
       * 3. Connect externally: authentication occurs normally (i.e. password is checked)
       */
        user1.setLogin(username);
        user1.setPassword(decryptedPassword);
        user1.setName(username);
        result.setUser(user1);
        // We need to have the application context and the session available in order for us to skip authentication
        if (PentahoSystem.getApplicationContext() != null && PentahoSessionHolder.getSession() != null && PentahoSessionHolder.getSession().isAuthenticated()) {
            if (inProcess()) {
                // connect to the IUnifiedRepository through PentahoSystem
                // this assumes we're running in a BI Platform
                result.setUnifiedRepository(PentahoSystem.get(IUnifiedRepository.class));
                if (result.getUnifiedRepository() != null) {
                    if (log.isDebug()) {
                        log.logDebug(BaseMessages.getString(PKG, "PurRepositoryConnector.ConnectInProgress.Begin"));
                    }
                    String name = PentahoSessionHolder.getSession().getName();
                    user1 = new EEUserInfo();
                    user1.setLogin(name);
                    user1.setName(name);
                    user1.setPassword(decryptedPassword);
                    result.setUser(user1);
                    result.setSuccess(true);
                    result.getUser().setAdmin(PentahoSystem.get(IAuthorizationPolicy.class).isAllowed(IAbsSecurityProvider.ADMINISTER_SECURITY_ACTION));
                    if (log.isDebug()) {
                        log.logDebug(BaseMessages.getString(PKG, "PurRepositoryConnector.ConnectInProgress", name, result.getUnifiedRepository()));
                    }
                    // what about security provider?
                    return result;
                }
            }
        }
        ExecutorService executor = getExecutor();
        Future<Boolean> authorizationWebserviceFuture = executor.submit(new Callable<Boolean>() {

            @Override
            public Boolean call() throws Exception {
                // IRoleSupportSecurityManager depends RepositorySecurityManager to be present
                if (log.isBasic()) {
                    log.logBasic(BaseMessages.getString(PKG, "PurRepositoryConnector.CreateServiceProvider.Start"));
                }
                result.setSecurityProvider(new AbsSecurityProvider(purRepository, repositoryMeta, result.getUser(), serviceManager));
                if (log.isBasic()) {
                    // $NON-NLS-1$
                    log.logBasic(BaseMessages.getString(PKG, "PurRepositoryConnector.CreateServiceProvider.End"));
                }
                // need to added them to the service list
                if (allowedActionsContains((AbsSecurityProvider) result.getSecurityProvider(), IAbsSecurityProvider.ADMINISTER_SECURITY_ACTION)) {
                    result.setSecurityManager(new AbsSecurityManager(purRepository, repositoryMeta, result.getUser(), serviceManager));
                    // Set the reference of the security manager to security provider for user role list change event
                    ((PurRepositorySecurityProvider) result.getSecurityProvider()).setUserRoleDelegate(((PurRepositorySecurityManager) result.getSecurityManager()).getUserRoleDelegate());
                    return true;
                }
                return false;
            }
        });
        Future<WebServiceException> repoWebServiceFuture = executor.submit(new Callable<WebServiceException>() {

            @Override
            public WebServiceException call() throws Exception {
                try {
                    IUnifiedRepositoryJaxwsWebService repoWebService = null;
                    if (log.isBasic()) {
                        // $NON-NLS-1$
                        log.logBasic(BaseMessages.getString(PKG, "PurRepositoryConnector.CreateRepositoryWebService.Start"));
                    }
                    repoWebService = // $NON-NLS-1$
                    serviceManager.createService(username, decryptedPassword, IUnifiedRepositoryJaxwsWebService.class);
                    if (log.isBasic()) {
                        // $NON-NLS-1$
                        log.logBasic(BaseMessages.getString(PKG, "PurRepositoryConnector.CreateRepositoryWebService.End"));
                    }
                    if (log.isBasic()) {
                        // $NON-NLS-1$
                        log.logBasic(BaseMessages.getString(PKG, "PurRepositoryConnector.CreateUnifiedRepositoryToWebServiceAdapter.Start"));
                    }
                    result.setUnifiedRepository(new UnifiedRepositoryToWebServiceAdapter(repoWebService));
                } catch (WebServiceException wse) {
                    return wse;
                }
                return null;
            }
        });
        Future<Exception> syncWebserviceFuture = executor.submit(new Callable<Exception>() {

            @Override
            public Exception call() throws Exception {
                try {
                    if (log.isBasic()) {
                        log.logBasic(BaseMessages.getString(PKG, "PurRepositoryConnector.CreateRepositorySyncWebService.Start"));
                    }
                    IRepositorySyncWebService syncWebService = // $NON-NLS-1$
                    serviceManager.createService(username, decryptedPassword, IRepositorySyncWebService.class);
                    if (log.isBasic()) {
                        // $NON-NLS-1$
                        log.logBasic(BaseMessages.getString(PKG, "PurRepositoryConnector.CreateRepositorySyncWebService.Sync"));
                    }
                    syncWebService.sync(repositoryMeta.getName(), repositoryMeta.getRepositoryLocation().getUrl());
                } catch (RepositorySyncException e) {
                    log.logError(e.getMessage(), e);
                    // this message will be presented to the user in spoon
                    result.setConnectMessage(e.getMessage());
                    return null;
                } catch (WebServiceException e) {
                    // if we can speak to the repository okay but not the sync service, assume we're talking to a BA Server
                    log.logError(e.getMessage(), e);
                    return new Exception(BaseMessages.getString(PKG, "PurRepository.BAServerLogin.Message"), e);
                }
                return null;
            }
        });
        Future<String> sessionServiceFuture = executor.submit(new Callable<String>() {

            @Override
            public String call() throws Exception {
                try {
                    if (log.isBasic()) {
                        log.logBasic(BaseMessages.getString(PKG, "PurRepositoryConnector.SessionService.Start"));
                    }
                    CredentialsProvider provider = new BasicCredentialsProvider();
                    UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, decryptedPassword);
                    provider.setCredentials(AuthScope.ANY, credentials);
                    HttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build();
                    HttpGet method = new HttpGet(repositoryMeta.getRepositoryLocation().getUrl() + "/api/session/userName");
                    if (StringUtils.isNotBlank(System.getProperty("pentaho.repository.client.attemptTrust"))) {
                        method.addHeader(TRUST_USER, username);
                    }
                    HttpResponse response = client.execute(method);
                    if (log.isBasic()) {
                        log.logBasic(BaseMessages.getString(PKG, "PurRepositoryConnector.SessionService.Sync"));
                    }
                    return EntityUtils.toString(response.getEntity());
                } catch (Exception e) {
                    if (log.isError()) {
                        log.logError(BaseMessages.getString(PKG, "PurRepositoryConnector.Error.EnableToGetUser"), e);
                    }
                    return null;
                }
            }
        });
        WebServiceException repoException = repoWebServiceFuture.get();
        if (repoException != null) {
            log.logError(repoException.getMessage());
            throw new Exception(BaseMessages.getString(PKG, "PurRepository.FailedLogin.Message"), repoException);
        }
        Exception syncException = syncWebserviceFuture.get();
        if (syncException != null) {
            throw syncException;
        }
        Boolean isAdmin = authorizationWebserviceFuture.get();
        result.getUser().setAdmin(isAdmin);
        String userName = sessionServiceFuture.get();
        if (userName != null) {
            result.getUser().setLogin(userName);
        }
        if (log.isBasic()) {
            log.logBasic(BaseMessages.getString(PKG, "PurRepositoryConnector.RegisterSecurityProvider.Start"));
        }
        purRepositoryServiceRegistry.registerService(RepositorySecurityProvider.class, result.getSecurityProvider());
        purRepositoryServiceRegistry.registerService(IAbsSecurityProvider.class, result.getSecurityProvider());
        if (isAdmin) {
            purRepositoryServiceRegistry.registerService(RepositorySecurityManager.class, result.getSecurityManager());
            purRepositoryServiceRegistry.registerService(IRoleSupportSecurityManager.class, result.getSecurityManager());
            purRepositoryServiceRegistry.registerService(IAbsSecurityManager.class, result.getSecurityManager());
        }
        purRepositoryServiceRegistry.registerService(PurRepositoryRestService.PurRepositoryPluginApiRevision.class, serviceManager.createService(username, decryptedPassword, PurRepositoryRestService.PurRepositoryPluginApiRevision.class));
        purRepositoryServiceRegistry.registerService(IRevisionService.class, new UnifiedRepositoryRevisionService(result.getUnifiedRepository(), rootRef));
        purRepositoryServiceRegistry.registerService(IAclService.class, new UnifiedRepositoryConnectionAclService(result.getUnifiedRepository()));
        purRepositoryServiceRegistry.registerService(IConnectionAclService.class, new UnifiedRepositoryConnectionAclService(result.getUnifiedRepository()));
        purRepositoryServiceRegistry.registerService(ITrashService.class, new UnifiedRepositoryTrashService(result.getUnifiedRepository(), rootRef));
        purRepositoryServiceRegistry.registerService(ILockService.class, new UnifiedRepositoryLockService(result.getUnifiedRepository()));
        if (log.isBasic()) {
            log.logBasic(BaseMessages.getString(PKG, "PurRepositoryConnector.RepositoryServicesRegistered.End"));
        }
        result.setSuccess(true);
    } catch (NullPointerException npe) {
        result.setSuccess(false);
        throw new KettleException(BaseMessages.getString(PKG, "PurRepository.LoginException.Message"));
    } catch (Throwable e) {
        result.setSuccess(false);
        serviceManager.close();
        throw new KettleException(e);
    }
    return result;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) HttpGet(org.apache.http.client.methods.HttpGet) RepositorySyncException(com.pentaho.pdi.ws.RepositorySyncException) IUser(org.pentaho.di.repository.IUser) IAbsSecurityManager(org.pentaho.di.ui.repository.pur.services.IAbsSecurityManager) IRepositorySyncWebService(com.pentaho.pdi.ws.IRepositorySyncWebService) WebServiceException(javax.xml.ws.WebServiceException) EEUserInfo(org.pentaho.di.repository.pur.model.EEUserInfo) HttpResponse(org.apache.http.HttpResponse) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) UnifiedRepositoryToWebServiceAdapter(org.pentaho.platform.repository2.unified.webservices.jaxws.UnifiedRepositoryToWebServiceAdapter) KettleException(org.pentaho.di.core.exception.KettleException) RepositorySyncException(com.pentaho.pdi.ws.RepositorySyncException) WebServiceException(javax.xml.ws.WebServiceException) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) IAbsSecurityProvider(org.pentaho.di.ui.repository.pur.services.IAbsSecurityProvider) HttpClient(org.apache.http.client.HttpClient) ExecutorService(java.util.concurrent.ExecutorService) IUnifiedRepositoryJaxwsWebService(org.pentaho.platform.repository2.unified.webservices.jaxws.IUnifiedRepositoryJaxwsWebService) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository)

Aggregations

IUser (org.pentaho.di.repository.IUser)37 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 ArrayList (java.util.ArrayList)5 IEEUser (org.pentaho.di.repository.pur.model.IEEUser)5 IRoleSupportSecurityManager (org.pentaho.di.ui.repository.pur.services.IRoleSupportSecurityManager)5 EEUserInfo (org.pentaho.di.repository.pur.model.EEUserInfo)3 UserRoleException (org.pentaho.platform.security.userroledao.ws.UserRoleException)3 Calendar (java.util.Calendar)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 HttpResponse (org.apache.http.HttpResponse)2 HttpClient (org.apache.http.client.HttpClient)2 MessageBox (org.eclipse.swt.widgets.MessageBox)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 LastUsedFile (org.pentaho.di.core.LastUsedFile)2 IRole (org.pentaho.di.repository.pur.model.IRole)2 PropsUI (org.pentaho.di.ui.core.PropsUI)2