Class UserRoleValidator
java.lang.Object
com.broadleafcommerce.auth.resource.service.validation.UserRoleValidator
- All Implemented Interfaces:
com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
public class UserRoleValidator
extends Object
implements com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
Validations for
UserRole.- Author:
- Samarth Dhruva (samarthd)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected UserPermissionService<UserPermission>protected UserRoleService<UserRole>protected StringprefixWithEntityValidationMessageKey(String errorCode) voidsetUserPermissionService(UserPermissionService<UserPermission> permissionService) voidsetUserRoleService(UserRoleService<UserRole> userRoleService) Lazy injection since this validator is itself a service component.booleansupports(Class<?> serviceClass, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) voidvalidate(Object businessInstance, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected voidvalidateAccountPermissions(UserRole userRole, org.springframework.validation.Errors errors, Set<UserPermission> rolePermissions) Validates that an account based role only has account permissions and that non-account roles do not have account permissions.voidvalidateForReplace(Object businessInstance, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected voidvalidateName(org.springframework.validation.Errors errors) protected voidvalidateParentRoleId(UserRole role, org.springframework.validation.Errors errors) Traverses the full ancestry of the role to confirm each ancestor still exists and there are no cycles, either in the case that the ancestors already had cycles, or in the case that this role itself causes a cycle.protected voidvalidateRolePermissions(UserRole userRole, org.springframework.validation.Errors errors) protected voidvalidateUserAssignablePermissions(UserRole userRole, org.springframework.validation.Errors errors, Set<UserPermission> permissions) Validates that permissions that are notuser assignableare not assigned to the role.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
validateForCreate, validateForUpdate
-
Constructor Details
-
UserRoleValidator
public UserRoleValidator()
-
-
Method Details
-
setUserRoleService
Lazy injection since this validator is itself a service component. This avoids circular dependency exceptions- Parameters:
userRoleService- the role service
-
setUserPermissionService
@Autowired @Lazy public void setUserPermissionService(UserPermissionService<UserPermission> permissionService) -
supports
public boolean supports(Class<?> serviceClass, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) - Specified by:
supportsin interfacecom.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
-
validate
public void validate(@NonNull Object businessInstance, @NonNull org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) - Specified by:
validatein interfacecom.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
-
validateForReplace
public void validateForReplace(Object businessInstance, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) - Specified by:
validateForReplacein interfacecom.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
-
validateName
protected void validateName(org.springframework.validation.Errors errors) -
validateRolePermissions
protected void validateRolePermissions(UserRole userRole, org.springframework.validation.Errors errors) -
validateUserAssignablePermissions
protected void validateUserAssignablePermissions(UserRole userRole, org.springframework.validation.Errors errors, Set<UserPermission> permissions) Validates that permissions that are notuser assignableare not assigned to the role. -
validateAccountPermissions
protected void validateAccountPermissions(UserRole userRole, org.springframework.validation.Errors errors, Set<UserPermission> rolePermissions) Validates that an account based role only has account permissions and that non-account roles do not have account permissions.- Parameters:
userRole-errors-
-
validateParentRoleId
Traverses the full ancestry of the role to confirm each ancestor still exists and there are no cycles, either in the case that the ancestors already had cycles, or in the case that this role itself causes a cycle. SeevalidateRoleAncestry(UserRole, Errors)for more information.- Parameters:
role- the role to validateerrors- the errors object bound to theroleon which errors can be registered
-
prefixWithEntityValidationMessageKey
-
getUserRoleService
-
getPermissionService
-