Search in sources :

Example 1 with IUnifiedRepositoryJaxwsWebService

use of org.pentaho.platform.repository2.unified.webservices.jaxws.IUnifiedRepositoryJaxwsWebService 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);
                    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 (ClientTransportException e) {
                    // caused by authentication errors, etc
                    return e;
                } 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, password);
                    provider.setCredentials(AuthScope.ANY, credentials);
                    HttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build();
                    HttpResponse response = client.execute(new HttpGet(repositoryMeta.getRepositoryLocation().getUrl() + "/api/session/userName"));
                    if (log.isBasic()) {
                        // $NON-NLS-1$
                        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 : ClientTransportException(com.sun.xml.ws.client.ClientTransportException) 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) ClientTransportException(com.sun.xml.ws.client.ClientTransportException) 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)

Example 2 with IUnifiedRepositoryJaxwsWebService

use of org.pentaho.platform.repository2.unified.webservices.jaxws.IUnifiedRepositoryJaxwsWebService in project pentaho-platform by pentaho.

the class CommandLineProcessor method getRepository.

/**
 * Why does this return a web service? Going directly to the IUnifiedRepository requires the following:
 * <p/>
 * <ul>
 * <li>PentahoSessionHolder setup including password and tenant ID. (The server doesn't even process passwords today--
 * it assumes that Spring Security processed it. This would require code changes.)</li>
 * <li>User must specify path to Jackrabbit files (i.e. system/jackrabbit).</li>
 * </ul>
 */
protected synchronized IUnifiedRepository getRepository() throws ParseException {
    if (repository != null) {
        return repository;
    }
    // $NON-NLS-1$
    final String NAMESPACE_URI = "http://www.pentaho.org/ws/1.0";
    // $NON-NLS-1$
    final String SERVICE_NAME = "unifiedRepository";
    String urlString = getOptionValue(INFO_OPTION_URL_NAME, true, false).trim();
    if (urlString.endsWith("/")) {
        urlString = urlString.substring(0, urlString.length() - 1);
    }
    urlString = urlString + "/webservices/" + SERVICE_NAME + "?wsdl";
    URL url;
    try {
        url = new URL(urlString);
    } catch (MalformedURLException e) {
        throw new IllegalArgumentException(e);
    }
    Service service = Service.create(url, new QName(NAMESPACE_URI, SERVICE_NAME));
    IUnifiedRepositoryJaxwsWebService port = service.getPort(IUnifiedRepositoryJaxwsWebService.class);
    // http basic authentication
    ((BindingProvider) port).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, getOptionValue(INFO_OPTION_USERNAME_NAME, true, false));
    ((BindingProvider) port).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, getOptionValue(INFO_OPTION_PASSWORD_NAME, true, true));
    // accept cookies to maintain session on server
    ((BindingProvider) port).getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
    // support streaming binary data
    // TODO mlowery this is not portable between JAX-WS implementations
    // (uses com.sun)
    ((BindingProvider) port).getRequestContext().put(JAXWSProperties.HTTP_CLIENT_STREAMING_CHUNK_SIZE, 8192);
    SOAPBinding binding = (SOAPBinding) ((BindingProvider) port).getBinding();
    binding.setMTOMEnabled(true);
    final UnifiedRepositoryToWebServiceAdapter unifiedRepositoryToWebServiceAdapter = new UnifiedRepositoryToWebServiceAdapter(port);
    repository = unifiedRepositoryToWebServiceAdapter;
    return unifiedRepositoryToWebServiceAdapter;
}
Also used : MalformedURLException(java.net.MalformedURLException) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) IUnifiedRepositoryJaxwsWebService(org.pentaho.platform.repository2.unified.webservices.jaxws.IUnifiedRepositoryJaxwsWebService) SOAPBinding(javax.xml.ws.soap.SOAPBinding) IUnifiedRepositoryJaxwsWebService(org.pentaho.platform.repository2.unified.webservices.jaxws.IUnifiedRepositoryJaxwsWebService) UnifiedRepositoryToWebServiceAdapter(org.pentaho.platform.repository2.unified.webservices.jaxws.UnifiedRepositoryToWebServiceAdapter) URL(java.net.URL)

Example 3 with IUnifiedRepositoryJaxwsWebService

use of org.pentaho.platform.repository2.unified.webservices.jaxws.IUnifiedRepositoryJaxwsWebService in project pentaho-kettle by pentaho.

the class RepositoryConfigController method test.

public void test() {
    // build the url handling whether or not the model's url ends wirth a slash
    final String url = // $NON-NLS-1$
    model.getUrl() + (model.getUrl().endsWith("/") ? "" : "/") + "webservices/unifiedRepository?wsdl";
    Service service;
    try {
        // $NON-NLS-1$ //$NON-NLS-2$
        service = Service.create(new URL(url), new QName("http://www.pentaho.org/ws/1.0", "unifiedRepository"));
        if (service != null) {
            IUnifiedRepositoryJaxwsWebService repoWebService = service.getPort(IUnifiedRepositoryJaxwsWebService.class);
            if (repoWebService != null) {
                // $NON-NLS-1$
                messageBox.setTitle(BaseMessages.getString(PurRepositoryDialog.class, "Dialog.Success"));
                // $NON-NLS-1$
                messageBox.setAcceptLabel(BaseMessages.getString(PurRepositoryDialog.class, "Dialog.Ok"));
                messageBox.setMessage(BaseMessages.getString(PurRepositoryDialog.class, // $NON-NLS-1$
                "RepositoryConfigDialog.RepositoryUrlTestPassed"));
                messageBox.open();
            } else {
                // $NON-NLS-1$
                messageBox.setTitle(BaseMessages.getString(PurRepositoryDialog.class, "Dialog.Error"));
                // $NON-NLS-1$
                messageBox.setAcceptLabel(BaseMessages.getString(PurRepositoryDialog.class, "Dialog.Ok"));
                messageBox.setMessage(BaseMessages.getString(PurRepositoryDialog.class, // $NON-NLS-1$
                "RepositoryConfigDialog.RepositoryUrlTestFailed"));
                messageBox.open();
            }
        } else {
            // $NON-NLS-1$
            messageBox.setTitle(BaseMessages.getString(PurRepositoryDialog.class, "Dialog.Error"));
            // $NON-NLS-1$
            messageBox.setAcceptLabel(BaseMessages.getString(PurRepositoryDialog.class, "Dialog.Ok"));
            messageBox.setMessage(BaseMessages.getString(PurRepositoryDialog.class, // $NON-NLS-1$
            "RepositoryConfigDialog.RepositoryUrlTestFailed"));
            messageBox.open();
        }
    } catch (Exception e) {
        // $NON-NLS-1$
        messageBox.setTitle(BaseMessages.getString(PurRepositoryDialog.class, "Dialog.Error"));
        // $NON-NLS-1$
        messageBox.setAcceptLabel(BaseMessages.getString(PurRepositoryDialog.class, "Dialog.Ok"));
        messageBox.setMessage(BaseMessages.getString(PurRepositoryDialog.class, "RepositoryConfigDialog.RepositoryUrlTestFailedMessage", // $NON-NLS-1$
        e.getLocalizedMessage()));
        messageBox.open();
    }
}
Also used : QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) IUnifiedRepositoryJaxwsWebService(org.pentaho.platform.repository2.unified.webservices.jaxws.IUnifiedRepositoryJaxwsWebService) PurRepositoryDialog(org.pentaho.di.ui.repository.pur.PurRepositoryDialog) IUnifiedRepositoryJaxwsWebService(org.pentaho.platform.repository2.unified.webservices.jaxws.IUnifiedRepositoryJaxwsWebService) URL(java.net.URL) IOException(java.io.IOException) ControllerInitializationException(org.pentaho.di.ui.repository.repositoryexplorer.ControllerInitializationException)

Example 4 with IUnifiedRepositoryJaxwsWebService

use of org.pentaho.platform.repository2.unified.webservices.jaxws.IUnifiedRepositoryJaxwsWebService in project pentaho-kettle by pentaho.

the class PurRepository method test.

@Override
public boolean test() {
    String repoUrl = repositoryMeta.getRepositoryLocation().getUrl();
    final String url = repoUrl + (repoUrl.endsWith("/") ? "" : "/") + "webservices/unifiedRepository?wsdl";
    Service service;
    try {
        service = Service.create(new URL(url), new QName("http://www.pentaho.org/ws/1.0", "unifiedRepository"));
        if (service != null) {
            IUnifiedRepositoryJaxwsWebService repoWebService = service.getPort(IUnifiedRepositoryJaxwsWebService.class);
            if (repoWebService != null) {
                return true;
            }
        }
    } catch (Exception e) {
        return false;
    }
    return false;
}
Also used : QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) ILockService(org.pentaho.di.ui.repository.pur.services.ILockService) IUnifiedRepositoryJaxwsWebService(org.pentaho.platform.repository2.unified.webservices.jaxws.IUnifiedRepositoryJaxwsWebService) IAclService(org.pentaho.di.ui.repository.pur.services.IAclService) IRepositoryService(org.pentaho.di.repository.IRepositoryService) IRevisionService(org.pentaho.di.ui.repository.pur.services.IRevisionService) IUnifiedRepositoryJaxwsWebService(org.pentaho.platform.repository2.unified.webservices.jaxws.IUnifiedRepositoryJaxwsWebService) URL(java.net.URL) MetaStoreNamespaceExistsException(org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) UnifiedRepositoryCreateFileException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryCreateFileException) UnifiedRepositoryUpdateFileException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryUpdateFileException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) KettleException(org.pentaho.di.core.exception.KettleException) IdNotFoundException(org.pentaho.di.core.exception.IdNotFoundException) KettleSecurityException(org.pentaho.di.core.exception.KettleSecurityException)

Aggregations

IUnifiedRepositoryJaxwsWebService (org.pentaho.platform.repository2.unified.webservices.jaxws.IUnifiedRepositoryJaxwsWebService)4 URL (java.net.URL)3 QName (javax.xml.namespace.QName)3 Service (javax.xml.ws.Service)3 KettleException (org.pentaho.di.core.exception.KettleException)2 UnifiedRepositoryToWebServiceAdapter (org.pentaho.platform.repository2.unified.webservices.jaxws.UnifiedRepositoryToWebServiceAdapter)2 IRepositorySyncWebService (com.pentaho.pdi.ws.IRepositorySyncWebService)1 RepositorySyncException (com.pentaho.pdi.ws.RepositorySyncException)1 ClientTransportException (com.sun.xml.ws.client.ClientTransportException)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 ExecutorService (java.util.concurrent.ExecutorService)1 WebServiceException (javax.xml.ws.WebServiceException)1 SOAPBinding (javax.xml.ws.soap.SOAPBinding)1 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)1 HttpResponse (org.apache.http.HttpResponse)1 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)1 CredentialsProvider (org.apache.http.client.CredentialsProvider)1 HttpClient (org.apache.http.client.HttpClient)1 HttpGet (org.apache.http.client.methods.HttpGet)1