Top Description Fields Constructors Methods
pt.davidafsilva.apple

public Class OSXKeychain

extends Object
Class Inheritance
Imports
java.io.File, .FileOutputStream, .IOException, .InputStream, .OutputStream, java.util.HashMap, .Map, .Optional

An interface to the OS X Keychain. The names of functions and parameters will mostly match the functions listed in the Keychain Services Reference.
Author
Conor McDermottroe

Field Summary

Modifier and TypeField and Description
private static OSXKeychain
instance

The singleton instance of the keychain.

private static final Map<Integer, OSXKeychainProtocolType>
PROTOCOLS

A fixed mapping of ports to known protocols.

Constructor Summary

AccessConstructor and Description
private
OSXKeychain()

Prevent this class from being instantiated directly.

Method Summary

Modifier and TypeMethod and Description
private native void
_addGenericPassword(String
The value which should be passed as the serviceName parameter to SecKeychainAddGenericPassword.
serviceName
,
String
The value which should be passed as the accountName parameter to SecKeychainAddGenericPassword.
accountName
,
String
The value which should be passed as the password parameter to SecKeychainAddGenericPassword.
password
)

See Java_pt_davidafsilva_ghn_service_options_osx_OSXKeychain__1addGenericPassword for the implementation of this and use addGenericPassword(String, String, String) to call this.

private native void
_deleteGenericPassword(String
The value which should be passed as the serviceName parameter to SecKeychainFindGenericPassword in order to find the password to delete it.
serviceName
,
String
The value for the accountName parameter to SecKeychainFindGenericPassword in order to find the password to delete it.
accountName
)

See Java_pt_davidafsilva_ghn_service_options_osx_OSXKeychain__1deleteGenericPassword for the implementation of this and use deleteGenericPassword(String, String) to call this.

private native String

Returns:

The first password which matches the details supplied.
_findGenericPassword
(String
The value which should be passed as the serviceName parameter to SecKeychainFindGenericPassword.
serviceName
,
String
The value for the accountName parameter to SecKeychainFindGenericPassword.
accountName
)

See Java_pt_davidafsilva_ghn_service_options_osx_OSXKeychain__1findGenericPassword for the implementation of this and use findGenericPassword(String, String) to call this.

private native void
_modifyGenericPassword(String
The value which should be passed as the serviceName parameter to SecKeychainAddGenericPassword.
serviceName
,
String
The value which should be passed as the accountName parameter to SecKeychainAddGenericPassword.
accountName
,
String
The value which should be passed as the password parameter to SecKeychainAddGenericPassword.
password
)

See Java_pt_davidafsilva_ghn_service_options_osx_OSXKeychain__1modifyGenericPassword for the implementation of this and use modifyGenericPassword(String, String, String) to call this.

public void
addGenericPassword(String
The name of the service the password is for.
serviceName
,
String
The account name/username for the service.
accountName
,
String
The password for the service.
password
)

Add a non-internet password to the keychain.

public void
deleteGenericPassword(String
The name of the service the password is for.
serviceName
,
String
The account name/username for the service.
accountName
)

Delete a generic password from the keychain.

public Optional<String>

Returns:

the password for the service or an empty optional
findGenericPassword
(String
The name of the service the password is for.
serviceName
,
String
The account name/username for the service.
accountName
)

Finds an existing non-internet password in the keychain

public static OSXKeychain

Returns:

An instance of this class.
getInstance
()

Get an instance of the keychain.

private static void
loadSharedObject()

Load the shared object which contains the implementations for the native methods in this class.

public void
modifyGenericPassword(String
The name of the service the password is for.
serviceName
,
String
The account name/username for the service.
accountName
,
String
The password for the service.
password
)

Update an existing non-internet password to the keychain.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

instanceback to summary
private static OSXKeychain instance

The singleton instance of the keychain. Lazily loaded in getInstance().

PROTOCOLSback to summary
private static final Map<Integer, OSXKeychainProtocolType> PROTOCOLS

A fixed mapping of ports to known protocols.

Constructor Detail

OSXKeychainback to summary
private OSXKeychain()

Prevent this class from being instantiated directly.

Method Detail

_addGenericPasswordback to summary
private native void _addGenericPassword(String serviceName, String accountName, String password) throws OSXKeychainException

See Java_pt_davidafsilva_ghn_service_options_osx_OSXKeychain__1addGenericPassword for the implementation of this and use addGenericPassword(String, String, String) to call this.

Parameters
serviceName:String

The value which should be passed as the serviceName parameter to SecKeychainAddGenericPassword.

accountName:String

The value which should be passed as the accountName parameter to SecKeychainAddGenericPassword.

password:String

The value which should be passed as the password parameter to SecKeychainAddGenericPassword.

Exceptions
OSXKeychainException:
If an error occurs when communicating with the OS X keychain.
_deleteGenericPasswordback to summary
private native void _deleteGenericPassword(String serviceName, String accountName) throws OSXKeychainException

See Java_pt_davidafsilva_ghn_service_options_osx_OSXKeychain__1deleteGenericPassword for the implementation of this and use deleteGenericPassword(String, String) to call this.

Parameters
serviceName:String

The value which should be passed as the serviceName parameter to SecKeychainFindGenericPassword in order to find the password to delete it.

accountName:String

The value for the accountName parameter to SecKeychainFindGenericPassword in order to find the password to delete it.

Exceptions
OSXKeychainException:
If an error occurs when communicating with the OS X keychain.
_findGenericPasswordback to summary
private native String _findGenericPassword(String serviceName, String accountName) throws OSXKeychainException

See Java_pt_davidafsilva_ghn_service_options_osx_OSXKeychain__1findGenericPassword for the implementation of this and use findGenericPassword(String, String) to call this.

Parameters
serviceName:String

The value which should be passed as the serviceName parameter to SecKeychainFindGenericPassword.

accountName:String

The value for the accountName parameter to SecKeychainFindGenericPassword.

Returns:String

The first password which matches the details supplied.

Exceptions
OSXKeychainException:
If an error occurs when communicating with the OS X keychain.
_modifyGenericPasswordback to summary
private native void _modifyGenericPassword(String serviceName, String accountName, String password) throws OSXKeychainException

See Java_pt_davidafsilva_ghn_service_options_osx_OSXKeychain__1modifyGenericPassword for the implementation of this and use modifyGenericPassword(String, String, String) to call this.

Parameters
serviceName:String

The value which should be passed as the serviceName parameter to SecKeychainAddGenericPassword.

accountName:String

The value which should be passed as the accountName parameter to SecKeychainAddGenericPassword.

password:String

The value which should be passed as the password parameter to SecKeychainAddGenericPassword.

Exceptions
OSXKeychainException:
If an error occurs when communicating with the OS X keychain.
addGenericPasswordback to summary
public void addGenericPassword(String serviceName, String accountName, String password) throws OSXKeychainException

Add a non-internet password to the keychain.

Parameters
serviceName:String

The name of the service the password is for.

accountName:String

The account name/username for the service.

password:String

The password for the service.

Exceptions
OSXKeychainException:
If an error occurs when communicating with the OS X keychain.
deleteGenericPasswordback to summary
public void deleteGenericPassword(String serviceName, String accountName) throws OSXKeychainException

Delete a generic password from the keychain.

Parameters
serviceName:String

The name of the service the password is for.

accountName:String

The account name/username for the service.

Exceptions
OSXKeychainException:
If an error occurs when communicating with the OS X keychain.
findGenericPasswordback to summary
public Optional<String> findGenericPassword(String serviceName, String accountName) throws OSXKeychainException

Finds an existing non-internet password in the keychain

Parameters
serviceName:String

The name of the service the password is for.

accountName:String

The account name/username for the service.

Returns:Optional<String>

the password for the service or an empty optional

Exceptions
OSXKeychainException:
If an error occurs when communicating with the OS X keychain.
getInstanceback to summary
public static OSXKeychain getInstance() throws OSXKeychainException

Get an instance of the keychain.

Returns:OSXKeychain

An instance of this class.

Exceptions
OSXKeychainException:
If it's not possible to connect to the keychain.
loadSharedObjectback to summary
private static void loadSharedObject() throws IOException

Load the shared object which contains the implementations for the native methods in this class.

Exceptions
IOException:
If the shared object could not be loaded.
modifyGenericPasswordback to summary
public void modifyGenericPassword(String serviceName, String accountName, String password) throws OSXKeychainException

Update an existing non-internet password to the keychain.

Parameters
serviceName:String

The name of the service the password is for.

accountName:String

The account name/username for the service.

password:String

The password for the service.

Exceptions
OSXKeychainException:
If an error occurs when communicating with the OS X keychain.