Package org.italiangrid.voms.credential.impl

# Class DefaultLoadCredentialsStrategy

java.lang.Object
org.italiangrid.voms.credential.impl.AbstractLoadCredentialsStrategy
org.italiangrid.voms.credential.impl.DefaultLoadCredentialsStrategy

All Implemented Interfaces:
  `LoadCredentialsStrategy`, `VOMSEnvironmentVariables`

public class DefaultLoadCredentialsStrategy extends AbstractLoadCredentialsStrategy
The default strategy used to load user credentials when no file is explicitly pointed out by the user of this API. Credentials are searched in the following places (in sequence):

- If the `X509_USER_CERT` and `X509_USER_KEY` environment variables are set, their values are used to load the user credentials
- If the `X509_USER_CERT` and `X509_USER_KEY` system properties are set, their values are used to load the user credentials
- If the `PKCS12_USER_CERT` environment variable is set, its value is used to load the user credentials.
- If the `PKCS12_USER_CERT` system property is set, its value is used to load the user credentials.
- The content of the `.globus` directory in the user's home is searched for a PEM certificate (in the `usercert.pem` and `userkey.pem` files).
- The content of the .globus directory in the user's home is searched for a PKC12 certificate (in the `usercert.p12` file).

## Field Summary

Fields
Modifier and Type
Field
Description
`static final String`
`HOME_PROPERTY`
`static final String`
`TMPDIR_PATH`
`static final String`
`TMPDIR_PROPERTY`

### Fields inherited from interface org.italiangrid.voms.credential.VOMSEnvironmentVariables

`PKCS12_USER_CERT, VOMS_USER_ID, X509_CERT_DIR, X509_USER_CERT, X509_USER_KEY, X509_USER_PROXY, X509_VOMS_DIR`

## Constructor Summary

Constructors
Constructor
Description
`DefaultLoadCredentialsStrategy()`
Constructs a strategy using default system properties.
`DefaultLoadCredentialsStrategy(String homeFolder)`
Constructs a strategy with a specified home directory.
`DefaultLoadCredentialsStrategy(String homeFolder, String tempDir, LoadCredentialsEventListener listener)`
Constructs a strategy with specified home and temp directories and a listener.
`DefaultLoadCredentialsStrategy(LoadCredentialsEventListener listener)`
Constructs a strategy with a specified event listener.

## Method Summary

Modifier and Type
Method
Description
`String`
`getFromEnvOrSystemProperty(String propName)`
Looks for the value of a given property in the environment or system properties.
`eu.emi.security.authn.x509.X509Credential`
`loadCredentials(eu.emi.security.authn.x509.helpers.PasswordSupplier pf)`
Loads user credentials using the available strategies.
`protected eu.emi.security.authn.x509.X509Credential`
`loadPEMCredentialFromEnv(eu.emi.security.authn.x509.helpers.PasswordSupplier pf)`
Loads a PEM credential from environment variables.
`protected eu.emi.security.authn.x509.X509Credential`
`loadPEMCredentialsFromGlobusDir(eu.emi.security.authn.x509.helpers.PasswordSupplier pf)`
Loads a PEM credential from the Globus directory.
`protected eu.emi.security.authn.x509.X509Credential`
`loadPKCS12CredentialFromEnv(eu.emi.security.authn.x509.helpers.PasswordSupplier pf)`
Loads a PKCS12 credential from environment variables.
`protected eu.emi.security.authn.x509.X509Credential`
`loadPKCS12CredentialsFromGlobusDir(eu.emi.security.authn.x509.helpers.PasswordSupplier pf)`
Loads a PKCS12 credential from the Globus directory.
`protected eu.emi.security.authn.x509.X509Credential`
`loadProxyFromEnv()`
Loads a proxy credential from environment variables.
`protected eu.emi.security.authn.x509.X509Credential`
`loadProxyFromUID()`
Loads a proxy credential based on the user ID.

### Methods inherited from class org.italiangrid.voms.credential.impl.AbstractLoadCredentialsStrategy

`fileExistsAndIsReadable, loadPEMCredential, loadPKCS12Credential, loadProxyCredential`

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

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

## Field Details

### HOME_PROPERTY

public static final String HOME_PROPERTY

See Also:
  - Constant Field Values

### TMPDIR_PROPERTY

public static final String TMPDIR_PROPERTY

See Also:
  - Constant Field Values

### TMPDIR_PATH

public static final String TMPDIR_PATH

See Also:
  - Constant Field Values

## Constructor Details

### DefaultLoadCredentialsStrategy

public DefaultLoadCredentialsStrategy(String homeFolder, String tempDir, LoadCredentialsEventListener listener)
Constructs a strategy with specified home and temp directories and a listener.

Parameters:
  `homeFolder` - the home directory path
  `tempDir` - the temporary directory path
  `listener` - event listener for credential loading

### DefaultLoadCredentialsStrategy

public DefaultLoadCredentialsStrategy(String homeFolder)
Constructs a strategy with a specified home directory.

Parameters:
  `homeFolder` - the home directory path

### DefaultLoadCredentialsStrategy

public DefaultLoadCredentialsStrategy()
Constructs a strategy using default system properties.

### DefaultLoadCredentialsStrategy

public DefaultLoadCredentialsStrategy(LoadCredentialsEventListener listener)
Constructs a strategy with a specified event listener.

Parameters:
  `listener` - the credential loading event listener

## Method Details

### getFromEnvOrSystemProperty

public String getFromEnvOrSystemProperty(String propName)
Looks for the value of a given property in the environment or system properties.

Parameters:
  `propName` - the property to look for
Returns:
  the property value, or null if not found

### loadCredentials

public eu.emi.security.authn.x509.X509Credential loadCredentials(eu.emi.security.authn.x509.helpers.PasswordSupplier pf)
Loads user credentials using the available strategies.

Parameters:
  `pf` - the password supplier
Returns:
  the loaded credentials

### loadProxyFromUID

protected eu.emi.security.authn.x509.X509Credential loadProxyFromUID()
Loads a proxy credential based on the user ID.

Returns:
  the loaded proxy credential or null if not found

### loadProxyFromEnv

protected eu.emi.security.authn.x509.X509Credential loadProxyFromEnv()
Loads a proxy credential from environment variables.

Returns:
  the loaded proxy credential or null if not found

### loadPEMCredentialFromEnv

protected eu.emi.security.authn.x509.X509Credential loadPEMCredentialFromEnv(eu.emi.security.authn.x509.helpers.PasswordSupplier pf)
Loads a PEM credential from environment variables.

Parameters:
  `pf` - the password supplier
Returns:
  the loaded credential or null if not found

### loadPKCS12CredentialFromEnv

protected eu.emi.security.authn.x509.X509Credential loadPKCS12CredentialFromEnv(eu.emi.security.authn.x509.helpers.PasswordSupplier pf)
Loads a PKCS12 credential from environment variables.

Parameters:
  `pf` - the password supplier
Returns:
  the loaded credential or null if not found

### loadPKCS12CredentialsFromGlobusDir

protected eu.emi.security.authn.x509.X509Credential loadPKCS12CredentialsFromGlobusDir(eu.emi.security.authn.x509.helpers.PasswordSupplier pf)
Loads a PKCS12 credential from the Globus directory.

Parameters:
  `pf` - the password supplier
Returns:
  the loaded credential or null if not found

### loadPEMCredentialsFromGlobusDir

protected eu.emi.security.authn.x509.X509Credential loadPEMCredentialsFromGlobusDir(eu.emi.security.authn.x509.helpers.PasswordSupplier pf)
Loads a PEM credential from the Globus directory.

Parameters:
  `pf` - the password supplier
Returns:
  the loaded credential or null if not found