I don't think the latter* is illegal because it's not discrimination against a member of a protected class. That doesn't make it okay or that it couldn't lead to other trouble.
California law provides some protection from discrimination by employers based on political affiliation or activities. NY state and Washington DC have similar statutes.