Example usage for java.net URI getUserInfo

List of usage examples for java.net URI getUserInfo

Introduction

In this page you can find the example usage for java.net URI getUserInfo.

Prototype

public String getUserInfo() 

Source Link

Document

Returns the decoded user-information component of this URI.

Usage

From source file:org.apache.syncope.core.provisioning.java.ConnIdBundleManagerImpl.java

private void initRemote(final URI location) {
    // 1. Extract conf params for remote connection from given URI
    String host = location.getHost();
    int port = location.getPort();
    GuardedString key = new GuardedString(location.getUserInfo().toCharArray());
    boolean useSSL = location.getScheme().equals("connids");

    List<TrustManager> trustManagers = new ArrayList<>();
    String[] params = StringUtils.isBlank(location.getQuery()) ? null : location.getQuery().split("&");
    if (params != null && params.length > 0) {
        final String[] trustAllCerts = params[0].split("=");
        if (trustAllCerts != null && trustAllCerts.length > 1
                && "trustAllCerts".equalsIgnoreCase(trustAllCerts[0])
                && "true".equalsIgnoreCase(trustAllCerts[1])) {

            trustManagers.add(new X509TrustManager() {

                @Override//  ww  w.  ja  va 2  s .c o  m
                public void checkClientTrusted(final X509Certificate[] chain, final String authType)
                        throws CertificateException {
                    // no checks, trust all
                }

                @Override
                public void checkServerTrusted(final X509Certificate[] chain, final String authType)
                        throws CertificateException {
                    // no checks, trust all
                }

                @Override
                public X509Certificate[] getAcceptedIssuers() {
                    return null;
                }
            });
        }
    }

    LOG.debug(
            "Configuring remote connector server:" + "\n\tHost: {}" + "\n\tPort: {}" + "\n\tKey: {}"
                    + "\n\tUseSSL: {}" + "\n\tTrustAllCerts: {}",
            host, port, key, useSSL, !trustManagers.isEmpty());

    RemoteFrameworkConnectionInfo info = new RemoteFrameworkConnectionInfo(host, port, key, useSSL,
            trustManagers, 60 * 1000);
    LOG.debug("Remote connection info: {}", info);

    // 2. Get connector info manager
    ConnectorInfoManager manager = ConnectorInfoManagerFactory.getInstance().getRemoteManager(info);
    if (manager == null) {
        throw new NotFoundException("Remote ConnectorInfoManager");
    }

    connInfoManagers.put(location, manager);
}

From source file:org.apache.stratos.integration.common.extensions.StratosServerExtension.java

private int startActiveMQServer() throws AutomationFrameworkException {
    try {/*  w w w.  j av a2 s  . c om*/
        String activemqBindAddress = getParameters().get(Util.ACTIVEMQ_BIND_ADDRESS);
        if (activemqBindAddress == null) {
            throw new AutomationFrameworkException("ActiveMQ bind address not found in automation.xml");
        }
        URI givenURI = new URI(activemqBindAddress);
        int initAMQPort = givenURI.getPort();
        // dynamically pick an open port starting from initial port given in automation.xml
        while (!Util.isPortAvailable(initAMQPort)) {
            initAMQPort++;
        }
        URI dynamicURL = new URI(givenURI.getScheme(), givenURI.getUserInfo(), givenURI.getHost(), initAMQPort,
                givenURI.getPath(), givenURI.getQuery(), givenURI.getFragment());
        long time1 = System.currentTimeMillis();
        log.info("Starting ActiveMQ with dynamic bind address: " + dynamicURL.toString());
        broker.setDataDirectory(StratosServerExtension.class.getResource(File.separator).getPath()
                + File.separator + ".." + File.separator + "activemq-data");
        broker.setBrokerName("testBroker");
        broker.addConnector(dynamicURL.toString());
        broker.start();
        long time2 = System.currentTimeMillis();
        log.info(String.format("ActiveMQ started in %d sec", (time2 - time1) / 1000));
        return initAMQPort;
    } catch (Exception e) {
        throw new AutomationFrameworkException("Could not start ActiveMQ", e);
    }
}

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

/**
 * Creates a new external root file and reads the structure from server.
 * /*  w  w  w  .  jav 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:org.eclipse.orion.server.git.objects.Status.java

private URI statusToIndexLocation(URI u) throws URISyntaxException {
    String uriPath = u.getPath();
    String prefix = uriPath.substring(0, uriPath.indexOf(GitServlet.GIT_URI));
    uriPath = uriPath.substring(prefix.length() + (GitServlet.GIT_URI + '/' + Status.RESOURCE).length());
    uriPath = prefix + GitServlet.GIT_URI + '/' + Index.RESOURCE + uriPath;
    return new URI(u.getScheme(), u.getUserInfo(), u.getHost(), u.getPort(), uriPath, u.getQuery(),
            u.getFragment());//  ww  w  .  j a va  2  s .co m
}

From source file:io.druid.cli.PullDependencies.java

private DefaultTeslaAether getAetherClient() {
    /*/*from w  ww .ja  v a 2 s.c  o  m*/
    DefaultTeslaAether logs a bunch of stuff to System.out, which is annoying.  We choose to disable that
    unless debug logging is turned on.  "Disabling" it, however, is kinda bass-ackwards.  We copy out a reference
    to the current System.out, and set System.out to a noop output stream.  Then after DefaultTeslaAether has pulled
    The reference we swap things back.
            
    This has implications for other things that are running in parallel to this.  Namely, if anything else also grabs
    a reference to System.out or tries to log to it while we have things adjusted like this, then they will also log
    to nothingness.  Fortunately, the code that calls this is single-threaded and shouldn't hopefully be running
    alongside anything else that's grabbing System.out.  But who knows.
    */

    final List<String> remoteUriList = Lists.newArrayList();
    if (!noDefaultRemoteRepositories) {
        remoteUriList.addAll(DEFAULT_REMOTE_REPOSITORIES);
    }
    remoteUriList.addAll(remoteRepositories);

    List<Repository> remoteRepositories = Lists.newArrayList();
    for (String uri : remoteUriList) {
        try {
            URI u = new URI(uri);
            Repository r = new Repository(uri);

            if (u.getUserInfo() != null) {
                String[] auth = u.getUserInfo().split(":", 2);
                if (auth.length == 2) {
                    r.setUsername(auth[0]);
                    r.setPassword(auth[1]);
                } else {
                    log.warn(
                            "Invalid credentials in repository URI, expecting [<user>:<password>], got [%s] for [%s]",
                            u.getUserInfo(), uri);
                }
            }
            remoteRepositories.add(r);
        } catch (URISyntaxException e) {
            throw Throwables.propagate(e);
        }
    }

    if (log.isTraceEnabled() || log.isDebugEnabled()) {
        return new DefaultTeslaAether(localRepository,
                remoteRepositories.toArray(new Repository[remoteRepositories.size()]));
    }

    PrintStream oldOut = System.out;
    try {
        System.setOut(new PrintStream(new OutputStream() {
            @Override
            public void write(int b) throws IOException {

            }

            @Override
            public void write(byte[] b) throws IOException {

            }

            @Override
            public void write(byte[] b, int off, int len) throws IOException {

            }
        }, false, StringUtils.UTF8_STRING));
        return new DefaultTeslaAether(localRepository,
                remoteRepositories.toArray(new Repository[remoteRepositories.size()]));
    } catch (UnsupportedEncodingException e) {
        // should never happen
        throw new IllegalStateException(e);
    } finally {
        System.setOut(oldOut);
    }
}

From source file:de.tiqsolutions.hdfs.HadoopFileSystemProvider.java

private String getURIKey(URI uri) {
    String s = String.format("%s://%s@%s:%d", getScheme(), uri.getUserInfo() == null ? "" : uri.getUserInfo(),
            uri.getHost(), uri.getPort());
    try {/*w w  w  . j av  a  2s .c o m*/
        MessageDigest cript = MessageDigest.getInstance("SHA-1");
        cript.reset();
        cript.update(s.getBytes("utf8"));
        return new HexBinaryAdapter().marshal(cript.digest());
    } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
    }
    return null;

}

From source file:org.eclipse.orion.server.git.objects.Status.java

private URI statusToCommitLocation(URI u, String ref) throws URISyntaxException {
    String uriPath = u.getPath();
    String prefix = uriPath.substring(0, uriPath.indexOf(GitServlet.GIT_URI));
    uriPath = uriPath.substring(prefix.length() + (GitServlet.GIT_URI + '/' + Status.RESOURCE).length());
    uriPath = prefix + GitServlet.GIT_URI + '/' + Commit.RESOURCE + '/' + ref + uriPath;
    return new URI(u.getScheme(), u.getUserInfo(), u.getHost(), u.getPort(), uriPath, u.getQuery(),
            u.getFragment());/*from  w ww  . j a  v  a  2  s.  com*/
}

From source file:org.eclipse.orion.server.git.objects.Status.java

private URI statusToDiffLocation(URI u, String diffType) throws URISyntaxException {
    String uriPath = u.getPath();
    String prefix = uriPath.substring(0, uriPath.indexOf(GitServlet.GIT_URI));
    uriPath = uriPath.substring(prefix.length() + (GitServlet.GIT_URI + '/' + Status.RESOURCE).length());
    uriPath = prefix + GitServlet.GIT_URI + '/' + Diff.RESOURCE + '/' + diffType + uriPath;
    return new URI(u.getScheme(), u.getUserInfo(), u.getHost(), u.getPort(), uriPath, u.getQuery(),
            u.getFragment());//from  w w  w  .j av a 2s  . c om
}

From source file:org.apache.druid.cli.PullDependencies.java

@SuppressForbidden(reason = "System#out")
private DefaultTeslaAether getAetherClient() {
    /*//ww w  .ja  v a 2 s. c o  m
    DefaultTeslaAether logs a bunch of stuff to System.out, which is annoying.  We choose to disable that
    unless debug logging is turned on.  "Disabling" it, however, is kinda bass-ackwards.  We copy out a reference
    to the current System.out, and set System.out to a noop output stream.  Then after DefaultTeslaAether has pulled
    The reference we swap things back.
            
    This has implications for other things that are running in parallel to this.  Namely, if anything else also grabs
    a reference to System.out or tries to log to it while we have things adjusted like this, then they will also log
    to nothingness.  Fortunately, the code that calls this is single-threaded and shouldn't hopefully be running
    alongside anything else that's grabbing System.out.  But who knows.
    */

    final List<String> remoteUriList = Lists.newArrayList();
    if (!noDefaultRemoteRepositories) {
        remoteUriList.addAll(DEFAULT_REMOTE_REPOSITORIES);
    }
    remoteUriList.addAll(remoteRepositories);

    List<Repository> remoteRepositories = Lists.newArrayList();
    for (String uri : remoteUriList) {
        try {
            URI u = new URI(uri);
            Repository r = new Repository(uri);

            if (u.getUserInfo() != null) {
                String[] auth = u.getUserInfo().split(":", 2);
                if (auth.length == 2) {
                    r.setUsername(auth[0]);
                    r.setPassword(auth[1]);
                } else {
                    log.warn(
                            "Invalid credentials in repository URI, expecting [<user>:<password>], got [%s] for [%s]",
                            u.getUserInfo(), uri);
                }
            }
            remoteRepositories.add(r);
        } catch (URISyntaxException e) {
            throw Throwables.propagate(e);
        }
    }

    if (log.isTraceEnabled() || log.isDebugEnabled()) {
        return createTeslaAether(remoteRepositories);
    }

    PrintStream oldOut = System.out;
    try {
        System.setOut(new PrintStream(new OutputStream() {
            @Override
            public void write(int b) {

            }

            @Override
            public void write(byte[] b) {

            }

            @Override
            public void write(byte[] b, int off, int len) {

            }
        }, false, StringUtils.UTF8_STRING));
        return createTeslaAether(remoteRepositories);
    } catch (UnsupportedEncodingException e) {
        // should never happen
        throw new IllegalStateException(e);
    } finally {
        System.setOut(oldOut);
    }
}

From source file:org.eclipse.orion.server.tests.servlets.git.GitRemoteTest.java

@Test
public void testGetUnknownRemote() throws Exception {
    // clone a  repo
    URI workspaceLocation = createWorkspace(getMethodName());
    String workspaceId = workspaceIdFromLocation(workspaceLocation);
    JSONObject project = createProjectOrLink(workspaceLocation, getMethodName(), null);
    IPath clonePath = getClonePath(workspaceId, project);
    clone(clonePath);/*from  w  ww.  j av a 2 s.c o  m*/

    // get project metadata
    WebRequest request = getGetRequest(project.getString(ProtocolConstants.KEY_CONTENT_LOCATION));
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    project = new JSONObject(response.getText());
    JSONObject gitSection = project.optJSONObject(GitConstants.KEY_GIT);
    assertNotNull(gitSection);
    String gitRemoteUri = gitSection.getString(GitConstants.KEY_REMOTE);

    request = getGetGitRemoteRequest(gitRemoteUri);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    JSONObject remotes = new JSONObject(response.getText());
    JSONArray remotesArray = remotes.getJSONArray(ProtocolConstants.KEY_CHILDREN);
    assertEquals(1, remotesArray.length());
    JSONObject remote = remotesArray.getJSONObject(0);
    assertNotNull(remote);
    String remoteLocation = remote.getString(ProtocolConstants.KEY_LOCATION);
    assertNotNull(remoteLocation);

    URI u = URI.create(toRelativeURI(remoteLocation));
    IPath p = new Path(u.getPath());
    p = p.uptoSegment(2).append("xxx").append(p.removeFirstSegments(3));
    URI nu = new URI(u.getScheme(), u.getUserInfo(), u.getHost(), u.getPort(), p.toString(), u.getQuery(),
            u.getFragment());

    request = getGetGitRemoteRequest(nu.toString());
    response = webConversation.getResponse(request);
    ServerStatus status = waitForTask(response);
    assertEquals(status.toString(), status.getHttpCode(), HttpURLConnection.HTTP_NOT_FOUND);

    p = new Path(u.getPath());
    p = p.uptoSegment(3).append("xxx").append(p.removeFirstSegments(3));
    nu = new URI(u.getScheme(), u.getUserInfo(), u.getHost(), u.getPort(), p.toString(), u.getQuery(),
            u.getFragment());

    request = getGetGitRemoteRequest(nu.toString());
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_NOT_FOUND, response.getResponseCode());
}