Freud had one theory, the rabbis a somewhat different one. But it is interesting to note that sometimes they are not so far apart. The rabbis answer that at the moment of the attempted seduction, at the exact instant that Potiphar's wife bared her body, Joseph saw before him the face of his father Jacob, and was unable to violate the moral law his father had taught him. In fact, the great moralist Luzzatto comments on this specifically, warning that princes, kings and men in power are in more danger than most, because the flattery of their companions leads them to delusions of grandeur. We often stress Judaism's positive outlook on human nature.
Human beings start out as a clean slate.
There is no sense of original sin passed down from Adam and Eve. In fact, the rabbis tend to read the Garden of Eden story as a set up. They conclude that God knew that Adam would eat of the fruit, leave the garden, and begin history as we know it. The rabbis posited a yezer ha tov- a desire to do good, and a yezer hara, often translated, the desire to do evil. In truth they probably thought of it as a force a little bit like Freud's libido, as they wrote that without a little yezer hara, a man would never plant a garden, build a house or court a woman.