code: public void checkRole(CmsDbContext dbc, CmsRole role) throws CmsRoleViolationException {
  
          if (!hasRole(dbc, dbc.currentUser(), role)) {
              if (role.getOuFqn() != null) {
                  throw role.createRoleViolationExceptionForOrgUnit(dbc.getRequestContext(), role.getOuFqn());
              } else {
                  throw role.createRoleViolationException(dbc.getRequestContext());
              }
          }
      }
docs: Checks if the user of the current database context has permissions to impersonate the given role
  in the given organizational unit.<p>
  
  If the organizational unit is <code>null</code>, this method will check if the
  given user has the given role for at least one organizational unit.<p>
  
  @param dbc the current OpenCms users database context
  @param role the role to check
  
  @throws CmsRoleViolationException if the user does not have the required role permissions
  
  @see org.opencms.security.CmsRoleManager#checkRole(CmsObject, CmsRole)