/** * Returns the login part of this URL, <code>null</code> if there isn't any. * * @return the login part of this URL, <code>null</code> if there isn't any * @see #getCredentials() */ public String getLogin() { return credentials==null?null:credentials.getLogin(); }
@Override public String[] promptKeyboardInteractive(String destination, String name, String instruction, String[] prompt, boolean[] echo) { String[] result = new String[prompt.length]; for (int i=0; i<echo.length; i++) result[i] = echo[i] ? credentials.getLogin() : credentials.getPassword(); return result; } }
private static String getUsername(FileURL url) { Credentials credentials = url.getCredentials(); String username; if(credentials==null||(username=credentials.getLogin()).equals("")) username = getDefaultUsername(); return username; }
/** * Opens and returns a <code>HttpURLConnection</code> to the resource denoted by the specified URL. * If the {@link FileURL} contained by this HTTPFile contains {@link Credentials}, these will be used as credentials * for <i>HTTP Basic Authentication<i>. * * @param url the URL to open * @return a HttpURLConnection to the resource denoted by the specified URL * @throws IOException if the HttpURLConnection could not be opened */ private HttpURLConnection getHttpURLConnection(URL url) throws IOException { // Get URLConnection instance HttpURLConnection conn = (HttpURLConnection)url.openConnection(); // If credentials are contained in this HTTPFile's FileURL, use them for Basic HTTP Authentication Credentials credentials = fileURL.getCredentials(); if(credentials!=null) conn.setRequestProperty( "Authorization", "Basic "+ Base64Encoder.encode(credentials.getLogin()+":"+credentials.getPassword()) ); // Set user-agent header. conn.setRequestProperty("User-Agent", USER_AGENT); return conn; }
sb.append(URLEncoder.encode(credentials.getLogin(), "UTF-8"));
public void comboBoxSelectionChanged(SaneComboBox source) { CredentialsMapping selectedCredentialsMapping = credentialsMappings[loginComboBox.getSelectedIndex()]; Credentials selectedCredentials = selectedCredentialsMapping.getCredentials(); loginField.setText(selectedCredentials.getLogin()); passwordField.setText(selectedCredentials.getPassword()); // Enable/disable 'save credentials' checkbox depending on whether the selected credentials are persistent or not if(saveCredentialsCheckBox!=null) saveCredentialsCheckBox.setSelected(selectedCredentialsMapping.isPersistent()); }
public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if(source == passiveCheckBox) { passiveMode = passiveCheckBox.isSelected(); } else if (source == anonymousCheckBox) { updateValues(); anonymousUser = anonymousCheckBox.isSelected(); if(anonymousUser) { usernameField.setEnabled(false); usernameField.setText(ANONYMOUS_CREDENTIALS.getLogin()); passwordField.setEnabled(false); passwordField.setText(ANONYMOUS_CREDENTIALS.getPassword()); } else { usernameField.setEnabled(true); usernameField.setText(lastUsername); passwordField.setEnabled(true); passwordField.setText(lastPassword); } } }
/** * Updates text fields and buttons' enabled state based on the current selection. Should be called * whenever the list selection has changed. */ private void updateComponents() { String loginValue = null; String passwordValue = null; boolean componentsEnabled = false; if(!credentialsList.isSelectionEmpty() && credentials.size()>0) { componentsEnabled = true; CredentialsMapping credentialsMapping = (CredentialsMapping) credentialsList.getSelectedValue(); Credentials credentials = credentialsMapping.getCredentials(); loginValue = credentials.getLogin(); passwordValue = credentials.getPassword(); } loginField.setText(loginValue); loginField.setEnabled(componentsEnabled); passwordField.setText(passwordValue); passwordField.setEnabled(componentsEnabled); removeButton.setEnabled(componentsEnabled); }
@Override protected FileSystem getHadoopFileSystem(FileURL url) throws IOException { if(!url.containsCredentials()) throw new AuthException(url); // Note: getRealm returns a fresh instance every time FileURL realm = url.getRealm(); // Import credentials Credentials creds = url.getCredentials(); if(creds!=null) { // URL-encode secret as it may contain non URL-safe characters ('+' and '/') realm.setCredentials(new Credentials(creds.getLogin(), URLEncoder.encode(creds.getPassword(), "UTF-8"))); } // Change the scheme to the actual Hadoop fileystem (s3 -> s3n) realm.setScheme("s3n"); return FileSystem.get(URI.create(realm.toString(true, false)), DEFAULT_CONFIGURATION); }
@Override FileURL getServerURL() throws MalformedURLException { updateValues(); if(!lastInitialDir.startsWith("/")) lastInitialDir = "/"+lastInitialDir; FileURL url = FileURL.getFileURL(FileProtocols.FTP+"://"+lastServer+lastInitialDir); if(anonymousUser) url.setCredentials(new Credentials(ANONYMOUS_CREDENTIALS.getLogin(), new String(passwordField.getPassword()))); else url.setCredentials(new Credentials(lastUsername, lastPassword)); // Set port url.setPort(lastPort); // Set passiveMode property to true (default) or false url.setProperty(FTPFile.PASSIVE_MODE_PROPERTY_NAME, ""+passiveMode); // Set FTP encoding property url.setProperty(FTPFile.ENCODING_PROPERTY_NAME, encodingSelectBox.getSelectedEncoding()); // Set connection retry properties url.setProperty(FTPFile.NB_CONNECTION_RETRIES_PROPERTY_NAME, ""+nbRetriesSpinner.getValue()); url.setProperty(FTPFile.CONNECTION_RETRY_DELAY_PROPERTY_NAME, ""+retryDelaySpinner.getValue()); return url; }
session = jsch.getSession(credentials.getLogin(), realm.getHost(), port); session.setUserInfo(new PasswordAuthentication());
/** * Creates and returns a <code>jcifs.smb.SmbFile</code> for the given location. The credentials contained by * the {@link FileURL} (if any) are passed along to the <code>SmbFile</code>. * * @param url the location to the SmbFile file to create * @return an SmbFile corresponding to the given location * @throws MalformedURLException if an error occurred while creating the SmbFile instance */ private static SmbFile createSmbFile(FileURL url) throws MalformedURLException { Credentials credentials = url.getCredentials(); if(credentials==null) return new SmbFile(url.toString(false)); // Extract the domain (if any) from the username String login = credentials.getLogin(); String domain; int domainStart = login.indexOf(";"); if(domainStart!=-1) { domain = login.substring(0, domainStart); login = login.substring(domainStart+1, login.length()); } else { domain = null; } // A NtlmPasswordAuthentication is created from the FileURL credentials and passed to a specific SmbFile constructor. // The reason for doing this rather than using the SmbFile(String) constructor is that SmbFile uses java.net.URL // for the URL parsing which is unable to properly parse urls where the password contains a '@' character, // such as smb://user:p@ssword@host/path . return new SmbFile(url.toString(false), new NtlmPasswordAuthentication(domain, login, credentials.getPassword())); }
public Object getElementAt(int i) { ConnectionHandler connHandler = connections.get(i); // Show login (but not password) in the URL // Note: realm returned by ConnectionHandler does not contain credentials FileURL clonedRealm = (FileURL)connHandler.getRealm().clone(); Credentials loginCredentials = new Credentials(connHandler.getCredentials().getLogin(), ""); clonedRealm.setCredentials(loginCredentials); return clonedRealm.toString(true) +" ("+Translator.get(connHandler.isLocked()?"server_connections_dialog.connection_busy":"server_connections_dialog.connection_idle")+")"; } });
private void initClientIfNeeded() throws RuntimeFaultFaultMsg, InvalidLocaleFaultMsg, InvalidLoginFaultMsg { if (client == null) { client = new VSphereClient(location.getHost(), location .getCredentials().getLogin(), location.getCredentials() .getPassword()); client.connect(); } }
public AbstractFile getFile(FileURL url, Object... instantiationParams) throws IOException { Credentials credentials = url.getCredentials(); if(credentials==null || credentials.getLogin().equals("") || credentials.getPassword().equals("")) throw new AuthException(url); service = new RestS3Service(new AWSCredentials(credentials.getLogin(), credentials.getPassword())); Jets3tProperties props = new Jets3tProperties(); props.setProperty("s3service.s3-endpoint", url.getHost());
guestRadioButton = new JRadioButton(StringUtils.capitalize(guestCredentials.getLogin())); guestRadioButton.addActionListener(this); compPanel.addRow(Translator.get("auth_dialog.connect_as"), guestRadioButton, 0); loginComboBox.addItem(credentialsMappings[i].getCredentials().getLogin()); loginField.setText(selectedCredentials.getLogin()); passwordField.setText(selectedCredentials.getPassword());
usernameField = new JTextField(anonymousUser?ANONYMOUS_CREDENTIALS.getLogin():lastUsername); usernameField.selectAll(); usernameField.setEditable(!anonymousUser);
/** * Ensure that non URL-safe characters in login and password parts are properly handled, both when parsing * and representing URLs as string. * * @throws MalformedURLException should not happen */ @Test public void testCredentialsURLEncoding() throws MalformedURLException { FileURL url = getRootURL(); String urlDecodedString = ":@&=+$,/?t%#[]"; String urlEncodedString = "%3A%40%26%3D%2B%24%2C%2F%3Ft%25%23%5B%5D"; url.setCredentials(new Credentials(urlDecodedString, urlDecodedString)); String urlRep = url.getScheme()+"://"+urlEncodedString+":"+urlEncodedString+"@"; assert urlRep.equals(url.toString(true, false)); url = FileURL.getFileURL(urlRep); Credentials credentials = url.getCredentials(); assert credentials.getLogin().equals(urlDecodedString); assert credentials.getPassword().equals(urlDecodedString); }
ftpClient.login(credentials.getLogin(), credentials.getPassword());
out.writeCData(credentials.getLogin()); out.endElement(ELEMENT_LOGIN);