I am not an expert in Confucius, but as a Chinese, I am pretty sure this quote isn't from Confucius.
Why? Because such a sentence contradicts the social tradition of ancient China. When Confucius lived, which is about 2500 years ago, sex are social taboos, especially in Confucius's theory(actually distance and so-called 'caution' between genders are emphasized in this theory). From this aspect, Confucius would not likely mention anything relating to such taboos, not to mention 'rape'. To be frank, the concept 'rape' may didn't even exist back to that time.
However, it is true that Confucius has some theory about how people should react when in bad situations. He believed we should be calm and peaceful even facing difficulties, and never gave up faith.
For example, here is a quote from Lunyu Chapter 12, phrasing his student Yan Hui:
What a man was Hui! A dish of rice, a gourd of water, in a low alleyway; no man can bear such misery! Yet Hui never fell from mirth. What a man he was!
Actually this is a concept rooted in Chinese culture, which is “随遇而安” in Chinese.
But, please notice this concept is totally different from the quote in your question, rape is not a 'difficult situation', it's crime.