Example usage for org.apache.commons.vfs.auth StaticUserAuthenticator StaticUserAuthenticator

List of usage examples for org.apache.commons.vfs.auth StaticUserAuthenticator StaticUserAuthenticator

Introduction

In this page you can find the example usage for org.apache.commons.vfs.auth StaticUserAuthenticator StaticUserAuthenticator.

Prototype

public StaticUserAuthenticator(String domain, String username, String password) 

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 ww w .  j a  va2  s .co 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:jfs.sync.vfs.JFSVFSFile.java

/**
 * Creates a new external root file and reads the structure from server.
 * /*w  ww.j  av 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;/*from   ww  w.j  a va  2  s.co m*/
            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();//w w  w. ja va2s.  c o  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  w ww  .j ava  2 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);

    /*//from w ww .ja  va 2  s  .  c  o  m
     * 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   www  .jav 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.S3FileUtil.java

public static FileObject resolveFile(String fileUri, String username, String password)
        throws FileSystemException {
    StaticUserAuthenticator userAuthenticator = new StaticUserAuthenticator(null, username, password);
    return resolveFile(fileUri, userAuthenticator);
}

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

@Test
public void testResolveFile_userAutheticator() throws FileSystemException {
    UserAuthenticator userAuthenticator = new StaticUserAuthenticator(null, awsAccessKey, awsAccessKey);
    FileObject file = S3FileUtil.resolveFile("s3://s3/", userAuthenticator);
    assertTrue(file.exists());/*from www. jav a 2  s.  com*/

    file = S3FileUtil.resolveFile("s3://s3/_this_does_not_exist_", userAuthenticator);
    assertFalse(file.exists());
}