Examples, syntax, and exceptions - Java
This topic describes syntax and examples of Java Application Password SDK.
The Java Application Password SDK comprises several classes, which contain methods that enable you to specify the password to retrieve and the configurations that enable the Credential Provider to retrieve them.
Examples
The following examples show how to retrieve a password from the Vault with the Java Application Password SDK.
|
|
|
|
Syntax - Class: PSDKPasswordRequest
This class manages requests for password objects. It specifies details about the password and its location in the Vault, as well as the location of the credential file that the application uses to authenticate to the Credential Provider.
This class has the following constructor:
This class has the following methods:
- setSafe
- setFolder
- setObject
- setAppID
- setReason
- setConnectionPort
- setConnectionTimeout
- setRequiredProperties
- setUserName
- setAddress
- setDatabase
- setPolicyID
- setQuery
- setQueryFormat
- setFailRequestOnPasswordChange
- setAttribute
These methods are described below.
Constructor
PSDKPasswordRequest ()
Description |
Constructs an object for the password request. |
Syntax |
|
Throws |
PSDKException |
Methods
setSafe
Description |
This method specifies the name of the Safe where the password is stored. |
||||
Mandatory |
Yes |
||||
Default |
No |
||||
Syntax |
|
||||
|
The following table displays the parameters of the setSafe method:
|
||||
Throws |
PSDKException |
setFolder
Description |
This method specifies the name of the folder where the password is stored. |
||||
Mandatory |
No |
||||
Default |
‘root’
|
||||
Syntax |
|
||||
|
The following table displays the parameters of the setFolder method:
|
||||
Throws |
PSDKException |
setObject
Description |
This method specifies the name of the password object to retrieve. |
||||
Mandatory |
Yes |
||||
Default |
No |
||||
Syntax |
|
||||
|
The following table displays the parameters of the setObject method:
|
||||
Throws |
PSDKException |
setAppID
Description |
This method specifies the unique ID of the application issuing the password request. This parameter is required. |
||||
Mandatory |
Yes |
||||
Default |
No |
||||
Syntax |
|
||||
|
The following table displays the parameters of the setAppID method:
|
||||
Throws: |
PSDKException |
setReason
Description |
This method specifies the reason for retrieving the password. |
||||
Mandatory |
No |
||||
Default |
No |
||||
Syntax |
|
||||
|
The following table displays the parameters of the setReason method:
|
||||
Throws |
PSDKException |
setConnectionPort
Description |
This method specifies the port that the Java SDK will use to connect to the Credential Provider. |
||||
Mandatory |
No |
||||
Default |
18923 |
||||
Syntax |
|
||||
|
The following table displays the parameters of the setConnectionPort method:
|
||||
Throws |
PSDKException |
setConnectionTimeout
Description |
This method specifies the number of seconds that the Credential Provider will try to retrieve the password. |
||||
Mandatory |
No |
||||
Default |
30 |
||||
Syntax |
|
||||
|
The following table displays the parameters of the setConnectionTimeout method:
|
||||
Throws |
PSDKException |
setRequiredProperties
Description |
This method specifies a list of password property values. You can specify specific password properties to return. If no properties are specified, by default all the password properties will be available to you through the PSDKPassword.getAttribute or through the direct PSDKPassword.getUserName, PSDKPassword.getAddress, PSDKPassword.getPolicyId, and PSDKPassword.getDatabase methods. |
||||||
Mandatory |
Yes |
||||||
Default |
All password properties |
||||||
Syntax |
|
||||||
|
The following table displays the parameters of the setRequiredProperties method: |
||||||
|
The following example shows how this method can be used to specify the PolicyID password property as a property to return with the password
|
||||||
Throws |
PSDKException |
setUserName
Description |
This method defines search criteria according to the UserName account property. |
||||
Mandatory |
No |
||||
Default |
None |
||||
Syntax |
|
||||
|
The following table displays the parameters of the setUserName method:
|
||||
Throws |
PSDKException |
setAddress
Description |
This method defines search criteria according to the Address account property. |
||||
Mandatory |
No |
||||
Default |
None |
||||
Syntax |
|
||||
|
The following table displays the parameters of the setAddress method:
|
||||
Throws |
PSDKException |
setDatabase
Description |
This method defines search criteria according to the Database account property. |
||||
Mandatory |
No |
||||
Default |
None |
||||
Syntax |
|
||||
|
The following table displays the parameters of the setDatabase method:
|
||||
Throws |
PSDKException |
setPolicyID
Description |
This method defines the format that will be used in the setPolicyID method. |
||||
Mandatory |
No |
||||
Default |
None |
||||
Syntax |
|
||||
|
The following table displays the parameters of the setPolicyID method:
|
||||
Throws |
PSDKException |
setQuery
Description |
This method defines a free query using account properties, including Safe, folder, and object. When this method is specified, all other search criteria (Safe/Folder/Object/UserName/Address/PolicyID/Database) are ignored and only the account properties that are specified in the query are passed to the Credential Provider in the account request. |
||||||||
Mandatory |
No |
||||||||
Default |
None |
||||||||
Syntax |
|
||||||||
|
The following table displays the parameters of the setQuery method:
The following example shows how this method can be used to specify one or more account properties in a request.
|
||||||||
Throws |
PSDKException |
setQueryFormat
Description |
This method defines the query format, which can optionally use regular expressions. |
||||||||||||
Mandatory |
No |
||||||||||||
Default |
PasswordQueryFormat.EXACT |
||||||||||||
Syntax |
|
||||||||||||
|
The following table displays the valid values of the setQueryFormat method:
In the following example, the application retrieves a database account which is part of a group (server1_OracleDB, server2_OracleDB, etc.). It can retrieve any of the group members as they all have the same password and it does not have previous knowledge of the accounts it can access. In the query it uses a regular expression in order to specify a partial address that ends with “OracleDB”, and a PolicyID with value “Oracle”:
|
||||||||||||
Throws |
PSDKException |
Although some attributes can be set directly, as shown in Example 1: Request a password, the user can also specify them using the setAttribute method as shown in Example 2: Request a password with query.
setFailRequestOnPasswordChange
Description |
This method determines whether the PSDKCRequestFailedOn PasswordChange exception will be thrown when a request is sent for an account that is currently being changed. |
||||
Mandatory |
No |
||||
Default |
False |
||||
Syntax |
|
||||
|
The following table displays the parameters of the setFailRequestOnPasswordChange method:
|
||||
Throws |
PSDKException |
setAttribute
Description |
This method sets password request attributes. You can either use this method or any of the methods described above. The table below indicates which attributes in this method must be specified. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Mandatory |
No |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Default |
None |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Syntax |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The following table displays the parameters of the setAttribute method:
This method can set the following attributes:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Throws |
PSDKException |
The following example shows how this method can be used to specify criteria that will identify the password to retrieve. You can see a full example in Example 2: Request a password with query
|
The SDK will use the last configuration. For example, if the user specifies SetAttribute (Query …) and then specifies SetSafe, SetFolder, and SetObject, the specific Safe, folder and object will be taken instead of the query. |
Syntax - Class: PasswordSDK
This class provides the Java Application Password SDK services.
Methods
Currently, the PasswordSDK class only provides one method to retrieve passwords:
This method is described below:
getPassword
Description |
This method retrieves the specified password from the Vault. |
||||
Mandatory |
Yes |
||||
Default Syntax |
No |
||||
|
|||||
|
The following table displays the parameters of the getPassword method:
|
||||
Throws |
PSDKException, PSDKRequestFailedOnPasswordChange
|
Syntax - Class: PSDKPassword
This class represents a password object that is returned from the getPassword service.
Methods
The PSDKPassword class has the following methods:
These methods are described below.
getUserName
Description |
This method returns the UserName property of the account. If this property does not exist, or it has an empty value, or the object was disposed of, an empty string is returned. |
Syntax |
|
getAddress
Description |
This method returns the Address property of the account. If this property does not exist, or it has an empty value, or the object was disposed of, an empty string is returned. |
Syntax |
|
getPolicyID
Description |
This method returns the PolicyID property of the account. If this property does not exist, or it has an empty value, or the object was disposed of, an empty string is returned. |
Syntax |
|
getDatabase
Description |
This method returns the Database property of the account. If this property does not exist, or it has an empty value, or the object was disposed of, an empty string is returned. |
Syntax |
|
getContent
Description |
This method returns the password as a String object. If an error occurred or the object was disposed of, an empty string is returned. Deprecated. Use getSecureContent() instead. |
Syntax |
|
getSecureContent
Description |
This method returns the password with enhanced security. If the object was disposed of, returns null. This method should always be followed by a dispose() method to clear the password held by the PSDKPassword object from memory. Moreover, the returned object must be cleared from memory. This can be done using:
It is recommended to use a FIPS-compliant Java Security Provider, such as Bouncy Castle. |
Syntax |
|
getAttribute
Description |
This method returns an attribute of an account. If this property does not exist, or it has an empty value, or the object was disposed of, an empty string is returned. |
||||||||||||||||||
Syntax |
|
||||||||||||||||||
|
The following table displays the parameters of the getAttribute method:
The parameter can get the following attributes:
|
||||||||||||||||||
Throws |
PSDKException |
dispose
Description |
Disposes of resources used by this PSDKPassword object. The PSDKPassword object cannot be used after being disposed of because all attributes will return as empty or null. It is preferable to manually free resources using this method rather than to rely on a finalization process which may not occur for a long period of time. |
Syntax |
|
Throws |
PSDKException |
Exceptions
This section lists the exceptions that may be issued by the SDK functions.
This exception is thrown by the following constructors and methods:
Class: |
PSDKPasswordRequest |
Constructor: |
PSDKPasswordRequest |
Methods: |
setSafe, setFolder, setObject, setAppID, setReason, setConnectionPort, setConnectionTimeout, setRequiredProperties, setAttribute, setPolicyId, setDatabase, setUserName, setAddress, setQuery, setQueryFormat, setFailRequestOnPasswordChange |
Class: |
PasswordSDK |
Methods: |
getPassword |
Class: |
PSDKPassword |
Methods: |
getAttribute |
This exception is thrown by the following methods:
Class |
PasswordSDK |
---|---|
Methods: |
getPassword |