Class PasswordPolicy
- All Implemented Interfaces:
Displayable,StringFiller,HasId
Attributes: - Defines the minimum and maximum allowed lengths for passwords. - Specifies character requirements, such as alphanumeric, special characters, or numeric-only. - Allows toggling case sensitivity and restriction on repeated characters. - Includes functionality for password expiry and reuse history. - Supports initial default password configuration.
-
Field Summary
Fields inherited from class com.storedobject.core.StoredObject
logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapply(char[] password) Applies a password validation check based on predefined rules such as length limits, character composition, and prohibitions against specific sequences or repetitions.static voidConfigures the specified columns with predefined attributes and their respective data types.describe()Generates a descriptive string about the password requirements.Generates a new password based on the current password policy.static PasswordPolicyRetrieves the password policy associated with the specified owner.static <T extends StoredObject>
PasswordPolicyget(T owner) Retrieves a PasswordPolicy associated with the specified owner object.booleanRetrieves the value indicating whether repeated characters are allowed.Retrieves the associated data class.intRetrieves the number of days until the item expires.static <T extends StoredObject>
PasswordPolicygetForClass(Class<T> owner) Retrieves thePasswordPolicyfor the specified class.Retrieves the initial password assigned to a user or system entity.intRetrieves the maximum length allowed by the password policy.intRetrieves the minimum length value.intRetrieves the requirement value for the password policy.Retrieves the requirement value associated with the current requirement.static StringgetRequirementValue(int value) Retrieves a requirement value based on the given index.static String[]Retrieves the array of requirement values associated with the password policy.booleanRetrieves the status of whether mixed-case characters are required.intRetrieves the reuse history count for the associated entity.Constructs and returns a unique condition string based on the `dataClass` value.static inthints()Provides a hint or constant value representing a specific object state, characteristic, or configuration.static voidAdds an index to the `indices` object with predefined parameters.voidsetAllowRepeatCharacters(boolean allowRepeatCharacters) Sets whether repeated characters are allowed in the password.voidsetDataClass(String dataClass) Sets the value of the dataClass field.voidsetExpiryDays(int expiryDays) Sets the number of days until expiration.voidsetInitialPassword(String initialPassword) Sets the initial password for this password policy.voidsetMaximumLength(int maximumLength) Sets the maximum length for the password.voidsetMinimumLength(int minimumLength) Sets the minimum length for passwords in the policy.voidsetRequirement(int requirement) Sets the requirement level for the password policy.voidsetRequireMixedcase(boolean requireMixedcase) Sets whether the password policy requires passwords to include a mix of uppercase and lowercase letters.voidsetReuseHistory(int reuseHistory) Sets the reuse history value.voidThe system will invoke this whenever the object is saved to the DB.Methods inherited from class com.storedobject.core.StoredObject
addLink, addLink, addLink, addLink, addLink, addLink, addLink, addLink, checkCurrency, checkCurrency, checkForDuplicate, checkForDuplicate, checkTimeZone, checkTransaction, clearObjectLinks, contemporary, copy, copy, count, count, count, count, count, count, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, create, created, delete, delete, delete, deleted, directUpdate, equals, exists, exists, exists, exists, exists, existsFileData, existsLink, existsLink, existsLink, existsLink, existsLink, existsLink, existsLink, existsLink, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsMaster, existsMaster, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, family, family, family, family, fill, get, get, get, get, get, get, get, get, get, get, get, get, get, get, get, get, get, getActor, getAttachment, getAttachmentId, getChildren, getContemporaryOf, getDeleted, getDeleted, getExistsCondition, getExistsCondition, getFileData, getFileData, getHistorical, getId, getKeyIndex, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getNotExistsCondition, getNotExistsCondition, getParent, getParent, getParent, getParentId, getParentId, getParentId, getRelated, getRelated, getTransaction, getTransactionId, getTransactionIP, getUnique, hashCode, inserted, isModified, isVirtual, list, list, list, list, list, list, list, list, list, list, list, list, list, listDeletedIds, listFileData, listFileData, listHistory, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listTree, listTree, listTree, listTree, listViaQuery, listViaQuery, load, load, load, load, loadAttributesFrom, loaded, loading, makeNew, makeVirtual, migrate, migrateLink, migrateLink, moduleName, nextVersion, objectLink, objectLink, objectLink, objectLinks, objectLinks, old, person, previousVersion, previousVersion, query, query, query, query, query, query, query, query, query, query, query, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, reload, reload, reloaded, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeLink, removeLink, removeLink, removeLink, removeLink, removeLink, removeLink, removeLink, removeLink, removeLink, removeLink, removeLink, removeReverseLinks, removeReverseLinks, save, save, save, save, save, save, save, save, save, save, save, save, save, save, save, saved, saving, setMaster, setRawValue, setTransaction, stringify, tableName, timestamp, toCode, toDisplay, toString, transacting, undelete, undelete, undeleted, updated, user, userId, validate, validateChildAttach, validateChildDetach, validateChildUpdate, validateDelete, validateInsert, validateParentAttach, validateParentDetach, validateParentUpdate, validateUndelete, validateUpdate, valueEquals
-
Constructor Details
-
PasswordPolicy
public PasswordPolicy()Constructs a new instance of the PasswordPolicy class. This class is typically used for defining and enforcing rules and constraints on passwords to ensure they comply with security standards.
-
-
Method Details
-
columns
Configures the specified columns with predefined attributes and their respective data types.- Parameters:
columns- The Columns object to which the specified attributes and data types will be added.
-
hints
public static int hints()Provides a hint or constant value representing a specific object state, characteristic, or configuration. In this implementation, it returns the constant value for a small list hint.- Returns:
- an integer constant representing the hint for a small list
-
indices
Adds an index to the `indices` object with predefined parameters.- Parameters:
indices- the `Indices` object where the index will be added
-
getUniqueCondition
Constructs and returns a unique condition string based on the `dataClass` value.- Overrides:
getUniqueConditionin classStoredObject- Returns:
- a string representing a unique condition in the format "DataClass='value'".
-
setDataClass
Sets the value of the dataClass field.- Parameters:
dataClass- the new value to assign to the dataClass field
-
getDataClass
-
setMinimumLength
public void setMinimumLength(int minimumLength) Sets the minimum length for passwords in the policy.- Parameters:
minimumLength- the minimum number of characters required for a password
-
getMinimumLength
-
setMaximumLength
public void setMaximumLength(int maximumLength) Sets the maximum length for the password.- Parameters:
maximumLength- the maximum number of characters allowed for the password
-
getMaximumLength
-
setRequirement
public void setRequirement(int requirement) Sets the requirement level for the password policy.- Parameters:
requirement- the requirement level to be set. It determines the password policy's specific constraints or rules.
-
getRequirement
-
getRequirementValues
Retrieves the array of requirement values associated with the password policy.- Returns:
- An array of strings representing the requirement values.
-
getRequirementValue
Retrieves a requirement value based on the given index. The value is determined from a predefined array of requirement values, cycling through the array if the index exceeds its length.- Parameters:
value- The index to retrieve the requirement value. If the index exceeds the length of the requirement values array, it wraps around using modulo operation.- Returns:
- A string representing the requirement value corresponding to the provided index.
-
getRequirementValue
Retrieves the requirement value associated with the current requirement.- Returns:
- A string representing the requirement value mapped to the current requirement.
-
setRequireMixedcase
public void setRequireMixedcase(boolean requireMixedcase) Sets whether the password policy requires passwords to include a mix of uppercase and lowercase letters.- Parameters:
requireMixedcase- a boolean indicating if mixed case is required; true if passwords must include both uppercase and lowercase letters, false otherwise.
-
getRequireMixedcase
-
setAllowRepeatCharacters
public void setAllowRepeatCharacters(boolean allowRepeatCharacters) Sets whether repeated characters are allowed in the password.- Parameters:
allowRepeatCharacters- a boolean value wheretrueallows repeated characters in the password, andfalsedisallows them.
-
getAllowRepeatCharacters
-
setExpiryDays
public void setExpiryDays(int expiryDays) Sets the number of days until expiration.- Parameters:
expiryDays- the number of days to set for expiration
-
getExpiryDays
-
setReuseHistory
public void setReuseHistory(int reuseHistory) Sets the reuse history value.- Parameters:
reuseHistory- the number of times an object or action has been reused
-
getReuseHistory
-
setInitialPassword
Sets the initial password for this password policy.- Parameters:
initialPassword- the initial password to be set
-
getInitialPassword
-
validateData
Description copied from class:StoredObjectThe system will invoke this whenever the object is saved to the DB. It will be invoked in all cases while creating new objects and updating/deleting/undeleting existing objects. If any exception is raised by this method, the process of saving to the DB will be abandoned.
Note: This method is mainly used to validate the data of all attributes of the object, and it may be used by others for validating the object. For example, front-end data-entry systems can use this method for validating the object.
- Overrides:
validateDatain classStoredObject- Parameters:
tm- Current transaction manager.- Throws:
Exception- If data is invalid.
-
describe
Generates a descriptive string about the password requirements. The description includes: - The type of characters allowed or required (e.g., alphanumeric, numeric, etc.). - Whether mixed case is required (upper and lowercase letters). - Whether repeating characters are allowed. - The history of previously used passwords that cannot be reused. - The minimum length required for the password.- Returns:
- A string describing the password requirements based on the current configuration.
-
apply
Applies a password validation check based on predefined rules such as length limits, character composition, and prohibitions against specific sequences or repetitions.- Parameters:
password- the input array of characters representing the password to be validated.- Returns:
- a string describing the validation result. Returns null if the password satisfies all rules, or an error message indicating the validation failure reason otherwise.
-
get
Retrieves the password policy associated with the specified owner. If the owner is null, it returns a default password policy.- Parameters:
owner- the identifier of the owner whose password policy is to be retrieved- Returns:
- the password policy associated with the given owner, or a default password policy if the owner is null
-
get
Retrieves a PasswordPolicy associated with the specified owner object. If the owner is null, a default PasswordPolicy is returned.- Type Parameters:
T- the type of the owner, which must extend StoredObject- Parameters:
owner- the owner object for which the PasswordPolicy is to be retrieved; if null, a default PasswordPolicy is returned- Returns:
- the PasswordPolicy associated with the owner's class, or a default PasswordPolicy if the owner is null
-
getForClass
Retrieves thePasswordPolicyfor the specified class.- Type Parameters:
T- The type parameter extendingStoredObject.- Parameters:
owner- The class for which thePasswordPolicyis to be retrieved. If null, a defaultPasswordPolicyis returned.- Returns:
- The
PasswordPolicyassociated with the specified class. If no policy is found, a defaultPasswordPolicyis returned.
-
generatePassword
Generates a new password based on the current password policy.- Returns:
- a string representing the generated password.
-