Good question. I'm not exactly qualified to talk about Germany, but I can explain at least some of the difficulties faced by the Soviets in imposing Communism on Poland.
First thing to remember is that the Second Polish Republic was a direct ally of Britain and France. The war in Europe started over the issue of Polish independence. Thus, the Soviets were in a delicate position, where their designs on Polish territory which they realized between 17 September and 6 October 1939 threatened to put them, like the Germans, into conflict with the Western Allies. In the event, the Soviets were extremely fortunate in that Rzydz-Śmigły's government did not formally declare war on the Soviet Union, that the British were unwilling to jeopardize their trade interests with the Soviets, and that both Britain and France explained to the Poles that their defensive alliances were, in practice if not in exact wording, directed exclusively against the Germans. Thus, the Soviets were able to take the Kresy regions of Poland (modern day Western Ukraine and Belarus) without triggering a war with the Western Allies.
The Second Reoublic ceased to exist except as an exile government and underground state after the joint German-Soviet invasions. But Great Britain continued in the conflict with Germany, even after the fall of France. In this conflict, the Polish Government in Exile continued to be a nominal and practical ally of the British, contributing tens of thousands of soldiers, sailors, and airmen to the Allied cause, and developing a large and effective underground state, which provided valuable intelligence and increasingly harried the German occupation forces in Poland. During the 1939-1941 period, the Soviets refused to recognize the Polish Government in Exile, and contented themselves with imposing Soviet rule on the Kresy region. The Polish underground state sought to oppose the Soviet occupation the same as the German occupation, with the goal of re-establishing an independent Polish state within their pre-1939 borders.
The Soviet Union resumed diplomatic relations with the Polish Government in Exile in 1941 after the German invasion of the USSR. The Sikorski-Mayski agreement re-establishing relations with the USSR specifically nullified the territorial agreements between the Soviets and Germans, thus opening the possibility that after the war the Kresy region, or parts thereof, might return to Polish rule. This open question of borders thus became the driving point of contention between the two states. The Poles continually sought for Churchill and later Roosevelt to press Stalin for a recognition of Poland's pre-war borders, but were unable to extract more than vague promises, sympathies, and assurances that any territorial change in the east would be compensated with German territory in the west. During the 1941-1943 period, the Poles were allowed to form the "Anders Army," from Polish exiles in the USSR, although these units would be forced by a lack of Soviet material support to make the trek through Iran to the Middle East, and eventually to Italy where they would serve with distinction alongside the British and Americans.
Relations between the USSR and the Polish Government in Exile were broken in 1943 after the Soviets refused to allow an independent Polish investigation of the Katyn Massacre (perpetrated by the Soviets on captured Polish officers in 1940.) This break in relations, combined with the advance of the Red Army towards Poland, provided Stalin with the opportunity and motive to press the British for a private agreement that the USSR would keep the Kresy region and that Poland's borders would shift to the west (the so-called Curzon line). They received this private agreement with Churchill at the 1943 Tehran conference, but this decision was not communicated to the Polish Government in Exile, which continued to press for their pre-war borders.
The Polish failure to gain Western support for their per-war borders was one of the contributing factors in the planning of Operation Tempest - a general uprising against the Germans immediately ahead of the Soviet advance, which would enable the Poles to welcome the Soviets as equals and establish some measure of Polish control over vital cities like Wilno and Lwow which were claimed by the Soviet Union. Operation Tempest, launched in the summer of 1944 as the Soviets began to enter Polish territory, was ultimately a failure, resulting in the capture and disarming of many Polish Home Army formations by the NKVD, and in the 63-day tragedy of the Warsaw Uprising. At the same time, the Soviets formally broke with the Polish Government in Exile by installing the Lublin Comittee (officially the Polish Comittee of National Liberation) and promoting them as an alternative government to the London Government in Exile.
At the Yalta conference in 1945, Poland's fate was really decided. Molotov revealed the private agreement with Churchill over the Curzon line borders, devastating the Poles, and essentially consigning Eastern Poland to the USSR. At the same time, the Western Allies were pressured into recognizing the Lublin Comittee as the basis for the postwar government of Poland. However, the West was able to secure agreements that the new government hold elections and establish a coalition Government which included the prewar major political parties. The Prime Minister of the Government in Exile, Stanisław Mikołajczyk, as well as a few other members of the London-based government agreed to participate in this coalition, albeit without much hope of exerting real democratic influence over the postwar state. Mikołajczyk would serve as deputy Prime Minister and Minister of Agriculture until his party's loss in the rigged 1947 elections. The Polish Communists, at Stalin's behest, also attempted to lend legitimacy to the political and territorial changes by holding the Polish People's Referendum of 1946, which confirmed the Oder-Niesse line as Poland's Western border, the nationalization of industry, and the abolition of the Senat. During the immediate postwar period, hundreds of thousands of Poles were involved in a massive population exchange, being expelled from the formerly-Polish regions of the east to the "reclaimed" territories of the west.
Thus we see that Stalin was caught in a difficult game, needing the support of the Western Allies who were, at least nominally tied to the issues if Polish independence and the sanctity of Polish borders. We can see that his principal concerns were for a border adjustment, which he achieved by a fait-acompli, first with the cooperation of the Germans, and later reaffirmed by skilful use of diplomacy, deception, and realpolitik. Once he had achieved his aim of territorial adjustment, it was much easier diplomatically to offer at least minor concessions in the way of promising "democratic" governments, rather than risk all the goodwill of the British and Americans by pursuing further territorial agrandizement. Stalin followed this line in many of the other countries which would ultimately become Communist-dominated puppets, first granting democratic concessions and then rigging elections and using the Red Army's influence to install governments friendly to the USSR - see Romania and Czechoslovakia in particular, since both also had outstanding territorial disagreements with the USSR. Stalin was in a strong position, but could not deny the legitimate interests of the British and Americans, and so chose to appease them with semi-democratic coalitions governments, knowing that he would later be able to turn those into loyal Communist regimes.