Package com.skava.util
Class UserUtil
java.lang.Object
com.skava.util.UserUtil
This is a Utility class for User model which contains validator and helper methods used in this service.
- Author:
- Infosys Equinox
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic void
deleteMultipleCustomPropertiesFromDB
(UsersEntity user, UserCommonServices userCommonServices, List<String> names) Deletes multiple custom properties from the database for a given user.static void
doCreateAddressValidation
(Addresses addresses, org.springframework.context.MessageSource messageSource, org.slf4j.Logger logger, String locale) This method is used to validate the address given and set a default Id to it.static PropertiesEntity
findOnePropertyByNameAndUserId
(PropertiesRepository propertiesRepository, long userId, String propertyName) static Long
getAdminOrUserId
(com.skava.core.auth.AuthTokenHandler authTokenHandler) This method will return admin userid if it is 0 then return useridstatic String
getBearerToken
(long userId, String identityType, String authorizationData, long bearerExpiryTimeMins, UserCommonServices userCommonServices) This method is used to generate bearer tokenstatic long
This method will return the current milliseconds using Calendar object.static String
getDecryptedSecretCode
(UserCommonServices userCommonServices, String randomToken) This method is used to decrypt secret code.static String
getEncryptedSecretCode
(UserCommonServices userCommonServices, String randomToken) This method is used to encrypt secret code.static String
getLoginToken
(long userId, UserCommonServices userCommonServices) This method is used to generate login token.static long
This method is used to convert the given Long to long value, also returns default value if the given input Long is invalid.static long
This method is used to convert the given string to long value, also returns default value if the given input string is invalid.getPropertiesMap
(long collectionId, String locale, UserCommonServices userCommonServices) This method is used to fetch collection from collection repository and returns the collection properties as key-value map.static String
This method is used to validate the given input string value and returns the same if valid else returns the default value.static boolean
isMFAEnabledFor
(Collection collection, UserCommonServices userCommonServices, CollectionCommonServices collectionCommonServices, String name) isMFAEnabledFor method will fetch the list of process that allows MFA , i.e. login/signup/updatestatic boolean
isValidateStatus
(String status) This method is used to validate the given status, return TRUE if given status is ACTIVE or INACTIVE else FALSE.static String
isValidateStatus
(String status, String locale, org.springframework.context.MessageSource messageSource) This method is used to validate the User status, returns ACTIVE if current status is null or ACTIVE, returns INACTIVE if current status is INACTIVE, else throws validate exception.static boolean
isValidSortOrder
(String order) This method is used to validate the sorting order, returns TRUE if valid else FALSE.static boolean
isValidSortParam
(String sortParam) This method is used to validate user sort params.static String
loadEnableUserMergeValueFromDB
(Collection collection, UserCommonServices userCommonServices, CollectionCommonServices collectionCommonServices) This method is used to load collection property value from DBstatic int
loadFailMaxLimitFromCollectionProperties
(Collection collection, UserCommonServices userCommonServices, CollectionCommonServices collectionCommonServices) This method used to load collection property of resend limit for MFAstatic String
loadMFAValueFromDB
(Collection collection, UserCommonServices userCommonServices, CollectionCommonServices collectionCommonServices, String name) This method is used to load collection property value from DBstatic int
loadResendMaxLimitFromCollectionProperties
(Collection collection, UserCommonServices userCommonServices, CollectionCommonServices collectionCommonServices) This method used to load collection property of resend limit for MFAstatic void
removePropertiesNotAllowedToUpdate
(Map<String, String> propertiesToUpdate, List<String> restrictedPatchFields) This method is used to remove properties that are not allowed to be updatedstatic Date
resetMillisecond
(Date date) This method is used to reset millisecond to zero in date object.static String
saveActivationParam
(com.skava.core.crypto.TextEncryptorComponent textEncryptorComponent, UsersEntity userEntity) This method is used save activation parameter as a User Property.static String
saveActivationParam
(PropertiesRepository userpropertiesRepository, com.skava.core.crypto.TextEncryptorComponent textEncryptorComponent, UsersEntity userEntity) This method is used save activation param as a User Property.static Date
setTimeStamp
(Date timeStamp) static UserCreateResponse
setUserCreateResponseAndToken
(String token, Users user, int availableRetries, int maxFailLimit) This method is used to set login token and availableRetries in auth response and set user id in user model object.static UsersResponse
setUsersResponseAndToken
(String token, Users user, int availableRetries, int maxFailLimit) This method is used to set login token and availableRetries in auth response and set user id in user model object.setUserValue
(UsersEntity usersEntity, long collectionId, String resetParam) This method is used to set user value.static boolean
useParamForExactSearch
(String param) This method is used to check whether the given parameter should be used for exact search or not.
-
Field Details
-
IS_VALIDATE_STATUS
The IS_VALIDATE_STATUS- See Also:
-
SLASH
The Constant SLASH.- See Also:
-
EXPIRATION_MONTH_MAX
public static final int EXPIRATION_MONTH_MAXMaximum Expiration Month.- See Also:
-
-
Method Details
-
getLong
This method is used to convert the given string to long value, also returns default value if the given input string is invalid.- Parameters:
strVal
- Indicates the string value which is used to parse into valid long valuedefaultValue
- Indicates the default value if the string value is null, then default value will be returned- Returns:
- The long value
-
getLong
This method is used to convert the given Long to long value, also returns default value if the given input Long is invalid.- Parameters:
longVal
- Indicates the string value which is used to parse into valid long valuedefaultValue
- Indicates the default value if the string value is null, then default value will be returned- Returns:
- The long value
-
getString
This method is used to validate the given input string value and returns the same if valid else returns the default value.- Parameters:
strVal
- Indicates the string value which is used to get the valid string valuedefaultValue
- Indicates the default value if the string value is null, then default value will be returned.- Returns:
- The valid string value.
-
getLoginToken
This method is used to generate login token.- Parameters:
userId
- Indicates the user id.userCommonServices
- Instance ofUserCommonServices
object for encryption.- Returns:
- The valid bearer token.
-
getEncryptedSecretCode
public static String getEncryptedSecretCode(UserCommonServices userCommonServices, String randomToken) This method is used to encrypt secret code.- Parameters:
userCommonServices
-randomToken
-- Returns:
-
getDecryptedSecretCode
public static String getDecryptedSecretCode(UserCommonServices userCommonServices, String randomToken) This method is used to decrypt secret code.- Parameters:
userCommonServices
-randomToken
-- Returns:
-
loadMFAValueFromDB
public static String loadMFAValueFromDB(Collection collection, UserCommonServices userCommonServices, CollectionCommonServices collectionCommonServices, String name) This method is used to load collection property value from DB- Parameters:
collection
- HoldsCollection
object to get collection property value.userCommonServices
- HoldsUserCommonServices
object to get property value from DB.collectionCommonServices
- HoldsCollectionCommonServices
object to get property value.name
- Indicates the name of the property which is used for loading the value from DB.- Returns:
- The valid String value.
-
getBearerToken
public static String getBearerToken(long userId, String identityType, String authorizationData, long bearerExpiryTimeMins, UserCommonServices userCommonServices) This method is used to generate bearer token- Parameters:
userId
- Indicates the user id.identityType
- identityTypeauthorizationData
- authorizationDatabearerExpiryTimeMins
- Indicates the bearer token expiry time in minutes.userCommonServices
- Instance ofUserCommonServices
object for encryption.- Returns:
- The valid bearer token.
-
deleteMultipleCustomPropertiesFromDB
public static void deleteMultipleCustomPropertiesFromDB(UsersEntity user, UserCommonServices userCommonServices, List<String> names) Deletes multiple custom properties from the database for a given user.- Parameters:
user
- The user entity for which the properties need to be deleted.userCommonServices
- The user common services object.names
- The list of property names to be deleted.
-
loadEnableUserMergeValueFromDB
public static String loadEnableUserMergeValueFromDB(Collection collection, UserCommonServices userCommonServices, CollectionCommonServices collectionCommonServices) This method is used to load collection property value from DB- Parameters:
collection
- HoldsCollection
object to get collection property value.userCommonServices
- HoldsUserCommonServices
object to get property value from DB.collectionCommonServices
- HoldsCollectionCommonServices
object to get property value.- Returns:
- The valid String value.
-
loadResendMaxLimitFromCollectionProperties
public static int loadResendMaxLimitFromCollectionProperties(Collection collection, UserCommonServices userCommonServices, CollectionCommonServices collectionCommonServices) This method used to load collection property of resend limit for MFA- Parameters:
collection
- HoldsCollection
object used to load resent limit property for that particular collection id.userCommonServices
- HoldsUserCommonServices
object for getting collection attributes.collectionCommonServices
- HoldsCollectionCommonServices
object for getting collection attributes.- Returns:
- The valid resends limit integer value.
-
loadFailMaxLimitFromCollectionProperties
public static int loadFailMaxLimitFromCollectionProperties(Collection collection, UserCommonServices userCommonServices, CollectionCommonServices collectionCommonServices) This method used to load collection property of resend limit for MFA- Parameters:
collection
- HoldsCollection
object used to load resent limit property for that particular collection id.userCommonServices
- HoldsUserCommonServices
object for getting collection attributes.collectionCommonServices
- HoldsCollectionCommonServices
object for getting collection attributes.- Returns:
- The valid resends limit integer value.
-
setUsersResponseAndToken
public static UsersResponse setUsersResponseAndToken(String token, Users user, int availableRetries, int maxFailLimit) This method is used to set login token and availableRetries in auth response and set user id in user model object.- Parameters:
token
- Indicates the login token.availableRetries
- Indicates the available retry count of an user.maxFailLimit
- Indicates the maximum fail limit of the user.- Returns:
- The
UserAuthResponse
object which contains user object and login tokens.
-
setUserCreateResponseAndToken
public static UserCreateResponse setUserCreateResponseAndToken(String token, Users user, int availableRetries, int maxFailLimit) This method is used to set login token and availableRetries in auth response and set user id in user model object.- Parameters:
token
- Indicates the login token.availableRetries
- Indicates the available retry count of an user.maxFailLimit
- Indicates the maximum fail limit of the user.- Returns:
- The
UserAuthResponse
object which contains user object and login tokens.
-
doCreateAddressValidation
public static void doCreateAddressValidation(Addresses addresses, org.springframework.context.MessageSource messageSource, org.slf4j.Logger logger, String locale) This method is used to validate the address given and set a default Id to it. In case of invalid address error message will be thrown.- Parameters:
addresses
- HoldsAddresses
object used for address validation while creating an address.messageSource
- HoldsMessageSource
object which is used to validate the address.logger
- Indicates the logger object.locale
- API Response and error messages will be responded in the locale mentioned in this parameter.
-
getAdminOrUserId
This method will return admin userid if it is 0 then return userid- Parameters:
authTokenHandler
- authTokenHandler- Returns:
- long adminid or userid
-
resetMillisecond
This method is used to reset millisecond to zero in date object.- Parameters:
date
- Indicates the date which is used for reseting the date into milliseconds- Returns:
- The date
-
isValidSortParam
This method is used to validate user sort params.- Parameters:
sortParam
- Indicates the search and sort params which is used for validating the sort and search params.- Returns:
- boolean value.
-
isValidSortOrder
This method is used to validate the sorting order, returns TRUE if valid else FALSE.- Parameters:
order
- Indicates the order of an user's sorting. eg : ASC or DESC- Returns:
- boolean value
-
saveActivationParam
public static String saveActivationParam(PropertiesRepository userpropertiesRepository, com.skava.core.crypto.TextEncryptorComponent textEncryptorComponent, UsersEntity userEntity) This method is used save activation param as a User Property.- Parameters:
userpropertiesRepository
- HoldsPropertiesRepository
object used to save activation param.textEncryptorComponent
- Instancs ofTextEncryptorComponent
object used to encrypt the activation param.userEntity
- Holds the List ofIdentitiesEntity
object used for saving the activation param.- Returns:
String
a valid activation param.
-
saveActivationParam
public static String saveActivationParam(com.skava.core.crypto.TextEncryptorComponent textEncryptorComponent, UsersEntity userEntity) This method is used save activation parameter as a User Property.- Parameters:
textEncryptorComponent
- HoldsTextEncryptorComponent
object which is used to encrypt the activation parameter.userEntity
- Holds the list ofIdentitiesEntity
object which is used to activation parameter.- Returns:
String
object.
-
isValidateStatus
public static String isValidateStatus(String status, String locale, org.springframework.context.MessageSource messageSource) This method is used to validate the User status, returns ACTIVE if current status is null or ACTIVE, returns INACTIVE if current status is INACTIVE, else throws validate exception.- Parameters:
status
- Indicates the user status which is used to validate the user's status.locale
- API Response and error messages will be responded in the locale mentioned in this parameter.messageSource
- HoldsMessageSource
object which is used for throwing response message.- Returns:
String
object.
-
isValidateStatus
This method is used to validate the given status, return TRUE if given status is ACTIVE or INACTIVE else FALSE.- Parameters:
status
- Indicates the user status which is used to validate the user's status.- Returns:
- boolean value
-
useParamForExactSearch
This method is used to check whether the given parameter should be used for exact search or not.- Parameters:
param
- Indicates the valid search param which is used for exact search- Returns:
- boolean value
-
getCurrentMilliseconds
public static long getCurrentMilliseconds()This method will return the current milliseconds using Calendar object.- Returns:
- long time in milliseconds
-
setUserValue
public static List<Users> setUserValue(UsersEntity usersEntity, long collectionId, String resetParam) This method is used to set user value.- Parameters:
usersEntity
- HoldsUsersEntity
object to set user value from entity.collectionId
- Indicates the collection id to set collection id value to users.resetParam
- Indicates the user's reset parameter which is used for reseting user's password- Returns:
- The list of user's object.
-
findOnePropertyByNameAndUserId
public static PropertiesEntity findOnePropertyByNameAndUserId(PropertiesRepository propertiesRepository, long userId, String propertyName) - Parameters:
propertiesRepository
- HoldsPropertiesRepository
object used to find property.userId
- Indicates the user id.propertyName
- Indicates the name of the user property.- Returns:
- propertiesEntity returns
PropertiesEntity
or null
-
getPropertiesMap
public static Map<String,String> getPropertiesMap(long collectionId, String locale, UserCommonServices userCommonServices) This method is used to fetch collection from collection repository and returns the collection properties as key-value map.- Parameters:
collectionId
- Indicates the user collection id.locale
- Indicates the locale value.userCommonServices
- Indicates the common service component.- Returns:
Map
object.
-
removePropertiesNotAllowedToUpdate
public static void removePropertiesNotAllowedToUpdate(Map<String, String> propertiesToUpdate, List<String> restrictedPatchFields) This method is used to remove properties that are not allowed to be updated- Parameters:
propertiesToUpdate
-restrictedPatchFields
-
-
isMFAEnabledFor
public static boolean isMFAEnabledFor(Collection collection, UserCommonServices userCommonServices, CollectionCommonServices collectionCommonServices, String name) isMFAEnabledFor method will fetch the list of process that allows MFA , i.e. login/signup/update- Parameters:
collection
-userCommonServices
-collectionCommonServices
-name
-- Returns:
-
setTimeStamp
-