## org.das2.util.filesystem.KeyChain

class that contains the credentials for websites. This is first introduced so that ftp://papco:@mrfrench.lanl.gov/ and subdirectories would just ask for credentials once. Also, this allows all the sensitive information to be stored in one class. https://datatracker.ietf.org/doc/html/rfc7617 talks about how this should be done. Presently this is done by URL and not the realm. TODO: This needs to be redone so that the keys are stored by realm as well, and once a directory is left a 401 and resending of the realm will be needed before the key is sent again.

## KeyChain( )

## addCookie

addCookie( String url, String cookie ) → void

Add a cookie for the URL. This was added as a work-around to provide access to the MMS data server at LASP.

### Parameters

url - a String
cookie - a String

### Returns:

void (returns nothing)
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## checkUserInfo

checkUserInfo( java.net.URL url ) → String

return null or the stored user info. This allows clients to attempt to use stored user info without bothering the scientist if the info isn't needed.

### Parameters

url - the URL

### Returns:

the user info (user:password) associated, or null if the user info isn't found.
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## clearAll

clearAll( ) → void

clear all passwords.

### Returns:

void (returns nothing)
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## clearUserPassword

clearUserPassword( java.net.URI uri ) → void

### Parameters

uri - an URI

### Returns:

void (returns nothing)
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## clearUserPassword

clearUserPassword( java.net.URL url ) → void

remove the password from the list of known passwords. This was introduced because we needed to clear a bad password in FTP.

### Parameters

url - an URL

### Returns:

void (returns nothing)
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## getDefault

getDefault( ) → org.das2.util.filesystem.KeyChain

get the single instance of the class.

### Returns:

the single instance of the class.
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## getInstance

getInstance( String name ) → org.das2.util.filesystem.KeyChain

get the instance for this name. This is added to support future applications, such as servlets, where multiple users are using the same process.

### Parameters

name - a String

### Returns:

an org.das2.util.filesystem.KeyChain
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## getUserInfo

getUserInfo( java.net.URI uri ) → String

get the user credentials, maybe throwing CancelledOperationException if the user hits cancel.

### Parameters

uri - an URI

### Returns:

a String

### See Also:

getUserInfo(java.net.URL)
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## getUserInfo

getUserInfo( java.net.URL url ) → String

return the user info (username:password) associated with this URL. Note if there is no user info in the URI, this will return null!

### Parameters

url - the URL

### Returns:

null or the user info.

### See Also:

getUserInfo(java.net.URL, java.lang.String) which will always check and prompt.
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## getUserInfo

getUserInfo( java.net.URL url, String userInfo ) → String

get the user credentials, maybe throwing CancelledOperationException if the user hits cancel. If the password is "pass" or "password" then don't use it, prompt for it instead. The userInfo passed in can contain just "user" or the user account to log in with, then maybe a colon and "pass" or the password. So examples include:

- null, where null is returned and credentials are presumed to not be needed.
- user, where both the username and password are needed.
- user:pass where both are needed
- joe:pass there the user joe is presumed and pass is needed
- joe:JoPass1 where both the user and password are already specified, and this is returned.

Note a %40 in the username is converted to @.

### Parameters

url - an URL
userInfo - that is available separately. (Java doesn't like user@usersHost:password@server)

### Returns:

the userinfo, like "us3r:passw0rd"

### See Also:

https://sourceforge.net/p/autoplot/bugs/1652/
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## getUserInfoBase64Encoded

getUserInfoBase64Encoded( java.net.URL url ) → String

return the user info but base-64 encoded. This is put in so that a future version of the software can cache these as well. This is intended to be inserted like so: `connection= theUrl.getConnection(); String encode= KeyChain.getDefault().getUserInfoBase64Encoded( theUrl ); if ( encode!=null ) connection.setRequestProperty("Authorization", "Basic " + encode);`

### Parameters

url - the URL which may contain user info.

### Returns:

the base-64 encoded credentials.
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## getWWWAuthenticate

getWWWAuthenticate( java.net.URL url ) → String

return null or the WWW-Authenticate string. Note this is not correctly implemented, as two URLs with the same realm from the same host and scheme will use the same password.

### Parameters

url - an URL

### Returns:

a String
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## hideUserInfo

hideUserInfo( java.net.URI root ) → String

### Parameters

root - an URI

### Returns:

java.lang.String
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## main

main( String[] args ) → void

### Parameters

args - a java.lang.String[]

### Returns:

void (returns nothing)
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## resolveUserInfo

resolveUserInfo( java.net.URI root ) → java.net.URI

plug the username and password into the URI.

### Parameters

root - the URI, possibly needing a username and password.

### Returns:

the URI with the username and password.
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## setParentGUI

setParentGUI( java.awt.Component c ) → void

### Parameters

c - a Component

### Returns:

void (returns nothing)
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## setUserInfo

setUserInfo( java.net.URL url, String userInfo ) → void

insert the userInfo into the table of stored passwords. TODO: note the path is not used in the hash, and it should be.

### Parameters

url - an URL
userInfo - a String

### Returns:

void (returns nothing)
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## writeKeysFile

writeKeysFile( ) → void

dump the loaded keys into the file new File( FileSystem.settings().getLocalCacheDir(), "keychain.txt" )

### Returns:

void (returns nothing)
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## writeKeysFile

writeKeysFile( boolean toFile ) → void

format the keys file. Since Java 5 didn't have a way to restrict access to the file, this would simply display the keychain file contents and have the operator write the keychain file to disk. The required Java7 is able to restict access to the file properly.

### Parameters

toFile - the file should be created.

### Returns:

void (returns nothing)

### See Also:

appendKeysFile(java.lang.String, java.lang.String)
[search for examples] [view on GitHub] [view on old javadoc] [view source]