Example usage for org.apache.commons.vfs.impl DefaultFileSystemConfigBuilder getInstance

List of usage examples for org.apache.commons.vfs.impl DefaultFileSystemConfigBuilder getInstance

Introduction

In this page you can find the example usage for org.apache.commons.vfs.impl DefaultFileSystemConfigBuilder getInstance.

Prototype

public static DefaultFileSystemConfigBuilder getInstance() 

Source Link

Usage

From source file:com.thinkberg.webdav.servlet.MoxoWebDAVServlet.java

public void init(ServletConfig servletConfig) throws ServletException {
    super.init(servletConfig);
    String rootUri = servletConfig.getInitParameter("vfs.uri");
    String authDomain = servletConfig.getInitParameter("vfs.auth.domain");
    String authUser = servletConfig.getInitParameter("vfs.auth.user");
    String authPass = servletConfig.getInitParameter("vfs.auth.password");
    try {//from   w  ww.j a  va  2  s  . c om
        StaticUserAuthenticator userAuthenticator = new StaticUserAuthenticator(authDomain, authUser, authPass);
        FileSystemOptions options = new FileSystemOptions();
        DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(options, userAuthenticator);

        VFSBackend.initialize(rootUri, options);
    } catch (FileSystemException e) {
        LOG.error(String.format("can't create file system backend for '%s'", rootUri));
    }
}

From source file:jfs.sync.vfs.JFSVFSFile.java

/**
 * Creates a new external root file and reads the structure from server.
 * // w  w  w .  ja v  a  2  s. c o m
 * @param fileProducer
 *            The assigned file producer.
 */
public JFSVFSFile(JFSVFSFileProducer fileProducer) {
    super(fileProducer, "");
    try {
        FileSystemOptions opts = new FileSystemOptions();

        // Avoid using known hosts file if SFTP is used:
        if (fileProducer.getScheme().equals("sftp")) {
            SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no");
        }

        // Get user name and password, if not specified:
        try {
            URI uriObject = new URI(fileProducer.getUri());
            String userInfo = uriObject.getUserInfo();
            if (userInfo == null || !userInfo.contains(":")) {
                JFSUserAuthentication userAuth = JFSUserAuthentication.getInstance();
                userAuth.setResource(fileProducer.getUri());
                JFSUserAuthenticationInterface userInterface = userAuth.getUserInterface();

                StaticUserAuthenticator auth = new StaticUserAuthenticator(null, userInterface.getUserName(),
                        userInterface.getPassword());
                DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);
            }
        } catch (URISyntaxException e) {
            JFSLog.getErr().getStream().println(e.getLocalizedMessage());
        }

        file = VFS.getManager().resolveFile(fileProducer.getUri(), opts);
    } catch (FileSystemException e) {
        JFSLog.getErr().getStream().println(e.getLocalizedMessage());
    }
}

From source file:com.naryx.tagfusion.cfm.file.vfs.cfVFSData.java

private void setFileObject(String fileUrl) throws Exception {

    // Check to see if this is a native file
    boolean bFoundScheme = false;
    String[] schemes = VFS.getManager().getSchemes();
    for (int x = 0; x < schemes.length; x++) {
        if (fileUrl.startsWith(schemes[x] + "://")) {
            bFoundScheme = true;//  ww  w .  ja  v  a  2 s .com
            break;
        }
    }

    if (!bFoundScheme) {
        file = new File(fileUrl);
        return;
    }

    if (fileUrl.toLowerCase().startsWith("s3://")) {
        /* This is an S3 object, so we pull out the details here */
        int c1 = fileUrl.indexOf("@");
        if (c1 == -1)
            throw new Exception(
                    "provider S3 authentication 's3://[accesskey]@[secretkey]/[bucket]' or 's3://@[datasource]/[bucket]'");

        int c2 = fileUrl.indexOf("/", c1 + 1);

        String accessKey = fileUrl.substring(5, c1);
        String secretKey = fileUrl.substring(c1 + 1, c2);
        String domain = null;

        if (accessKey.length() == 0) {
            //This is an Amazon datasource format
            org.alanwilliamson.amazon.AmazonKey amazonKey = org.alanwilliamson.amazon.AmazonKeyFactory
                    .getDS(secretKey);
            if (amazonKey == null)
                throw new Exception("The Amazon Datasource [" + secretKey
                        + "] has not been registered; use AmazonRegisterDataSource()");

            accessKey = amazonKey.getKey();
            secretKey = amazonKey.getSecret();
            domain = amazonKey.getS3Host();
        } else
            domain = "http://s3.amazonaws.com/";

        fileUrl = "s3://" + fileUrl.substring(c2);

        FileSystemOptions opts = new FileSystemOptions();
        DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts,
                new StaticUserAuthenticator(domain, accessKey, secretKey));

        this.fileUrl = fileUrl;

        fileObject = VFS.getManager().resolveFile(this.fileUrl, opts).resolveFile(null);
    } else {
        this.fileUrl = fileUrl;
        fileObject = VFS.getManager().resolveFile(this.fileUrl);
    }
}

From source file:egovframework.rte.fdl.filehandling.FilehandlingServiceTest.java

@Test
public void testUserAuthentication() throws Exception {
    StaticUserAuthenticator auth = new StaticUserAuthenticator(null, "username", "password");
    FileSystemOptions opts = new FileSystemOptions();
    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);

    FileSystemManager manager = VFS.getManager();

    FileObject baseDir = manager.resolveFile(System.getProperty("user.dir"));
    FileObject file = manager.resolveFile(baseDir, "testfolder/file1.txt");
    FileObject fo = manager.resolveFile("d:" + file.getName().getPath(), opts);

    fo.createFile();//  ww  w. jav a 2s . co m

}

From source file:org.efaps.webdav4vfs.WebDAVServlet.java

@Override()
public void init(final ServletConfig servletConfig) throws ServletException {
    super.init(servletConfig);
    String rootUri = servletConfig.getInitParameter("vfs.uri");
    String authDomain = servletConfig.getInitParameter("vfs.auth.domain");
    String authUser = servletConfig.getInitParameter("vfs.auth.user");
    String authPass = servletConfig.getInitParameter("vfs.auth.password");
    try {//from  ww  w .ja v a2  s.  c  o m
        StaticUserAuthenticator userAuthenticator = new StaticUserAuthenticator(authDomain, authUser, authPass);
        FileSystemOptions options = new FileSystemOptions();
        DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(options, userAuthenticator);

        VFSBackend.initialize(rootUri, options);
    } catch (FileSystemException e) {
        LOG.error(String.format("can't create file system backend for '%s'", rootUri));
    }
}

From source file:org.pentaho.amazon.emr.ui.AmazonElasticMapReduceJobExecutorDialog.java

public AmazonElasticMapReduceJobExecutorDialog(Shell parent, JobEntryInterface jobEntry, Repository rep,
        JobMeta jobMeta) throws XulException, DocumentException {
    super(parent, jobEntry, rep, jobMeta);

    /*/*w  w w  .j av  a 2  s.  com*/
     * final BindingConvertor<String, Integer> bindingConverter = new BindingConvertor<String, Integer>() {
     * 
     * public Integer sourceToTarget(String value) { return Integer.parseInt(value); }
     * 
     * public String targetToSource(Integer value) { return value.toString(); }
     * 
     * };
     */

    this.jobEntry = (AmazonElasticMapReduceJobExecutor) jobEntry;

    SwtXulLoader swtXulLoader = new SwtXulLoader();
    swtXulLoader.registerClassLoader(getClass().getClassLoader());
    swtXulLoader.register("VARIABLETEXTBOX", "org.pentaho.di.ui.core.database.dialog.tags.ExtTextbox");
    swtXulLoader.setOuterContext(shell);

    container = swtXulLoader.loadXul("org/pentaho/amazon/emr/ui/AmazonElasticMapReduceJobExecutorDialog.xul", //$NON-NLS-1$
            bundle);

    final XulRunner runner = new SwtXulRunner();
    runner.addContainer(container);

    container.addEventHandler(controller);

    bf = new DefaultBindingFactory();
    bf.setDocument(container.getDocumentRoot());
    bf.setBindingType(Type.BI_DIRECTIONAL);

    bf.createBinding("jobentry-name", "value", controller, //$NON-NLS-1$//$NON-NLS-2$
            AmazonElasticMapReduceJobExecutorController.JOB_ENTRY_NAME); //$NON-NLS-3$
    bf.createBinding("jobentry-hadoopjob-name", "value", controller, //$NON-NLS-1$//$NON-NLS-2$
            AmazonElasticMapReduceJobExecutorController.HADOOP_JOB_NAME); //$NON-NLS-3$
    bf.createBinding("jobentry-hadoopjob-flow-id", "value", controller, //$NON-NLS-1$//$NON-NLS-2$
            AmazonElasticMapReduceJobExecutorController.HADOOP_JOB_FLOW_ID); //$NON-NLS-3$
    bf.createBinding("jar-url", "value", controller, AmazonElasticMapReduceJobExecutorController.JAR_URL); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    bf.createBinding("access-key", "value", controller, AmazonElasticMapReduceJobExecutorController.ACCESS_KEY); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    bf.createBinding("secret-key", "value", controller, AmazonElasticMapReduceJobExecutorController.SECRET_KEY); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    BindingConvertor<String, FileObject> stagingDirBinding = new BindingConvertor<String, FileObject>() {

        @Override
        public FileObject sourceToTarget(String s) {
            // resolve the file
            try {
                VariableSpace vs = controller.getVariableSpace();
                FileSystemOptions opts = new FileSystemOptions();
                DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts,
                        new StaticUserAuthenticator(null, controller.getAccessKey(),
                                controller.getSecretKey()));
                FileObject file = KettleVFS.getFileObject(s, vs, opts);
                return file;
            } catch (FileSystemException e) {
                return null;
            } catch (KettleFileException e) {
                return null;
            }
        }

        @Override
        public String targetToSource(FileObject fileObject) {
            return fileObject.getName().getURI();
        }
    };

    bf.createBinding("s3-staging-directory", "value", controller, //$NON-NLS-1$//$NON-NLS-2$
            AmazonElasticMapReduceJobExecutorController.STAGING_DIR); //$NON-NLS-3$

    bf.setBindingType(Type.ONE_WAY);
    bf.createBinding("s3-staging-directory", "value", controller, //$NON-NLS-1$//$NON-NLS-2$
            AmazonElasticMapReduceJobExecutorController.STAGING_DIR_FILE, stagingDirBinding); //$NON-NLS-3$

    bf.setBindingType(Type.BI_DIRECTIONAL);
    //    bf.createBinding("num-instances", "value", controller, AmazonElasticMapReduceJobExecutorController.NUM_INSTANCES, bindingConverter); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    bf.createBinding("num-instances", "value", controller, //$NON-NLS-1$//$NON-NLS-2$
            AmazonElasticMapReduceJobExecutorController.NUM_INSTANCES); //$NON-NLS-3$
    bf.createBinding("master-instance-type", "selectedItem", controller, //$NON-NLS-1$//$NON-NLS-2$
            AmazonElasticMapReduceJobExecutorController.MASTER_INSTANCE_TYPE); //$NON-NLS-3$
    bf.createBinding("slave-instance-type", "selectedItem", controller, //$NON-NLS-1$//$NON-NLS-2$
            AmazonElasticMapReduceJobExecutorController.SLAVE_INSTANCE_TYPE); //$NON-NLS-3$

    bf.createBinding("command-line-arguments", "value", controller, //$NON-NLS-1$//$NON-NLS-2$
            AmazonElasticMapReduceJobExecutorController.CMD_LINE_ARGS); //$NON-NLS-3$

    XulTextbox numInstances = (XulTextbox) container.getDocumentRoot().getElementById("num-instances");
    numInstances.setValue("" + controller.getNumInstances());

    XulMenuList<String> masterInstanceType = (XulMenuList<String>) container.getDocumentRoot()
            .getElementById("master-instance-type");
    masterInstanceType.setSelectedItem("" + controller.getMasterInstanceType());

    XulMenuList<String> slaveInstanceType = (XulMenuList<String>) container.getDocumentRoot()
            .getElementById("slave-instance-type");
    slaveInstanceType.setSelectedItem("" + controller.getSlaveInstanceType());

    bf.createBinding("blocking", "selected", controller, AmazonElasticMapReduceJobExecutorController.BLOCKING); //$NON-NLS-1$ //$NON-NLS-2$ 
    //    bf.createBinding("logging-interval", "value", controller, AmazonElasticMapReduceJobExecutorController.LOGGING_INTERVAL, bindingConverter); //$NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding("logging-interval", "value", controller, //$NON-NLS-1$//$NON-NLS-2$
            AmazonElasticMapReduceJobExecutorController.LOGGING_INTERVAL);

    XulTextbox loggingInterval = (XulTextbox) container.getDocumentRoot().getElementById("logging-interval");
    loggingInterval.setValue("" + controller.getLoggingInterval());

    ExtTextbox tempBox = (ExtTextbox) container.getDocumentRoot().getElementById("access-key");
    tempBox.setVariableSpace(controller.getVariableSpace());
    tempBox = (ExtTextbox) container.getDocumentRoot().getElementById("secret-key");
    tempBox.setVariableSpace(controller.getVariableSpace());
    tempBox = (ExtTextbox) container.getDocumentRoot().getElementById("jobentry-hadoopjob-name");
    tempBox.setVariableSpace(controller.getVariableSpace());
    tempBox = (ExtTextbox) container.getDocumentRoot().getElementById("jobentry-hadoopjob-flow-id");
    tempBox.setVariableSpace(controller.getVariableSpace());
    tempBox = (ExtTextbox) container.getDocumentRoot().getElementById("s3-staging-directory");
    tempBox.setVariableSpace(controller.getVariableSpace());
    tempBox = (ExtTextbox) container.getDocumentRoot().getElementById("jar-url");
    tempBox.setVariableSpace(controller.getVariableSpace());
    tempBox = (ExtTextbox) container.getDocumentRoot().getElementById("command-line-arguments");
    tempBox.setVariableSpace(controller.getVariableSpace());
    tempBox = (ExtTextbox) container.getDocumentRoot().getElementById("num-instances");
    tempBox.setVariableSpace(controller.getVariableSpace());
    tempBox = (ExtTextbox) container.getDocumentRoot().getElementById("logging-interval");
    tempBox.setVariableSpace(controller.getVariableSpace());

    bf.setBindingType(Type.BI_DIRECTIONAL);

    controller.setJobEntry((AmazonElasticMapReduceJobExecutor) jobEntry);
    controller.init();
}

From source file:org.pentaho.amazon.s3.S3FileOutput.java

protected FileSystemOptions createFileSystemOptions() throws KettleFileException {
    try {/*from w  w w .j av a  2  s . c o  m*/
        FileSystemOptions opts = new FileSystemOptions();
        S3FileOutputMeta s3Meta = (S3FileOutputMeta) meta;
        DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts,
                new StaticUserAuthenticator(null,
                        Encr.decryptPasswordOptionallyEncrypted(environmentSubstitute(s3Meta.getAccessKey())),
                        Encr.decryptPasswordOptionallyEncrypted(environmentSubstitute(s3Meta.getSecretKey()))));
        return opts;
    } catch (FileSystemException e) {
        throw new KettleFileException(e);
    }
}

From source file:org.pentaho.s3.vfs.S3FileSystem.java

public S3Service getS3Service() {
    if (service == null || service.getProviderCredentials() == null
            || service.getProviderCredentials().getAccessKey() == null) {

        UserAuthenticator userAuthenticator = DefaultFileSystemConfigBuilder.getInstance()
                .getUserAuthenticator(getFileSystemOptions());

        String awsAccessKey = null;
        String awsSecretKey = null;

        if (userAuthenticator != null) {
            UserAuthenticationData data = userAuthenticator
                    .requestAuthentication(S3FileProvider.AUTHENTICATOR_TYPES);
            awsAccessKey = String.valueOf(data.getData(UserAuthenticationData.USERNAME));
            awsSecretKey = String.valueOf(data.getData(UserAuthenticationData.PASSWORD));
        } else {//ww w . jav  a2s .  c  om
            awsAccessKey = ((URLFileName) getRootName()).getUserName();
            awsSecretKey = ((URLFileName) getRootName()).getPassword();
        }
        ProviderCredentials awsCredentials = new AWSCredentials(awsAccessKey, awsSecretKey);
        try {
            service = new RestS3Service(awsCredentials);
        } catch (Throwable t) {
            System.out.println("Could not getS3Service() for " + awsCredentials.getLogString());
            t.printStackTrace();
        }
    }
    return service;
}

From source file:org.pentaho.s3.vfs.S3FileUtil.java

public static FileObject resolveFile(String fileUri, UserAuthenticator userAuthenticator)
        throws FileSystemException {
    FileSystemOptions opts = null;//from w  w  w . jav a 2  s . com
    if (VFS.getManager().getBaseFile() != null) {
        opts = VFS.getManager().getBaseFile().getFileSystem().getFileSystemOptions();
    }
    if (opts == null) {
        opts = new FileSystemOptions();
    }
    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, userAuthenticator);
    FileObject file = resolveFile(fileUri, opts);
    return file;
}