Class VUtil
- java.lang.Object
-
- org.apache.directory.fortress.core.util.VUtil
-
- All Implemented Interfaces:
ConstraintValidator
public final class VUtil extends Object implements ConstraintValidator
This class contains simple data validation utilities. The data validations include null, length and simple reasonability checking. All utilities will throwValidationException
for failures.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
VUtil.ConstraintType
enum specifies what type of constraint is being targeted - User or Role.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
assertNotNull(Object obj, int errorCode, String method)
Method will throw exception with supplied error id and object.method name if object reference is null.static void
assertNotNullOrEmpty(char[] value, int errorCode, String method)
Method will throw exception with supplied error id and object.method name if string reference is null or empty.static void
assertNotNullOrEmpty(String value, int errorCode, String method)
Method will throw exception with supplied error id and object.method name if string reference is null or empty.void
beginDate(String beginDate)
Perform simple reasonability check on contraint beginDate value.void
beginTime(String beginTime)
Perform simple reasonability check on contraint beginTime value.void
dayMask(String dayMask)
Perform simple reasonability check on contraint dayMask value.static void
description(String value)
Simple length check and safe text validation on description field that usesGlobalIds.DESC_LEN
.void
endDate(String endDate)
Perform simple reasonability check on contraint endDate value.void
endTime(String endTime)
Perform simple reasonability check on contraint endTime value.static ConstraintValidator
getConstraintValidator()
This class is an implementation of ConstraintValidator.static VUtil
getInstance()
static void
orgUnit(String orgUnitId)
Simple length check on orgunit that usesGlobalIds.OU_LEN
.static void
password(char[] password)
Simple length check on User password that usesGlobalIds.PASSWORD_LEN
.static void
properties(Properties props)
Perform simple length and safe text validations on collection of name-value pairs.static void
safeText(String value, int validLen)
Perform a simple length and safe text validation.void
timeout(Integer timeout)
Perform simple reasonability check on contraint timeout value.static void
userId(String userId)
Simple null,GlobalErrIds.USER_ID_NULL
, and length checks,GlobalErrIds.CONST_INVLD_FIELD_LEN
, on userId.void
validateConstraints(Session session, VUtil.ConstraintType type, boolean checkDsd)
This utility iterates over all of the Validators initialized for runtime and calls them passing theConstraint
contained within the targeted entity.
-
-
-
Method Detail
-
getInstance
public static VUtil getInstance()
-
getConstraintValidator
public static ConstraintValidator getConstraintValidator()
This class is an implementation of ConstraintValidator.- Returns:
- reference to newly constructed self.
-
orgUnit
public static void orgUnit(String orgUnitId) throws ValidationException
Simple length check on orgunit that usesGlobalIds.OU_LEN
.- Parameters:
orgUnitId
- contains the ou name.- Throws:
ValidationException
- in the event of failure,GlobalErrIds.ORG_LEN_INVLD
.
-
password
public static void password(char[] password) throws ValidationException
Simple length check on User password that usesGlobalIds.PASSWORD_LEN
.- Parameters:
password
- contains the User's password.- Throws:
ValidationException
- in the event of failure,GlobalErrIds.USER_PW_INVLD_LEN
.
-
description
public static void description(String value) throws ValidationException
Simple length check and safe text validation on description field that usesGlobalIds.DESC_LEN
.- Parameters:
value
- contains the entity description.- Throws:
ValidationException
- in the event of failure,GlobalErrIds.CONST_DESC_LEN_INVLD
.
-
safeText
public static void safeText(String value, int validLen) throws ValidationException
Perform a simple length and safe text validation.- Parameters:
value
- contains the attribute to check.validLen
- contains the length to use.- Throws:
ValidationException
- in the event of lengthGlobalErrIds.CONST_INVLD_FIELD_LEN
or regex failure.
-
userId
public static void userId(String userId) throws ValidationException
Simple null,GlobalErrIds.USER_ID_NULL
, and length checks,GlobalErrIds.CONST_INVLD_FIELD_LEN
, on userId.- Parameters:
userId
- contains the userId, maps toUser.userId
.- Throws:
ValidationException
- in the event of failure,GlobalErrIds.CONST_INVLD_FIELD_LEN
.
-
properties
public static void properties(Properties props) throws ValidationException
Perform simple length and safe text validations on collection of name-value pairs.- Parameters:
props
- contains name-value pairs inname:value
format.- Throws:
ValidationException
- in the event of failure.
-
timeout
public void timeout(Integer timeout) throws ValidationException
Perform simple reasonability check on contraint timeout value.- Specified by:
timeout
in interfaceConstraintValidator
- Parameters:
timeout
- must be greater than 0 and less than max value forInteger.MAX_VALUE
- Throws:
ValidationException
- in the event value falls out of range.
-
beginTime
public void beginTime(String beginTime) throws ValidationException
Perform simple reasonability check on contraint beginTime value.- Specified by:
beginTime
in interfaceConstraintValidator
- Parameters:
beginTime
- if set, must be equal toTIME_LEN
.- Throws:
ValidationException
- in the event value falls out of range.
-
endTime
public void endTime(String endTime) throws ValidationException
Perform simple reasonability check on contraint endTime value.- Specified by:
endTime
in interfaceConstraintValidator
- Parameters:
endTime
- if set, must be equal toTIME_LEN
.- Throws:
ValidationException
- in the event value falls out of range.
-
beginDate
public void beginDate(String beginDate) throws ValidationException
Perform simple reasonability check on contraint beginDate value.- Specified by:
beginDate
in interfaceConstraintValidator
- Parameters:
beginDate
- if set, must be equal toDATE_LEN
.- Throws:
ValidationException
- in the event value falls out of range.
-
endDate
public void endDate(String endDate) throws ValidationException
Perform simple reasonability check on contraint endDate value.- Specified by:
endDate
in interfaceConstraintValidator
- Parameters:
endDate
- if set, must be equal toDATE_LEN
.- Throws:
ValidationException
- in the event value falls out of range.
-
dayMask
public void dayMask(String dayMask) throws ValidationException
Perform simple reasonability check on contraint dayMask value.- Specified by:
dayMask
in interfaceConstraintValidator
- Parameters:
dayMask
- if set, will be validated.- Throws:
ValidationException
- in the event value falls out of range.
-
assertNotNull
public static void assertNotNull(Object obj, int errorCode, String method) throws ValidationException
Method will throw exception with supplied error id and object.method name if object reference is null.- Parameters:
obj
- contains the reference to check.errorCode
- contains the error id to use if null.method
- contains the method name of caller.- Throws:
ValidationException
- in the event object is null.
-
assertNotNullOrEmpty
public static void assertNotNullOrEmpty(String value, int errorCode, String method) throws ValidationException
Method will throw exception with supplied error id and object.method name if string reference is null or empty.- Parameters:
value
- contains the reference to check.errorCode
- contains the error id to use if null.method
- contains the method name of caller.- Throws:
ValidationException
- in the event supplied string is null or empty.
-
assertNotNullOrEmpty
public static void assertNotNullOrEmpty(char[] value, int errorCode, String method) throws ValidationException
Method will throw exception with supplied error id and object.method name if string reference is null or empty.- Parameters:
value
- contains the reference to check.errorCode
- contains the error id to use if null.method
- contains the method name of caller.- Throws:
ValidationException
- in the event supplied string is null or empty.
-
validateConstraints
public void validateConstraints(Session session, VUtil.ConstraintType type, boolean checkDsd) throws SecurityException
This utility iterates over all of the Validators initialized for runtime and calls them passing theConstraint
contained within the targeted entity. If a particularUserRole
violates constraint it will not be activated. IfUser
validation fails a ValidationException will be thrown thus preventing User logon.- Parameters:
session
- containsUser
andUserRole
constraintsConstraint
to be checked.type
- specifies UserVUtil.ConstraintType.USER
or rOLEVUtil.ConstraintType.ROLE
.checkDsd
- will check DSD constraints if true- Throws:
SecurityException
- in the event validation fails for User or system error occurs.
-
-