Such play can often be discouraged in early years settings, but is a continuing source of discussiong amoung practitioners relating to whether this is a developmentally appropriate activity and is largely due to some prevenlent pieces of writing on this subject e.g. "We don't play with duns here: war and weapon play in the early years" and "Boys and Girls: Superheros in the doll corner" There are also a three case studies on the subject published by The National Strategies, which make interesting discussion points. Additionally I like this succinct article from the national childcare accreditation council (Australia).
I would however suggest that rules are created to support safe play when allowing children to engage in activity that may result in potential physical contact. The rules in this picture were created in collaboration with children, when doing this be mindful of making an effort to create rules that tell children what they are supposed to do rather that not do. This is sometimes difficult for children to create, so at least attempt a balance or some compromise. Two more rules have been added "When an adult is not around jedi practice only (no lightsaber contact) and "Only play with people who have agreed or want to keep playing"
Lastly on a safety note after you have cut the foam it will be sharp, I suggest you tape the end that has been cut as it will scratch. Alternatively squish or stamp on the end.