public abstract class AS400Credential extends java.lang.Object implements java.io.Serializable, AS400SwappableCredential
Credentials may be used for authenticating to system services, or may simply enable certain actions to be performed.
Typical IBM i system credentials include, but are not limited to, profile tokens.
This abstract class must be subclassed to provide specific credential functions. Each subclass can contain credential data that may be security-sensitive. It is the responsibility of each class to provide appropriate access controls to sensitive data.
AS400Credential objects generate the following events:
Modifier and Type | Field and Description |
---|---|
static int |
CR_AUTO_REFRESH_FAILED
ID indicating that automatic refresh has failed.
|
static int |
CR_AUTO_REFRESH_NOT_VALID
ID indicating that automatic refresh is not a valid operation.
|
static int |
CR_AUTO_REFRESH_STARTED
ID indicating that automatic refresh is started.
|
static int |
CR_AUTO_REFRESH_STOPPED
ID indicating that automatic refresh is stopped.
|
Constructor and Description |
---|
AS400Credential()
Constructs an AS400Credential object.
|
Modifier and Type | Method and Description |
---|---|
void |
addCredentialListener(AS400CredentialListener listener)
Adds a listener to receive credential events.
|
void |
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds a PropertyChangeListener.
|
void |
addVetoableChangeListener(java.beans.VetoableChangeListener listener)
Adds a VetoableChangeListener.
|
java.lang.String[] |
basicAuthenticationPrompt()
Returns text that can be displayed to prompt for the basic user
and password information used to initialize the credential.
|
void |
destroy()
Destroys the credential by destroying or clearing
sensitive information for the credential.
|
protected void |
finalize()
Called when garbage collection determines that there are
no more references to the object.
|
java.lang.Throwable |
getAutomaticRefreshFailure()
Returns the exception resulting from failure of
the most recent auto-refresh attempt.
|
int |
getAutomaticRefreshStatus()
Returns the current status of automatic refresh
activity for the credential.
|
AS400Principal |
getPrincipal()
Returns the AS400Principal associated with the credential.
|
AS400 |
getSystem()
Returns the AS400 system object for the credential.
|
int |
getTimeToExpiration()
Returns the number of seconds before the
credential is due to expire.
|
boolean |
isCurrent()
Indicates if a timed credential is still considered valid
for authenticating to associated IBM i system services
or performing related actions.
|
boolean |
isDestroyed()
Indicates if the credential has been destroyed.
|
boolean |
isPrivate()
Indicates whether the credential is considered private.
|
boolean |
isRenewable()
Indicates if the credential can be refreshed.
|
boolean |
isTimed()
Indicates if the credential will expire based on time.
|
void |
refresh()
Updates or extends the validity period for the credential.
|
void |
removeCredentialListener(AS400CredentialListener listener)
Removes the specified listener from the internal list.
|
void |
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes the specified listener from the internal list.
|
void |
removeVetoableChangeListener(java.beans.VetoableChangeListener listener)
Removes the specified listener from the internal list.
|
void |
setPrincipal(AS400Principal p)
Sets the principal associated with the credential.
|
void |
setSystem(AS400 system)
Sets the AS400 system object for the credential.
|
void |
startAutomaticRefresh(int refreshInterval,
int maxRefreshes)
Starts automatic refresh for the credential.
|
void |
stopAutomaticRefresh()
Stops and clears the state of any automatic refresh
in progress for the credential.
|
void |
swap()
Attempts to swap the current thread identity based on this credential.
|
AS400Credential |
swap(boolean returnCredential)
Attempts to swap the current thread identity based on this credential.
|
public static final int CR_AUTO_REFRESH_FAILED
public static final int CR_AUTO_REFRESH_NOT_VALID
public static final int CR_AUTO_REFRESH_STARTED
public static final int CR_AUTO_REFRESH_STOPPED
public void addCredentialListener(AS400CredentialListener listener)
listener
- The AS400CredentialListener.removeCredentialListener(com.ibm.as400.security.auth.AS400CredentialListener)
public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
The specified listener's propertyChange method will be called each time the value of a bound property is changed.
listener
- The PropertyChangeListener.removePropertyChangeListener(java.beans.PropertyChangeListener)
public void addVetoableChangeListener(java.beans.VetoableChangeListener listener)
The specified listener's vetoableChange method will be called each time the value of a constrained property is changed.
listener
- The VetoableChangeListener.removeVetoableChangeListener(java.beans.VetoableChangeListener)
public java.lang.String[] basicAuthenticationPrompt()
public void destroy() throws AS400SecurityException
AS400SecurityException
- If an IBM i system security or authentication error occurs.protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
- If an error occurs.public java.lang.Throwable getAutomaticRefreshFailure()
Available when the automatic refresh status is CR_AUTO_REFRESH_FAILED.
getAutomaticRefreshStatus()
public int getAutomaticRefreshStatus()
Possible identifiers are defined as fields on this class:
Automatic refresh is not valid if the credential cannot be programmatically updated or extended, or if the associated AS400 system object is not set or not allowed to start additional threads.
If automatic refresh fails, the associated exception is available from the getAutomaticRefreshFailure() method.
startAutomaticRefresh(int, int)
,
stopAutomaticRefresh()
,
getAutomaticRefreshFailure()
public AS400Principal getPrincipal()
public AS400 getSystem()
public int getTimeToExpiration() throws AS400SecurityException
AS400SecurityException
- If an IBM i system security or authentication error occurs.public boolean isCurrent()
public boolean isDestroyed()
The credential is considered destroyed if the contained information is no longer sufficient to access host information for or take action against the credential.
public boolean isPrivate()
This value can be referenced by authentication services as an indication of when to check permissions or otherwise protect access to sensitive credentials.
public boolean isRenewable()
refresh()
public boolean isTimed()
public void refresh() throws AS400SecurityException
Does nothing if the credential cannot be programmatically updated or extended.
AS400SecurityException
- If an IBM i system security or authentication error occurs.public void removeCredentialListener(AS400CredentialListener listener)
Does nothing if the listener is not in the list.
listener
- The AS400CredentialListener.addCredentialListener(com.ibm.as400.security.auth.AS400CredentialListener)
public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Does nothing if the listener is not in the list.
listener
- The PropertyChangeListener.addPropertyChangeListener(java.beans.PropertyChangeListener)
public void removeVetoableChangeListener(java.beans.VetoableChangeListener listener)
Does nothing if the listener is not in the list.
listener
- The VetoableChangeListener.addVetoableChangeListener(java.beans.VetoableChangeListener)
public void setPrincipal(AS400Principal p) throws java.beans.PropertyVetoException
This property cannot be changed once a request initiates a connection for the object to the IBM i system (for example, refresh).
p
- The principal.java.beans.PropertyVetoException
- If the change is vetoed.ExtendedIllegalStateException
- If the property cannot be changed due
to the current state.public void setSystem(AS400 system) throws java.beans.PropertyVetoException
This property cannot be changed once a request initiates a connection for the object to the IBM i system (for example, refresh).
system
- The AS400 system object.java.beans.PropertyVetoException
- If the change is vetoed.ExtendedIllegalStateException
- If the property cannot be changed due
to the current state.public void startAutomaticRefresh(int refreshInterval, int maxRefreshes)
While this action is designed to automatically refresh the credential at the specified interval, this is subject to current workload and scheduling of the underlying Java Virtual Machine. Calling applications should take this into consideration when defining the refresh interval in relation to the credential's time to expiration, as it may not be possible to revive a credential once it has expired.
refreshInterval
- The number of seconds between refresh attempts.
The first refresh will occur immediately;
the second will occur this many seconds after
the first, and so on.maxRefreshes
- The maximum number of times to refresh the
credential. A value of negative one (-1)
indicates no maximum.java.lang.IllegalStateException
- If automatic refresh has already been started or
is not a valid operation for the credential.
Automatic refresh is not valid if the credential
cannot be programmatically updated or extended,
or if the associated AS400 system object is
not allowed to start additional threads.ExtendedIllegalArgumentException
- If a parameter value is out of range.refresh()
,
getAutomaticRefreshStatus()
,
stopAutomaticRefresh()
public void stopAutomaticRefresh()
Does nothing if automatic refresh is not active.
public void swap() throws java.lang.Exception
No return credential is generated.
Note: This method affects the running user profile for subsequent native code invocations and any further requests against the assigned IBM i system. Any currently existing AS400 instances, even if defined for the local host and current user, are not affected if connections have been established under the old identity.
Note: swap() is supported only when running natively on IBM i. It is unsupported as a remote operation.
swap
in interface AS400SwappableCredential
java.lang.Exception
- If an exception occurs.Swapper
public AS400Credential swap(boolean returnCredential) throws AS400SecurityException
Note: This method affects the running user profile for subsequent native code invocations and any further requests against the assigned IBM i system. Any currently existing AS400 instances, even if defined for the local host and current user, are not affected if connections have been established under the old identity.
Note: swap() is supported only when running natively on IBM i. It is unsupported as a remote operation.
returnCredential
- Indicates whether a credential should be returned
that is capable of swapping back to the original
thread identity. Not generating a return credential
optimizes performance and avoids any potential
problems in generating the return value.
This parameter is ignored by credentials not
supporting the ability to swap back to the
original thread identity.AS400SecurityException
- If an IBM i system security or authentication error occurs.Swapper