com.amazon.redshift.plugin

## Class BasicSamlCredentialsProvider

- java.lang.Object
- - com.amazon.redshift.plugin.SamlCredentialsProvider
  - - com.amazon.redshift.plugin.BasicSamlCredentialsProvider

All Implemented Interfaces:
  IPlugin

    public class BasicSamlCredentialsProvider
    extends SamlCredentialsProvider

A basic SAML credential provider class. This class can be changed and implemented to work with any desired SAML service provider.

### Field Summary

Fields
`protected static Pattern` `IAM_HTTP_URL_PATTERN`
`protected static Pattern` `IAM_URL_PATTERN`
`static String` `KEY_SAML_ASSERTION` Here we are defining a new connection property key called "saml_assertion".
`protected static String` `KEY_SSL_INSECURE`
`protected RedshiftLogger` `m_log`
`protected boolean` `m_sslInsecure`

### Fields inherited from class com.amazon.redshift.plugin.SamlCredentialsProvider

`KEY_IDP_HOST, m_autoCreate, m_dbGroups, m_dbGroupsFilter, m_dbUser, m_disableCache, m_duration, m_forceLowercase, m_groupFederation, m_idpHost, m_idpPort, m_password, m_preferredRole, m_region, m_stsEndpoint, m_userName`

### Constructor Summary

Constructors
Constructor and Description
`BasicSamlCredentialsProvider()` Optional default constructor.

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`void` `addParameter(String key, String value)` This method is used to get the values associated with different connection string properties.
`protected CloseableHttpClient` `getHttpClient()`
`protected static String` `getRegexForJsonKey(String keyName)`
`protected String` `getSamlAssertion()` This method needs to return the SAML assertion string returned by the specific SAML provider being used for this implementation.
`protected void` `validateURL(String paramString)`

### Methods inherited from class com.amazon.redshift.plugin.SamlCredentialsProvider

`checkRequiredParameters, escapeHtmlEntity, getCacheKey, getFormAction, getIdpToken, getInputTagsfromHTML, getPluginSpecificCacheKey, getSubType, getValueByKey, getValueByKeyWithoutQuotesAndValueInSingleQuote, isPassword, isText, refresh, resolveCredentials, setGroupFederation, setLogger`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### KEY_SAML_ASSERTION

    public static final String KEY_SAML_ASSERTION

Here we are defining a new connection property key called "saml_assertion". This property will be specific to the BasicSamlCredentialsProvider and will be used to provide some information through the connection string.

This means that a user wanting to use this credential provider may include the following in the connection string:

`jdbc:redshift:iam://[host]:[port]/[database]?saml_assertion=[value]`

If your implementation requires user input through the connection string, this is how you can define the connection property name. You can add as many new connection properties as needed following the same pattern:

`public static final String PROPERTY_NAME = "key_name";`

The restrictions on "key_name" are:

- The name must be unique. It can not match any existing connection property key name in the Redshift JDBC driver. The connection property names are case-insensitive, so even if the case does not match what is found in the documentation, it is not allowed.

- The key name may not have any spaces.

- The key name may only contain the characters [a-z]|[A-Z] or underscore '_'.

See Also:
  Constant Field Values

#### KEY_SSL_INSECURE

    protected static final String KEY_SSL_INSECURE

See Also:
  Constant Field Values

#### m_sslInsecure

    protected boolean m_sslInsecure

#### IAM_URL_PATTERN

    protected static final Pattern IAM_URL_PATTERN

#### IAM_HTTP_URL_PATTERN

    protected static final Pattern IAM_HTTP_URL_PATTERN

#### m_log

    protected RedshiftLogger m_log

### Constructor Detail

#### BasicSamlCredentialsProvider

    public BasicSamlCredentialsProvider()

Optional default constructor.

### Method Detail

#### addParameter

    public void addParameter(String key,
                             String value)

This method is used to get the values associated with different connection string properties.

We override it in this custom credentials provider to add a check for any additional connection properties that were added, which are not included in the existing Redshift JDBC driver. It allows us to store these values using the appropriate fields as mentioned above.

For any new connection property keys added to this class, add an if-condition to check, if the current key matches the connection property key, store the value associated with the key in the appropriate field.

If no new connection property keys are required, you may leave the implementation blank and simply return a call to the parent class implementation.

Please see the example below.

Specified by:
  `addParameter` in interface `IPlugin`
Overrides:
  `addParameter` in class `SamlCredentialsProvider`
Parameters:
  `key` - A string representing the connection property key.
  `value` - The value associated with the connection property key.

#### getSamlAssertion

    protected String getSamlAssertion()
                               throws IOException

This method needs to return the SAML assertion string returned by the specific SAML provider being used for this implementation. How you get this string will depend on the specific SAML provider you are using.

This will be used by the SamlCredentialsProvider parent class to get the temporary credentials.

Specified by:
  `getSamlAssertion` in class `SamlCredentialsProvider`
Returns:
  The SAML assertion string.
Throws:
  `IOException` - no error as such. It's an overridden method.

#### getHttpClient

    protected CloseableHttpClient getHttpClient()
                                         throws GeneralSecurityException

Throws:
  `GeneralSecurityException`

#### validateURL

    protected void validateURL(String paramString)
                        throws IOException

Throws:
  `IOException`

#### getRegexForJsonKey

    protected static String getRegexForJsonKey(String keyName)